├── .gitattributes ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ ├── codeql-analysis.yml │ ├── gradle-build.yml │ └── gradle-test.yml ├── .gitignore ├── .idea ├── .gitignore ├── compiler.xml ├── discord.xml ├── jarRepositories.xml ├── misc.xml └── vcs.xml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── SECURITY.md ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src ├── main └── java │ └── xyz │ └── theprogramsrc │ └── supercoreapi │ ├── Base.java │ ├── SuperModule.java │ ├── SuperPlugin.java │ ├── SuperUtils.java │ ├── bungee │ ├── BungeeModule.java │ ├── BungeePlugin.java │ ├── commands │ │ ├── BungeeCommand.java │ │ └── CommandResult.java │ ├── events │ │ └── BungeeEventManager.java │ ├── storage │ │ └── Settings.java │ └── utils │ │ ├── BungeeConsole.java │ │ ├── BungeeUtils.java │ │ └── tasks │ │ └── BungeeTasks.java │ ├── global │ ├── LogsFilter.java │ ├── Metrics.java │ ├── apis │ │ ├── groupez │ │ │ └── GroupeZAPI.java │ │ ├── songoda │ │ │ └── SongodaAPI.java │ │ └── spigot │ │ │ └── SpigotAPI.java │ ├── data │ │ └── PluginDataStorage.java │ ├── dependencies │ │ ├── Dependencies.java │ │ ├── Dependency.java │ │ ├── DependencyManager.java │ │ ├── Repositories.java │ │ └── classloader │ │ │ ├── IsolatedClassLoader.java │ │ │ ├── LoaderType.java │ │ │ ├── PluginClassLoader.java │ │ │ └── ReflectionClassLoader.java │ ├── files │ │ ├── FlatFile.java │ │ ├── JsonConfig.java │ │ └── yml │ │ │ ├── ConfigField.java │ │ │ └── YMLConfig.java │ ├── networking │ │ ├── ConnectionBuilder.java │ │ └── CustomConnection.java │ ├── objects │ │ ├── Pair.java │ │ └── RecurringTask.java │ ├── placeholders │ │ ├── BungeePlaceholderManager.java │ │ ├── Placeholder.java │ │ ├── PlaceholderManager.java │ │ └── SpigotPlaceholderManager.java │ ├── storage │ │ ├── DataBase.java │ │ ├── DataBaseSettings.java │ │ ├── DataBaseStorage.java │ │ ├── MySQLDataBase.java │ │ ├── SQLiteDataBase.java │ │ ├── global │ │ │ └── GlobalStorage.java │ │ ├── memory │ │ │ └── MemoryStorage.java │ │ └── universal │ │ │ └── UniversalStorage.java │ ├── translations │ │ ├── Base.java │ │ ├── Translation.java │ │ ├── TranslationDownloader.java │ │ ├── TranslationManager.java │ │ └── TranslationPack.java │ ├── updater │ │ ├── IUpdateChecker.java │ │ ├── SongodaUpdateChecker.java │ │ ├── SpigotUpdateChecker.java │ │ └── TheProgramSrcUpdateChecker.java │ └── utils │ │ ├── ServerUtils.java │ │ ├── StringUtils.java │ │ ├── Utils.java │ │ ├── VersioningUtil.java │ │ ├── files │ │ └── FileUtils.java │ │ ├── json │ │ └── JSONUtil.java │ │ └── serverutils │ │ ├── BungeeServerUtils.java │ │ └── SpigotServerUtils.java │ └── spigot │ ├── SpigotModule.java │ ├── SpigotPlugin.java │ ├── commands │ ├── CommandResult.java │ ├── SpigotCommand.java │ └── precreated │ │ └── SuperCoreAPICommand.java │ ├── dialog │ └── Dialog.java │ ├── events │ └── EventManager.java │ ├── gui │ ├── BrowserGui.java │ ├── Gui.java │ ├── events │ │ ├── GuiCloseEvent.java │ │ ├── GuiEmptyClickEvent.java │ │ ├── GuiEvent.java │ │ ├── GuiOpenEvent.java │ │ ├── GuiOutsideClickEvent.java │ │ └── GuiUpdateEvent.java │ ├── objets │ │ ├── GuiAction.java │ │ ├── GuiEntry.java │ │ ├── GuiModel.java │ │ ├── GuiRows.java │ │ └── GuiTitle.java │ └── precreated │ │ ├── ConfirmationGui.java │ │ ├── MaterialBrowser.java │ │ └── settings │ │ ├── CustomSettingPane.java │ │ ├── SettingPane.java │ │ ├── SettingsGui.java │ │ └── precreated │ │ ├── GeneralConfigurationSettingPane.java │ │ └── LanguageSelectionSettingPane.java │ ├── guis │ ├── BrowserGUI.java │ ├── GUI.java │ ├── GUIButton.java │ ├── action │ │ ├── Action.java │ │ ├── ClickAction.java │ │ └── ClickType.java │ ├── events │ │ ├── GUIClickEvent.java │ │ ├── GUICloseEvent.java │ │ ├── GUIEmptyClickEvent.java │ │ ├── GUIEvent.java │ │ ├── GUIOpenEvent.java │ │ ├── GUIOutsideClickEvent.java │ │ └── GUIUpdateEvent.java │ ├── objects │ │ └── GUIRows.java │ └── precreated │ │ ├── ConfirmationGUI.java │ │ ├── MaterialBrowser.java │ │ └── settings │ │ ├── CustomSettingPane.java │ │ ├── SettingPane.java │ │ ├── SettingsGUI.java │ │ └── precreated │ │ ├── GeneralConfigurationSettingPane.java │ │ └── LanguageSelectionSettingPane.java │ ├── hologram │ └── Hologram.java │ ├── items │ ├── PreloadedItems.java │ ├── SimpleItem.java │ └── Skulls.java │ ├── packets │ ├── DemoMessage.java │ └── sky │ │ ├── SkyChanger.java │ │ └── SkyColor.java │ ├── recipes │ ├── CustomRecipe.java │ ├── RecipeCreator.java │ └── RecipeItem.java │ ├── storage │ └── SettingsStorage.java │ ├── update │ └── SpigotUpdater.java │ └── utils │ ├── BlockUtils.java │ ├── ItemUtils.java │ ├── MinecraftServer.java │ ├── ReflectionUtils.java │ ├── ServerVersion.java │ ├── SpigotConsole.java │ ├── SpigotUtils.java │ ├── skintexture │ ├── PlayerGameProfile.java │ ├── SkinTexture.java │ └── SkinTextureManager.java │ └── tasks │ └── SpigotTasks.java └── test └── java └── xyz └── theprogramsrc └── supercoreapi └── global ├── networking └── CustomConnectionTest.java ├── objects └── PairTest.java ├── updater └── SongodaUpdateCheckerTest.java └── utils ├── StringUtilsTest.java ├── UtilsTest.java └── json └── JSONUtilTest.java /.gitattributes: -------------------------------------------------------------------------------- 1 | # 2 | # https://help.github.com/articles/dealing-with-line-endings/ 3 | # 4 | # These are explicitly windows files and should use crlf 5 | *.bat text eol=crlf 6 | 7 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: TheProgramSrc # 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: ['https://go.theprogramsrc.xyz/donate']# Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "[BUG]" 5 | labels: bug 6 | assignees: TheProgramSrc 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **System Details (please complete the following information):** 27 | - OS: [e.g. Paper, Spigot, Bukkit, Bungee] 28 | - OS Version: [e.g 1.12, 1.15.2] 29 | - Version [e.g. v3.1.0, v3.1.1., v.3.2.0] 30 | 31 | **Additional context** 32 | Add any other context about the problem here. 33 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: "[FEATURE REQUEST]" 5 | labels: enhancement 6 | assignees: TheProgramSrc 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ master ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ master ] 20 | schedule: 21 | - cron: '22 12 * * 1' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'java' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] 37 | # Learn more: 38 | # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed 39 | 40 | steps: 41 | - name: Checkout repository 42 | uses: actions/checkout@v2 43 | 44 | # Initializes the CodeQL tools for scanning. 45 | - name: Initialize CodeQL 46 | uses: github/codeql-action/init@v1 47 | with: 48 | languages: ${{ matrix.language }} 49 | # If you wish to specify custom queries, you can do so here or in a config file. 50 | # By default, queries listed here will override any specified in a config file. 51 | # Prefix the list here with "+" to use these queries and those in the config file. 52 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 53 | 54 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 55 | # If this step fails, then you should remove it and run the build manually (see below) 56 | - name: Autobuild 57 | uses: github/codeql-action/autobuild@v1 58 | 59 | # ℹ️ Command-line programs to run using the OS shell. 60 | # 📚 https://git.io/JvXDl 61 | 62 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 63 | # and modify them (or add more) to build your code if your project 64 | # uses a compiled language 65 | 66 | #- run: | 67 | # make bootstrap 68 | # make release 69 | 70 | - name: Perform CodeQL Analysis 71 | uses: github/codeql-action/analyze@v1 -------------------------------------------------------------------------------- /.github/workflows/gradle-build.yml: -------------------------------------------------------------------------------- 1 | name: "Build and Deploy" 2 | on: 3 | release: 4 | types: [published,edited] 5 | jobs: 6 | build: 7 | # Set up the OS 8 | runs-on: ubuntu-latest 9 | env: 10 | # Nexus credentials and GitHub token 11 | NEXUS_USERNAME: '${{ secrets.NEXUS_USERNAME }}' 12 | NEXUS_PASSWORD: '${{ secrets.NEXUS_PASSWORD }}' 13 | GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' 14 | # Set environment 15 | env: 'prod' 16 | steps: 17 | # Checkout the Code 18 | - name: Checkout Code 19 | uses: actions/checkout@v2 20 | # Set up git hashes environment variables 21 | - name: Git Hashes 22 | uses: Im-Fran/git-hashes-action@v1.0.0 23 | # Set up version from tag environment variables 24 | - name: Version from Tag Action 25 | uses: Im-Fran/version-from-tag-action@v1.0.1 26 | with: 27 | remove-first-character: 'v' 28 | # Set up the JDK 29 | - name: Set up JDK 8 30 | uses: actions/setup-java@v2 31 | with: 32 | distribution: adopt 33 | java-version: 8 34 | # Validate Gradle Wrapper 35 | - name: Validate Gradle Wrapper 36 | uses: gradle/wrapper-validation-action@v1 37 | # Make gradle executable 38 | - name: Make gradle executable 39 | run: chmod +x gradlew 40 | # Clean, Test, Publish and Build (in that order to save the artifact to the action) 41 | - name: Test, Deploy and Build with Gradle 42 | run: ./gradlew clean test publish shadow 43 | # Now we store the artifact in the action 44 | - name: Upload the artifact 45 | uses: actions/upload-artifact@v2 46 | with: 47 | name: SuperCoreAPI 48 | path: ./build/libs/SuperCoreAPI.jar 49 | # Now we deploy the documents to GitHub pages 50 | - name: Deploy Javadoc 51 | uses: JamesIves/github-pages-deploy-action@4.1.7 52 | with: 53 | branch: gh-pages 54 | folder: build/docs/javadoc 55 | clean: true 56 | -------------------------------------------------------------------------------- /.github/workflows/gradle-test.yml: -------------------------------------------------------------------------------- 1 | name: Gradle Test 2 | # Only execute this workflow when a PR is opened or when something is pushed to a the master branch 3 | on: 4 | push 5 | jobs: 6 | testBuilds: 7 | strategy: 8 | fail-fast: false 9 | max-parallel: 4 10 | matrix: 11 | java-version: [8,11,16] 12 | # Setup OS 13 | runs-on: ubuntu-latest 14 | steps: 15 | # Checkout code 16 | - name: Checkout Code 17 | uses: actions/checkout@v2 18 | # Setup java and maven 19 | - name: Set up JDK ${{ matrix.java-version }} 20 | uses: actions/setup-java@v2 21 | with: 22 | distribution: adopt 23 | java-version: ${{ matrix.java-version }} 24 | # Validate Gradle Wrapper 25 | - name: Validate Gradle Wrapper 26 | uses: gradle/wrapper-validation-action@v1 27 | # Setup executable gradle 28 | - name: Make Gradle executable 29 | run: chmod +x gradlew 30 | # Run gradle test 31 | - name: Run Gradle Test with Java ${{ matrix.java-version }} 32 | run: ./gradlew test 33 | # Test bulding without javadocs 34 | - name: Build Jar with Java ${{ matrix.java-version }} 35 | run: ./gradlew build --no-daemon --no-build-cache --no-scan -x javadoc -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | pom.xml.tag 3 | pom.xml.releaseBackup 4 | pom.xml.versionsBackup 5 | pom.xml.next 6 | release.properties 7 | dependency-reduced-pom.xml 8 | buildNumber.properties 9 | .mvn/timing.properties 10 | .mvn/wrapper/maven-wrapper.jar 11 | .idea/**/workspace.xml 12 | .idea/**/tasks.xml 13 | .idea/**/usage.statistics.xml 14 | .idea/**/dictionaries 15 | .idea/**/shelf 16 | .idea/**/contentModel.xml 17 | .idea/**/dataSources/ 18 | .idea/**/dataSources.ids 19 | .idea/**/dataSources.local.xml 20 | .idea/**/sqlDataSources.xml 21 | .idea/**/dynamic.xml 22 | .idea/**/uiDesigner.xml 23 | .idea/**/dbnavigator.xml 24 | .idea/**/gradle.xml 25 | .idea/**/libraries 26 | cmake-build-*/ 27 | .idea/**/mongoSettings.xml 28 | *.iws 29 | out/ 30 | .idea_modules/ 31 | atlassian-ide-plugin.xml 32 | .idea/replstate.xml 33 | com_crashlytics_export_strings.xml 34 | crashlytics.properties 35 | crashlytics-build.properties 36 | fabric.properties 37 | .idea/httpRequests 38 | .idea/caches/build_file_checksums.ser 39 | *.class 40 | *.log 41 | *.ctxt 42 | .mtj.tmp/ 43 | *.jar 44 | *.war 45 | *.nar 46 | *.ear 47 | *.zip 48 | *.tar.gz 49 | *.rar 50 | hs_err_pid* 51 | *.iml 52 | .DS_Store 53 | .AppleDouble 54 | .LSOverride 55 | Icon 56 | ._* 57 | .DocumentRevisions-V100 58 | .fseventsd 59 | .Spotlight-V100 60 | .TemporaryItems 61 | .Trashes 62 | .VolumeIcon.icns 63 | .com.apple.timemachine.donotpresent 64 | .AppleDB 65 | .AppleDesktop 66 | Network Trash Folder 67 | Temporary Items 68 | .apdisk 69 | .classpath 70 | .project 71 | .settings/ 72 | .env 73 | .secrets.env 74 | .gradle/ 75 | build/ 76 | bin/ 77 | *.pom.xml -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | # Editor-based HTTP Client requests 8 | /httpRequests/ 9 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/discord.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | 34 | 35 | 39 | 40 | 44 | 45 | 49 | 50 | 54 | 55 | 59 | 60 | 64 | 65 | 69 | 70 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SuperCoreAPI 2 | _The best way to create a plugin_
3 | [![Latest Release](https://img.shields.io/nexus/r/xyz.theprogramsrc/supercoreapi?color=%2300ff00&label=Latest%20Release&nexusVersion=3&server=https%3A%2F%2Frepo.theprogramsrc.xyz)](https://repo.theprogramsrc.xyz/#browse/browse:maven-releases) 4 | [![Latest Snapshot](https://img.shields.io/badge/dynamic/xml?url=https://repo.theprogramsrc.xyz/repository/maven-snapshots/xyz/theprogramsrc/supercoreapi/maven-metadata.xml&label=Latest%20Snapshot&color=orange&query=.//versioning/latest&prefix=v)](https://repo.theprogramsrc.xyz/#browse/browse:maven-snapshots) 5 |
6 | [![Discord](https://i.imgur.com/J1XhmMd.png)](https://go.theprogramsrc.xyz/discord) 7 | [![Terms of Service](https://i.imgur.com/4tFAGtE.png)](https://go.theprogramsrc.xyz/tos) 8 | [![Wiki](https://i.imgur.com/x0ZMnSx.png)](https://github.com/TheProgramSrc/SuperCoreAPI/wiki) 9 | [![Become a Patron](https://i.imgur.com/h9Y1X2X.png)](https://go.theprogramsrc.xyz/patreon) 10 | 11 | 12 | ## Available extensions: 13 | This is the list of included extensions in the SuperCoreAPI Package. 14 | ### [Global](https://github.com/TheProgramSrc/SuperCoreAPI/tree/master/src/main/java/xyz/theprogramsrc/supercoreapi/global) 15 | * Songoda / Spigot Update Checker 16 | * Plugin Injection 17 | * Dependency Manager 18 | * Translations 19 | * Metrics 20 | * File Utils 21 | * String Utils 22 | * Server Utils 23 | 24 | ### [BungeeCord](https://github.com/TheProgramSrc/SuperCoreAPI/tree/master/src/main/java/xyz/theprogramsrc/supercoreapi/bungee) 25 | * Custom Command Creator 26 | * Messaging Services (Not tested yet) 27 | * Custom File Storage 28 | * BungeeCord Utils 29 | * BungeeCord Console Utils 30 | 31 | ### [Spigot](https://github.com/TheProgramSrc/SuperCoreAPI/tree/master/src/main/java/xyz/theprogramsrc/supercoreapi/spigot) 32 | * Custom Command Creator 33 | * Dialog Creator 34 | * Custom Events 35 | * Interactive GUI Creator 36 | * Hologram creator 37 | * Item Builder 38 | * Packet Utils 39 | * Reflection Utils 40 | * Plugin Updater 41 | * Custom Head Texture Util 42 | * Storage Utils 43 | * Cross-Version materials 44 | * Task Utils 45 | 46 | ## Included Libraries 47 | * [XSeries](https://github.com/CryptoMorin/XSeries) ([License](https://github.com/CryptoMorin/XSeries/blob/master/LICENSE.txt)) 48 | * [slf4j-api, slf4j-nop](https://github.com/qos-ch/slf4j) ([License](http://www.slf4j.org/license.html)) 49 | * [commons-codec](https://github.com/apache/commons-codec) ([License](https://www.apache.org/licenses/LICENSE-2.0)) 50 | * [commons-io](https://github.com/apache/commons-io) ([License](https://www.apache.org/licenses/LICENSE-2.0)) 51 | * [gson](https://github.com/google/gson) ([License](https://github.com/google/gson/blob/master/LICENSE)) 52 | * [SimpleYaml](https://github.com/Carleslc/Simple-YAML) ([License](https://github.com/Carleslc/Simple-YAML/blob/master/LICENSE)) 53 | * [HikariCP](https://github.com/brettwooldridge/HikariCP/) ([License](https://github.com/brettwooldridge/HikariCP/blob/dev/LICENSE)) 54 | * [sqlite-jdbc](https://github.com/xerial/sqlite-jdbc/) ([License](https://github.com/xerial/sqlite-jdbc/blob/master/LICENSE)) 55 | * [log4j2](https://github.com/apache/logging-log4j2) ([License](https://github.com/apache/logging-log4j2/blob/master/LICENSE.txt)) 56 | * [Zip4J](https://github.com/srikanth-lingala/zip4j) ([License](https://github.com/srikanth-lingala/zip4j/blob/master/LICENSE)) 57 | * [PlaceholderAPI](https://github.com/PlaceholderAPI/PlaceholderAPI) ([License](https://github.com/PlaceholderAPI/PlaceholderAPI/blob/master/LICENSE)) 58 | 59 | 60 | ## Links 61 | * Become a [Patron](https://go.theprogramsrc.xyz/patreon) and support us! 62 | * [Donate](https://go.theprogramsrc.xyz/donate) to support us! 63 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | The following list can tell you if the version is supported or not. If the version is not supported you won't get support from the team 6 | 7 | | Version | Supported | 8 | | ------- | ------------------ | 9 | | [![Sonatype Nexus (Repository)](https://img.shields.io/nexus/maven-public/xyz.theprogramsrc/SuperCoreAPI?label=Current%20Release&server=https%3A%2F%2Frepo.theprogramsrc.xyz)](https://github.com/TheProgramSrc/SuperCoreAPI) | :white_check_mark: | 10 | | < 4.8.5 | :x: | 11 | 12 | ## Reporting a Vulnerability 13 | 14 | If you find any vulnerability, you can create a new [issue](https://github.com/TheProgramSrc/SuperCoreAPI/issues) 15 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheProgramSrc/SuperCoreAPI/3303d2db44b59c2ea1b45548248fe4cf6d0e7d75/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | * 4 | * The settings file is used to specify which projects to include in your build. 5 | * 6 | * Detailed information about configuring a multi-project build in Gradle can be found 7 | * in the user manual at https://docs.gradle.org/7.2/userguide/multi_project_builds.html 8 | */ 9 | 10 | rootProject.name = 'SuperCoreAPI' 11 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/Base.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi; 2 | 3 | /** 4 | * This is a set of utils that need to be loaded before everything 5 | */ 6 | public class Base { 7 | 8 | protected SuperPlugin plugin; 9 | 10 | public Base(SuperPlugin plugin){ 11 | this.plugin = plugin; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/SuperModule.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi; 2 | 3 | import java.io.File; 4 | 5 | /** 6 | * Representation of a Plugin Module 7 | * @param The listener of the plugin 8 | */ 9 | public abstract class SuperModule { 10 | 11 | protected SuperPlugin plugin; 12 | 13 | public SuperModule(SuperPlugin plugin){ 14 | this.plugin = plugin; 15 | } 16 | 17 | /** 18 | * Executed on the module load 19 | */ 20 | public void onLoad(){ 21 | 22 | } 23 | 24 | /** 25 | * Sends a message with prefix through console 26 | * @param message Message to send 27 | */ 28 | protected void log(String message){ 29 | this.plugin.log(message); 30 | } 31 | 32 | /** 33 | * Show a debug message if the debug mode is enabled 34 | * @param message the message to show if the debug mode is enabled 35 | */ 36 | protected void debug(String message){ 37 | this.plugin.debug(message); 38 | } 39 | 40 | /** 41 | * Checks if the debug mode is enabled 42 | * @return if the debug mode is enabled 43 | */ 44 | protected boolean isDebugEnabled(){ 45 | return this.plugin.isDebugEnabled(); 46 | } 47 | 48 | /** 49 | * Registers new listeners 50 | * @param listeners Listeners to register 51 | */ 52 | protected abstract void listener(LISTENER... listeners); 53 | 54 | /** 55 | * Gets the server folder 56 | * @return server folder 57 | */ 58 | protected File getServerFolder(){ 59 | return this.plugin.getServerFolder(); 60 | } 61 | 62 | /** 63 | * Gets the plugin file 64 | * @return plugin file 65 | */ 66 | protected File getPluginFile(){ 67 | return this.plugin.getPluginFile(); 68 | } 69 | 70 | /** 71 | * Gets the plugin folder 72 | * @return plugin folder 73 | */ 74 | protected File getPluginFolder(){ 75 | return this.plugin.getPluginFolder(); 76 | } 77 | 78 | /** 79 | * Gets the translation folder 80 | * @return translation folder 81 | */ 82 | protected File getTranslationsFolder(){ 83 | return this.plugin.getTranslationsFolder(); 84 | } 85 | 86 | /** 87 | * Gets the plugin version 88 | * @return plugin version 89 | */ 90 | protected String getPluginVersion(){ 91 | return this.plugin.getPluginVersion(); 92 | } 93 | 94 | /** 95 | * Gets the plugin name 96 | * @return plugin name 97 | */ 98 | protected String getPluginName(){ 99 | return this.plugin.getPluginName(); 100 | } 101 | 102 | /** 103 | * Gets the plugin 104 | * @return plugin 105 | */ 106 | public SuperPlugin getPlugin() { 107 | return plugin; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/SuperUtils.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi; 2 | 3 | import net.md_5.bungee.api.ChatColor; 4 | 5 | import java.util.Arrays; 6 | import java.util.Collection; 7 | import java.util.stream.Collectors; 8 | 9 | /** 10 | * Representation of a set of utils for 11 | * a plugin 12 | */ 13 | public interface SuperUtils { 14 | 15 | /** 16 | * Translate the given Hex into ChatColor 17 | * @param hex The color in hex 18 | * @return the hex color as ChatColor 19 | */ 20 | ChatColor parseHex(String hex); 21 | 22 | /** 23 | * Translates the message into minecraft coloured message 24 | * @param message Message to translate 25 | * @return Translated message 26 | */ 27 | String color(String message); 28 | 29 | /** 30 | * Translates the array into minecraft coloured message 31 | * @param strings Array to translate 32 | * @return Translated array 33 | */ 34 | default String[] color(String... strings){ 35 | return Arrays.stream(strings).map(this::color).toArray(String[]::new); 36 | } 37 | 38 | /** 39 | * Translates the collection into minecraft coloured message 40 | * @param strings Collection to translate 41 | * @return Translated collection 42 | */ 43 | default Collection color(Collection strings){ 44 | return strings.stream().map(this::color).collect(Collectors.toList()); 45 | } 46 | 47 | /** 48 | * Removes the color from the specified message 49 | * @param message Message to translate 50 | * @return Message without colors 51 | */ 52 | String removeColor(String message); 53 | 54 | /** 55 | * Removes the color from the specified array 56 | * @param strings Array to translate 57 | * @return Array without colors 58 | */ 59 | default String[] removeColor(String... strings){ 60 | return Arrays.stream(strings).map(this::removeColor).toArray(String[]::new); 61 | } 62 | 63 | /** 64 | * Removes the color from the specified collection 65 | * @param strings Collection to translate 66 | * @return Collection without colors 67 | */ 68 | default Collection removeColor(Collection strings){ 69 | return strings.stream().map(this::removeColor).collect(Collectors.toList()); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/bungee/BungeeModule.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.bungee; 2 | 3 | import net.md_5.bungee.api.ProxyServer; 4 | import net.md_5.bungee.api.plugin.Listener; 5 | import xyz.theprogramsrc.supercoreapi.SuperModule; 6 | import xyz.theprogramsrc.supercoreapi.bungee.storage.Settings; 7 | import xyz.theprogramsrc.supercoreapi.bungee.utils.BungeeUtils; 8 | import xyz.theprogramsrc.supercoreapi.bungee.utils.tasks.BungeeTasks; 9 | 10 | public class BungeeModule extends SuperModule implements Listener { 11 | 12 | protected BungeePlugin bungeePlugin; 13 | 14 | public BungeeModule(boolean registerListener){ 15 | super(BungeePlugin.i); 16 | this.bungeePlugin = BungeePlugin.i; 17 | if(registerListener) this.listener(this); 18 | this.onLoad(); 19 | } 20 | 21 | public BungeeModule(){ 22 | this(true); 23 | } 24 | 25 | @Override 26 | protected void listener(Listener... listeners) { 27 | this.bungeePlugin.listener(listeners); 28 | } 29 | 30 | /** 31 | * Gets the BungeeCord Plugin Settings 32 | * @return The Plugin Settings 33 | */ 34 | protected Settings getSettings(){ 35 | return this.bungeePlugin.getSettings(); 36 | } 37 | 38 | /** 39 | * Gets the proxy 40 | * @return The proxy 41 | */ 42 | protected ProxyServer getProxy(){ 43 | return this.bungeePlugin.getProxy(); 44 | } 45 | 46 | /** 47 | * Gets the BungeeTasks util 48 | * @return the BungeeTasks util 49 | */ 50 | protected BungeeTasks getBungeeTasks(){ 51 | return this.bungeePlugin.getBungeeTasks(); 52 | } 53 | 54 | /** 55 | * Gets the Bungee Utils 56 | * @return the Bungee Utils 57 | */ 58 | protected BungeeUtils getSuperUtils(){ 59 | return this.bungeePlugin.getSuperUtils(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/bungee/commands/BungeeCommand.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.bungee.commands; 2 | 3 | import net.md_5.bungee.api.CommandSender; 4 | import net.md_5.bungee.api.chat.TextComponent; 5 | import net.md_5.bungee.api.connection.ProxiedPlayer; 6 | import net.md_5.bungee.api.plugin.Command; 7 | import xyz.theprogramsrc.supercoreapi.bungee.BungeeModule; 8 | import xyz.theprogramsrc.supercoreapi.bungee.utils.BungeeConsole; 9 | import xyz.theprogramsrc.supercoreapi.global.translations.Base; 10 | 11 | /** 12 | * BungeeCommand is a representation of a {@link Command Command} 13 | * with ease of control and customization. 14 | */ 15 | public abstract class BungeeCommand extends BungeeModule { 16 | 17 | /** 18 | * Create a new {@link BungeeCommand BungeeCommand} 19 | */ 20 | public BungeeCommand(){ 21 | this.debug("Registering command '" + this.getCommand() + "'"); 22 | getProxy().getPluginManager().registerCommand(this.bungeePlugin, new Command(this.getCommand(), this.getPermission(), this.getAliases()) { 23 | @Override 24 | public void execute(CommandSender sender, String[] args) { 25 | CommandResult result; 26 | if(sender instanceof ProxiedPlayer){ 27 | ProxiedPlayer player = ((ProxiedPlayer) sender); 28 | result = BungeeCommand.this.onPlayerExecute(player, args); 29 | }else{ 30 | result = BungeeCommand.this.onConsoleExecute(new BungeeConsole(), args); 31 | } 32 | BungeeCommand.this.onResult(sender, result); 33 | } 34 | }); 35 | } 36 | 37 | private void onResult(CommandSender sender, CommandResult result){ 38 | if(result == CommandResult.NO_PERMISSION){ 39 | sender.sendMessage(new TextComponent(this.bungeePlugin.getSuperUtils().color(Base.NO_PERMISSION.toString()))); 40 | }else if(result == CommandResult.NO_ACCESS){ 41 | sender.sendMessage(new TextComponent(this.bungeePlugin.getSuperUtils().color(Base.NO_ACCESS.toString()))); 42 | }else if(result == CommandResult.NOT_SUPPORTED){ 43 | if(sender instanceof ProxiedPlayer){ 44 | sender.sendMessage(new TextComponent(this.bungeePlugin.getSuperUtils().color(Base.NOT_SUPPORTED.options().vars(Base.CONSOLE.toString()).toString()))); 45 | }else{ 46 | sender.sendMessage(new TextComponent(this.bungeePlugin.getSuperUtils().color(Base.NOT_SUPPORTED.options().vars(Base.PLAYERS.toString()).toString()))); 47 | } 48 | }else if(result == CommandResult.INVALID_ARGS){ 49 | sender.sendMessage(new TextComponent(this.bungeePlugin.getSuperUtils().color(Base.INVALID_ARGUMENTS.toString()))); 50 | } 51 | } 52 | 53 | /** 54 | * Gets the command executed to run the {@link BungeeCommand BungeeCommand} 55 | * @return The command 56 | */ 57 | public abstract String getCommand(); 58 | 59 | /** 60 | * Gets the permission to use the command 61 | * 62 | * @return The permission to use the command 63 | * @see #getCommand() 64 | */ 65 | public String getPermission(){ 66 | return null; 67 | } 68 | 69 | /** 70 | * Gets all the available aliases. 71 | * The aliases are more commands to run the {@link BungeeCommand BungeeCommand} 72 | * 73 | * @return The aliases 74 | */ 75 | public String[] getAliases(){ 76 | return new String[0]; 77 | } 78 | 79 | /** 80 | * Executed when a player executes the command 81 | * 82 | * @param player Who execute the command 83 | * @param args The arguments of the command 84 | * @return The {@link CommandResult Result} of the command 85 | */ 86 | public abstract CommandResult onPlayerExecute(ProxiedPlayer player, String[] args); 87 | 88 | /** 89 | * Executed when the console executes the command 90 | * 91 | * @param console The console 92 | * @param args The arguments of the command 93 | * @return The {@link CommandResult Result} of the command 94 | */ 95 | public abstract CommandResult onConsoleExecute(BungeeConsole console, String[] args); 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/bungee/commands/CommandResult.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.bungee.commands; 2 | 3 | /** 4 | * Representation of the possible results of a command 5 | */ 6 | public enum CommandResult { 7 | COMPLETED, 8 | INVALID_ARGS, 9 | NO_PERMISSION, 10 | NOT_SUPPORTED, 11 | NO_ACCESS; 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/bungee/events/BungeeEventManager.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.bungee.events; 2 | 3 | import xyz.theprogramsrc.supercoreapi.bungee.BungeeModule; 4 | 5 | /** 6 | * This manages the customized events 7 | */ 8 | public class BungeeEventManager extends BungeeModule { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/bungee/storage/Settings.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.bungee.storage; 2 | 3 | import xyz.theprogramsrc.supercoreapi.bungee.BungeeModule; 4 | import xyz.theprogramsrc.supercoreapi.global.files.yml.YMLConfig; 5 | 6 | /** 7 | * Basic BungeeCord Settings used by the Plugin 8 | */ 9 | public class Settings extends BungeeModule { 10 | 11 | private YMLConfig config; 12 | 13 | private String defaultPrefix; 14 | 15 | @Override 16 | public void onLoad() { 17 | this.config = new YMLConfig(this.getPluginFolder(), "Settings.yml"); 18 | this.defaultPrefix = "&9" + this.getPluginName() + "»&r"; 19 | if(this.plugin.isFirstStart()){ 20 | this.loadDefaults(); 21 | } 22 | } 23 | 24 | /** 25 | * Gets the current language of the plugin 26 | * @return the current language of the plugin 27 | */ 28 | public String getLanguage(){ 29 | return this.config.getString("Language", "en_US"); 30 | } 31 | 32 | /** 33 | * Gets the prefix from the plugin or returns the default prefix if there is no prefix in config 34 | * @return the prefix of the plugin 35 | */ 36 | public String getPrefix(){ 37 | return this.config.getString("Prefix", this.defaultPrefix); 38 | } 39 | 40 | public YMLConfig getConfig() { 41 | return config; 42 | } 43 | 44 | public void loadDefaults(){ 45 | this.config.add("Prefix", this.defaultPrefix); 46 | this.config.add("Language","en"); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/bungee/utils/BungeeConsole.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.bungee.utils; 2 | 3 | import net.md_5.bungee.api.CommandSender; 4 | import net.md_5.bungee.api.plugin.Listener; 5 | import xyz.theprogramsrc.supercoreapi.bungee.BungeeModule; 6 | 7 | /** 8 | * Representation of a BungeeCord Console 9 | */ 10 | public class BungeeConsole extends BungeeModule { 11 | 12 | /** 13 | * Registers the specified listeners 14 | * @param listeners The listeners to register 15 | */ 16 | public void listeners(Listener... listeners){ 17 | this.bungeePlugin.listener(listeners); 18 | } 19 | 20 | /** 21 | * Executes a command as Console 22 | * @param command The command to execute 23 | */ 24 | public void execute(String command){ 25 | this.getProxy().getPluginManager().dispatchCommand(this.getProxy().getConsole(), command); 26 | } 27 | 28 | /** 29 | * Gets the {@link CommandSender} 30 | * @return The CommandSender 31 | */ 32 | public CommandSender parseCommandSender(){ 33 | return this.getProxy().getConsole(); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/bungee/utils/BungeeUtils.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.bungee.utils; 2 | 3 | import net.md_5.bungee.api.ChatColor; 4 | import net.md_5.bungee.api.CommandSender; 5 | import net.md_5.bungee.api.chat.TextComponent; 6 | import xyz.theprogramsrc.supercoreapi.SuperUtils; 7 | 8 | /** 9 | * For documentation see {@link SuperUtils} 10 | */ 11 | public class BungeeUtils implements SuperUtils { 12 | 13 | @Override 14 | public ChatColor parseHex(String hex) { 15 | return ChatColor.of(hex); 16 | } 17 | 18 | @Override 19 | public String color(String message) { 20 | return ChatColor.translateAlternateColorCodes('&', message); 21 | } 22 | 23 | @Override 24 | public String removeColor(String message) { 25 | return ChatColor.stripColor(message); 26 | } 27 | 28 | /** 29 | * Send a message with color support 30 | * @param sender the sender 31 | * @param message the message 32 | */ 33 | public void sendMessage(CommandSender sender, String message) { 34 | sender.sendMessage(new TextComponent(color(message))); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/bungee/utils/tasks/BungeeTasks.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.bungee.utils.tasks; 2 | 3 | import net.md_5.bungee.api.scheduler.ScheduledTask; 4 | import net.md_5.bungee.api.scheduler.TaskScheduler; 5 | import xyz.theprogramsrc.supercoreapi.bungee.BungeeModule; 6 | import xyz.theprogramsrc.supercoreapi.global.objects.RecurringTask; 7 | 8 | import java.util.concurrent.TimeUnit; 9 | 10 | public class BungeeTasks extends BungeeModule { 11 | 12 | private final TaskScheduler scheduler; 13 | 14 | public BungeeTasks() { 15 | this.scheduler = this.getProxy().getScheduler(); 16 | } 17 | 18 | /** 19 | * Schedule a task to be executed asynchronously. The task will commence 20 | * running as soon as this method returns. 21 | * 22 | * @param task the task to run 23 | * @return the scheduled task 24 | */ 25 | public ScheduledTask runAsync(Runnable task){ 26 | return this.scheduler.runAsync(this.bungeePlugin, task); 27 | } 28 | 29 | /** 30 | * Schedules a task to be executed asynchronously after the specified delay 31 | * is up. 32 | * 33 | * @param task the task to run 34 | * @param delay the delay before this task will be executed (in ticks) 35 | * @return the scheduled task 36 | */ 37 | public ScheduledTask runAsyncLater(Runnable task, long delay){ 38 | return this.scheduler.schedule(this.bungeePlugin, task, delay*50L, TimeUnit.MILLISECONDS); 39 | } 40 | 41 | /** 42 | * Schedules a task to be executed asynchronously after the specified delay 43 | * is up. The scheduled task will continue running at the specified 44 | * interval. The interval will not begin to count down until the last task 45 | * invocation is complete. 46 | * 47 | * @param task the task to run 48 | * @param delay the delay before this task will be executed (in ticks) 49 | * @param period the interval before subsequent executions of this task (in ticks) 50 | * @return the scheduled task 51 | */ 52 | public RecurringTask runAsyncTimer(Runnable task, long delay, long period){ 53 | ScheduledTask scheduledTask = this.scheduler.schedule(this.bungeePlugin, task, delay*50L, period*50L, TimeUnit.MILLISECONDS); 54 | return new RecurringTask() { 55 | private boolean cancelled; 56 | @Override 57 | public void start() { 58 | if(this.cancelled){ 59 | BungeeTasks.this.runAsyncTimer(task, delay, period); 60 | } 61 | } 62 | 63 | @Override 64 | public void stop() { 65 | scheduledTask.cancel(); 66 | this.cancelled = true; 67 | } 68 | }; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/LogsFilter.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global; 2 | 3 | import org.apache.logging.log4j.Level; 4 | import org.apache.logging.log4j.LogManager; 5 | import org.apache.logging.log4j.Marker; 6 | import org.apache.logging.log4j.core.LogEvent; 7 | import org.apache.logging.log4j.core.Logger; 8 | import org.apache.logging.log4j.core.filter.AbstractFilter; 9 | import org.apache.logging.log4j.message.Message; 10 | 11 | import java.util.Arrays; 12 | 13 | public class LogsFilter extends AbstractFilter{ 14 | 15 | private final FilterResult result; 16 | private final String[] filteredStrings; 17 | 18 | /** 19 | * Constructor of a log filter 20 | * @param result the default result for the filtered words 21 | * @param filteredStrings the strings to filter 22 | */ 23 | public LogsFilter(FilterResult result, String... filteredStrings){ 24 | this.result = result; 25 | this.filteredStrings = filteredStrings; 26 | } 27 | 28 | private Result process(String message){ 29 | if(message != null){ 30 | String msg = message.toLowerCase(); 31 | if(Arrays.stream(this.filteredStrings).anyMatch(s-> msg.contains(s.toLowerCase()) && Arrays.stream(this.getExtraRequirements()).anyMatch(s1-> msg.contains(s1.toLowerCase())))){ 32 | return Result.toResult(this.result.name(), Result.NEUTRAL); 33 | } 34 | } 35 | 36 | return Result.NEUTRAL; 37 | } 38 | 39 | public void register(){ 40 | Logger consoleLogger = ((Logger) LogManager.getRootLogger()); 41 | consoleLogger.addFilter(this); 42 | } 43 | 44 | @Override 45 | public Result filter(LogEvent event) { 46 | return this.process(event.getMessage().getFormattedMessage()); 47 | } 48 | 49 | @Override 50 | public Result filter(Logger logger, Level level, Marker marker, Message msg, Throwable t) { 51 | return this.process(msg.getFormattedMessage()); 52 | } 53 | 54 | @Override 55 | public Result filter(Logger logger, Level level, Marker marker, Object msg, Throwable t) { 56 | return this.process(msg.toString()); 57 | } 58 | 59 | @Override 60 | public Result filter(Logger logger, Level level, Marker marker, String msg, Object... params) { 61 | return this.process(msg); 62 | } 63 | 64 | /** 65 | * An array of strings that will be checked if a message contains one of those to filter the message 66 | * @return the strings 67 | */ 68 | public String[] getExtraRequirements(){ 69 | return new String[0]; 70 | } 71 | 72 | public enum FilterResult{ 73 | DENY, 74 | NEUTRAL, 75 | NONE 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/apis/groupez/GroupeZAPI.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.apis.groupez; 2 | 3 | import xyz.theprogramsrc.supercoreapi.global.utils.Utils; 4 | 5 | public class GroupeZAPI { 6 | 7 | /** 8 | * Used to retrieve the last version using the GroupeZ API 9 | * 10 | * @param pluginId Identifier of the plugin 11 | * @return Null if there is an error, otherwise you'll get the last version 12 | */ 13 | public static String getLastVersion(String pluginId){ 14 | String url = "https://groupez.dev/api/v1/resource/version/" + pluginId; 15 | return Utils.readWithInputStream(url); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/apis/songoda/SongodaAPI.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.apis.songoda; 2 | 3 | import com.google.gson.JsonElement; 4 | import com.google.gson.JsonParser; 5 | import xyz.theprogramsrc.supercoreapi.global.utils.Utils; 6 | 7 | public class SongodaAPI { 8 | 9 | /** 10 | * Gets the last version of a plugin 11 | * @param pluginId The id of the plugin 12 | * @return The last version of the plugin 13 | */ 14 | public static String getLastVersion(String pluginId){ 15 | String content = Utils.readWithInputStream("https://songoda.com/api/v2/products/id/" + pluginId); 16 | if(content == null) { 17 | return null; 18 | } 19 | JsonElement element = new JsonParser().parse(content).getAsJsonObject().get("data").getAsJsonObject().get("versions").getAsJsonArray().get(0); 20 | if(element.isJsonNull()){ 21 | return null; 22 | } 23 | 24 | return element.getAsJsonObject().get("version").getAsString(); 25 | } 26 | 27 | /** 28 | * Gets the amount of downloads of a plugin 29 | * @param pluginId The id of the plugin 30 | * @return The amount of downloads 31 | */ 32 | public static int getDownloads(String pluginId){ 33 | String content = Utils.readWithInputStream("https://songoda.com/api/v2/products/id/" + pluginId); 34 | if(content == null) { 35 | return 0; 36 | } 37 | return new JsonParser().parse(content).getAsJsonObject().get("data").getAsJsonObject().get("downloads").getAsInt(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/apis/spigot/SpigotAPI.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.apis.spigot; 2 | 3 | import xyz.theprogramsrc.supercoreapi.global.utils.Utils; 4 | 5 | public class SpigotAPI { 6 | 7 | /** 8 | * Used to retrieve the last version using the SpigotWebAPI 9 | * @param pluginId Identifier of the plugin 10 | * @return Null if there is an error, otherwise you'll get the last version 11 | */ 12 | public static String getLastVersion(String pluginId){ 13 | String url = "https://api.spigotmc.org/legacy/update.php?resource=" + pluginId; 14 | return Utils.readWithInputStream(url); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/data/PluginDataStorage.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.data; 2 | 3 | import xyz.theprogramsrc.supercoreapi.SuperPlugin; 4 | import xyz.theprogramsrc.supercoreapi.global.files.JsonConfig; 5 | 6 | import java.util.UUID; 7 | 8 | public class PluginDataStorage extends JsonConfig { 9 | 10 | public PluginDataStorage(SuperPlugin plugin){ 11 | super(plugin.getPluginFolder(), "PluginData.json"); 12 | this.add("stats_id", UUID.randomUUID().toString()); 13 | this.add("low_resource_usage", false); 14 | this.add("share_stats", true); 15 | this.add("debug", "false"); 16 | } 17 | 18 | public boolean isDebugEnabled(){ 19 | return this.getBoolean("debug"); 20 | } 21 | 22 | public boolean isLowResourceUsageEnabled(){ 23 | return this.getBoolean("low_resource_usage"); 24 | } 25 | 26 | public boolean isShareStatsEnabled(){ 27 | return this.getBoolean("share_stats"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/dependencies/Dependencies.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.dependencies; 2 | 3 | import xyz.theprogramsrc.supercoreapi.global.dependencies.classloader.LoaderType; 4 | 5 | import java.util.Arrays; 6 | 7 | public enum Dependencies { 8 | 9 | SQLITE_DRIVER( 10 | "org.xerial", 11 | "sqlite-jdbc", 12 | "3.25.2", 13 | "pF2mGr7WFWilM/3s4SUJMYCCjt6w1Lb21XLgz0V0ZfY=", 14 | LoaderType.ISOLATED 15 | ), 16 | HIKARI( 17 | "com.zaxxer", 18 | "HikariCP", 19 | "3.3.1", 20 | "SIaA1yzGHOZNpZNoIt903f5ScJrIB3u8CT2cNkaLcy0=", 21 | LoaderType.ISOLATED 22 | ), 23 | 24 | ; 25 | 26 | private final Dependency dependency; 27 | 28 | Dependencies(String groupId, String artifactId, String version, String checksum, LoaderType loaderType) { 29 | this.dependency = new Dependency(name(), groupId, artifactId, version, checksum, loaderType); 30 | } 31 | 32 | public Dependency getDependency() { 33 | return dependency; 34 | } 35 | 36 | public static Dependency[] get(){ 37 | return Arrays.stream(values()).map(Dependencies::getDependency).toArray(Dependency[]::new); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/dependencies/Dependency.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of LuckPerms, licensed under the MIT License. 3 | * 4 | * Copyright (c) lucko (Luck) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | package xyz.theprogramsrc.supercoreapi.global.dependencies; 26 | 27 | import com.google.common.collect.ImmutableList; 28 | import xyz.theprogramsrc.supercoreapi.global.dependencies.classloader.LoaderType; 29 | 30 | import java.net.URL; 31 | import java.util.Base64; 32 | import java.util.List; 33 | 34 | public class Dependency { 35 | 36 | private static final String MAVEN_FORMAT = "%s/%s/%s/%s-%s.jar"; 37 | 38 | private final String name; 39 | private final List urls; 40 | private final String version; 41 | private final byte[] checksum; 42 | private boolean autoLoad; 43 | private LoaderType loaderType; 44 | 45 | public Dependency(String name, String groupId, String artifactId, String version, String checksum, LoaderType loaderType) { 46 | this.name = name; 47 | this.autoLoad = true; 48 | this.loaderType = loaderType; 49 | 50 | String path = String.format(MAVEN_FORMAT, 51 | rewriteEscaping(groupId).replace(".", "/"), 52 | rewriteEscaping(artifactId), 53 | version, 54 | rewriteEscaping(artifactId), 55 | version 56 | ); 57 | try { 58 | ImmutableList.Builder b = ImmutableList.builder(); 59 | for(Repositories r : Repositories.values()){ 60 | b.add(new URL(r.getURL() + path)); 61 | } 62 | this.urls = b.build(); 63 | } catch (Exception e) { 64 | throw new RuntimeException(e); // propagate 65 | } 66 | this.version = version; 67 | this.checksum = Base64.getDecoder().decode(checksum); 68 | } 69 | 70 | private static String rewriteEscaping(String s) { 71 | return s.replace("{}", "."); 72 | } 73 | 74 | public static String getMavenFormat() { 75 | return MAVEN_FORMAT; 76 | } 77 | 78 | public String getName() { 79 | return name; 80 | } 81 | 82 | public List getUrls() { 83 | return urls; 84 | } 85 | 86 | public String getVersion() { 87 | return version; 88 | } 89 | 90 | public byte[] getChecksum() { 91 | return checksum; 92 | } 93 | 94 | public boolean isAutoLoad() { 95 | return autoLoad; 96 | } 97 | 98 | public LoaderType getLoaderType() { 99 | return loaderType; 100 | } 101 | 102 | public void setAutoLoad(boolean autoLoad) { 103 | this.autoLoad = autoLoad; 104 | } 105 | 106 | public void setLoaderType(LoaderType loaderType) { 107 | this.loaderType = loaderType; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/dependencies/Repositories.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.dependencies; 2 | 3 | public enum Repositories { 4 | 5 | MAVEN_CENTRAL("https://repo1.maven.org/maven2/"), 6 | SONATYPE("https://oss.sonatype.org/content/groups/public/"), 7 | CODE_MC("https://repo.codemc.org/repository/maven-public/"), 8 | 9 | 10 | ; 11 | private final String url; 12 | 13 | Repositories(String url){ 14 | this.url = url; 15 | } 16 | 17 | public String getURL() { 18 | return url; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/dependencies/classloader/IsolatedClassLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of LuckPerms, licensed under the MIT License. 3 | * 4 | * Copyright (c) lucko (Luck) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | package xyz.theprogramsrc.supercoreapi.global.dependencies.classloader; 26 | 27 | import java.net.URL; 28 | import java.net.URLClassLoader; 29 | 30 | /** 31 | * A classloader "isolated" from the rest of the Minecraft server. 32 | * 33 | *

Used to load specific LuckPerms dependencies without causing conflicts 34 | * with other plugins, or libraries provided by the server implementation.

35 | */ 36 | public class IsolatedClassLoader extends URLClassLoader { 37 | static { 38 | ClassLoader.registerAsParallelCapable(); 39 | } 40 | 41 | public IsolatedClassLoader(URL[] urls) { 42 | /* 43 | * ClassLoader#getSystemClassLoader returns the AppClassLoader 44 | * 45 | * Calling #getParent on this returns the ExtClassLoader (Java 8) or 46 | * the PlatformClassLoader (Java 9). Since we want this classloader to 47 | * be isolated from the Minecraft server (the app), we set the parent 48 | * to be the platform class loader. 49 | */ 50 | super(urls, ClassLoader.getSystemClassLoader().getParent()); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/dependencies/classloader/LoaderType.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.dependencies.classloader; 2 | 3 | public enum LoaderType { 4 | ISOLATED, 5 | REFLECTION; 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/dependencies/classloader/PluginClassLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of LuckPerms, licensed under the MIT License. 3 | * 4 | * Copyright (c) lucko (Luck) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | package xyz.theprogramsrc.supercoreapi.global.dependencies.classloader; 26 | 27 | import java.nio.file.Path; 28 | 29 | /** 30 | * Represents the plugins classloader 31 | */ 32 | public interface PluginClassLoader { 33 | 34 | void loadJar(Path file); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/dependencies/classloader/ReflectionClassLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of LuckPerms, licensed under the MIT License. 3 | * 4 | * Copyright (c) lucko (Luck) 5 | * Copyright (c) contributors 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | 26 | package xyz.theprogramsrc.supercoreapi.global.dependencies.classloader; 27 | 28 | import java.lang.reflect.InvocationTargetException; 29 | import java.lang.reflect.Method; 30 | import java.net.MalformedURLException; 31 | import java.net.URL; 32 | import java.net.URLClassLoader; 33 | import java.nio.file.Path; 34 | 35 | public class ReflectionClassLoader implements PluginClassLoader { 36 | private static final Method ADD_URL_METHOD; 37 | 38 | static { 39 | try { 40 | ADD_URL_METHOD = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); 41 | ADD_URL_METHOD.setAccessible(true); 42 | } catch (NoSuchMethodException e) { 43 | throw new ExceptionInInitializerError(e); 44 | } 45 | } 46 | 47 | private final URLClassLoader classLoader; 48 | 49 | public ReflectionClassLoader(Object plugin) throws IllegalStateException { 50 | ClassLoader classLoader = plugin.getClass().getClassLoader(); 51 | if (classLoader instanceof URLClassLoader) { 52 | this.classLoader = (URLClassLoader) classLoader; 53 | } else { 54 | throw new IllegalStateException("ClassLoader is not instance of URLClassLoader"); 55 | } 56 | } 57 | 58 | @Override 59 | public void loadJar(Path file) { 60 | try { 61 | ADD_URL_METHOD.invoke(this.classLoader, file.toUri().toURL()); 62 | } catch (IllegalAccessException | InvocationTargetException | MalformedURLException e) { 63 | throw new RuntimeException(e); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/networking/ConnectionBuilder.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.networking; 2 | 3 | import java.io.IOException; 4 | import java.net.MalformedURLException; 5 | import java.net.URL; 6 | import java.util.LinkedHashMap; 7 | 8 | public class ConnectionBuilder { 9 | 10 | private final URL url; 11 | private final LinkedHashMap props; 12 | 13 | /** 14 | * Create a new connection builder 15 | * @param url the url 16 | * @throws MalformedURLException if any error occurs 17 | */ 18 | public ConnectionBuilder(String url) throws MalformedURLException { 19 | this.url = new URL(url); 20 | this.props = new LinkedHashMap<>(); 21 | } 22 | 23 | /** 24 | * Adds a new property to the connection 25 | * @param key the name of the property 26 | * @param value the value of the property 27 | * @return this class 28 | */ 29 | public ConnectionBuilder addProperty(String key, String value){ 30 | this.props.put(key, value); 31 | return this; 32 | } 33 | 34 | /** 35 | * Create the Custom Connection 36 | * @return the {@link CustomConnection} 37 | * @throws IOException if any error occurs 38 | */ 39 | public CustomConnection connect() throws IOException { 40 | return new CustomConnection(url, this.url.openConnection(), this.props); 41 | } 42 | 43 | /** 44 | * Create the Custom Connection 45 | * @param url the url 46 | * @return the {@link CustomConnection} 47 | * @throws IOException if any error occurs 48 | */ 49 | public static CustomConnection connect(String url) throws IOException{ 50 | return new ConnectionBuilder(url).connect(); 51 | } 52 | 53 | /** 54 | * Create the Custom Connection 55 | * @param url the url 56 | * @param properties the connection properties 57 | * @return the {@link CustomConnection} 58 | * @throws IOException if any error occurs 59 | */ 60 | public static CustomConnection connect(String url, LinkedHashMap properties) throws IOException{ 61 | ConnectionBuilder builder = new ConnectionBuilder(url); 62 | properties.forEach(builder::addProperty); 63 | return builder.connect(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/objects/Pair.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.objects; 2 | 3 | public class Pair { 4 | 5 | private final L l; 6 | private final R r; 7 | 8 | /** 9 | * Initializer 10 | * @param left the object in the left side of the pair 11 | * @param right the object in the right side of the pair 12 | */ 13 | public Pair(L left, R right){ 14 | this.l = left; 15 | this.r = right; 16 | } 17 | 18 | /** 19 | * Gets the object in the left side of the pair 20 | * @return the object in the left side 21 | * @deprecated As of v4.12.0. Replaced by {@link #getLeft()} 22 | * 23 | * NOTE: This will be removed in the release v4.13.0 or higher 24 | */ 25 | public L getA() { 26 | return l; 27 | } 28 | 29 | /** 30 | * Gets the object in the right side of the pair 31 | * @return the object in the right side 32 | * @deprecated As of v4.12.0. Replaced by {@link #getRight()} 33 | * 34 | * NOTE: This will be removed in the release v4.13.0 or higher 35 | */ 36 | public R getB() { 37 | return r; 38 | } 39 | 40 | /** 41 | * Gets the object in the left side of the pair 42 | * @return the object in the left side 43 | */ 44 | public L getLeft() { 45 | return l; 46 | } 47 | 48 | /** 49 | * Gets the object in the right side of the pair 50 | * @return the object in the right side 51 | */ 52 | public R getRight() { 53 | return r; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/objects/RecurringTask.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.objects; 2 | 3 | public abstract class RecurringTask { 4 | 5 | public abstract void start(); 6 | 7 | public abstract void stop(); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/placeholders/BungeePlaceholderManager.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.placeholders; 2 | 3 | import net.md_5.bungee.api.connection.ProxiedPlayer; 4 | 5 | import java.util.LinkedList; 6 | 7 | public class BungeePlaceholderManager extends PlaceholderManager{ 8 | 9 | public String applyPlaceholders(String string, ProxiedPlayer player) { 10 | LinkedList placeholders = new LinkedList<>(this.placeholders); 11 | placeholders.add(new Placeholder("{Player}", player.getName())); 12 | placeholders.add(new Placeholder("{DisplayName}", player.getDisplayName())); 13 | placeholders.add(new Placeholder("{UUID}", player.getUniqueId().toString())); 14 | placeholders.add(new Placeholder("{Server}", player.getServer().getInfo().getName())); 15 | placeholders.add(new Placeholder("{IP}", player.getPendingConnection().getVirtualHost().getAddress().getHostAddress())); 16 | return PlaceholderManager.applyPlaceholders(placeholders, string); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/placeholders/Placeholder.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.placeholders; 2 | 3 | public class Placeholder { 4 | 5 | private final String placeholder, replacement; 6 | 7 | public Placeholder(String placeholder, String replacement) { 8 | this.placeholder = placeholder; 9 | this.replacement = replacement; 10 | } 11 | 12 | public String getPlaceholder() { 13 | return this.placeholder; 14 | } 15 | 16 | public String getReplacement() { 17 | return this.replacement; 18 | } 19 | 20 | public String apply(String text){ 21 | return text.replace(this.getPlaceholder(), this.getReplacement()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/placeholders/PlaceholderManager.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.placeholders; 2 | 3 | import java.util.Collection; 4 | import java.util.LinkedList; 5 | import java.util.Map; 6 | 7 | public class PlaceholderManager { 8 | 9 | protected final LinkedList placeholders; 10 | 11 | public PlaceholderManager(){ 12 | this.placeholders = new LinkedList<>(); 13 | } 14 | 15 | public PlaceholderManager registerPlaceholder(Placeholder placeholder){ 16 | this.placeholders.add(placeholder); 17 | return this; 18 | } 19 | 20 | public PlaceholderManager registerPlaceholder(String placeholder, String replacement){ 21 | this.registerPlaceholder(new Placeholder(placeholder, replacement)); 22 | return this; 23 | } 24 | 25 | public PlaceholderManager registerPlaceholders(Map placeholders){ 26 | for (Map.Entry entry : placeholders.entrySet()) { 27 | this.registerPlaceholder(entry.getKey(), entry.getValue()); 28 | } 29 | return this; 30 | } 31 | 32 | public PlaceholderManager registerPlaceholders(Collection placeholders){ 33 | for (Placeholder placeholder : placeholders) { 34 | this.registerPlaceholder(placeholder); 35 | } 36 | return this; 37 | } 38 | 39 | public PlaceholderManager registerPlaceholders(Placeholder... placeholders){ 40 | for (Placeholder placeholder : placeholders) { 41 | this.registerPlaceholder(placeholder); 42 | } 43 | return this; 44 | } 45 | 46 | public String applyPlaceholders(String string){ 47 | return applyPlaceholders(this.placeholders, string); 48 | } 49 | 50 | public static String applyPlaceholders(Collection placeholders, String string){ 51 | String result = string; 52 | for (Placeholder placeholder : placeholders) { 53 | result = placeholder.apply(result); 54 | } 55 | 56 | return result; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/placeholders/SpigotPlaceholderManager.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.placeholders; 2 | 3 | import org.bukkit.entity.Player; 4 | import xyz.theprogramsrc.supercoreapi.spigot.SpigotPlugin; 5 | 6 | import java.util.LinkedList; 7 | 8 | public class SpigotPlaceholderManager extends PlaceholderManager{ 9 | 10 | private final boolean placeholderAPI; 11 | 12 | public SpigotPlaceholderManager(SpigotPlugin plugin){ 13 | this.placeholderAPI = plugin.getSuperUtils().isPlugin("PlaceholderAPI"); 14 | } 15 | 16 | public String applyPlaceholders(String string, Player player) { 17 | LinkedList placeholders = new LinkedList<>(this.placeholders); 18 | placeholders.add(new Placeholder("{Player}", player.getName())); 19 | placeholders.add(new Placeholder("{DisplayName}", player.getDisplayName())); 20 | placeholders.add(new Placeholder("{World}", player.getWorld().getName())); 21 | placeholders.add(new Placeholder("{UUID}", player.getUniqueId().toString())); 22 | String result = PlaceholderManager.applyPlaceholders(placeholders, string); 23 | if(this.placeholderAPI){ 24 | result = me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(player, result); 25 | } 26 | 27 | return result; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/storage/DataBase.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.storage; 2 | 3 | import java.sql.Connection; 4 | import java.sql.SQLException; 5 | import java.util.concurrent.atomic.AtomicBoolean; 6 | 7 | public interface DataBase{ 8 | 9 | /** 10 | * Gets the DataBase Settings 11 | * @return DataBase Settings 12 | */ 13 | DataBaseSettings getDataBaseSettings(); 14 | 15 | /** 16 | * Checks if the DataBase is loaded 17 | * (Recommended to use before executing anything) 18 | * 19 | * @return If the DataBase is loaded or not 20 | */ 21 | boolean isLoaded(); 22 | 23 | /** 24 | * Closes the current connection with the DataBase 25 | */ 26 | void closeConnection(); 27 | 28 | /** 29 | * Used to connect to the DataBase and execute a {@link ConnectionCall} 30 | * @param call ConnectionCall to execute 31 | */ 32 | void connect(ConnectionCall call); 33 | 34 | /** 35 | * Interface executed when a Connection is called 36 | */ 37 | interface ConnectionCall{ 38 | void onConnect(Connection connection); 39 | } 40 | 41 | /** 42 | * Tests the current database connection by requesting the database name 43 | * @return true if the connection is successful, false otherwise 44 | */ 45 | default boolean testConnection(){ 46 | AtomicBoolean atomicBoolean = new AtomicBoolean(false); 47 | this.connect(c-> { 48 | try{ 49 | c.getMetaData().getDatabaseProductName(); 50 | atomicBoolean.set(true); 51 | }catch (SQLException ex){ 52 | ex.printStackTrace(); 53 | } 54 | }); 55 | 56 | return atomicBoolean.get(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/storage/DataBaseSettings.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.storage; 2 | 3 | /** 4 | * A representation of the DataBase Settings 5 | */ 6 | public interface DataBaseSettings { 7 | 8 | /** 9 | * Gets the host of the DataBase 10 | * @return the host 11 | */ 12 | String host(); 13 | 14 | /** 15 | * The port of the DataBase 16 | * @return the port 17 | */ 18 | default String port(){ 19 | return "3306"; 20 | } 21 | 22 | /** 23 | * Gets the database to Connect 24 | * @return the database 25 | */ 26 | String database(); 27 | 28 | /** 29 | * Gets the username of the DataBase 30 | * @return the username 31 | */ 32 | String username(); 33 | 34 | /** 35 | * Gets the password of the DataBase 36 | * @return the password 37 | */ 38 | String password(); 39 | 40 | /** 41 | * Gets if the DataBase uses SSL 42 | * @return if the DataBase uses SSL 43 | */ 44 | default boolean useSSL(){ 45 | return false; 46 | } 47 | 48 | /** 49 | * Gets the URL connection of the DataBase 50 | * @return the URL connection 51 | */ 52 | default String getURL(){ 53 | return "jdbc:mysql://{Host}:{Port}/{Database}?useSSL={UseSSL}"; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/storage/DataBaseStorage.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.storage; 2 | 3 | import xyz.theprogramsrc.supercoreapi.SuperPlugin; 4 | 5 | import java.sql.Connection; 6 | import java.sql.ResultSet; 7 | import java.sql.Statement; 8 | 9 | /** 10 | * An util to manage and use DataBase Storage 11 | */ 12 | public class DataBaseStorage { 13 | 14 | protected DataBase dataBase; 15 | protected SuperPlugin plugin; 16 | 17 | public DataBaseStorage(SuperPlugin plugin, DataBase dataBase){ 18 | this.plugin = plugin; 19 | this.dataBase = dataBase; 20 | } 21 | 22 | /** 23 | * Gets the prefix of the tables (PluginName_) 24 | * 25 | * @return the prefix of the tables 26 | */ 27 | public String getTablePrefix(){ 28 | return this.plugin.getPluginName().toLowerCase() + "_"; 29 | } 30 | 31 | /** 32 | * Used to get the last inserted id (using the column 'id') 33 | * @param connection The connection 34 | * @param table The table to check 35 | * @return the last inserted id 36 | */ 37 | protected int requestLastInsertedID(Connection connection, String table) { 38 | String select = "SELECT * FROM " + this.getTablePrefix() + table + " ORDER BY id DESC LIMIT 1"; 39 | String query; 40 | if (this.dataBase instanceof SQLiteDataBase) { 41 | query = table == null ? "SELECT last_insert_rowid()" : select; 42 | } else { 43 | query = table == null ? "SELECT LAST_INSERT_ID()" : select; 44 | } 45 | 46 | int id = -1; 47 | try (Statement statement = connection.createStatement()) { 48 | ResultSet result = statement.executeQuery(query); 49 | result.next(); 50 | id = result.getInt(1); 51 | } catch (Exception ex) { 52 | ex.printStackTrace(); 53 | } 54 | return id; 55 | } 56 | 57 | 58 | /** 59 | * Gets the plugin 60 | * @return the plugin 61 | */ 62 | public SuperPlugin getPlugin() { 63 | return plugin; 64 | } 65 | 66 | /** 67 | * Gets the DataBase that it's being used 68 | * @return the database 69 | */ 70 | public DataBase getDataBase() { 71 | return dataBase; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/storage/MySQLDataBase.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.storage; 2 | 3 | import java.sql.Connection; 4 | 5 | import com.zaxxer.hikari.HikariConfig; 6 | import com.zaxxer.hikari.HikariDataSource; 7 | 8 | import xyz.theprogramsrc.supercoreapi.SuperPlugin; 9 | import xyz.theprogramsrc.supercoreapi.global.LogsFilter; 10 | 11 | public abstract class MySQLDataBase implements DataBase { 12 | 13 | protected Connection connection; 14 | private HikariDataSource dataSource; 15 | protected SuperPlugin plugin; 16 | private boolean loaded; 17 | 18 | public MySQLDataBase(SuperPlugin plugin) { 19 | boolean debug = plugin != null && plugin.isDebugEnabled(); 20 | this.plugin = plugin; 21 | this.log("Connecting to '" + getDataBaseSettings().host() + ":" + getDataBaseSettings().port() + "'..."); 22 | if (this.hideHikariLogs() && !debug) { 23 | new LogsFilter(LogsFilter.FilterResult.DENY, "com.zaxxer.hikari").register(); 24 | } 25 | if (plugin != null) this.plugin.debug("Loading HikariConfig"); 26 | HikariConfig cfg = new HikariConfig(); 27 | cfg.setJdbcUrl( 28 | getDataBaseSettings().getURL() 29 | .replace("{Host}", getDataBaseSettings().host()) 30 | .replace("{Port}", getDataBaseSettings().port()) 31 | .replace("{Database}", getDataBaseSettings().database()) 32 | .replace("{UseSSL}", Boolean.toString(getDataBaseSettings().useSSL())) 33 | ); 34 | cfg.setUsername(getDataBaseSettings().username()); 35 | cfg.setPassword(getDataBaseSettings().password()); 36 | cfg.setMaximumPoolSize(3); 37 | this.processSettings(cfg); 38 | 39 | if (plugin != null) this.plugin.debug("Loading HikariDataSource"); 40 | try { 41 | this.dataSource = new HikariDataSource(cfg); 42 | this.loaded = true; 43 | } catch (Exception ex) { 44 | this.log("&cCannot connect to MySQL DataBase:"); 45 | if (plugin != null) this.plugin.addError(ex); 46 | ex.printStackTrace(); 47 | } 48 | } 49 | 50 | /** 51 | * Process the Hikari Settings 52 | * @param config the hikari config 53 | */ 54 | public void processSettings(HikariConfig config){ 55 | 56 | } 57 | 58 | /** 59 | * Used to check if the Connection is loaded 60 | * 61 | * @return if the connection is loaded 62 | */ 63 | @Override 64 | public boolean isLoaded() { 65 | return this.loaded; 66 | } 67 | 68 | /** 69 | * Closes the connection between the plugin and the DataBase 70 | */ 71 | @Override 72 | public void closeConnection() { 73 | if (this.plugin != null) this.plugin.debug("Closing connection with DataBase"); 74 | try { 75 | if (this.dataSource != null) { 76 | this.dataSource.close(); 77 | } 78 | } catch (Exception ex) { 79 | this.log("&cCannot close MySQL Connection:"); 80 | if (this.plugin != null) this.plugin.addError(ex); 81 | ex.printStackTrace(); 82 | } 83 | } 84 | 85 | /** 86 | * Used to connect to the DataBase and execute a {@link xyz.theprogramsrc.supercoreapi.global.storage.DataBase.ConnectionCall ConnectionCall} 87 | * 88 | * @param call ConnectionCall to execute 89 | */ 90 | @Override 91 | public void connect(ConnectionCall call) { 92 | try (Connection connection = this.dataSource.getConnection()) { 93 | call.onConnect(connection); 94 | } catch (Exception ex) { 95 | this.log("&cCannot execute MySQL Connection Call:"); 96 | if (this.plugin != null) this.plugin.addError(ex); 97 | ex.printStackTrace(); 98 | } 99 | } 100 | 101 | /** 102 | * @return true to hide the hikaricp logs, otherwise false 103 | */ 104 | public boolean hideHikariLogs() { 105 | return true; 106 | } 107 | 108 | private void log(String msg){ 109 | if(this.plugin == null) 110 | System.out.println(msg); 111 | else 112 | this.plugin.log(msg); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/storage/SQLiteDataBase.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.storage; 2 | 3 | import xyz.theprogramsrc.supercoreapi.SuperPlugin; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | import java.sql.Connection; 8 | import java.sql.DriverManager; 9 | import java.sql.SQLException; 10 | 11 | public class SQLiteDataBase implements DataBase { 12 | 13 | protected Connection connection; 14 | protected SuperPlugin plugin; 15 | private final File databaseFile; 16 | 17 | public SQLiteDataBase(SuperPlugin plugin){ 18 | this.plugin = plugin; 19 | this.databaseFile = new File(this.plugin.getPluginFolder(), this.plugin.getPluginName().toLowerCase()+".db"); 20 | this.createConnection(); 21 | } 22 | 23 | public SQLiteDataBase(File databaseFile){ 24 | this.databaseFile = databaseFile; 25 | this.createConnection(); 26 | } 27 | 28 | private void createConnection() { 29 | if(this.plugin != null) this.plugin.debug("Connecting to SQLite DataBase"); 30 | try{ 31 | if(!databaseFile.exists()) databaseFile.createNewFile(); 32 | Class.forName("org.sqlite.JDBC"); 33 | this.connection = DriverManager.getConnection("jdbc:sqlite:" + databaseFile.getPath()); 34 | }catch (SQLException | ClassNotFoundException | IOException ex){ 35 | if(this.plugin != null) this.plugin.addError(ex); 36 | this.log("&cCannot create SQLite Connection:"); 37 | ex.printStackTrace(); 38 | } 39 | } 40 | 41 | /** 42 | * SQLite is always available 43 | * @return True because SQLite dont require internet 44 | */ 45 | @Override 46 | public boolean isLoaded() { 47 | return true; 48 | } 49 | 50 | /** 51 | * Closes the current connection with DataBase 52 | */ 53 | @Override 54 | public void closeConnection() { 55 | if(this.plugin != null) this.plugin.debug("Closing connection with SQLite DataBase"); 56 | try{ 57 | if(this.connection != null){ 58 | this.connection.close(); 59 | } 60 | }catch (SQLException ex){ 61 | if(this.plugin != null) this.plugin.addError(ex); 62 | this.log("&cCannot close SQLite Connection:"); 63 | ex.printStackTrace(); 64 | } 65 | } 66 | 67 | /** 68 | * Connects to the DataBase and execute the specified call 69 | * @param call ConnectionCall to execute 70 | */ 71 | @Override 72 | public void connect(ConnectionCall call) { 73 | try{ 74 | if(this.connection == null){ 75 | this.createConnection(); 76 | }else if(this.connection.isClosed()){ 77 | this.createConnection(); 78 | } 79 | }catch (SQLException e){ 80 | if(this.plugin != null) this.plugin.addError(e); 81 | this.log("&cError while connecting to SQLite:"); 82 | e.printStackTrace(); 83 | } 84 | 85 | call.onConnect(this.connection); 86 | } 87 | 88 | /** 89 | * This is not needed because SQLite doesn't use credentials 90 | * @return null 91 | */ 92 | @Override 93 | public DataBaseSettings getDataBaseSettings() { 94 | return null; 95 | } 96 | 97 | private void log(String msg){ 98 | if(this.plugin == null) 99 | System.out.println(msg); 100 | else 101 | this.plugin.log(msg); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/storage/memory/MemoryStorage.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.storage.memory; 2 | 3 | import xyz.theprogramsrc.supercoreapi.SuperPlugin; 4 | 5 | import java.util.LinkedHashMap; 6 | import java.util.LinkedHashSet; 7 | import java.util.LinkedList; 8 | import java.util.Map; 9 | import java.util.function.BiConsumer; 10 | 11 | public class MemoryStorage { 12 | 13 | protected SuperPlugin plugin; 14 | protected LinkedHashMap memory; 15 | 16 | public MemoryStorage(SuperPlugin plugin){ 17 | this.plugin = plugin; 18 | this.memory = new LinkedHashMap<>(); 19 | } 20 | 21 | public void add(String key, OBJ value){ 22 | if(!this.memory.containsKey(key)){ 23 | this.memory.put(key, value); 24 | } 25 | } 26 | 27 | public void set(String key, OBJ value){ 28 | this.memory.put(key, value); 29 | } 30 | 31 | public void remove(String key){ 32 | this.memory.remove(key); 33 | } 34 | 35 | public boolean has(String key){ 36 | return this.memory.containsKey(key); 37 | } 38 | 39 | public boolean hasValue(OBJ value){ 40 | return this.memory.containsValue(value); 41 | } 42 | 43 | public void forEach(BiConsumer consumer){ 44 | this.memory.forEach(consumer); 45 | } 46 | 47 | public LinkedHashSet> entrySet(){ 48 | return new LinkedHashSet<>(this.memory.entrySet()); 49 | } 50 | 51 | public OBJ get(String key){ 52 | return this.memory.get(key); 53 | } 54 | 55 | public String fromValue(OBJ obj){ 56 | return this.keys().stream().filter(k-> this.memory.get(k).equals(obj)).findFirst().orElse(null); 57 | } 58 | 59 | public LinkedList keys(){ 60 | final LinkedList keys = new LinkedList<>(); 61 | this.forEach((k,v)-> keys.add(k)); 62 | return keys; 63 | } 64 | 65 | public LinkedList values(){ 66 | final LinkedList values = new LinkedList<>(); 67 | this.forEach((k,v)-> values.add(v)); 68 | return values; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/translations/Translation.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.translations; 2 | 3 | import xyz.theprogramsrc.supercoreapi.global.utils.StringUtils; 4 | 5 | /** 6 | * A representation of a translation 7 | */ 8 | public class Translation { 9 | 10 | private final TranslationPack pack; 11 | private final String path, value; 12 | 13 | public Translation(TranslationPack pack, String path, String value) { 14 | this.pack = pack; 15 | this.path = path; 16 | this.value = value; 17 | } 18 | 19 | public TranslationPack getPack() { 20 | return pack; 21 | } 22 | 23 | public String getPath() { 24 | return path; 25 | } 26 | 27 | public String getValue() { 28 | return value; 29 | } 30 | 31 | public String translate(){ 32 | return this.pack.getManager().translate(this.path); 33 | } 34 | 35 | public StringUtils options(){ 36 | return new StringUtils(this.translate()); 37 | } 38 | } -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/translations/TranslationDownloader.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.translations; 2 | 3 | import java.io.File; 4 | 5 | import com.google.gson.JsonArray; 6 | import com.google.gson.JsonElement; 7 | import com.google.gson.JsonObject; 8 | import com.google.gson.JsonParser; 9 | 10 | import xyz.theprogramsrc.supercoreapi.SuperPlugin; 11 | import xyz.theprogramsrc.supercoreapi.global.utils.Utils; 12 | import xyz.theprogramsrc.supercoreapi.global.utils.files.FileUtils; 13 | 14 | public class TranslationDownloader { 15 | 16 | /** 17 | * Used to download all translations from github 18 | * @param core The Plugin 19 | * @param username The GitHub Username 20 | * @param repository The GitHub Repository 21 | * @param folder The folder of the Translations 22 | * @deprecated due to new translation system 23 | */ 24 | @Deprecated public static void downloadFromGitHub(final SuperPlugin core, final String username, final String repository, final String folder){ 25 | JsonParser parser = new JsonParser(); 26 | try{ 27 | String url = "https://api.github.com/repos/{Username}/{Repository}/contents/{Folder}"; 28 | url = url.replace("{Username}", username); 29 | url = url.replace("{Repository}", repository); 30 | url = url.replace("{Folder}", folder); 31 | url = url.replace("{PluginName}", core.getPluginName().toLowerCase()); 32 | String content = Utils.readWithInputStream(url); 33 | if(content != null){ 34 | JsonArray availableFiles = parser.parse(content).getAsJsonArray(); 35 | for (JsonElement jsonElement : availableFiles) { 36 | JsonObject json = jsonElement.getAsJsonObject(); 37 | String name = json.get("name").getAsString(); 38 | if(name.endsWith(".lang") && name.contains("_")){ 39 | String download = json.get("download_url").getAsString(); 40 | File file = new File(core.getTranslationsFolder(), name); 41 | file.delete(); 42 | FileUtils.downloadUsingCommons(download, file); 43 | } 44 | } 45 | } 46 | core.getTranslationManager().loadTranslations(); 47 | }catch (Exception ex){ 48 | ex.printStackTrace(); 49 | } 50 | } 51 | 52 | /** 53 | * Download a specific translation from web 54 | * @param core The Plugin 55 | * @param directUrl The DirectURl (This API doesn't support redirection) 56 | * @param fileName The name of the file to save 57 | * @deprecated due to new translation system 58 | */ 59 | @Deprecated public static void downloadTranslation(final SuperPlugin core, String directUrl, String fileName){ 60 | try{ 61 | File file = new File(core.getTranslationsFolder(), fileName.endsWith(".lang") ? fileName : (fileName+".lang")); 62 | file.delete(); 63 | FileUtils.downloadUsingCommons(directUrl, file); 64 | }catch (Exception ex){ 65 | ex.printStackTrace(); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/translations/TranslationPack.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.translations; 2 | 3 | import xyz.theprogramsrc.supercoreapi.global.utils.StringUtils; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * This util is designed for the Enum class 9 | */ 10 | public interface TranslationPack { 11 | 12 | /** 13 | * Gets the language of the file 14 | * @return Language locale of the file 15 | */ 16 | String getLanguage(); 17 | 18 | /** 19 | * Gets a single translation 20 | * @return Current Translation 21 | */ 22 | Translation get(); 23 | 24 | /** 25 | * Gets all the available translations 26 | * @return Available translations 27 | */ 28 | List translations(); 29 | 30 | /** 31 | * Sets the translation manager 32 | * @param manager Translation Manager 33 | */ 34 | void setManager(TranslationManager manager); 35 | 36 | /** 37 | * Gets the translation manager 38 | * @return Translation manager 39 | */ 40 | TranslationManager getManager(); 41 | 42 | /** 43 | * String options for the current translation 44 | * @return String utils 45 | */ 46 | default StringUtils options(){ 47 | return this.get().options(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/updater/IUpdateChecker.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.updater; 2 | 3 | public interface IUpdateChecker { 4 | 5 | void checkUpdates(); 6 | 7 | void onFailCheck(); 8 | 9 | void onSuccessCheck(String lastVersion); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/updater/SongodaUpdateChecker.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.updater; 2 | 3 | import com.google.gson.JsonObject; 4 | import xyz.theprogramsrc.supercoreapi.global.networking.ConnectionBuilder; 5 | import xyz.theprogramsrc.supercoreapi.global.networking.CustomConnection; 6 | 7 | import java.io.IOException; 8 | 9 | public abstract class SongodaUpdateChecker implements IUpdateChecker{ 10 | 11 | private final String apiEndpoint; 12 | 13 | public SongodaUpdateChecker(String product){ 14 | this.apiEndpoint = "https://songoda.com/api/v2/products/" + product; 15 | } 16 | 17 | public void checkUpdates(){ 18 | try{ 19 | CustomConnection connection = ConnectionBuilder.connect(this.apiEndpoint); 20 | if(connection.isValidResponse() && connection.isResponseNotNull()){ 21 | JsonObject json = connection.getResponseJson(); 22 | if(json != null && !json.isJsonNull()){ 23 | String version = json.get("data").getAsJsonObject().get("versions").getAsJsonArray().get(0).getAsJsonObject().get("version").getAsString(); 24 | this.onSuccessCheck(version); 25 | }else{ 26 | this.onFailCheck(); 27 | } 28 | }else{ 29 | this.onFailCheck(); 30 | } 31 | }catch (IOException ex){ 32 | ex.printStackTrace(); 33 | this.onFailCheck(); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/updater/SpigotUpdateChecker.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.updater; 2 | 3 | import xyz.theprogramsrc.supercoreapi.global.utils.Utils; 4 | 5 | public abstract class SpigotUpdateChecker implements IUpdateChecker{ 6 | 7 | private final String apiEndpoint; 8 | 9 | public SpigotUpdateChecker(String pluginId){ 10 | this.apiEndpoint = "https://api.spigotmc.org/legacy/update.php?resource=" + pluginId; 11 | } 12 | 13 | public void check(){ 14 | try{ 15 | String content = Utils.readWithInputStream(this.apiEndpoint); 16 | if(content == null){ 17 | this.onFailCheck(); 18 | }else{ 19 | this.onSuccessCheck(content); 20 | } 21 | }catch (Exception ex){ 22 | ex.printStackTrace(); 23 | this.onFailCheck(); 24 | } 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/updater/TheProgramSrcUpdateChecker.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.updater; 2 | 3 | import com.google.gson.JsonObject; 4 | import xyz.theprogramsrc.supercoreapi.global.networking.ConnectionBuilder; 5 | import xyz.theprogramsrc.supercoreapi.global.networking.CustomConnection; 6 | 7 | import java.io.IOException; 8 | 9 | public abstract class TheProgramSrcUpdateChecker implements IUpdateChecker{ 10 | 11 | private final String apiEndpoint; 12 | 13 | public TheProgramSrcUpdateChecker(String productId){ 14 | this.apiEndpoint = "https://theprogramsrc.xyz/api/v1/products/id/" + productId; 15 | } 16 | 17 | @Override 18 | public void checkUpdates() { 19 | try{ 20 | CustomConnection connection = ConnectionBuilder.connect(this.apiEndpoint); 21 | if(connection.isValidResponse() && connection.isResponseNotNull()){ 22 | JsonObject json = connection.getResponseJson(); 23 | if(json != null && !json.isJsonNull()){ 24 | JsonObject versionJson = json.get("data").getAsJsonObject().get("versions").getAsJsonArray().get(0).getAsJsonObject(); 25 | String version = versionJson.get("version").getAsString(); 26 | this.onSuccessCheck(version); 27 | }else{ 28 | this.onFailCheck(); 29 | } 30 | }else{ 31 | this.onFailCheck(); 32 | } 33 | }catch (IOException e){ 34 | e.printStackTrace(); 35 | this.onFailCheck(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/utils/ServerUtils.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.utils; 2 | 3 | import xyz.theprogramsrc.supercoreapi.global.utils.serverutils.BungeeServerUtils; 4 | import xyz.theprogramsrc.supercoreapi.global.utils.serverutils.SpigotServerUtils; 5 | 6 | public class ServerUtils { 7 | 8 | public SpigotServerUtils spigot(){ 9 | return new SpigotServerUtils(); 10 | } 11 | 12 | public BungeeServerUtils bungee(){ 13 | return new BungeeServerUtils(); 14 | } 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/utils/StringUtils.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.utils; 2 | 3 | import java.util.HashMap; 4 | import java.util.concurrent.atomic.AtomicReference; 5 | 6 | /** 7 | * A set of utils for strings 8 | */ 9 | public class StringUtils { 10 | private String content; 11 | 12 | /** 13 | * String utils constructor 14 | * @param content String to use 15 | */ 16 | public StringUtils(String content){ 17 | this.content = content; 18 | } 19 | 20 | /** 21 | * Make all the characters lower case 22 | * @return This class 23 | */ 24 | public StringUtils lower(){ 25 | this.content = this.content.toLowerCase(); 26 | return this; 27 | } 28 | 29 | /** 30 | * Make all the characters upper case 31 | * @return This class 32 | */ 33 | public StringUtils upper(){ 34 | this.content = this.content.toUpperCase(); 35 | return this; 36 | } 37 | 38 | /** 39 | * Capitalize the content with Camel Case 40 | * @return This class 41 | */ 42 | public StringUtils capitalize(){ 43 | this.content = Utils.capitalize(this.content); 44 | return this; 45 | } 46 | 47 | /** 48 | * Replace variables with format ($1,$2,$3...) 49 | * @param vars Placeholders replacement in order 50 | * @return This class 51 | */ 52 | public StringUtils vars(String... vars){ 53 | return this.variables("$INDEX", vars); 54 | } 55 | 56 | /** 57 | * Replace custom vars 58 | * @param format Format to replace (INDEX will be replaced with the index, See {@link #vars(String...)}) 59 | * @param vars The value of every format 60 | * @return This class 61 | */ 62 | public StringUtils variables(String format, String... vars){ 63 | String r = this.content; 64 | for(int i = 0; i < vars.length; ++i){ 65 | String var = vars[i]; 66 | String replace = format.replace("INDEX", (i+1)+""); 67 | r = r.replace(replace, var); 68 | } 69 | this.content = r; 70 | return this; 71 | } 72 | 73 | /** 74 | * Inject placeholders to the content 75 | * @param placeholders Placeholders to inject 76 | * @return This class 77 | */ 78 | public StringUtils placeholders(HashMap placeholders){ 79 | AtomicReference r = new AtomicReference<>(this.content); 80 | placeholders.forEach((k,v)-> r.set(r.get().replace(k,v))); 81 | this.content = r.get(); 82 | return this; 83 | } 84 | 85 | /** 86 | * Inject a single placeholder 87 | * @param key Placeholder to replace 88 | * @param value Placeholder replacement 89 | * @return This class 90 | */ 91 | public StringUtils placeholder(String key, String value){ 92 | this.content = this.content.replace(key, value); 93 | return this; 94 | } 95 | 96 | /** 97 | * Makes the first character uppercase 98 | * @return This class 99 | */ 100 | public StringUtils firstUpper(){ 101 | this.content = this.content.substring(0, 1).toUpperCase() + this.content.substring(1); 102 | return this; 103 | } 104 | 105 | /** 106 | * Gets the final string 107 | * @return the final string 108 | */ 109 | public String get(){ 110 | return this.content; 111 | } 112 | 113 | /** 114 | * Gets the final string 115 | * @return the final string 116 | */ 117 | public String toString(){ 118 | return this.get(); 119 | } 120 | 121 | } 122 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/utils/VersioningUtil.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.utils; 2 | 3 | public class VersioningUtil { 4 | 5 | /** 6 | * Check any type of version into numbers to check the version. 7 | * 8 | * @param currentVersion the current version (usually stored in the plugin.yml or bungee.yml) 9 | * @param latestVersion the latest version stored in the database, or the platform with the latest update 10 | * @return 1 if there latest version is higher than the current one; 2 if the current version is higher than the latest version; 0 if booth versions are the same 11 | */ 12 | public static int checkVersions(String currentVersion, String latestVersion){ 13 | StringBuilder latest = new StringBuilder(latestVersion.split(" ")[0].replaceAll("\\.", "").replaceAll("[a-zA-Z]", "")), 14 | current = new StringBuilder(currentVersion.split(" ")[0].replaceAll("[^\\d.]", "").replaceAll("\\.", "").replaceAll("[a-zA-Z]", "")); 15 | if(latest.length() > current.length()){ 16 | int amount = latest.length() - current.length(); 17 | for(int i = 0; i < amount; ++i){ 18 | current.append("0"); 19 | } 20 | }else if(current.length() > latest.length()){ 21 | int amount = current.length() - latest.length(); 22 | for(int i = 0; i < amount; ++i){ 23 | latest.append("0"); 24 | } 25 | } 26 | int l = Integer.parseInt(latest.toString()), c = Integer.parseInt(current.toString()); 27 | if(l > c){ 28 | return 1; 29 | }else if(l < c){ 30 | return 2; 31 | }else { 32 | return 0; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/utils/files/FileUtils.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.utils.files; 2 | 3 | import java.io.BufferedInputStream; 4 | import java.io.File; 5 | import java.io.FileOutputStream; 6 | import java.io.IOException; 7 | import java.net.HttpURLConnection; 8 | import java.net.URL; 9 | 10 | public class FileUtils { 11 | 12 | /** 13 | * Used to download a file using CommonsIO 14 | * @param url Url of the file 15 | * @param file Output file 16 | * @throws IOException If occurs any exception 17 | */ 18 | public static void downloadUsingCommons(String url, File file) throws IOException { 19 | org.apache.commons.io.FileUtils.copyURLToFile(new URL(url), file); 20 | } 21 | 22 | /** 23 | * Download a File using Stream 24 | * @param urlLocation The url to download 25 | * @param output The output of the file 26 | * @return false if occurs any error, otherwise true 27 | */ 28 | public static boolean downloadUsingStream(String urlLocation, File output){ 29 | try{ 30 | URL url = new URL(followRedirects(urlLocation)); 31 | BufferedInputStream bis = new BufferedInputStream(url.openStream()); 32 | FileOutputStream fis = new FileOutputStream(output); 33 | byte[] buffer = new byte[1024]; 34 | int count; 35 | while((count = bis.read(buffer,0,1024)) != -1) { 36 | fis.write(buffer, 0, count); 37 | } 38 | fis.close(); 39 | bis.close(); 40 | return true; 41 | }catch (Exception ex){ 42 | ex.printStackTrace(); 43 | return false; 44 | } 45 | } 46 | 47 | private static String followRedirects(String url) { 48 | URL urlTmp; 49 | String redUrl; 50 | HttpURLConnection connection; 51 | try { urlTmp = new URL(url); } catch (Exception e1) { return url; } 52 | try { connection = (HttpURLConnection) urlTmp.openConnection(); } catch (Exception e) { return url; } 53 | try { connection.getResponseCode(); } catch (Exception e) { return url; } 54 | redUrl = connection.getURL().toString(); 55 | connection.disconnect(); 56 | if(redUrl.equals(url)) { 57 | try { 58 | URL obj = new URL(url); 59 | HttpURLConnection conn = (HttpURLConnection) obj.openConnection(); 60 | conn.setReadTimeout(5000); 61 | conn.addRequestProperty("Accept-Language", "en-US,en;q=0.8"); 62 | conn.addRequestProperty("User-Agent", "Mozilla"); 63 | conn.addRequestProperty("Referer", "google.com"); 64 | boolean redirect = false; 65 | int status = conn.getResponseCode(); 66 | if (status != HttpURLConnection.HTTP_OK) { 67 | if (status == HttpURLConnection.HTTP_MOVED_TEMP 68 | || status == HttpURLConnection.HTTP_MOVED_PERM 69 | || status == HttpURLConnection.HTTP_SEE_OTHER) 70 | redirect = true; 71 | } 72 | if (redirect) { 73 | return conn.getHeaderField("Location"); 74 | } 75 | } catch (Exception ignored) {} 76 | } else { 77 | return redUrl; 78 | } 79 | return url; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/utils/serverutils/BungeeServerUtils.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.utils.serverutils; 2 | 3 | import net.md_5.bungee.api.connection.ProxiedPlayer; 4 | import xyz.theprogramsrc.supercoreapi.bungee.BungeePlugin; 5 | 6 | import java.io.ByteArrayOutputStream; 7 | import java.io.DataOutputStream; 8 | 9 | public class BungeeServerUtils { 10 | 11 | private final BungeePlugin plugin; 12 | 13 | public BungeeServerUtils(){ 14 | this.plugin = BungeePlugin.i; 15 | } 16 | 17 | public void sendToServer(ProxiedPlayer player, String server){ 18 | this.plugin.getProxy().registerChannel("BungeeCord"); 19 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); 20 | DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); 21 | 22 | try{ 23 | dataOutputStream.writeUTF("Connect"); 24 | dataOutputStream.writeUTF(server); 25 | }catch (Exception ex){ 26 | ex.printStackTrace(); 27 | } 28 | player.sendData("BungeeCord", byteArrayOutputStream.toByteArray()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/global/utils/serverutils/SpigotServerUtils.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.utils.serverutils; 2 | 3 | import org.bukkit.entity.Player; 4 | import xyz.theprogramsrc.supercoreapi.spigot.SpigotPlugin; 5 | 6 | import java.io.ByteArrayOutputStream; 7 | import java.io.DataOutputStream; 8 | 9 | public class SpigotServerUtils { 10 | 11 | protected SpigotPlugin plugin; 12 | 13 | public SpigotServerUtils(){ 14 | this.plugin = SpigotPlugin.i; 15 | } 16 | 17 | /** 18 | * Send a player to another server 19 | * @param player the player 20 | * @param server the server 21 | */ 22 | public void sendToServer(Player player, String server){ 23 | if(!this.plugin.getPlugin().getServer().getMessenger().isOutgoingChannelRegistered(this.plugin.getPlugin(), "BungeeCord")){ 24 | this.plugin.getPlugin().getServer().getMessenger().registerOutgoingPluginChannel(this.plugin.getPlugin(), "BungeeCord"); 25 | } 26 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); 27 | DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); 28 | 29 | try{ 30 | dataOutputStream.writeUTF("Connect"); 31 | dataOutputStream.writeUTF(server); 32 | }catch (Exception ex){ 33 | ex.printStackTrace(); 34 | } 35 | 36 | player.sendPluginMessage(this.plugin.getPlugin(), "BungeeCord", byteArrayOutputStream.toByteArray()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/SpigotModule.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot; 2 | 3 | import org.bukkit.event.Listener; 4 | import xyz.theprogramsrc.supercoreapi.SuperModule; 5 | import xyz.theprogramsrc.supercoreapi.spigot.items.PreloadedItems; 6 | import xyz.theprogramsrc.supercoreapi.spigot.storage.SettingsStorage; 7 | import xyz.theprogramsrc.supercoreapi.spigot.utils.SpigotUtils; 8 | import xyz.theprogramsrc.supercoreapi.spigot.utils.tasks.SpigotTasks; 9 | 10 | /** 11 | * For more docs see {@link SuperModule} 12 | */ 13 | public class SpigotModule extends SuperModule implements Listener { 14 | 15 | protected SpigotPlugin spigotPlugin; 16 | 17 | /** 18 | * Creates a new Spigot Module 19 | * @param registerListener if the listener should be registered 20 | */ 21 | public SpigotModule(boolean registerListener){ 22 | super(SpigotPlugin.i); 23 | this.spigotPlugin = SpigotPlugin.i; 24 | if(registerListener) this.listener(this); 25 | this.onLoad(); 26 | } 27 | 28 | /** 29 | * Creates a new Spigot Module (this will register automatically the listener) 30 | */ 31 | public SpigotModule(){ 32 | this(true); 33 | } 34 | 35 | /** 36 | * Gets the {@link SpigotTasks} 37 | * @return the {@link SpigotTasks} 38 | */ 39 | protected SpigotTasks getSpigotTasks() { 40 | return this.spigotPlugin.getSpigotTasks(); 41 | } 42 | 43 | /** 44 | * Gets the {@link PreloadedItems} 45 | * @return the {@link PreloadedItems} 46 | */ 47 | protected PreloadedItems getPreloadedItems(){ 48 | return this.spigotPlugin.getPreloadedItems(); 49 | } 50 | 51 | /** 52 | * Registers {@link Listener listeners} 53 | * @param listeners the array of {@link Listener listeners} to register 54 | */ 55 | protected void listener(Listener... listeners){ 56 | this.spigotPlugin.listener(listeners); 57 | } 58 | 59 | /** 60 | * Gets the plugin {@link SettingsStorage} 61 | * @return the {@link SettingsStorage} 62 | */ 63 | protected SettingsStorage getSettings() { 64 | return this.spigotPlugin.getSettingsStorage(); 65 | } 66 | 67 | /** 68 | * Gets the {@link SpigotUtils} 69 | * @return the {@link SpigotUtils} 70 | */ 71 | protected SpigotUtils getSuperUtils(){ 72 | return this.spigotPlugin.getSuperUtils(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/commands/CommandResult.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.commands; 2 | 3 | /** 4 | * A representation of a Command Result 5 | */ 6 | public enum CommandResult { 7 | COMPLETED, 8 | INVALID_ARGS, 9 | NO_PERMISSION, 10 | NOT_SUPPORTED, 11 | NO_ACCESS; 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/events/EventManager.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.events; 2 | 3 | import xyz.theprogramsrc.supercoreapi.spigot.SpigotModule; 4 | 5 | public class EventManager extends SpigotModule { 6 | 7 | @Override 8 | public void onLoad() { 9 | this.spigotPlugin.getServer().getMessenger().registerOutgoingPluginChannel(this.spigotPlugin, "BungeeCord"); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/gui/events/GuiCloseEvent.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.gui.events; 2 | 3 | import xyz.theprogramsrc.supercoreapi.spigot.gui.Gui; 4 | 5 | public class GuiCloseEvent extends GuiEvent { 6 | 7 | public GuiCloseEvent(Gui gui) { 8 | super(gui); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/gui/events/GuiEmptyClickEvent.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.gui.events; 2 | 3 | import xyz.theprogramsrc.supercoreapi.spigot.gui.Gui; 4 | 5 | public class GuiEmptyClickEvent extends GuiEvent{ 6 | 7 | public GuiEmptyClickEvent(Gui gui) { 8 | super(gui); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/gui/events/GuiEvent.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.gui.events; 2 | 3 | import xyz.theprogramsrc.supercoreapi.spigot.gui.Gui; 4 | 5 | public class GuiEvent { 6 | 7 | public final Gui gui; 8 | 9 | public GuiEvent(Gui gui) { 10 | this.gui = gui; 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/gui/events/GuiOpenEvent.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.gui.events; 2 | 3 | import xyz.theprogramsrc.supercoreapi.spigot.gui.Gui; 4 | 5 | public class GuiOpenEvent extends GuiEvent{ 6 | 7 | public GuiOpenEvent(Gui gui) { 8 | super(gui); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/gui/events/GuiOutsideClickEvent.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.gui.events; 2 | 3 | import xyz.theprogramsrc.supercoreapi.spigot.gui.Gui; 4 | 5 | public class GuiOutsideClickEvent extends GuiEvent{ 6 | 7 | public GuiOutsideClickEvent(Gui gui) { 8 | super(gui); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/gui/events/GuiUpdateEvent.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.gui.events; 2 | 3 | import xyz.theprogramsrc.supercoreapi.spigot.gui.Gui; 4 | 5 | public class GuiUpdateEvent extends GuiEvent{ 6 | 7 | public GuiUpdateEvent(Gui gui) { 8 | super(gui); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/gui/objets/GuiAction.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.gui.objets; 2 | 3 | import org.bukkit.entity.Player; 4 | import org.bukkit.event.inventory.InventoryClickEvent; 5 | 6 | import xyz.theprogramsrc.supercoreapi.spigot.gui.Gui; 7 | 8 | /** 9 | * Representation of a GUI action. 10 | * @since 5.2.0 11 | */ 12 | public class GuiAction { 13 | 14 | /** 15 | * The player executing the action 16 | */ 17 | public final Player player; 18 | /** 19 | * The type of click 20 | */ 21 | public final ClickType clickType; 22 | /** 23 | * The Gui that the action is executed on 24 | */ 25 | public final Gui gui; 26 | 27 | /** 28 | * The InventoryClickEvent that triggered the action 29 | */ 30 | public final InventoryClickEvent inventoryClickEvent; 31 | 32 | 33 | public GuiAction(Gui gui, Player player, ClickType clickType, InventoryClickEvent inventoryClickEvent){ 34 | this.gui = gui; 35 | this.player = player; 36 | this.clickType = clickType; 37 | this.inventoryClickEvent = inventoryClickEvent; 38 | } 39 | 40 | /** 41 | * Representation of a click type. 42 | */ 43 | public enum ClickType { 44 | 45 | LEFT_CLICK, 46 | SHIFT_LEFT, 47 | MIDDLE_CLICK, 48 | RIGHT_CLICK, 49 | SHIFT_RIGHT, 50 | Q, 51 | CTRL_Q, 52 | DOUBLE 53 | 54 | ; 55 | 56 | 57 | public static ClickType fromEvent(InventoryClickEvent event){ 58 | switch (event.getClick()){ 59 | default: 60 | return LEFT_CLICK; 61 | case RIGHT: 62 | return RIGHT_CLICK; 63 | case DROP: 64 | return Q; 65 | case SHIFT_LEFT: 66 | return SHIFT_LEFT; 67 | case MIDDLE: 68 | return MIDDLE_CLICK; 69 | case SHIFT_RIGHT: 70 | return SHIFT_RIGHT; 71 | case CONTROL_DROP: 72 | return CTRL_Q; 73 | case DOUBLE_CLICK: 74 | return DOUBLE; 75 | } 76 | } 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/gui/objets/GuiEntry.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.gui.objets; 2 | 3 | import java.util.function.Consumer; 4 | 5 | import org.bukkit.inventory.ItemStack; 6 | 7 | import xyz.theprogramsrc.supercoreapi.spigot.items.SimpleItem; 8 | 9 | /** 10 | * Representation of a GuiEntry 11 | * @since 5.2.0 12 | */ 13 | public class GuiEntry { 14 | 15 | public final ItemStack item; 16 | public final Consumer action; 17 | 18 | /** 19 | * Creates a new GuiEntry from an ItemStack and a Consumer 20 | * @param item The ItemStack 21 | * @param action The Consumer 22 | */ 23 | public GuiEntry(ItemStack item, Consumer action) { 24 | this.item = item; 25 | this.action = action; 26 | } 27 | 28 | /** 29 | * Creates a new GuiEntry from a SimpleItem and a Consumer 30 | * @param item The SimpleItem 31 | * @param action The Consumer 32 | */ 33 | public GuiEntry(SimpleItem item, Consumer action) { 34 | this(item.build(), action); 35 | } 36 | 37 | /** 38 | * Creates a new GuiEntry from an ItemStack but without an action. 39 | * @param item The ItemStack 40 | */ 41 | public GuiEntry(ItemStack item) { 42 | this(item, null); 43 | } 44 | 45 | /** 46 | * Creates a new GuiEntry from a SimpleItem but without an action. 47 | * @param item The SimpleItem 48 | */ 49 | public GuiEntry(SimpleItem item) { 50 | this(item.build(), null); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/gui/objets/GuiModel.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.gui.objets; 2 | 3 | import java.util.LinkedHashMap; 4 | 5 | import xyz.theprogramsrc.supercoreapi.spigot.SpigotModule; 6 | 7 | /** 8 | * Representation of the Gui Model 9 | * @since 5.2.0 10 | */ 11 | public class GuiModel extends SpigotModule{ 12 | 13 | private GuiTitle title; 14 | private GuiRows rows; 15 | private final LinkedHashMap buttons; 16 | 17 | public GuiModel(GuiTitle title, GuiRows rows) { 18 | this.title = title; 19 | this.rows = rows; 20 | this.buttons = new LinkedHashMap<>(); 21 | } 22 | 23 | public GuiTitle getTitle() { 24 | return title; 25 | } 26 | 27 | /** 28 | * Sets the title of the Gui 29 | * @param title The title of the Gui 30 | */ 31 | public void setTitle(GuiTitle title) { 32 | this.title = title; 33 | } 34 | 35 | public GuiRows getRows() { 36 | return rows; 37 | } 38 | 39 | /** 40 | * Sets the rows of the Gui 41 | * @param rows The rows of the Gui 42 | */ 43 | public void setRows(GuiRows rows) { 44 | this.rows = rows; 45 | } 46 | 47 | public LinkedHashMap getButtons() { 48 | return buttons; 49 | } 50 | 51 | /** 52 | * Clear the buttons from the Gui 53 | */ 54 | public void clearButtons(){ 55 | this.buttons.clear(); 56 | } 57 | 58 | /** 59 | * Sets a new button in the Gui overriding it if it already exists 60 | * @param slot The slot of the button to add 61 | * @param entry The entry of the button to add 62 | */ 63 | public void setButton(int slot, GuiEntry entry) { 64 | buttons.put(slot, entry); 65 | } 66 | 67 | /** 68 | * Adds the button to the first empty slot 69 | * @param entry The entry of the button to add 70 | */ 71 | public void addButton(GuiEntry entry){ 72 | for(int i = 0; i < this.rows.size; i++){ 73 | if(!this.buttons.containsKey(i)){ 74 | this.buttons.put(i, entry); 75 | break; 76 | } 77 | } 78 | } 79 | 80 | /** 81 | * Fills all the empty slots with the given entry 82 | * @param entry The entry of the button to add to all the empty slots 83 | * @since 5.2.1 84 | */ 85 | public void fillEmptySlotsWithEntry(GuiEntry entry){ 86 | for(int i = 0; i < this.rows.size; i++){ 87 | if(!this.buttons.containsKey(i)){ 88 | this.setButton(i, entry); 89 | } 90 | } 91 | } 92 | 93 | /** 94 | * Fills the empty slots with the empty item. 95 | * See {@link xyz.theprogramsrc.supercoreapi.spigot.items.PreloadedItems#emptyItem} 96 | * @since 5.2.1 97 | */ 98 | public void fillEmptySlots(){ 99 | this.fillEmptySlotsWithEntry(new GuiEntry(this.getPreloadedItems().emptyItem())); 100 | } 101 | 102 | /** 103 | * Fills the specified slots with the specified entry. 104 | * @param entry The entry of the button to add to the given slots 105 | * @param slots The slots to fill 106 | * @since 5.2.1 107 | */ 108 | 109 | public void fillWithEntry(GuiEntry entry, int[] slots){ 110 | for(int slot : slots){ 111 | this.setButton(slot, entry); 112 | } 113 | } 114 | 115 | /** 116 | * Fills the specified slots with an empty item. 117 | * @param slots The slots to fill with the empty item 118 | * @since 5.2.1 119 | */ 120 | public void fillWithEmptyItem(int[] slots){ 121 | this.fillWithEntry(new GuiEntry(this.getPreloadedItems().emptyItem()), slots); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/gui/objets/GuiRows.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.gui.objets; 2 | 3 | /** 4 | * Representation of the Gui Rows 5 | * @since 5.2.0 6 | */ 7 | public enum GuiRows { 8 | ONE(9), 9 | TWO(18), 10 | THREE(27), 11 | FOUR(36), 12 | FIVE(45), 13 | SIX(54); 14 | 15 | public final int size; 16 | 17 | GuiRows(int size){ 18 | this.size = size; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/gui/objets/GuiTitle.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.gui.objets; 2 | 3 | import xyz.theprogramsrc.supercoreapi.spigot.SpigotPlugin; 4 | 5 | /** 6 | * Representation of a GuiTitle 7 | * @since 5.2.0 8 | */ 9 | public class GuiTitle { 10 | 11 | private final String title; 12 | private final boolean centered; 13 | 14 | private GuiTitle(String title, boolean centered) { 15 | this.title = title; 16 | this.centered = centered; 17 | } 18 | 19 | public String getTitle() { 20 | String title = this.title; 21 | if(this.centered){ 22 | StringBuilder result = new StringBuilder(); 23 | int spaces = (27 - SpigotPlugin.i.getSuperUtils().removeColor(title).length()); 24 | 25 | for (int i = 0; i < spaces; i++) { 26 | result.append(" "); 27 | } 28 | 29 | title = result.append(title).toString(); 30 | } 31 | 32 | return SpigotPlugin.i.getSuperUtils().color(title); 33 | } 34 | 35 | /** 36 | * Creates a new GuiTitle with the given title 37 | * @param title The title of the GuiTitle 38 | * @param centered If the title should be centered 39 | * @return A new GuiTitle 40 | */ 41 | public static GuiTitle of(String title, boolean centered) { 42 | return new GuiTitle(title, centered); 43 | } 44 | 45 | /** 46 | * Creates a new GuiTitle with the given title without being centered. See {@link #of(String, boolean)} 47 | * @param title The title of the GuiTitle 48 | * @return A new GuiTitle 49 | */ 50 | public static GuiTitle of(String title) { 51 | return new GuiTitle(title, false); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/gui/precreated/ConfirmationGui.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.gui.precreated; 2 | 3 | import com.cryptomorin.xseries.XMaterial; 4 | 5 | import org.bukkit.entity.Player; 6 | 7 | import xyz.theprogramsrc.supercoreapi.global.translations.Base; 8 | import xyz.theprogramsrc.supercoreapi.spigot.gui.Gui; 9 | import xyz.theprogramsrc.supercoreapi.spigot.gui.objets.*; 10 | import xyz.theprogramsrc.supercoreapi.spigot.items.SimpleItem; 11 | 12 | public abstract class ConfirmationGui extends Gui{ 13 | 14 | public ConfirmationGui(Player player, boolean automaticallyOpen){ 15 | super(player, automaticallyOpen); 16 | } 17 | 18 | public ConfirmationGui(Player player) { 19 | super(player); 20 | } 21 | 22 | @Override 23 | public GuiRows getRows() { 24 | return GuiRows.THREE; 25 | } 26 | 27 | @Override 28 | public void onBuild(GuiModel model) { 29 | model.setButton(12, new GuiEntry(new SimpleItem(XMaterial.EMERALD_BLOCK).setDisplayName(Base.CONFIRM.toString()), this::onConfirm)); 30 | model.setButton(14, new GuiEntry(new SimpleItem(XMaterial.REDSTONE_BLOCK).setDisplayName(Base.DECLINE.toString()), this::onDecline)); 31 | 32 | } 33 | 34 | public abstract void onConfirm(GuiAction action); 35 | 36 | public abstract void onDecline(GuiAction action); 37 | 38 | public abstract void onBack(GuiAction action); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/gui/precreated/MaterialBrowser.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.gui.precreated; 2 | 3 | import java.util.Arrays; 4 | 5 | import com.cryptomorin.xseries.XMaterial; 6 | 7 | import org.bukkit.Bukkit; 8 | import org.bukkit.entity.Player; 9 | import org.bukkit.inventory.Inventory; 10 | 11 | import xyz.theprogramsrc.supercoreapi.global.translations.Base; 12 | import xyz.theprogramsrc.supercoreapi.global.utils.Utils; 13 | import xyz.theprogramsrc.supercoreapi.spigot.gui.BrowserGui; 14 | import xyz.theprogramsrc.supercoreapi.spigot.gui.objets.GuiAction; 15 | import xyz.theprogramsrc.supercoreapi.spigot.gui.objets.GuiEntry; 16 | import xyz.theprogramsrc.supercoreapi.spigot.items.SimpleItem; 17 | 18 | public abstract class MaterialBrowser extends BrowserGui{ 19 | 20 | public MaterialBrowser(Player player, boolean automaticallyOpen) { 21 | super(player, automaticallyOpen); 22 | } 23 | 24 | public MaterialBrowser(Player player) { 25 | super(player); 26 | } 27 | 28 | @Override 29 | public GuiEntry getEntry(XMaterial obj) { 30 | SimpleItem item = new SimpleItem(obj) 31 | .setDisplayName("&a" + Base.MATERIAL_SELECTOR_ITEM_NAME) 32 | .setLore( 33 | "&7", 34 | "&7" + Base.MATERIAL_SELECTOR_ITEM_DESCRIPTION 35 | ).addPlaceholder("{Material}", Utils.getEnumName(obj)); 36 | return new GuiEntry(item, a-> this.onSelect(a, obj)); 37 | } 38 | 39 | @Override 40 | public String[] getSearchTags(XMaterial obj) { 41 | return Arrays.stream(obj.name().split("_")).map(s-> s.toLowerCase()).toArray(String[]::new); 42 | } 43 | 44 | @Override 45 | public XMaterial[] getObjects() { 46 | Inventory inventory = Bukkit.createInventory(null, 9); 47 | return Arrays.stream(XMaterial.values()).filter(XMaterial::isSupported).filter(m-> m.parseMaterial() != null).filter(m->{ 48 | inventory.setItem(4, m.parseItem()); 49 | if(inventory.getItem(4) != null){ 50 | inventory.clear(); 51 | return true; 52 | } 53 | return false; 54 | }).toArray(XMaterial[]::new); 55 | } 56 | 57 | public abstract void onSelect(GuiAction action, XMaterial material); 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/gui/precreated/settings/CustomSettingPane.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.gui.precreated.settings; 2 | 3 | import java.util.LinkedList; 4 | 5 | import xyz.theprogramsrc.supercoreapi.spigot.gui.objets.GuiEntry; 6 | 7 | public abstract class CustomSettingPane extends SettingPane { 8 | 9 | public abstract GuiEntry getEntry(OBJ obj); 10 | 11 | public abstract OBJ[] getObjects(); 12 | 13 | @Override 14 | public GuiEntry[] getButtons() { 15 | LinkedList list = new LinkedList<>(); 16 | for(OBJ obj : getObjects()) { 17 | list.add(getEntry(obj)); 18 | } 19 | return list.toArray(new GuiEntry[list.size()]); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/gui/precreated/settings/SettingPane.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.gui.precreated.settings; 2 | 3 | import xyz.theprogramsrc.supercoreapi.spigot.SpigotModule; 4 | import xyz.theprogramsrc.supercoreapi.spigot.gui.objets.GuiEntry; 5 | import xyz.theprogramsrc.supercoreapi.spigot.gui.objets.GuiRows; 6 | import xyz.theprogramsrc.supercoreapi.spigot.items.SimpleItem; 7 | 8 | public abstract class SettingPane extends SpigotModule { 9 | 10 | /** 11 | * Gets the name to display in the setting title 12 | * @return the name to show in the title 13 | */ 14 | public abstract String getDisplayName(); 15 | 16 | /** 17 | * Gets the item to display in the setting selector gui 18 | * @return the item to display 19 | */ 20 | public abstract SimpleItem getDisplayItem(); 21 | 22 | /** 23 | * Gets the available buttons to show in the gui 24 | * @return the available buttons to show 25 | */ 26 | public abstract GuiEntry[] getButtons(); 27 | 28 | /** 29 | * If this is true when a container slot is empty this will 30 | * show a white stained glass pane, otherwise the slot will 31 | * be empty. 32 | * @return true to show item in an empty slot container, false to leave empty 33 | */ 34 | public boolean showItemsForEmpty(){ 35 | return false; 36 | } 37 | 38 | public GuiRows getRows(){ 39 | return GuiRows.SIX; 40 | } 41 | 42 | /** 43 | * Available slots to use in the Setting pane 44 | * @return the available slots to use in the setting pane 45 | */ 46 | public int[] getContainerSlots(){ 47 | return new int[]{ 48 | 19, 20, 21, 22, 23, 24, 25, 49 | 28, 29, 30, 31, 32, 33, 34, 50 | 37, 38, 39, 40, 41, 42, 43, 51 | }; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/gui/precreated/settings/SettingsGui.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.gui.precreated.settings; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import xyz.theprogramsrc.supercoreapi.global.translations.Base; 6 | import xyz.theprogramsrc.supercoreapi.spigot.gui.Gui; 7 | import xyz.theprogramsrc.supercoreapi.spigot.gui.objets.GuiAction; 8 | import xyz.theprogramsrc.supercoreapi.spigot.gui.objets.GuiEntry; 9 | import xyz.theprogramsrc.supercoreapi.spigot.gui.objets.GuiModel; 10 | import xyz.theprogramsrc.supercoreapi.spigot.gui.objets.GuiRows; 11 | import xyz.theprogramsrc.supercoreapi.spigot.gui.objets.GuiTitle; 12 | 13 | public abstract class SettingsGui extends Gui{ 14 | 15 | private final int[] containerSlots = { 16 | 19, 20, 21, 22, 23, 24, 25, 17 | 28, 29, 30, 31, 32, 33, 34, 18 | 37, 38, 39, 40, 41, 42, 43, 19 | }; 20 | private int current; 21 | private SettingPane[] settingPanes; 22 | 23 | public SettingsGui(Player player){ 24 | super(player, false); 25 | this.current = -1; 26 | this.settingPanes = this.getSettingPanes(); 27 | this.open(); 28 | } 29 | 30 | @Override 31 | public void open() { 32 | this.settingPanes = this.getSettingPanes(); 33 | if(this.settingPanes == null) 34 | this.settingPanes = new SettingPane[0]; 35 | super.open(); 36 | } 37 | 38 | @Override 39 | public GuiRows getRows() { 40 | if(this.current == -1){ 41 | return GuiRows.SIX; 42 | } 43 | 44 | SettingPane settingPane = this.settingPanes[this.current]; 45 | return settingPane.getRows() != null ? settingPane.getRows() : GuiRows.SIX; 46 | } 47 | 48 | @Override 49 | public GuiTitle getTitle() { 50 | String result; 51 | if(this.current != -1){ 52 | SettingPane settingPane = this.settingPanes[this.current]; 53 | result = "&c" + Base.SETTING_PANE_GUI_TITLE.options().placeholder("{Setting}", settingPane.getDisplayName()).get(); 54 | }else{ 55 | result = "&c" + Base.SETTINGS_GUI_TITLE; 56 | } 57 | 58 | return GuiTitle.of(result); 59 | } 60 | 61 | @Override 62 | public void onBuild(GuiModel model) { 63 | model.clearButtons(); 64 | if(this.current == -1){ 65 | model.setButton(0, new GuiEntry(this.getPreloadedItems().getBackItem(), this::onBack)); 66 | for(int i = 0; i < this.containerSlots.length; i++){ 67 | int slot = this.containerSlots[i]; 68 | if(i < this.settingPanes.length){ 69 | int newCurrent = i; 70 | model.setButton(slot, new GuiEntry(this.settingPanes[i].getDisplayItem(), a -> { 71 | this.current = newCurrent; 72 | this.open(); 73 | })); 74 | }else{ 75 | model.setButton(slot, new GuiEntry(this.getPreloadedItems().emptyItem())); 76 | } 77 | } 78 | }else{ 79 | SettingPane pane = this.settingPanes[current]; 80 | int[] paneContainerSlots = pane.getContainerSlots(); 81 | GuiEntry[] paneEntries = pane.getButtons(); 82 | for(int i = 0; i < paneContainerSlots.length; i++){ 83 | int slot = paneContainerSlots[i]; 84 | if(i < paneEntries.length){ 85 | model.setButton(slot, paneEntries[i]); 86 | }else{ 87 | if(pane.showItemsForEmpty()){ 88 | model.setButton(slot, new GuiEntry(this.getPreloadedItems().emptyItem())); 89 | } 90 | } 91 | } 92 | 93 | model.setButton(0, new GuiEntry(this.getPreloadedItems().getBackItem(), a -> { 94 | this.current = -1; 95 | this.open(); 96 | })); 97 | } 98 | } 99 | 100 | public abstract SettingPane[] getSettingPanes(); 101 | 102 | public abstract void onBack(GuiAction action); 103 | 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/gui/precreated/settings/precreated/GeneralConfigurationSettingPane.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.gui.precreated.settings.precreated; 2 | 3 | import com.cryptomorin.xseries.XMaterial; 4 | 5 | import xyz.theprogramsrc.supercoreapi.global.translations.Base; 6 | import xyz.theprogramsrc.supercoreapi.spigot.dialog.Dialog; 7 | import xyz.theprogramsrc.supercoreapi.spigot.gui.objets.GuiEntry; 8 | import xyz.theprogramsrc.supercoreapi.spigot.gui.objets.GuiRows; 9 | import xyz.theprogramsrc.supercoreapi.spigot.gui.precreated.settings.SettingPane; 10 | import xyz.theprogramsrc.supercoreapi.spigot.items.SimpleItem; 11 | 12 | public class GeneralConfigurationSettingPane extends SettingPane { 13 | 14 | @Override 15 | public String getDisplayName() { 16 | return Base.GENERAL.toString(); 17 | } 18 | 19 | @Override 20 | public GuiRows getRows(){ 21 | return GuiRows.THREE; 22 | } 23 | 24 | @Override 25 | public SimpleItem getDisplayItem() { 26 | return new SimpleItem(XMaterial.COMMAND_BLOCK_MINECART) 27 | .setDisplayName("&a" + Base.SETTINGS_GENERAL_NAME) 28 | .setLore( 29 | "&7", 30 | "&7" + Base.SETTINGS_GENERAL_DESCRIPTION 31 | ); 32 | } 33 | 34 | @Override 35 | public GuiEntry[] getButtons() { 36 | return new GuiEntry[]{ 37 | this.getChangePrefixButton() 38 | }; 39 | } 40 | 41 | @Override 42 | public int[] getContainerSlots() { 43 | return new int[]{13}; 44 | } 45 | 46 | private GuiEntry getChangePrefixButton(){ 47 | SimpleItem item = new SimpleItem(XMaterial.NAME_TAG) 48 | .setDisplayName("&a" + Base.GENERAL_SET_PREFIX_NAME) 49 | .setLore( 50 | "&7", 51 | "&7" + Base.GENERAL_SET_PREFIX_DESCRIPTION 52 | ).addPlaceholder("{Prefix}", "&r" + this.getSettings().getPrefix() + "&r"); 53 | return new GuiEntry(item, a-> new Dialog(a.player){ 54 | @Override 55 | public String getTitle() { 56 | return "&9" + Base.DIALOG_CHANGE_PREFIX_TITLE; 57 | } 58 | 59 | @Override 60 | public String getSubtitle() { 61 | return "&7" + Base.DIALOG_CHANGE_PREFIX_SUBTITLE; 62 | } 63 | 64 | @Override 65 | public String getActionbar() { 66 | return "&a" + Base.DIALOG_CHANGE_PREFIX_ACTIONBAR; 67 | } 68 | 69 | @Override 70 | public boolean onResult(String playerInput) { 71 | this.getSettings().setPrefix(playerInput); 72 | a.gui.open(); 73 | return true; 74 | } 75 | }.addPlaceholder("{Prefix}", "&r"+this.getSettings().getPrefix()+"&r")); 76 | } 77 | } -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/gui/precreated/settings/precreated/LanguageSelectionSettingPane.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.gui.precreated.settings.precreated; 2 | 3 | import com.cryptomorin.xseries.XMaterial; 4 | 5 | import xyz.theprogramsrc.supercoreapi.global.translations.Base; 6 | import xyz.theprogramsrc.supercoreapi.spigot.gui.objets.GuiEntry; 7 | import xyz.theprogramsrc.supercoreapi.spigot.gui.precreated.settings.CustomSettingPane; 8 | import xyz.theprogramsrc.supercoreapi.spigot.items.SimpleItem; 9 | 10 | public class LanguageSelectionSettingPane extends CustomSettingPane { 11 | 12 | @Override 13 | public String getDisplayName() { 14 | return Base.LANGUAGES.toString(); 15 | } 16 | 17 | @Override 18 | public SimpleItem getDisplayItem() { 19 | return new SimpleItem(XMaterial.BOOKSHELF) 20 | .setDisplayName("&a" + Base.LANGUAGE_SELECTOR_NAME) 21 | .setLore( 22 | "&7", 23 | "&7" + Base.LANGUAGE_SELECTOR_DESCRIPTION 24 | ); 25 | } 26 | 27 | @Override 28 | public GuiEntry getEntry(String language) { 29 | boolean selected = this.getSettings().getLanguage().equals(language); 30 | SimpleItem item = new SimpleItem(XMaterial.BOOK) 31 | .setDisplayName("&a" + this.plugin.getTranslationManager().translate("Display", language)) 32 | .setLore( 33 | "&7", 34 | "&7" + (selected ? Base.LANGUAGE_SELECTED_DESCRIPTION : Base.LANGUAGE_SELECT_DESCRIPTION) 35 | ).addPlaceholder("{Language}", this.plugin.getTranslationManager().translate("Display", language)); 36 | return new GuiEntry(item, a -> { 37 | this.getSettings().setLanguage(language); 38 | a.gui.open(); 39 | }); 40 | } 41 | 42 | @Override 43 | public String[] getObjects() { 44 | return this.spigotPlugin.getTranslationManager().getTranslations(); 45 | } 46 | 47 | @Override 48 | public boolean showItemsForEmpty() { 49 | return true; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/guis/GUIButton.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.guis; 2 | 3 | import org.bukkit.inventory.ItemStack; 4 | 5 | import xyz.theprogramsrc.supercoreapi.spigot.guis.action.Action; 6 | import xyz.theprogramsrc.supercoreapi.spigot.items.SimpleItem; 7 | 8 | /** 9 | * Representation of a GUI Button 10 | * @deprecated As of version 5.2.0 the GUI system has been replaced with {@link xyz.theprogramsrc.supercoreapi.spigot.gui.Gui}. 11 | */ 12 | @Deprecated public class GUIButton { 13 | 14 | private int slot; 15 | private final ItemStack itemStack; 16 | private Action action; 17 | 18 | /** 19 | * Constructor of a GUI Button 20 | * @param slot The slot where should be placed (See https://i.theprogramsrc.xyz/files/DoubleChest-slots.png) 21 | * @param itemStack The item to place {@link SimpleItem} 22 | * @param action The action to execute when is clicked 23 | */ 24 | public GUIButton(int slot, ItemStack itemStack, Action action){ 25 | this.slot = slot; 26 | this.itemStack = itemStack; 27 | this.action = action; 28 | } 29 | 30 | /** 31 | * Constructor of a GUI Button 32 | * @param slot The slot where should be placed (See https://i.theprogramsrc.xyz/files/DoubleChest-slots.png) 33 | * @param simpleItem The item to place 34 | * @param action The action to execute when is clicked 35 | */ 36 | public GUIButton(int slot, SimpleItem simpleItem, Action action){ 37 | this(slot, simpleItem.build(), action); 38 | } 39 | 40 | /** 41 | * Constructor of a GUI Button 42 | * @param slot The slot where should be placed (See https://i.theprogramsrc.xyz/files/DoubleChest-slots.png) 43 | * @param itemStack The item to place {@link SimpleItem} 44 | */ 45 | public GUIButton(int slot, ItemStack itemStack) { 46 | this(slot, itemStack, null); 47 | } 48 | 49 | /** 50 | * Constructor of a GUI Button 51 | * @param slot The slot where should be placed (See https://i.theprogramsrc.xyz/files/DoubleChest-slots.png) 52 | * @param simpleItem The item to place 53 | */ 54 | public GUIButton(int slot, SimpleItem simpleItem){ 55 | this(slot, simpleItem.build()); 56 | } 57 | 58 | /** 59 | * Constructor of a GUI Button 60 | * @param itemStack The item to place {@link SimpleItem} 61 | */ 62 | public GUIButton(ItemStack itemStack, Action action){ 63 | this(-1, itemStack, action); 64 | } 65 | 66 | /** 67 | * Constructor of a GUI Button 68 | * @param simpleItem The item to place 69 | */ 70 | public GUIButton(SimpleItem simpleItem, Action action){ 71 | this(simpleItem.build(), action); 72 | } 73 | 74 | /** 75 | * Constructor of a GUI Button 76 | * @param itemStack The item to place {@link SimpleItem} 77 | */ 78 | public GUIButton(ItemStack itemStack){ 79 | this(-1, itemStack); 80 | } 81 | 82 | /** 83 | * Constructor of a GUI Button 84 | * @param simpleItem The item to place 85 | */ 86 | public GUIButton(SimpleItem simpleItem){ 87 | this(simpleItem.build()); 88 | } 89 | 90 | /** 91 | * Sets the action to trigger when the button is clicked 92 | * @param action the action 93 | * @return this GUIButton 94 | */ 95 | public GUIButton setAction(Action action) { 96 | this.action = action; 97 | return this; 98 | } 99 | 100 | /** 101 | * Sets the slot of this button 102 | * @param slot the slot 103 | * @return this GUIButton 104 | */ 105 | public GUIButton setSlot(int slot){ 106 | this.slot = slot; 107 | return this; 108 | } 109 | 110 | /** 111 | * Gets the action to trigger when the button is clicked 112 | * @return the action 113 | */ 114 | public Action getAction() { 115 | return action; 116 | } 117 | 118 | /** 119 | * Gets the item to place 120 | * @return the item 121 | */ 122 | public ItemStack getItemStack() { 123 | return itemStack; 124 | } 125 | 126 | /** 127 | * Gets the slot where should be placed the button 128 | * @return the slot 129 | */ 130 | public int getSlot() { 131 | return slot; 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/guis/action/Action.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.guis.action; 2 | 3 | /** 4 | * Representation of an Action executed while a GUI Button is clicked 5 | * @deprecated As of version 5.2.0 the GUI system has been replaced with {@link xyz.theprogramsrc.supercoreapi.spigot.gui.Gui}. 6 | */ 7 | @Deprecated public interface Action { 8 | 9 | void onClick(ClickAction clickAction); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/guis/action/ClickAction.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.guis.action; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import xyz.theprogramsrc.supercoreapi.spigot.SpigotPlugin; 6 | import xyz.theprogramsrc.supercoreapi.spigot.guis.GUI; 7 | import xyz.theprogramsrc.supercoreapi.spigot.guis.GUIButton; 8 | 9 | /** 10 | * The ClickAction of a GUI 11 | * @deprecated As of version 5.2.0 the GUI system has been replaced with {@link xyz.theprogramsrc.supercoreapi.spigot.gui.Gui}. 12 | */ 13 | @Deprecated public class ClickAction { 14 | 15 | private final GUI gui; 16 | private final Player player; 17 | private final ClickType clickType; 18 | private final GUIButton button; 19 | private final int slot; 20 | 21 | public ClickAction(GUI gui, Player player, GUIButton button, ClickType clickType, int slot) { 22 | this.gui = gui; 23 | this.player = player; 24 | this.clickType = clickType; 25 | this.button = button; 26 | this.slot = slot; 27 | } 28 | 29 | public GUI getGui() { 30 | return gui; 31 | } 32 | 33 | public Player getPlayer() { 34 | return player; 35 | } 36 | 37 | public ClickType getAction() { 38 | return clickType; 39 | } 40 | 41 | public GUIButton getButton() { 42 | return button; 43 | } 44 | 45 | public int getSlot() { 46 | return slot; 47 | } 48 | 49 | public SpigotPlugin getPlugin(){ 50 | return ((SpigotPlugin)this.gui.getPlugin()); 51 | } 52 | 53 | /** 54 | * Opens the GUI 55 | */ 56 | public void openGUI() { 57 | this.getGui().open(); 58 | } 59 | 60 | /** 61 | * Closed the GUI 62 | */ 63 | public void closeGUI(){ 64 | this.getGui().close(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/guis/action/ClickType.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.guis.action; 2 | 3 | import org.bukkit.event.inventory.InventoryClickEvent; 4 | 5 | /** 6 | * Representation of the ClickType 7 | * @deprecated As of version 5.2.0 the GUI system has been replaced with {@link xyz.theprogramsrc.supercoreapi.spigot.gui.Gui}. 8 | */ 9 | @Deprecated public enum ClickType { 10 | 11 | LEFT_CLICK, 12 | SHIFT_LEFT, 13 | MIDDLE_CLICK, 14 | RIGHT_CLICK, 15 | SHIFT_RIGHT, 16 | Q, 17 | CTRL_Q, 18 | DOUBLE 19 | 20 | ; 21 | 22 | 23 | public static ClickType fromEvent(InventoryClickEvent event){ 24 | switch (event.getClick()){ 25 | default: 26 | return LEFT_CLICK; 27 | case RIGHT: 28 | return RIGHT_CLICK; 29 | case DROP: 30 | return Q; 31 | case SHIFT_LEFT: 32 | return SHIFT_LEFT; 33 | case MIDDLE: 34 | return MIDDLE_CLICK; 35 | case SHIFT_RIGHT: 36 | return SHIFT_RIGHT; 37 | case CONTROL_DROP: 38 | return CTRL_Q; 39 | case DOUBLE_CLICK: 40 | return DOUBLE; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/guis/events/GUIClickEvent.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.guis.events; 2 | 3 | import xyz.theprogramsrc.supercoreapi.spigot.guis.GUI; 4 | import xyz.theprogramsrc.supercoreapi.spigot.guis.GUIButton; 5 | 6 | /** 7 | * Executed when a player click a slot with item 8 | * @deprecated As of version 5.2.0 the GUI system has been replaced with {@link xyz.theprogramsrc.supercoreapi.spigot.gui.Gui}. 9 | */ 10 | @Deprecated public class GUIClickEvent extends GUIEvent { 11 | 12 | private final GUIButton button; 13 | private final int slot; 14 | 15 | public GUIClickEvent(GUI gui, GUIButton button, int slot) { 16 | super(gui); 17 | this.button = button; 18 | this.slot = slot; 19 | } 20 | 21 | public GUIButton getButton() { 22 | return button; 23 | } 24 | 25 | public int getSlot() { 26 | return slot; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/guis/events/GUICloseEvent.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.guis.events; 2 | 3 | import xyz.theprogramsrc.supercoreapi.spigot.guis.GUI; 4 | 5 | /** 6 | * @deprecated As of version 5.2.0 the GUI system has been replaced with {@link xyz.theprogramsrc.supercoreapi.spigot.gui.Gui}. 7 | */ 8 | 9 | @Deprecated public class GUICloseEvent extends GUIEvent{ 10 | 11 | private boolean cancelled; 12 | 13 | public GUICloseEvent(GUI gui) { 14 | super(gui); 15 | this.cancelled = false; 16 | } 17 | 18 | public boolean isCancelled() { 19 | return cancelled; 20 | } 21 | 22 | public void setCancelled(boolean cancelled) { 23 | this.cancelled = cancelled; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/guis/events/GUIEmptyClickEvent.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.guis.events; 2 | 3 | 4 | import xyz.theprogramsrc.supercoreapi.spigot.guis.GUI; 5 | 6 | /** 7 | * Executed when a player clicks on a empty slot 8 | * @deprecated As of version 5.2.0 the GUI system has been replaced with {@link xyz.theprogramsrc.supercoreapi.spigot.gui.Gui}. 9 | */ 10 | @Deprecated public class GUIEmptyClickEvent extends GUIEvent { 11 | 12 | private final int slot; 13 | 14 | public GUIEmptyClickEvent(GUI gui, int slot) { 15 | super(gui); 16 | this.slot = slot; 17 | } 18 | 19 | public int getSlot() { 20 | return slot; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/guis/events/GUIEvent.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.guis.events; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import xyz.theprogramsrc.supercoreapi.spigot.guis.GUI; 6 | 7 | /** 8 | * @deprecated As of version 5.2.0 the GUI system has been replaced with {@link xyz.theprogramsrc.supercoreapi.spigot.gui.Gui}. 9 | */ 10 | @Deprecated public class GUIEvent { 11 | 12 | private final GUI gui; 13 | 14 | public GUIEvent(GUI gui){ 15 | this.gui = gui; 16 | } 17 | 18 | public GUI getGUI() { 19 | return gui; 20 | } 21 | 22 | public Player getPlayer(){ 23 | return this.getGUI().getPlayer(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/guis/events/GUIOpenEvent.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.guis.events; 2 | 3 | import xyz.theprogramsrc.supercoreapi.spigot.guis.GUI; 4 | 5 | /** 6 | * @deprecated As of version 5.2.0 the GUI system has been replaced with {@link xyz.theprogramsrc.supercoreapi.spigot.gui.Gui}. 7 | */ 8 | @Deprecated public class GUIOpenEvent extends GUIEvent{ 9 | 10 | public GUIOpenEvent(GUI gui) { 11 | super(gui); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/guis/events/GUIOutsideClickEvent.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.guis.events; 2 | 3 | import xyz.theprogramsrc.supercoreapi.spigot.guis.GUI; 4 | 5 | /** 6 | * Executed when a player clicks outside the GUI 7 | * @deprecated As of version 5.2.0 the GUI system has been replaced with {@link xyz.theprogramsrc.supercoreapi.spigot.gui.Gui}. 8 | */ 9 | @Deprecated public class GUIOutsideClickEvent extends GUIEvent { 10 | private boolean canDrop; 11 | 12 | public GUIOutsideClickEvent(GUI gui) { 13 | super(gui); 14 | } 15 | 16 | public void setCanDrop(boolean canDrop){ 17 | this.canDrop = canDrop; 18 | } 19 | 20 | public boolean canDrop() { 21 | return canDrop; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/guis/events/GUIUpdateEvent.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.guis.events; 2 | 3 | import xyz.theprogramsrc.supercoreapi.spigot.guis.GUI; 4 | 5 | /** 6 | * @deprecated As of version 5.2.0 the GUI system has been replaced with {@link xyz.theprogramsrc.supercoreapi.spigot.gui.Gui}. 7 | */ 8 | @Deprecated public class GUIUpdateEvent extends GUIEvent{ 9 | 10 | public GUIUpdateEvent(GUI gui) { 11 | super(gui); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/guis/objects/GUIRows.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.guis.objects; 2 | 3 | /** 4 | * Representation of the rows of a GUI 5 | * @deprecated As of version 5.2.0 the GUI system has been replaced with {@link xyz.theprogramsrc.supercoreapi.spigot.gui.Gui}. 6 | */ 7 | @Deprecated public enum GUIRows { 8 | ONE(9), 9 | TWO(18), 10 | THREE(27), 11 | FOUR(36), 12 | FIVE(45), 13 | SIX(54); 14 | 15 | private final int size; 16 | 17 | GUIRows(int size){ 18 | this.size = size; 19 | } 20 | 21 | public int getSize() { 22 | return size; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/guis/precreated/ConfirmationGUI.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.guis.precreated; 2 | 3 | import com.cryptomorin.xseries.XMaterial; 4 | 5 | import org.bukkit.entity.Player; 6 | 7 | import xyz.theprogramsrc.supercoreapi.global.translations.Base; 8 | import xyz.theprogramsrc.supercoreapi.spigot.guis.GUI; 9 | import xyz.theprogramsrc.supercoreapi.spigot.guis.GUIButton; 10 | import xyz.theprogramsrc.supercoreapi.spigot.guis.action.ClickAction; 11 | import xyz.theprogramsrc.supercoreapi.spigot.guis.objects.GUIRows; 12 | import xyz.theprogramsrc.supercoreapi.spigot.items.SimpleItem; 13 | 14 | /** 15 | * @deprecated As of version 5.2.0 the GUI system has been replaced with {@link xyz.theprogramsrc.supercoreapi.spigot.gui.Gui}. 16 | */ 17 | @Deprecated public abstract class ConfirmationGUI extends GUI { 18 | 19 | public ConfirmationGUI(Player player) { 20 | super(player); 21 | } 22 | 23 | @Override 24 | protected GUIRows getRows() { 25 | return GUIRows.THREE; 26 | } 27 | 28 | @Override 29 | protected GUIButton[] getButtons() { 30 | return new GUIButton[]{ 31 | new GUIButton(12, new SimpleItem(XMaterial.EMERALD_BLOCK).setDisplayName(Base.CONFIRM.toString()), this::onConfirm), 32 | new GUIButton(14, new SimpleItem(XMaterial.REDSTONE_BLOCK).setDisplayName(Base.DECLINE.toString()), this::onDecline), 33 | new GUIButton(26, this.getPreloadedItems().getBackItem(), this::onBack) 34 | }; 35 | } 36 | 37 | public abstract void onConfirm(ClickAction clickAction); 38 | 39 | public abstract void onDecline(ClickAction clickAction); 40 | 41 | public abstract void onBack(ClickAction clickAction); 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/guis/precreated/MaterialBrowser.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.guis.precreated; 2 | 3 | import java.util.Arrays; 4 | 5 | import com.cryptomorin.xseries.XMaterial; 6 | 7 | import org.bukkit.Bukkit; 8 | import org.bukkit.entity.Player; 9 | import org.bukkit.inventory.Inventory; 10 | 11 | import xyz.theprogramsrc.supercoreapi.global.translations.Base; 12 | import xyz.theprogramsrc.supercoreapi.global.utils.Utils; 13 | import xyz.theprogramsrc.supercoreapi.spigot.guis.BrowserGUI; 14 | import xyz.theprogramsrc.supercoreapi.spigot.guis.GUIButton; 15 | import xyz.theprogramsrc.supercoreapi.spigot.guis.action.ClickAction; 16 | import xyz.theprogramsrc.supercoreapi.spigot.items.SimpleItem; 17 | 18 | /** 19 | * @deprecated As of version 5.2.0 the GUI system has been replaced with {@link xyz.theprogramsrc.supercoreapi.spigot.gui.Gui}. 20 | */ 21 | @Deprecated public abstract class MaterialBrowser extends BrowserGUI { 22 | 23 | public MaterialBrowser(Player player) { 24 | super(player); 25 | } 26 | 27 | @Override 28 | public XMaterial[] getObjects() { 29 | Inventory inventory = Bukkit.createInventory(null, 9); 30 | return Arrays.stream(XMaterial.values()).filter(XMaterial::isSupported).filter(m-> m.parseMaterial() != null).filter(m->{ 31 | inventory.setItem(4, m.parseItem()); 32 | if(inventory.getItem(4) != null){ 33 | inventory.clear(); 34 | return true; 35 | } 36 | return false; 37 | }).toArray(XMaterial[]::new); 38 | } 39 | 40 | @Override 41 | public GUIButton getButton(XMaterial xMaterial) { 42 | SimpleItem item = new SimpleItem(xMaterial) 43 | .setDisplayName("&a" + Base.MATERIAL_SELECTOR_ITEM_NAME) 44 | .setLore( 45 | "&7", 46 | "&7" + Base.MATERIAL_SELECTOR_ITEM_DESCRIPTION 47 | ).addPlaceholder("{Material}", Utils.getEnumName(xMaterial)); 48 | return new GUIButton(item).setAction(a-> this.onSelect(a, xMaterial)); 49 | } 50 | 51 | @Override 52 | public void onBack(ClickAction clickAction) { 53 | this.close(); 54 | } 55 | 56 | @Override 57 | protected String getTitle() { 58 | return Base.MATERIAL_SELECTOR_TITLE.toString(); 59 | } 60 | 61 | public abstract void onSelect(ClickAction clickAction, XMaterial xMaterial); 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/guis/precreated/settings/CustomSettingPane.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.guis.precreated.settings; 2 | 3 | import java.util.LinkedList; 4 | 5 | import xyz.theprogramsrc.supercoreapi.spigot.guis.GUIButton; 6 | 7 | /** 8 | * @deprecated As of version 5.2.0 the GUI system has been replaced with {@link xyz.theprogramsrc.supercoreapi.spigot.gui.Gui}. 9 | */ 10 | @Deprecated public abstract class CustomSettingPane extends SettingPane { 11 | 12 | public abstract GUIButton getButton(OBJ obj); 13 | 14 | public abstract OBJ[] getObjects(); 15 | 16 | @Override 17 | public GUIButton[] getButtons() { 18 | LinkedList buttons = new LinkedList<>(); 19 | for(OBJ obj : this.getObjects()){ 20 | buttons.add(this.getButton(obj)); 21 | } 22 | return buttons.toArray(new GUIButton[0]); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/guis/precreated/settings/SettingPane.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.guis.precreated.settings; 2 | 3 | import xyz.theprogramsrc.supercoreapi.spigot.SpigotModule; 4 | import xyz.theprogramsrc.supercoreapi.spigot.guis.GUIButton; 5 | import xyz.theprogramsrc.supercoreapi.spigot.guis.objects.GUIRows; 6 | import xyz.theprogramsrc.supercoreapi.spigot.items.SimpleItem; 7 | 8 | /** 9 | * @deprecated As of version 5.2.0 the GUI system has been replaced with {@link xyz.theprogramsrc.supercoreapi.spigot.gui.Gui}. 10 | */ 11 | @Deprecated public abstract class SettingPane extends SpigotModule { 12 | 13 | /** 14 | * Gets the name to display in the setting title 15 | * @return the name to show in the title 16 | */ 17 | public abstract String getDisplayName(); 18 | 19 | /** 20 | * Gets the item to display in the setting selector gui 21 | * @return the item to display 22 | */ 23 | public abstract SimpleItem getDisplayItem(); 24 | 25 | /** 26 | * Gets the available buttons to show in the gui 27 | * @return the available buttons to show 28 | */ 29 | public abstract GUIButton[] getButtons(); 30 | 31 | /** 32 | * If this is true when a container slot is empty this will 33 | * show a white stained glass pane, otherwise the slot will 34 | * be empty. 35 | * @return true to show item in an empty slot container, false to leave empty 36 | */ 37 | public boolean showItemsForEmpty(){ 38 | return false; 39 | } 40 | 41 | public GUIRows getRows(){ 42 | return GUIRows.SIX; 43 | } 44 | 45 | /** 46 | * Available slots to use in the Setting pane 47 | * @return the available slots to use in the setting pane 48 | */ 49 | public int[] getContainerSlots(){ 50 | return new int[]{ 51 | 19, 20, 21, 22, 23, 24, 25, 52 | 28, 29, 30, 31, 32, 33, 34, 53 | 37, 38, 39, 40, 41, 42, 43, 54 | }; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/guis/precreated/settings/SettingsGUI.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.guis.precreated.settings; 2 | 3 | import java.util.LinkedList; 4 | 5 | import org.bukkit.entity.Player; 6 | 7 | import xyz.theprogramsrc.supercoreapi.global.translations.Base; 8 | import xyz.theprogramsrc.supercoreapi.spigot.guis.GUI; 9 | import xyz.theprogramsrc.supercoreapi.spigot.guis.GUIButton; 10 | import xyz.theprogramsrc.supercoreapi.spigot.guis.action.ClickAction; 11 | import xyz.theprogramsrc.supercoreapi.spigot.guis.objects.GUIRows; 12 | 13 | /** 14 | * @deprecated As of version 5.2.0 the GUI system has been replaced with {@link xyz.theprogramsrc.supercoreapi.spigot.gui.Gui}. 15 | */ 16 | @Deprecated public abstract class SettingsGUI extends GUI { 17 | 18 | private final int[] containerSlots = { 19 | 19, 20, 21, 22, 23, 24, 25, 20 | 28, 29, 30, 31, 32, 33, 34, 21 | 37, 38, 39, 40, 41, 42, 43, 22 | }; 23 | private int current; 24 | private SettingPane[] settingPanes; 25 | 26 | public SettingsGUI(Player player) { 27 | super(player); 28 | this.current = -1; 29 | this.settingPanes = this.getSettingPanes(); 30 | this.open(); 31 | } 32 | 33 | @Override 34 | public void open() { 35 | this.settingPanes = this.getSettingPanes(); 36 | if(this.settingPanes == null) 37 | this.settingPanes = new SettingPane[0]; 38 | super.open(); 39 | } 40 | 41 | @Override 42 | protected GUIRows getRows() { 43 | if(this.current == -1){ 44 | return GUIRows.SIX; 45 | } 46 | 47 | SettingPane settingPane = this.settingPanes[this.current]; 48 | return settingPane.getRows() != null ? settingPane.getRows() : GUIRows.SIX; 49 | } 50 | 51 | @Override 52 | protected String getTitle() { 53 | if(this.current != -1){ 54 | SettingPane settingPane = this.settingPanes[this.current]; 55 | return "&c" + Base.SETTING_PANE_GUI_TITLE.options().placeholder("{Setting}", settingPane.getDisplayName()).get(); 56 | } 57 | 58 | return "&c" + Base.SETTINGS_GUI_TITLE; 59 | } 60 | 61 | public abstract SettingPane[] getSettingPanes(); 62 | 63 | @Override 64 | protected GUIButton[] getButtons() { 65 | LinkedList buttons = new LinkedList<>(); 66 | this.clearButtons(); 67 | if(this.current == -1){ 68 | buttons.add(new GUIButton(0, this.getPreloadedItems().getBackItem(), this::onBack)); 69 | 70 | for(int i = 0; i < this.containerSlots.length; ++i){ 71 | int slot = this.containerSlots[i]; 72 | if(i < this.settingPanes.length){ 73 | int finalI = i; 74 | buttons.add(new GUIButton(slot, this.settingPanes[i].getDisplayItem(), a-> { 75 | this.current = finalI; 76 | this.open(); 77 | })); 78 | }else{ 79 | buttons.add(new GUIButton(slot, this.getPreloadedItems().emptyItem())); 80 | } 81 | } 82 | }else{ 83 | SettingPane pane = this.settingPanes[current]; 84 | int[] _containerSlots = pane.getContainerSlots(); 85 | GUIButton[] paneButtons = pane.getButtons(); 86 | for(int i = 0; i < _containerSlots.length; ++i){ 87 | int slot = _containerSlots[i]; 88 | if(i < paneButtons.length){ 89 | buttons.add(paneButtons[i].setSlot(slot)); 90 | }else{ 91 | if(pane.showItemsForEmpty()){ 92 | buttons.add(new GUIButton(slot, this.getPreloadedItems().emptyItem())); 93 | } 94 | } 95 | } 96 | buttons.add(new GUIButton(0, this.getPreloadedItems().getBackItem(), a-> { 97 | this.current = -1; 98 | this.open(); 99 | })); 100 | } 101 | return buttons.toArray(new GUIButton[0]); 102 | } 103 | 104 | public abstract void onBack(ClickAction clickAction); 105 | } 106 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/guis/precreated/settings/precreated/GeneralConfigurationSettingPane.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.guis.precreated.settings.precreated; 2 | 3 | import java.util.LinkedList; 4 | 5 | import com.cryptomorin.xseries.XMaterial; 6 | 7 | import xyz.theprogramsrc.supercoreapi.global.translations.Base; 8 | import xyz.theprogramsrc.supercoreapi.spigot.dialog.Dialog; 9 | import xyz.theprogramsrc.supercoreapi.spigot.guis.GUIButton; 10 | import xyz.theprogramsrc.supercoreapi.spigot.guis.objects.GUIRows; 11 | import xyz.theprogramsrc.supercoreapi.spigot.guis.precreated.settings.SettingPane; 12 | import xyz.theprogramsrc.supercoreapi.spigot.items.SimpleItem; 13 | 14 | /** 15 | * @deprecated As of version 5.2.0 the GUI system has been replaced with {@link xyz.theprogramsrc.supercoreapi.spigot.gui.Gui}. 16 | */ 17 | @Deprecated public class GeneralConfigurationSettingPane extends SettingPane { 18 | 19 | @Override 20 | public String getDisplayName() { 21 | return Base.GENERAL.toString(); 22 | } 23 | 24 | @Override 25 | public SimpleItem getDisplayItem() { 26 | return new SimpleItem(XMaterial.COMMAND_BLOCK_MINECART) 27 | .setDisplayName("&a" + Base.SETTINGS_GENERAL_NAME) 28 | .setLore( 29 | "&7", 30 | "&7" + Base.SETTINGS_GENERAL_DESCRIPTION 31 | ); 32 | } 33 | 34 | @Override 35 | public GUIButton[] getButtons() { 36 | LinkedList buttons = new LinkedList<>(); 37 | buttons.add(this.getChangePrefixButton()); 38 | return buttons.toArray(new GUIButton[0]); 39 | } 40 | 41 | @Override 42 | public int[] getContainerSlots() { 43 | return new int[]{13}; 44 | } 45 | 46 | @Override 47 | public GUIRows getRows() { 48 | return GUIRows.THREE; 49 | } 50 | 51 | private GUIButton getChangePrefixButton(){ 52 | SimpleItem item = new SimpleItem(XMaterial.NAME_TAG) 53 | .setDisplayName("&a" + Base.GENERAL_SET_PREFIX_NAME) 54 | .setLore( 55 | "&7", 56 | "&7" + Base.GENERAL_SET_PREFIX_DESCRIPTION 57 | ).addPlaceholder("{Prefix}", "&r" + this.getSettings().getPrefix() + "&r"); 58 | return new GUIButton(item, a-> new Dialog(a.getPlayer()){ 59 | @Override 60 | public String getTitle() { 61 | return "&9" + Base.DIALOG_CHANGE_PREFIX_TITLE; 62 | } 63 | 64 | @Override 65 | public String getSubtitle() { 66 | return "&7" + Base.DIALOG_CHANGE_PREFIX_SUBTITLE; 67 | } 68 | 69 | @Override 70 | public String getActionbar() { 71 | return "&a" + Base.DIALOG_CHANGE_PREFIX_ACTIONBAR; 72 | } 73 | 74 | @Override 75 | public boolean onResult(String playerInput) { 76 | this.getSettings().setPrefix(playerInput); 77 | a.openGUI(); 78 | return true; 79 | } 80 | }.addPlaceholder("{Prefix}", "&r"+this.getSettings().getPrefix()+"&r")); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/guis/precreated/settings/precreated/LanguageSelectionSettingPane.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.guis.precreated.settings.precreated; 2 | 3 | import com.cryptomorin.xseries.XMaterial; 4 | 5 | import xyz.theprogramsrc.supercoreapi.global.translations.Base; 6 | import xyz.theprogramsrc.supercoreapi.spigot.guis.GUIButton; 7 | import xyz.theprogramsrc.supercoreapi.spigot.guis.precreated.settings.CustomSettingPane; 8 | import xyz.theprogramsrc.supercoreapi.spigot.items.SimpleItem; 9 | 10 | /** 11 | * @deprecated As of version 5.2.0 the GUI system has been replaced with {@link xyz.theprogramsrc.supercoreapi.spigot.gui.Gui}. 12 | */ 13 | @Deprecated public class LanguageSelectionSettingPane extends CustomSettingPane { 14 | 15 | @Override 16 | public String getDisplayName() { 17 | return Base.LANGUAGES.toString(); 18 | } 19 | 20 | @Override 21 | public SimpleItem getDisplayItem() { 22 | return new SimpleItem(XMaterial.BOOKSHELF) 23 | .setDisplayName("&a" + Base.LANGUAGE_SELECTOR_NAME) 24 | .setLore( 25 | "&7", 26 | "&7" + Base.LANGUAGE_SELECTOR_DESCRIPTION 27 | ); 28 | } 29 | 30 | @Override 31 | public GUIButton getButton(String language) { 32 | boolean selected = this.getSettings().getLanguage().equals(language); 33 | SimpleItem item = new SimpleItem(XMaterial.BOOK) 34 | .setDisplayName("&a" + this.plugin.getTranslationManager().translate("Display", language)) 35 | .setLore( 36 | "&7", 37 | "&7" + (selected ? Base.LANGUAGE_SELECTED_DESCRIPTION : Base.LANGUAGE_SELECT_DESCRIPTION) 38 | ).addPlaceholder("{Language}", this.plugin.getTranslationManager().translate("Display", language)); 39 | return new GUIButton(item, a->{ 40 | this.getSettings().setLanguage(language); 41 | this.getSettings().getConfig().load(); 42 | a.openGUI(); 43 | }); 44 | } 45 | 46 | @Override 47 | public String[] getObjects() { 48 | return this.spigotPlugin.getTranslationManager().getTranslations(); 49 | } 50 | 51 | @Override 52 | public boolean showItemsForEmpty() { 53 | return true; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/hologram/Hologram.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.hologram; 2 | 3 | import org.bukkit.Location; 4 | import org.bukkit.entity.ArmorStand; 5 | import org.bukkit.entity.EntityType; 6 | import org.bukkit.event.EventHandler; 7 | import org.bukkit.event.player.PlayerArmorStandManipulateEvent; 8 | import org.bukkit.event.player.PlayerInteractEntityEvent; 9 | import xyz.theprogramsrc.supercoreapi.global.utils.Utils; 10 | import xyz.theprogramsrc.supercoreapi.spigot.SpigotModule; 11 | 12 | import java.util.LinkedList; 13 | 14 | public class Hologram extends SpigotModule { 15 | 16 | private final LinkedList lines; 17 | private final LinkedList armorStands; 18 | private final Location location; 19 | 20 | /** 21 | * Create a new Hologram 22 | * @param location The location 23 | * @param lines The content of the hologram 24 | */ 25 | public Hologram(Location location, LinkedList lines){ 26 | String worldName = location.getWorld() == null ? "Unknown World" : location.getWorld().getName(); 27 | this.debug("Registering Hologram with " + lines.size() + " lines in the world '" + worldName + "'"); 28 | this.location = location; 29 | this.armorStands = new LinkedList<>(); 30 | this.lines = lines; 31 | this.loadHologram(); 32 | } 33 | 34 | /** 35 | * Loads the hologram 36 | */ 37 | public void loadHologram(){ 38 | try{ 39 | for(double i = 0.0; i < this.lines.size(); ++i){ 40 | String line = this.lines.get((int) i); 41 | double y = this.location.getY() - (i / 5); 42 | Location loc = new Location(this.location.getWorld(), this.location.getX(), y, this.location.getZ(), this.location.getYaw(), this.location.getPitch()); 43 | ArmorStand armorStand = ((ArmorStand) Utils.requireNonNull(loc.getWorld()).spawnEntity(loc, EntityType.ARMOR_STAND)); 44 | armorStand.setGravity(false); 45 | armorStand.setArms(false); 46 | armorStand.setBasePlate(false); 47 | armorStand.setSmall(true); 48 | armorStand.setVisible(false); 49 | armorStand.setCustomName(Utils.ct(line)); 50 | armorStand.setCustomNameVisible(true); 51 | this.armorStands.add(armorStand); 52 | } 53 | }catch (Exception ex){ 54 | ex.printStackTrace(); 55 | } 56 | } 57 | 58 | /** 59 | * Unloads the hologram 60 | */ 61 | public void unloadHologram(){ 62 | for(ArmorStand armorStand : this.armorStands){ 63 | armorStand.remove(); 64 | } 65 | } 66 | 67 | /** 68 | * Sets the specified line in the specified index 69 | * @param index the index 70 | * @param text the text to place 71 | */ 72 | public void setLine(int index, String text){ 73 | this.lines.set(index,text); 74 | this.unloadHologram(); 75 | this.loadHologram(); 76 | } 77 | 78 | /** 79 | * Adds a line at the bottom of the hologram 80 | * @param text the text to add 81 | */ 82 | public void addLine(String text){ 83 | this.lines.add(text); 84 | this.unloadHologram(); 85 | this.loadHologram(); 86 | } 87 | 88 | @EventHandler 89 | public void onInteract(PlayerInteractEntityEvent e){ 90 | if(e.getRightClicked() instanceof ArmorStand){ 91 | ArmorStand armorStand = ((ArmorStand) e.getRightClicked()); 92 | if(!armorStand.isVisible()){ 93 | e.setCancelled(true); 94 | } 95 | } 96 | } 97 | 98 | @EventHandler 99 | public void onManipulate(PlayerArmorStandManipulateEvent e){ 100 | if(!e.getRightClicked().isVisible()){ 101 | e.setCancelled(true); 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/items/PreloadedItems.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.items; 2 | 3 | import com.cryptomorin.xseries.XMaterial; 4 | import org.bukkit.enchantments.Enchantment; 5 | import xyz.theprogramsrc.supercoreapi.global.translations.Base; 6 | import xyz.theprogramsrc.supercoreapi.global.utils.Utils; 7 | import xyz.theprogramsrc.supercoreapi.spigot.SpigotModule; 8 | 9 | /** 10 | * Representation of the Pre-Created Items 11 | */ 12 | public class PreloadedItems extends SpigotModule { 13 | 14 | /** 15 | * Common item that represent a back button 16 | * @return the item 17 | */ 18 | public SimpleItem getBackItem(){ 19 | if(Utils.isConnected()){ 20 | return new SimpleItem(Skulls.BACK.asSkinTexture()).setDisplayName(Base.ITEM_BACK_NAME.toString()).setLore(Base.ITEM_BACK_DESCRIPTION.toString()); 21 | }else{ 22 | return new SimpleItem(XMaterial.ARROW).setDisplayName(Base.ITEM_BACK_NAME.toString()).setLore(Base.ITEM_BACK_DESCRIPTION.toString()); 23 | } 24 | } 25 | 26 | /** 27 | * Common item that represent a next page button 28 | * @return the item 29 | */ 30 | public SimpleItem getNextItem(){ 31 | if(Utils.isConnected()){ 32 | return new SimpleItem(Skulls.ARROW_RIGHT.asSkinTexture()).setDisplayName(Base.ITEM_NEXT_NAME.toString()).setLore(Base.ITEM_NEXT_DESCRIPTION.toString()); 33 | }else{ 34 | return new SimpleItem(XMaterial.PAPER).setDisplayName(Base.ITEM_NEXT_NAME.toString()).setLore(Base.ITEM_NEXT_DESCRIPTION.toString()); 35 | } 36 | } 37 | 38 | /** 39 | * Common item that represent a previous page button 40 | * @return the item 41 | */ 42 | public SimpleItem getPreviousItem(){ 43 | if(Utils.isConnected()){ 44 | return new SimpleItem(Skulls.ARROW_LEFT.asSkinTexture()).setDisplayName(Base.ITEM_PREVIOUS_NAME.toString()).setLore(Base.ITEM_PREVIOUS_DESCRIPTION.toString()); 45 | }else{ 46 | return new SimpleItem(XMaterial.PAPER).setDisplayName(Base.ITEM_PREVIOUS_NAME.toString()).setLore(Base.ITEM_PREVIOUS_DESCRIPTION.toString()); 47 | } 48 | } 49 | 50 | /** 51 | * Common item that represent a Search button 52 | * @return the item 53 | */ 54 | public SimpleItem getSearchItem(){ 55 | return new SimpleItem(XMaterial.BOOKSHELF).setDisplayName(Base.ITEM_SEARCH_NAME.toString()).setLore(Base.ITEM_SEARCH_DESCRIPTION.toString()); 56 | } 57 | 58 | /** 59 | * Common item that represent a End Search button 60 | * @return the item 61 | */ 62 | public SimpleItem getEndSearchItem(){ 63 | return new SimpleItem(XMaterial.BOOKSHELF).addEnchantment(Enchantment.DURABILITY).setShowEnchantments(false).setDisplayName(Base.ITEM_END_SEARCH_NAME.toString()).setLore(Base.ITEM_END_SEARCH_DESCRIPTION.toString()); 64 | } 65 | 66 | /** 67 | * Common item that represent an empty button 68 | * @return the item 69 | */ 70 | public SimpleItem emptyItem(){ 71 | return new SimpleItem(XMaterial.WHITE_STAINED_GLASS_PANE).setDisplayName("&7").addEnchantment(Enchantment.DURABILITY).setShowEnchantments(false); 72 | } 73 | 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/items/Skulls.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.items; 2 | 3 | import xyz.theprogramsrc.supercoreapi.global.utils.Utils; 4 | import xyz.theprogramsrc.supercoreapi.spigot.SpigotPlugin; 5 | import xyz.theprogramsrc.supercoreapi.spigot.utils.skintexture.SkinTexture; 6 | 7 | import java.util.LinkedHashMap; 8 | import java.util.LinkedList; 9 | import java.util.List; 10 | 11 | public enum Skulls { 12 | 13 | BACK("https://textures.minecraft.net/texture/9c042597eda9f061794fe11dacf78926d247f9eea8ddef39dfbe6022989b8395"), 14 | ARROW_LEFT("https://textures.minecraft.net/texture/f7aacad193e2226971ed95302dba433438be4644fbab5ebf818054061667fbe2"), 15 | ARROW_RIGHT("https://textures.minecraft.net/texture/a5fb343b2e7822c7de47abac4c3679f6ad1fa12efc5866c033c7584d6848"), 16 | 17 | ; 18 | 19 | private static LinkedHashMap cache = new LinkedHashMap<>(); 20 | 21 | private final String url; 22 | 23 | Skulls(String url){ 24 | this.url = url; 25 | } 26 | 27 | /** 28 | * Gets the url of the texture 29 | * @return the url of the texture 30 | */ 31 | public String asUrl(){ 32 | return this.url; 33 | } 34 | 35 | /** 36 | * Gets the SkinTexture of this skull 37 | * @return the texture of this skull 38 | */ 39 | public SkinTexture asSkinTexture(){ 40 | return SkinTexture.fromURL(this.asUrl()); 41 | } 42 | 43 | /** 44 | * Gets a SkinTexture from the GitHub Heads DataBase 45 | * @param key the key/name of the SkinTexture 46 | * @return the texture of the specified key 47 | */ 48 | public static SkinTexture fromDataBase(String key){ 49 | if(cache == null) cache = new LinkedHashMap<>(); 50 | return new SkinTexture(cache.getOrDefault(key, "https://textures.minecraft.net/texture/badc048a7ce78f7dad72a07da27d85c0916881e5522eeed1e3daf217a38c1a")); 51 | } 52 | 53 | /** 54 | * Gets a URL from the GitHub Heads DataBase 55 | * @param key the key/name of the Texture URL 56 | * @return the URL of the texture 57 | */ 58 | public static String urlFromDataBase(String key){ 59 | if(cache == null) cache = new LinkedHashMap<>(); 60 | return cache.getOrDefault(key, "https://textures.minecraft.net/texture/badc048a7ce78f7dad72a07da27d85c0916881e5522eeed1e3daf217a38c1a"); 61 | } 62 | 63 | /** 64 | * Gets all the keys/names of the GitHub Heads DataBase 65 | * @return all the keys/names of the GitHub Heads DataBase 66 | */ 67 | public static LinkedList getDataBaseKeys(){ 68 | if(cache == null) cache = new LinkedHashMap<>(); 69 | return new LinkedList<>(cache.keySet()); 70 | } 71 | 72 | /** 73 | * Caches the Heads DataBase from GitHub 74 | */ 75 | public static void loadFromGitHub(){ 76 | if(cache == null) cache = new LinkedHashMap<>(); 77 | try { 78 | List content = Utils.readLinesWithInputStream("https://raw.githubusercontent.com/TheProgramSrc/PluginsResources/master/SuperCoreAPI/Heads"); 79 | for (String line : content) { 80 | String[] data = line.split(":", 2); 81 | cache.put(data[0], data[1]); 82 | } 83 | SpigotPlugin.i.log("Successfully loaded " + cache.size() + " Heads from the GitHub DataBase"); 84 | } catch (Exception e) { 85 | SpigotPlugin.i.log("&cError while loading Heads DataBase from GitHub"); 86 | e.printStackTrace(); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/packets/DemoMessage.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.packets; 2 | 3 | 4 | import java.lang.reflect.Constructor; 5 | import java.util.Objects; 6 | 7 | import org.bukkit.entity.Player; 8 | 9 | import xyz.theprogramsrc.supercoreapi.spigot.utils.ReflectionUtils; 10 | 11 | public class DemoMessage { 12 | 13 | /** 14 | * Sends the demo screen as packet 15 | * @param player the player to send the demo screen 16 | */ 17 | public static void send(Player player) { 18 | try { 19 | Class gameStateChange = ReflectionUtils.getNMSClass("PacketPlayOutGameStateChange"); 20 | Constructor playOutConstructor = ReflectionUtils.getConstructor(gameStateChange, Integer.TYPE, Float.TYPE); 21 | Object packet = Objects.requireNonNull(playOutConstructor).newInstance(5, 0); 22 | ReflectionUtils.sendPacket(player, packet); 23 | } catch (Exception ex) { 24 | ex.printStackTrace(); 25 | } 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/packets/sky/SkyChanger.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.packets.sky; 2 | 3 | import org.bukkit.entity.Player; 4 | import xyz.theprogramsrc.supercoreapi.spigot.utils.ReflectionUtils; 5 | 6 | import java.lang.reflect.Constructor; 7 | 8 | public class SkyChanger{ 9 | 10 | /** 11 | * Changes the sky of a player with packets 12 | * @param player the player 13 | * @param color the sky color 14 | */ 15 | public static void changeSky(Player player, SkyColor color) { 16 | change(player, color.getValue()); 17 | } 18 | 19 | private static void change(Player player, int number) { 20 | try { 21 | Class packetClass = ReflectionUtils.getNMSClass("PacketPlayOutGameStateChange"); 22 | Constructor packetConstructor = packetClass.getConstructor(Integer.TYPE, Float.TYPE); 23 | Object packet = packetConstructor.newInstance(7, number); 24 | ReflectionUtils.sendPacket(player, packet); 25 | } catch (Exception ex) { 26 | ex.printStackTrace(); 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/packets/sky/SkyColor.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.packets.sky; 2 | 3 | /** 4 | * Representation of the sky colors for the {@link SkyChanger} packet 5 | */ 6 | public enum SkyColor{ 7 | 8 | NORMAL(0), 9 | RAIN(1), 10 | // FREEZE(0), 11 | // UNFREEZE(0), 12 | CRASH(3.4028236E38D), 13 | BLUE_SCREEN(7), 14 | YELLOW_SCREEN(15), 15 | BLACK_AND_RED_SKY(5), 16 | DARK_RED_SKY(4), 17 | RED_SKY(3), 18 | YELLOW_SKY(2), 19 | NIGHT(-1); 20 | 21 | private final int value; 22 | 23 | SkyColor(int value) { 24 | this.value = value; 25 | } 26 | 27 | SkyColor(Double value) { 28 | this.value = value.intValue(); 29 | } 30 | 31 | public int getValue() { 32 | return this.value; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/recipes/CustomRecipe.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.recipes; 2 | 3 | import org.bukkit.inventory.ItemStack; 4 | 5 | public class CustomRecipe { 6 | 7 | private final ItemStack result; 8 | private final RecipeItem[] recipeItems; 9 | 10 | public CustomRecipe(ItemStack result, RecipeItem[] recipeItems) { 11 | this.result = result; 12 | this.recipeItems = recipeItems; 13 | } 14 | 15 | public ItemStack getResult() { 16 | return result; 17 | } 18 | 19 | public RecipeItem[] getRecipeItems() { 20 | return recipeItems; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/recipes/RecipeCreator.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.recipes; 2 | 3 | import org.bukkit.event.EventHandler; 4 | import org.bukkit.event.inventory.PrepareItemCraftEvent; 5 | import org.bukkit.inventory.CraftingInventory; 6 | import org.bukkit.inventory.ItemStack; 7 | import xyz.theprogramsrc.supercoreapi.global.utils.Utils; 8 | import xyz.theprogramsrc.supercoreapi.spigot.SpigotModule; 9 | import xyz.theprogramsrc.supercoreapi.spigot.items.SimpleItem; 10 | import xyz.theprogramsrc.supercoreapi.spigot.utils.ItemUtils; 11 | 12 | import java.util.Arrays; 13 | import java.util.HashMap; 14 | import java.util.List; 15 | import java.util.Objects; 16 | import java.util.stream.Collectors; 17 | 18 | public class RecipeCreator extends SpigotModule { 19 | 20 | private final HashMap recipes; 21 | 22 | /** 23 | * Create a new custom recipe! 24 | */ 25 | public RecipeCreator(){ 26 | this.recipes = new HashMap<>(); 27 | } 28 | 29 | public void addRecipe(String id, CustomRecipe recipe){ 30 | if(this.recipes.containsKey(id)){ 31 | throw new IllegalArgumentException("The identifier '" + id + "' is already in use!"); 32 | }else{ 33 | this.recipes.put(id, recipe); 34 | } 35 | } 36 | 37 | public void removeRecipe(String id){ 38 | this.recipes.remove(id); 39 | } 40 | 41 | public HashMap getRecipes() { 42 | return recipes; 43 | } 44 | 45 | @EventHandler 46 | public void onCraftPrepare(PrepareItemCraftEvent event){ 47 | if(!event.isRepair()){ 48 | CraftingInventory inv = event.getInventory(); 49 | HashMap items = new HashMap<>(); 50 | List contents = Arrays.stream(inv.getMatrix()).filter(Utils::nonNull).collect(Collectors.toList()); 51 | 52 | for(int i = 1; i <= 9; ++i){ 53 | items.put(i, inv.getItem(i)); 54 | } 55 | 56 | for (CustomRecipe recipe : this.recipes.values()) { 57 | List unordered = Arrays.stream(recipe.getRecipeItems()).filter(i-> i.getSlot() == -1).map(RecipeItem::getItem).filter(Objects::nonNull).collect(Collectors.toList()); 58 | if(!unordered.isEmpty()){ 59 | if(contents.containsAll(unordered)){ 60 | inv.setResult(recipe.getResult()); 61 | } 62 | }else{ 63 | HashMap recipes = new HashMap<>(); 64 | Arrays.stream(recipe.getRecipeItems()).filter(i-> i.getSlot() != -1).forEach(r-> recipes.put(r.getSlot(), r.getItem())); 65 | int matches = 0; 66 | for(int i = 1; i <= 9; ++i){ 67 | ItemStack recipeItem = recipes.get(i); 68 | ItemStack inCraft = items.get(i); 69 | if(inCraft != null && recipeItem != null){ 70 | if(check(inCraft, recipeItem)){ 71 | matches++; 72 | } 73 | } 74 | } 75 | 76 | if(matches == recipes.size()){ 77 | inv.setResult(recipe.getResult()); 78 | } 79 | } 80 | } 81 | } 82 | } 83 | 84 | private boolean check(ItemStack i1, ItemStack i2){ 85 | SimpleItem s1 = new SimpleItem(i1), s2 = new SimpleItem(i2); 86 | boolean base = ItemUtils.check(i1, i2), lore = ItemUtils.checkLore(i1, i2), name = ItemUtils.checkName(i1, i2, false), type = ItemUtils.checkType(i1, i2); 87 | if(!s1.hasLore() || !s2.hasLore()){ 88 | if(!s1.hasDisplayName() || !s2.hasDisplayName()){ 89 | return base && type; 90 | }else{ 91 | return base && type && name; 92 | } 93 | }else{ 94 | if(!s1.hasDisplayName() || !s2.hasDisplayName()){ 95 | return base && type && lore; 96 | }else{ 97 | return base && type && lore && name; 98 | } 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/recipes/RecipeItem.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.recipes; 2 | 3 | import org.bukkit.inventory.ItemStack; 4 | import xyz.theprogramsrc.supercoreapi.global.utils.Utils; 5 | 6 | /** 7 | * {@link RecipeItem Recipe Item} is a representation of an item 8 | * inside the crafting table. 9 | */ 10 | public class RecipeItem { 11 | 12 | private final int slot; 13 | private final ItemStack item; 14 | 15 | /** 16 | * Create an ordered-item. 17 | * An ordered-item represents an item inside the 18 | * crafting table that must be placed on a specific 19 | * slot. 20 | * @param slot where should be placed the item 21 | * @param item the item to check 22 | */ 23 | public RecipeItem(int slot, ItemStack item) { 24 | Utils.notNull(item, "Item for RecipeItem cannot be null!"); 25 | if(slot < 1 || slot > 9){ 26 | throw new IllegalArgumentException("The slot '" + slot + "' for the item with material '" + Utils.getEnumName(item.getType()) + "' must be between 1 and 9. Please see: https://github.com/TheProgramSrc/PluginsResources/blob/master/SuperCoreAPI/README.md#custom-crafting-api"); 27 | } 28 | this.slot = slot; 29 | this.item = item; 30 | } 31 | 32 | /** 33 | * Create an unordered-item. 34 | * An unordered-item represents an item inside the 35 | * crafting table that don't have a specific place where should be. 36 | * @param item the item to check 37 | */ 38 | public RecipeItem(ItemStack item){ 39 | this.slot = -1; 40 | this.item = item; 41 | } 42 | 43 | /** 44 | * Gets the slot where should be placed the item 45 | * NOTE: If this is an unordered-item will return -1 46 | * @return the slot where should be the item. If this is an unordered-item will return -1 47 | */ 48 | public int getSlot() { 49 | return slot; 50 | } 51 | 52 | /** 53 | * Gets the item to check 54 | * @return the item to check 55 | */ 56 | public ItemStack getItem() { 57 | return item; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/storage/SettingsStorage.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.storage; 2 | 3 | import xyz.theprogramsrc.supercoreapi.global.files.yml.YMLConfig; 4 | import xyz.theprogramsrc.supercoreapi.spigot.SpigotModule; 5 | 6 | /** 7 | * Representation of the Plugin Settings File 8 | */ 9 | public class SettingsStorage extends SpigotModule { 10 | 11 | private YMLConfig cfg; 12 | private String defaultPrefix; 13 | 14 | @Override 15 | public void onLoad() { 16 | this.cfg = new YMLConfig(this.getPluginFolder(), "Settings.yml"); 17 | this.defaultPrefix = "&9" + this.getPluginName() + "»&r "; 18 | if(this.plugin.isFirstStart()){ 19 | this.loadDefaults(); 20 | } 21 | } 22 | 23 | /** 24 | * Sets the prefix of the Plugin 25 | * @param prefix the prefix 26 | */ 27 | public void setPrefix(String prefix){ 28 | this.cfg.set("Prefix", prefix); 29 | } 30 | 31 | /** 32 | * Sets the language of the Plugin 33 | * @param language the language 34 | */ 35 | public void setLanguage(String language) { 36 | this.cfg.set("Language", language); 37 | } 38 | 39 | /** 40 | * Gets the prefix of the plugin 41 | * @return the prefix 42 | */ 43 | public String getPrefix(){ 44 | String prefix = this.cfg.getString("Prefix", this.defaultPrefix); 45 | return prefix.endsWith(" ") ? prefix : (prefix + " "); 46 | } 47 | 48 | /** 49 | * Gets the language of the plugin 50 | * @return the language 51 | */ 52 | public String getLanguage() { 53 | return this.cfg.getString("Language", "en"); 54 | } 55 | 56 | private void loadDefaults(){ 57 | this.cfg.add("Prefix", this.defaultPrefix); 58 | this.cfg.add("Language", "en"); 59 | } 60 | 61 | /** 62 | * Gets the Config 63 | * @return the config 64 | */ 65 | public YMLConfig getConfig() { 66 | return cfg; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/update/SpigotUpdater.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.update; 2 | 3 | import xyz.theprogramsrc.supercoreapi.global.utils.Utils; 4 | import xyz.theprogramsrc.supercoreapi.spigot.SpigotModule; 5 | 6 | import java.io.File; 7 | 8 | public class SpigotUpdater extends SpigotModule { 9 | 10 | /** 11 | * Downloads the new file from internet 12 | * 13 | * To apply the changes you should restart the server 14 | * @param url Direct url to the file 15 | * @throws Exception if there is an exception (See {@link Utils#downloadFile(String, File)}) 16 | */ 17 | public void downloadUpdate(String url) throws Exception{ 18 | File pluginsFolder = Utils.folder(new File(this.getServerFolder(), "plugins/")); 19 | File updateFolder = Utils.folder(new File(pluginsFolder, "update/")); 20 | File destination = new File(updateFolder, this.plugin.getPluginFile().getName()); 21 | Utils.downloadFile(url, destination); 22 | } 23 | 24 | /** 25 | * This restarts the server 26 | * (Dont use automatically, use with user agreement) 27 | * @param script If is true the API will stop the server and start the bash script specified in the server configurations 28 | * otherwise the API will execute the command "restart" through console 29 | */ 30 | public void restartServer(boolean script){ 31 | if(script){ 32 | this.spigotPlugin.getServer().spigot().restart(); 33 | }else{ 34 | this.spigotPlugin.getServer().dispatchCommand((this.spigotPlugin).getServer().getConsoleSender(), "restart"); 35 | } 36 | } 37 | 38 | /** 39 | * See {@link #restartServer(boolean)} 40 | * (By default is used the value script as false) 41 | */ 42 | public void restartServer(){ 43 | this.restartServer(false); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/utils/BlockUtils.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.utils; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.bukkit.Location; 6 | import org.bukkit.block.Block; 7 | 8 | public class BlockUtils{ 9 | 10 | /** 11 | * Gets the blocks in a specifier radius 12 | * @param location The central location 13 | * @param radius the blocks radius amount 14 | * @return the blocks in the specified radius 15 | */ 16 | public static Block[] getBlocksInRadius(Location location, int radius) { 17 | ArrayList r = new ArrayList<>(); 18 | 19 | for(double x = location.getX() - (double)radius; x <= location.getX() + (double)radius; ++x) { 20 | for(double y = location.getY() - (double)radius; y <= location.getY() + (double)radius; ++y) { 21 | for(double z = location.getZ() - (double)radius; z <= location.getZ() + (double)radius; ++z) { 22 | Location loc = new Location(location.getWorld(), x, y, z); 23 | r.add(loc.getBlock()); 24 | } 25 | } 26 | } 27 | Block[] blocks = new Block[r.size()]; 28 | blocks = r.toArray(blocks); 29 | return blocks; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/utils/ItemUtils.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.utils; 2 | 3 | import org.bukkit.inventory.ItemStack; 4 | import xyz.theprogramsrc.supercoreapi.global.utils.Utils; 5 | import xyz.theprogramsrc.supercoreapi.spigot.items.SimpleItem; 6 | 7 | public class ItemUtils { 8 | 9 | public static boolean check(ItemStack i1, ItemStack i2){ 10 | return i1.equals(i2); 11 | } 12 | 13 | public static boolean checkName(ItemStack i1, ItemStack i2, boolean ignoreCase){ 14 | SimpleItem s1 = new SimpleItem(i1), s2 = new SimpleItem(i2); 15 | if(s1.getDisplayName() == null || s2.getDisplayName() == null) return false; 16 | String n1 = Utils.ct(s1.getDisplayName()), n2 = Utils.ct(s2.getDisplayName()); 17 | return ignoreCase ? n1.equalsIgnoreCase(n2) : n1.contentEquals(n2); 18 | } 19 | 20 | public static boolean checkType(ItemStack i1, ItemStack i2) { 21 | return i1.getType().name().contentEquals(i2.getType().name()); 22 | } 23 | 24 | public static boolean checkAmount(ItemStack i1, ItemStack i2) { 25 | return i1.getAmount() == i2.getAmount(); 26 | } 27 | 28 | public static boolean checkLore(ItemStack i1, ItemStack i2) { 29 | SimpleItem s1 = new SimpleItem(i1), s2 = new SimpleItem(i2); 30 | if(s1.getLore() == null || s2.getLore() == null) return false; 31 | return s1.getLore().containsAll(s2.getLore()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/utils/MinecraftServer.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.utils; 2 | 3 | import org.bukkit.Bukkit; 4 | import xyz.theprogramsrc.supercoreapi.global.utils.Utils; 5 | 6 | public enum MinecraftServer { 7 | 8 | UNKNOWN, CRAFTBUKKIT, SPIGOT, PAPER, TACO, GLOWSTONE; 9 | private final static MinecraftServer minecraftServer = checkProject(); 10 | 11 | private static MinecraftServer checkProject() { 12 | String serverPath = Bukkit.getServer().getClass().getName(); 13 | if (serverPath.contains("glowstone")) { 14 | return GLOWSTONE; 15 | } 16 | 17 | // Taco is pretty easy to check. it uses paper stuff, though, so should be checked first 18 | try { 19 | Class.forName("net.techcable.tacospigot.TacoSpigotConfig"); 20 | return TACO; 21 | } catch (ClassNotFoundException ignored) { } 22 | 23 | // Paper used to be called "paperclip" 24 | try { 25 | Class.forName("com.destroystokyo.paperclip.Paperclip"); 26 | return PAPER; 27 | } catch (ClassNotFoundException ignored) {} 28 | 29 | try { 30 | Class.forName("com.destroystokyo.paper.PaperConfig"); 31 | return PAPER; 32 | } catch (ClassNotFoundException ignored) { } 33 | 34 | // Spigot is the fork that pretty much all builds are based on anymore 35 | try { 36 | Class.forName("org.spigotmc.SpigotConfig"); 37 | return SPIGOT; 38 | } catch (ClassNotFoundException ignored) { } 39 | 40 | return serverPath.contains("craftbukkit") ? CRAFTBUKKIT : UNKNOWN; 41 | } 42 | 43 | /** 44 | * Gets tge current server software name 45 | * @return the current server software name 46 | */ 47 | public static MinecraftServer getServerVersion() { 48 | return minecraftServer; 49 | } 50 | 51 | /** 52 | * Checks if the current server software it's the same as the provided one 53 | * @param version the other version to check 54 | * @return true if booth are the same, false otherwise 55 | */ 56 | public static boolean isServer(MinecraftServer version) { 57 | return minecraftServer == version; 58 | } 59 | 60 | /** 61 | * Checks if the current server software it's one of the provided ones 62 | * @param versions the versions to check 63 | * @return true if the current server software it's in the list, false otherwise 64 | */ 65 | public static boolean isServer(MinecraftServer... versions) { 66 | return Utils.inArray(versions, minecraftServer); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/utils/SpigotConsole.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.utils; 2 | 3 | import org.bukkit.command.ConsoleCommandSender; 4 | import org.bukkit.event.Listener; 5 | import xyz.theprogramsrc.supercoreapi.spigot.SpigotModule; 6 | import xyz.theprogramsrc.supercoreapi.spigot.SpigotPlugin; 7 | 8 | /** 9 | * Representation of a SpigotConsole 10 | */ 11 | public class SpigotConsole extends SpigotModule { 12 | 13 | /** 14 | * Registers listeners 15 | * @param listeners the listeners 16 | */ 17 | public void listeners(Listener... listeners){ 18 | ((SpigotPlugin)this.plugin).listener(listeners); 19 | } 20 | 21 | /** 22 | * Executes a command in the console 23 | * @param command the command 24 | */ 25 | public void execute(final String command){ 26 | ((SpigotPlugin)this.plugin).getServer().getScheduler().runTask(((SpigotPlugin)this.plugin), ()->((SpigotPlugin)this.plugin).getServer().dispatchCommand(((SpigotPlugin)this.plugin).getServer().getConsoleSender(), command)); 27 | } 28 | 29 | /** 30 | * Log a message in the console 31 | * @param msg the message 32 | */ 33 | public void logMessage(String msg){ 34 | this.log(msg); 35 | } 36 | 37 | /** 38 | * Gets the command sender 39 | * @return the command sender 40 | */ 41 | public ConsoleCommandSender parseConsoleCommandSender(){ 42 | return ((SpigotPlugin)this.plugin).getServer().getConsoleSender(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/utils/skintexture/PlayerGameProfile.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.utils.skintexture; 2 | 3 | import com.mojang.authlib.GameProfile; 4 | import org.bukkit.entity.Player; 5 | import xyz.theprogramsrc.supercoreapi.global.utils.Utils; 6 | import xyz.theprogramsrc.supercoreapi.spigot.utils.ReflectionUtils; 7 | 8 | public class PlayerGameProfile{ 9 | 10 | /** 11 | * Gets the {@link GameProfile} of a player 12 | * @param player the player 13 | * @return null if there is any exception, otherwise the GameProfile 14 | */ 15 | public static GameProfile get(Player player){ 16 | try{ 17 | Class craftPlayer = ReflectionUtils.getOCBClass("entity.CraftPlayer"); 18 | return ((GameProfile) Utils.requireNonNull(ReflectionUtils.getMethod(craftPlayer, "getProfile")).invoke(player)); 19 | }catch(Exception ex){ 20 | ex.printStackTrace(); 21 | return null; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/xyz/theprogramsrc/supercoreapi/spigot/utils/skintexture/SkinTextureManager.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.spigot.utils.skintexture; 2 | 3 | 4 | import org.bukkit.Bukkit; 5 | import org.bukkit.entity.Player; 6 | import xyz.theprogramsrc.supercoreapi.global.utils.Utils; 7 | import xyz.theprogramsrc.supercoreapi.spigot.items.Skulls; 8 | 9 | import java.util.HashMap; 10 | 11 | public class SkinTextureManager { 12 | 13 | private final HashMap cache; 14 | private final HashMap urls; 15 | private final HashMap db; 16 | public static SkinTextureManager INSTANCE; 17 | 18 | public SkinTextureManager(){ 19 | this.cache = new HashMap<>(); 20 | this.urls = new HashMap<>(); 21 | this.db = new HashMap<>(); 22 | INSTANCE = this; 23 | } 24 | 25 | /** 26 | * Gets a skin from cache 27 | * @param player the player 28 | * @return the skin 29 | */ 30 | public SkinTexture getSkin(Player player) { 31 | String key = Utils.encodeBase64(player.getName()); 32 | if(!this.cache.containsKey(key)){ 33 | SkinTexture skinTexture = Bukkit.getOnlineMode() ? SkinTexture.fromPlayer(player) : SkinTexture.fromMojang(player.getName()); 34 | if(skinTexture == null){ 35 | return null; 36 | } 37 | this.cache.put(key, skinTexture); 38 | } 39 | return this.cache.get(key); 40 | } 41 | 42 | /** 43 | * Gets a skin from an url 44 | * @param url the url of the skin 45 | * @return the skin 46 | */ 47 | public SkinTexture getSkin(String url){ 48 | String key = Utils.encodeBase64(url); 49 | if(!this.urls.containsKey(key)){ 50 | SkinTexture texture = SkinTexture.fromURL(url); 51 | this.urls.put(key, texture); 52 | } 53 | 54 | return this.urls.get(key); 55 | } 56 | 57 | /** 58 | * Clears the skin cache 59 | */ 60 | public void clearCache(){ 61 | this.cache.clear(); 62 | this.urls.clear(); 63 | this.db.clear(); 64 | } 65 | 66 | /** 67 | * Gets a SkinTexture from the database 68 | * @param name the key/name of the SkinTexture 69 | * @return null if there is any error, otherwise the skin 70 | */ 71 | public SkinTexture fromDataBase(String name){ 72 | String key = Utils.encodeBase64(name); 73 | if(!this.db.containsKey(key)){ 74 | this.db.put(key, Skulls.fromDataBase(name)); 75 | } 76 | return this.db.get(key); 77 | } 78 | 79 | /** 80 | * Gets the cache of the player skulls 81 | * @return the cache of the players skulls 82 | */ 83 | public HashMap getPlayersCache() { 84 | return this.cache; 85 | } 86 | 87 | /** 88 | * Gets the cache of the database skulls 89 | * @return the cache of the database skulls 90 | */ 91 | public HashMap getDataBaseCache() { 92 | return this.db; 93 | } 94 | 95 | /** 96 | * Gets the cache of the URLs skulls 97 | * @return the cache of the URLs skulls 98 | */ 99 | public HashMap getURLsCache() { 100 | return this.urls; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/test/java/xyz/theprogramsrc/supercoreapi/global/networking/CustomConnectionTest.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.networking; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; 4 | 5 | import java.io.IOException; 6 | import java.net.URISyntaxException; 7 | 8 | import org.junit.jupiter.api.Test; 9 | 10 | class CustomConnectionTest { 11 | 12 | private CustomConnection customConnection; 13 | 14 | @Test 15 | void ContentTest() throws IOException { 16 | if(this.customConnection == null) this.customConnection = ConnectionBuilder.connect("https://raw.githubusercontent.com/TheProgramSrc/PluginsResources/master/SuperCoreAPI/connection-test"); 17 | assertEquals("true", this.customConnection.getResponseString()); 18 | } 19 | 20 | @Test 21 | void ResponseCodeTest() throws IOException{ 22 | if(this.customConnection == null) this.customConnection = ConnectionBuilder.connect("https://raw.githubusercontent.com/TheProgramSrc/PluginsResources/master/SuperCoreAPI/connection-test"); 23 | assertEquals("200", this.customConnection.getResponseCode()); 24 | } 25 | 26 | @Test 27 | void URLStringTest() throws IOException, URISyntaxException{ 28 | if(this.customConnection == null) this.customConnection = ConnectionBuilder.connect("https://raw.githubusercontent.com/TheProgramSrc/PluginsResources/master/SuperCoreAPI/connection-test"); 29 | assertEquals("https://raw.githubusercontent.com/TheProgramSrc/PluginsResources/master/SuperCoreAPI/connection-test", this.customConnection.getURLString()); 30 | } 31 | } -------------------------------------------------------------------------------- /src/test/java/xyz/theprogramsrc/supercoreapi/global/objects/PairTest.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.objects; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.*; 6 | 7 | class PairTest { 8 | 9 | private final Pair pair = new Pair<>("test", 1); 10 | 11 | @Test 12 | void left() { 13 | assertEquals("test", this.pair.getLeft()); 14 | } 15 | 16 | @Test 17 | void right() { 18 | assertEquals(1, this.pair.getRight()); 19 | } 20 | } -------------------------------------------------------------------------------- /src/test/java/xyz/theprogramsrc/supercoreapi/global/updater/SongodaUpdateCheckerTest.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.updater; 2 | 3 | import org.junit.jupiter.api.BeforeEach; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.junit.jupiter.api.Assertions.assertFalse; 7 | import static org.junit.jupiter.api.Assertions.assertNotNull; 8 | 9 | class SongodaUpdateCheckerTest { 10 | 11 | private boolean failed = false; 12 | private String last = null; 13 | 14 | @BeforeEach 15 | void setUp() { 16 | new SongodaUpdateChecker("supercoreapi-the-best-way-to-create-a-plugin") { 17 | @Override 18 | public void onFailCheck() { 19 | SongodaUpdateCheckerTest.this.failed = true; 20 | } 21 | 22 | @Override 23 | public void onSuccessCheck(String lastVersion) { 24 | SongodaUpdateCheckerTest.this.last = lastVersion; 25 | } 26 | }.checkUpdates(); 27 | } 28 | 29 | @Test 30 | void check() { 31 | assertFalse(this.failed); 32 | } 33 | 34 | @Test 35 | void version() { 36 | assertNotNull(this.last); 37 | } 38 | } -------------------------------------------------------------------------------- /src/test/java/xyz/theprogramsrc/supercoreapi/global/utils/StringUtilsTest.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.utils; 2 | 3 | import org.junit.jupiter.api.BeforeEach; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | class StringUtilsTest { 9 | 10 | private StringUtils stringUtils; 11 | 12 | @BeforeEach 13 | void setUp() { 14 | this.stringUtils = new StringUtils("This is just {TestingPlaceholder}! $1"); 15 | } 16 | 17 | @Test 18 | void lower() { 19 | StringUtils tmp = this.stringUtils; 20 | assertEquals("this is just {testingplaceholder}! $1", tmp.lower().get()); 21 | } 22 | 23 | @Test 24 | void upper() { 25 | StringUtils tmp = this.stringUtils; 26 | assertEquals("THIS IS JUST {TESTINGPLACEHOLDER}! $1", tmp.upper().get()); 27 | } 28 | 29 | @Test 30 | void placeholder() { 31 | StringUtils tmp = this.stringUtils; 32 | assertEquals("This is just Testing! $1", tmp.placeholder("{TestingPlaceholder}", "Testing").get()); 33 | } 34 | 35 | @Test 36 | void var() { 37 | StringUtils tmp = this.stringUtils; 38 | assertEquals("This is just {TestingPlaceholder}! test", tmp.vars("test").get()); 39 | } 40 | 41 | @Test 42 | void capitalize() { 43 | StringUtils tmp = this.stringUtils; 44 | assertEquals("This Is Just {TestingPlaceholder}! $1", tmp.capitalize().get()); 45 | } 46 | } -------------------------------------------------------------------------------- /src/test/java/xyz/theprogramsrc/supercoreapi/global/utils/UtilsTest.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.utils; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; 4 | import static org.junit.jupiter.api.Assertions.assertTrue; 5 | 6 | import java.io.File; 7 | import java.io.IOException; 8 | import java.security.MessageDigest; 9 | import java.security.NoSuchAlgorithmException; 10 | 11 | import org.junit.jupiter.api.Test; 12 | 13 | class UtilsTest { 14 | 15 | @Test 16 | void capitalizeTest() { 17 | String capitalized = Utils.capitalize("abCde"); 18 | assertEquals("AbCde", capitalized); 19 | } 20 | 21 | @Test 22 | void toTicksTest() { 23 | long ticks = Utils.toTicks(5); 24 | assertEquals(100, ticks); 25 | } 26 | 27 | @Test 28 | void toMillisTest() { 29 | long millis = Utils.toMillis(5); 30 | assertEquals(5000, millis); 31 | } 32 | 33 | @Test 34 | void isIntegerTest() { 35 | boolean integer = Utils.isInteger("1"); 36 | assertTrue(integer); 37 | } 38 | 39 | @Test 40 | void parseHypotenuseTest() { 41 | double hypotenuse = Utils.parseHypotenuse(3,4); 42 | assertEquals(25, hypotenuse); 43 | } 44 | 45 | @Test 46 | void squareRootTest() { 47 | double sqrt = Utils.squareRoot(Utils.parseHypotenuse(3,4)); 48 | assertEquals(5, sqrt); 49 | } 50 | 51 | @Test 52 | void checksumGeneratorTest() throws IOException, NoSuchAlgorithmException { 53 | // First we download the sample jar 54 | File tmpFile = new File("4.13.0.pom.xml"); 55 | Utils.downloadFile("https://repo.theprogramsrc.xyz/repository/maven-public/xyz/theprogramsrc/SuperCoreAPI/4.13.0/SuperCoreAPI-4.13.0.pom", tmpFile); 56 | String knownHash = "f70c0d83eab4bb30e8794f929299fd9a"; // We Store the known hash 57 | MessageDigest messageDigest = Utils.getDigest("MD5"); // We generate the message digest 58 | String generatedHash = Utils.generateFileChecksum(messageDigest, tmpFile); // Now we generate the hash 59 | assertEquals(knownHash, generatedHash); // Now we check the hash 60 | tmpFile.deleteOnExit(); 61 | } 62 | 63 | @Test 64 | void getTimeSecondsFromStringTest(){ 65 | long seconds = Utils.getTimeSecondsFromString("1h 30s"); 66 | assertEquals(3630l, seconds); 67 | } 68 | 69 | @Test 70 | void getTimeSecondsFromWordTest(){ 71 | long seconds = Utils.getTimeSecondsFromWord("1h"); 72 | assertEquals(3600l, seconds); 73 | } 74 | } -------------------------------------------------------------------------------- /src/test/java/xyz/theprogramsrc/supercoreapi/global/utils/json/JSONUtilTest.java: -------------------------------------------------------------------------------- 1 | package xyz.theprogramsrc.supercoreapi.global.utils.json; 2 | 3 | import org.junit.jupiter.api.BeforeEach; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | class JSONUtilTest { 9 | 10 | private JSONUtil jsonUtil; 11 | 12 | @BeforeEach 13 | void setUp() { 14 | this.jsonUtil = new JSONUtil(); 15 | this.jsonUtil.add("boolean", true); 16 | this.jsonUtil.add("string", "Text"); 17 | this.jsonUtil.add("number", 1); 18 | } 19 | 20 | @Test 21 | void BooleanTest() { 22 | assertTrue(this.jsonUtil.getBoolean("boolean")); 23 | } 24 | 25 | @Test 26 | void StringTest() { 27 | assertNotNull(this.jsonUtil.getString("string")); 28 | assertEquals("Text", this.jsonUtil.getString("string")); 29 | } 30 | 31 | @Test 32 | void NumberTest() { 33 | assertEquals(1, this.jsonUtil.getInt("number")); 34 | assertEquals(2, this.jsonUtil.incr("number")); 35 | assertEquals(1, this.jsonUtil.decr("number")); 36 | } 37 | 38 | @Test 39 | void NullTest() { 40 | boolean result = false; 41 | try{ 42 | assertNull(this.jsonUtil.getString("non_existent")); 43 | }catch (NullPointerException e){ 44 | result = true; 45 | } 46 | 47 | assertTrue(result); 48 | } 49 | } --------------------------------------------------------------------------------