├── .gitignore ├── .gitlab-ci.yml ├── .gitlab └── issue_templates │ ├── Bug Report.md │ ├── Exception Report.md │ └── Feature Request.md ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle ├── publish.gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── img ├── assassin-gloves.png ├── craft-extensions.png ├── horse-summoning-stone.png ├── horse.png ├── inventory.png └── slot-sell.png ├── proguard.gradle ├── proguard └── proguard-rules.pro ├── settings.gradle └── src ├── main ├── java │ └── ru │ │ └── endlesscode │ │ └── rpginventory │ │ ├── RPGInventory.java │ │ ├── RPGInventoryCommandExecutor.java │ │ ├── RPGInventoryPlugin.java │ │ ├── api │ │ ├── InventoryAPI.java │ │ └── PetAPI.java │ │ ├── compat │ │ ├── MaterialCompat.java │ │ ├── PlayerCompat.java │ │ ├── SoundCompat.java │ │ ├── VersionHandler.java │ │ ├── mimic │ │ │ ├── RPGInventoryItemsRegistry.java │ │ │ └── RPGInventoryPlayerInventory.java │ │ └── mypet │ │ │ └── MyPetManager.java │ │ ├── event │ │ ├── ItemCommandEvent.java │ │ ├── PetEquipEvent.java │ │ ├── PetUnequipEvent.java │ │ ├── PlayerInventoryLoadEvent.java │ │ ├── PlayerInventoryUnloadEvent.java │ │ ├── listener │ │ │ ├── ArmorEquipListener.java │ │ │ ├── BackpackListener.java │ │ │ ├── CraftListener.java │ │ │ ├── ElytraListener.java │ │ │ ├── HandSwapListener.java │ │ │ ├── InventoryListener.java │ │ │ ├── ItemListener.java │ │ │ ├── LockerListener.java │ │ │ ├── PetListener.java │ │ │ ├── PlayerListener.java │ │ │ └── WorldListener.java │ │ └── updater │ │ │ └── StatsUpdater.java │ │ ├── inventory │ │ ├── ActionType.java │ │ ├── ArmorType.java │ │ ├── InventoryLocker.java │ │ ├── InventoryManager.java │ │ ├── InventorySaver.java │ │ ├── PlayerWrapper.java │ │ ├── backpack │ │ │ ├── Backpack.java │ │ │ ├── BackpackHolder.java │ │ │ ├── BackpackManager.java │ │ │ ├── BackpackType.java │ │ │ └── BackpackUpdater.java │ │ ├── craft │ │ │ ├── CraftExtension.java │ │ │ └── CraftManager.java │ │ └── slot │ │ │ ├── ActionSlot.java │ │ │ ├── Slot.java │ │ │ └── SlotManager.java │ │ ├── item │ │ ├── ClassedItem.java │ │ ├── CustomItem.java │ │ ├── ItemAction.java │ │ ├── ItemManager.java │ │ ├── ItemStat.java │ │ ├── Modifier.java │ │ ├── Texture.java │ │ └── TexturedItem.java │ │ ├── misc │ │ ├── FileLanguage.java │ │ ├── Updater.java │ │ ├── config │ │ │ ├── Config.java │ │ │ ├── ConfigUpdater.java │ │ │ ├── TexturesType.java │ │ │ └── VanillaSlotAction.java │ │ └── serialization │ │ │ ├── InventorySnapshot.java │ │ │ ├── LegacySerialization.java │ │ │ ├── Serialization.java │ │ │ └── SlotSnapshot.java │ │ ├── pet │ │ ├── Attributes.java │ │ ├── CooldownTimer.java │ │ ├── CooldownsTimer.java │ │ ├── PetFood.java │ │ ├── PetManager.java │ │ └── PetType.java │ │ ├── resourcepack │ │ ├── ResourcePackModule.java │ │ └── ResourcePackValidator.java │ │ └── utils │ │ ├── CommandUtils.java │ │ ├── EffectUtils.java │ │ ├── EntityUtils.java │ │ ├── FileUtils.java │ │ ├── InventoryUtils.java │ │ ├── ItemUtils.java │ │ ├── LocationUtils.java │ │ ├── Log.java │ │ ├── NbtFactoryMirror.java │ │ ├── PlayerUtils.java │ │ ├── SafeEnums.java │ │ ├── StringUtils.java │ │ ├── Utils.java │ │ └── Version.java └── resources │ ├── backpacks.yml │ ├── config.yml │ ├── items.yml │ ├── lang │ ├── cs.lang │ ├── de.lang │ ├── en.lang │ ├── es.lang │ ├── jp.lang │ ├── kr.lang │ ├── pt.lang │ ├── rs.lang │ ├── ru.lang │ ├── tr.lang │ └── zh.lang │ ├── pets.yml │ ├── pets.yml.legacy │ ├── plugin.yml │ └── slots.yml └── test └── java └── ru └── endlesscode └── rpginventory └── utils ├── LogTest.java └── VersionTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | ### JetBrains template 2 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 3 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 4 | 5 | # User-specific stuff: 6 | /.idea/ 7 | *.iml 8 | 9 | ## Plugin-specific files: 10 | 11 | # IntelliJ 12 | /out/ 13 | /classes/ 14 | 15 | # mpeltonen/sbt-idea plugin 16 | .idea_modules/ 17 | 18 | ### Java template 19 | *.class 20 | 21 | # Package Files # 22 | *.jar 23 | *.war 24 | *.ear 25 | 26 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 27 | hs_err_pid* 28 | 29 | ### Gradle template 30 | .gradle 31 | /build/ 32 | 33 | # Ignore Gradle GUI config 34 | gradle-app.setting 35 | 36 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 37 | !gradle-wrapper.jar 38 | 39 | # Cache of project 40 | .gradletasknamecache 41 | 42 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 43 | # gradle/wrapper/gradle-wrapper.properties 44 | 45 | !/libs/*.jar 46 | !/antlibs/*.jar 47 | 48 | # Local files 49 | local.properties 50 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | image: gradle:alpine 2 | 3 | # Disable the Gradle daemon for Continuous Integration servers as correctness 4 | # is usually a priority over speed in CI environments. Using a fresh 5 | # runtime for each build is more reliable since the runtime is completely 6 | # isolated from any previous builds. 7 | variables: 8 | GRADLE_OPTS: "-Dorg.gradle.daemon=false" 9 | 10 | before_script: 11 | - export GRADLE_USER_HOME=`pwd`/.gradle 12 | 13 | build: 14 | stage: build 15 | script: gradle build 16 | only: 17 | - push 18 | except: 19 | - develop 20 | cache: 21 | key: "$CI_COMMIT_REF_NAME" 22 | policy: push 23 | paths: 24 | - build 25 | - .gradle 26 | 27 | test: 28 | stage: test 29 | script: gradle check 30 | only: 31 | - push 32 | except: 33 | - develop 34 | cache: 35 | key: "$CI_COMMIT_REF_NAME" 36 | policy: pull 37 | paths: 38 | - build 39 | - .gradle 40 | 41 | deploy: 42 | stage: deploy 43 | script: gradle build 44 | only: 45 | - develop 46 | artifacts: 47 | paths: 48 | - build/libs/* 49 | -------------------------------------------------------------------------------- /.gitlab/issue_templates/Bug Report.md: -------------------------------------------------------------------------------- 1 | 5 | 6 | **Prerequisites** 7 | * [ ] Are you running the latest version? 8 | * [ ] Did you check the FAQs on [plugin's page](https://www.spigotmc.org/resources/12498/)? 9 | * [ ] Did you check the [Wiki](http://rpginventory.endlesscode.ru/)? 10 | * [ ] Did you configure [config.yml](https://github.com/EndlessCodeGroup/RPGInventory/blob/master/src/main/resources/config.yml)? 11 | * [ ] Did you perform a cursory search? 12 | * [ ] Can you reproduce the problem on clean server (with installed only the plugin and dependencies)? 13 | 14 | **Describe the bug** 15 | 16 | 17 | **To Reproduce** 18 | 25 | 26 | **Expected behavior** 27 | 28 | 29 | **Screenshots or video** 30 | 31 | 32 | **Environment:** 33 | - Server Core: 34 | - Server Version: 35 | - Plugin Version: 36 | 37 | **Additional context** 38 | 42 | -------------------------------------------------------------------------------- /.gitlab/issue_templates/Exception Report.md: -------------------------------------------------------------------------------- 1 | 5 | 6 | **Prerequisites** 7 | * [ ] Are you running the latest version? 8 | * [ ] Did you perform a cursory search? 9 | 10 | **Exception stacktrace** 11 | ``` 12 | PUT YOUR STACKTRACE HERE 13 | ``` 14 | 15 | **To Reproduce** 16 | 22 | 23 | **Environment:** 24 | - Server Core: 25 | - Server Version: 26 | - Plugin Version: 27 | 28 | **Additional context** 29 | 33 | -------------------------------------------------------------------------------- /.gitlab/issue_templates/Feature Request.md: -------------------------------------------------------------------------------- 1 | 5 | 6 | **Prerequisites** 7 | * [ ] Did you check the [Wiki](http://rpginventory.endlesscode.ru/) for this feature? 8 | * [ ] Did you perform a cursory search? 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | 12 | 13 | **Describe the solution you'd like** 14 | 15 | 16 | **Describe alternatives you've considered** 17 | 18 | 19 | **Additional context** 20 | 21 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | jdk: 4 | - openjdk8 5 | 6 | before_install: 7 | - chmod +x gradlew 8 | 9 | before_cache: 10 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock 11 | - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ 12 | 13 | cache: 14 | directories: 15 | - $HOME/.gradle/caches/ 16 | - $HOME/.gradle/wrapper/ 17 | - $HOME/.m2/ 18 | 19 | after_success: 20 | - bash <(curl -s https://codecov.io/bash) 21 | 22 | notifications: 23 | email: 24 | on_success: never 25 | on_failure: always 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RPGInventory [![Latest Version](https://img.shields.io/badge/latest-2.4.1-blue.svg)](https://www.spigotmc.org/resources/12498/updates) [![Minecraft Vesrion](https://img.shields.io/badge/minecraft-1.14_--_1.18.x-blue.svg)](#) [![Travis](https://img.shields.io/travis/EndlessCodeGroup/RPGInventory.svg)](https://travis-ci.org/EndlessCodeGroup/RPGInventory) 2 | [![Discord](https://img.shields.io/badge/discord-join_chat-7289da.svg)](https://discord.gg/RBDHyuu) 3 | ![Logo](http://rpginventory.endlesscode.ru/_media/ru/logo-big.png?w=780&h=290&tok=a123f9) 4 | 5 | This plugin will add many RPG features to your server, main of which - RPG-style inventory. 6 | > **You can find screenshots and more info on [SpigotMC](https://www.spigotmc.org/resources/11809/).** 7 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | import org.apache.tools.ant.filters.ReplaceTokens 2 | 3 | plugins { 4 | id 'com.github.johnrengelman.shadow' version '7.1.2' 5 | id 'ru.endlesscode.bukkitgradle' version '0.10.1' 6 | id 'com.github.ben-manes.versions' version "0.42.0" 7 | id 'jacoco' 8 | } 9 | 10 | group = 'ru.endlesscode.rpginventory' 11 | version = pluginVersion 12 | description = pluginDesc 13 | 14 | bukkit { 15 | apiVersion = '1.18.2' 16 | 17 | meta { 18 | name.set("RPGInventory") 19 | main.set("${group}.RPGInventoryPlugin") 20 | apiVersion.set("1.14") 21 | authors.set(["osipxd", "EndlessCode Group"]) 22 | } 23 | 24 | server { 25 | core = "paper" 26 | eula = true 27 | } 28 | } 29 | 30 | // Replace sentry credentials in code 31 | def processSources = tasks.register("processSource", Sync) { 32 | // The key should be declared in ~/.gradle/gradle.properties 33 | def dsn = findProperty("rpginvSentryDsn") ?: "" 34 | 35 | from(sourceSets.main.java) 36 | inputs.property("dsn", dsn) 37 | filter(ReplaceTokens, tokens: [sentry_dsn: dsn]) 38 | into("$buildDir/src") 39 | } 40 | 41 | compileJava { 42 | source = processSources.get().outputs 43 | } 44 | 45 | repositories { 46 | mavenCentral() 47 | spigot() 48 | dmulloy2() 49 | md5() 50 | placeholderapi() 51 | jitpack() 52 | 53 | // You should configure credentials for this repo 54 | def myPetRepo = maven { 55 | name = "githubPackages" 56 | url = uri("https://maven.pkg.github.com/MyPetORG/MyPet") 57 | credentials(PasswordCredentials) 58 | } 59 | 60 | exclusiveContent { 61 | forRepositories(myPetRepo) 62 | filter { includeGroup("de.keyle") } 63 | } 64 | } 65 | 66 | shadowJar { 67 | dependencies { 68 | exclude(dependency("com.google.code.gson:gson:.*")) 69 | exclude(dependency("org.jetbrains:annotations:.*")) 70 | } 71 | 72 | exclude("DebugProbesKt.bin") 73 | exclude("META-INF/proguard/**") 74 | exclude("META-INF/native-image/**") 75 | 76 | minimize() 77 | 78 | def shadowPackage = "shade.ru.endlesscode.rpginventory" 79 | relocate "com.comphenix.packetwrapper", "${shadowPackage}.packetwrapper" 80 | 81 | // inspector 82 | relocate "ru.endlesscode.inspector", "${shadowPackage}.inspector" 83 | relocate "kotlinx", "${shadowPackage}.kotlinx" 84 | relocate "kotlin", "${shadowPackage}.kotlin" 85 | 86 | // inspector-sentry-reporter 87 | relocate "io.sentry", "${shadowPackage}.sentry" 88 | 89 | // bstats 90 | relocate "org.bstats", "${shadowPackage}.bstats" 91 | } 92 | 93 | def inspectorVersion = "0.12.1" 94 | 95 | dependencies { 96 | compileOnly(spigotApi()) 97 | compileOnly('com.github.MilkBowl:VaultAPI:1.7.1') { 98 | exclude group: 'org.bukkit' 99 | } 100 | compileOnly('com.comphenix.protocol:ProtocolLib:4.8.0') 101 | compileOnly('org.jetbrains:annotations:23.0.0') 102 | compileOnly('me.clip:placeholderapi:2.11.1') 103 | compileOnly('de.keyle:mypet:3.12-SNAPSHOT') 104 | compileOnly('ru.endlesscode.mimic:mimic-bukkit-api:0.8.0') 105 | implementation("ru.endlesscode.inspector:inspector-bukkit:$inspectorVersion") 106 | implementation("ru.endlesscode.inspector:inspector-sentry-reporter:$inspectorVersion") 107 | implementation("ru.endlesscode.inspector:sentry-bukkit:$inspectorVersion") 108 | implementation('com.comphenix.packetwrapper:PacketWrapper:1.13-R0.1-SNAPSHOT') 109 | implementation('org.bstats:bstats-bukkit:3.0.0') 110 | testImplementation('junit:junit:4.13.2') 111 | testImplementation('org.mockito:mockito-core:4.4.0') 112 | } 113 | 114 | jacocoTestReport { 115 | reports { 116 | xml.enabled = true 117 | html.enabled = true 118 | } 119 | } 120 | 121 | // Add custom tasks 122 | tasks.assemble.dependsOn tasks.shadowJar 123 | tasks.check.dependsOn tasks.jacocoTestReport 124 | 125 | // Add ProGuard minimization task 126 | // TODO: minimized Jar not works, fix it 127 | //apply(from: file("proguard.gradle")) 128 | //apply(from: file("gradle/publish.gradle")) 129 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | pluginVersion=2.4.1 2 | pluginDesc=Change inventory how you need 3 | url=https://github.com/EndlessCodeGroup/RPGInventory 4 | 5 | org.gradle.caching=true 6 | -------------------------------------------------------------------------------- /gradle/publish.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "maven-publish" 2 | apply plugin: "com.jfrog.bintray" 3 | 4 | java { 5 | withSourcesJar() 6 | } 7 | 8 | publishing { 9 | publications { 10 | "maven"(MavenPublication) { publication -> 11 | from(components.java) 12 | } 13 | "shadow"(MavenPublication) { publication -> 14 | project.shadow.component(publication) 15 | } 16 | } 17 | } 18 | 19 | def repoUrl = "https://github.com/EndlessCodeGroup/RPGInventory" 20 | def pluginName = "RPGInventory" 21 | def bintrayUsername = System.getProperty("bintray.username") ?: System.getenv("BINTRAY_USERNAME") 22 | def bintrayApiKey = System.getProperty("bintray.apiKey") ?: System.getenv("BINTRAY_API_KEY") 23 | if (bintrayUsername == null || bintrayApiKey == null) { 24 | println(""" 25 | System properties 'bintray.username' and 'bintray.apiKey' are not specified. 26 | Publication to Bintray is unavailable. 27 | Alternatively, you can specify environment variables 'BINTRAY_USERNAME' and 'BINTRAY_API_KEY'. 28 | https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_system_properties 29 | """.stripIndent()) 30 | return 31 | } 32 | 33 | bintray { 34 | user = bintrayUsername 35 | key = bintrayApiKey 36 | setPublications("maven", "shadow") 37 | 38 | pkg { 39 | repo = "repo" 40 | name = pluginName.toLowerCase() 41 | userOrg = "endlesscode" 42 | setLicenses("GPL-3.0-or-later") 43 | setLabels("plugin", "bukkit", "rpg", "minecraft") 44 | publicDownloadNumbers = true 45 | vcsUrl = "${repoUrl}.git" 46 | websiteUrl = repoUrl 47 | issueTrackerUrl = "$repoUrl/issues" 48 | 49 | version { 50 | name = project.version.toString() 51 | desc = "$pluginName v$name" 52 | released = new Date().toString() 53 | vcsTag = "v$name" 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EndlessCodeGroup/RPGInventory/134ddc9197c262e5ac1fc894c146ce18722219d5/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.4.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 | -------------------------------------------------------------------------------- /img/assassin-gloves.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EndlessCodeGroup/RPGInventory/134ddc9197c262e5ac1fc894c146ce18722219d5/img/assassin-gloves.png -------------------------------------------------------------------------------- /img/craft-extensions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EndlessCodeGroup/RPGInventory/134ddc9197c262e5ac1fc894c146ce18722219d5/img/craft-extensions.png -------------------------------------------------------------------------------- /img/horse-summoning-stone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EndlessCodeGroup/RPGInventory/134ddc9197c262e5ac1fc894c146ce18722219d5/img/horse-summoning-stone.png -------------------------------------------------------------------------------- /img/horse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EndlessCodeGroup/RPGInventory/134ddc9197c262e5ac1fc894c146ce18722219d5/img/horse.png -------------------------------------------------------------------------------- /img/inventory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EndlessCodeGroup/RPGInventory/134ddc9197c262e5ac1fc894c146ce18722219d5/img/inventory.png -------------------------------------------------------------------------------- /img/slot-sell.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EndlessCodeGroup/RPGInventory/134ddc9197c262e5ac1fc894c146ce18722219d5/img/slot-sell.png -------------------------------------------------------------------------------- /proguard.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | def proguardVersion = "6.0.3" 3 | dependencies { 4 | classpath("net.sf.proguard:proguard-gradle:$proguardVersion") 5 | } 6 | 7 | repositories { 8 | mavenCentral() 9 | } 10 | } 11 | 12 | task minimizeJar(type: proguard.gradle.ProGuardTask, dependsOn: shadowJar) { 13 | // We will minimize result of shadowJar task 14 | def jarFile = (tasks.shadowJar as Jar).archivePath 15 | 16 | // Specify the input jars and output jars 17 | injars(jarFile.path) 18 | outjars("${jarFile.parent}/${jarFile.name.replace("-all", ".min")}") 19 | 20 | // Don't obfuscate/minimize calls of provided libraries 21 | libraryjars("${System.properties.'java.home'}/lib/rt.jar") 22 | def providedLibs = project.configurations.compileOnly 23 | for (lib in providedLibs) { 24 | libraryjars(lib.path) 25 | } 26 | 27 | // More logs 28 | verbose 29 | 30 | // Proguard warnings will not stop build 31 | ignorewarnings 32 | dontwarn 33 | 34 | // Import static configurations 35 | configuration("proguard/proguard-rules.pro") 36 | } 37 | -------------------------------------------------------------------------------- /proguard/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | ## Read more about ProGuard configuration: 2 | ## https://www.guardsquare.com/en/products/proguard/manual 3 | 4 | ## You can comment it out to enable obfuscation, but with wrong configuration it can break your plugin 5 | -dontobfuscate 6 | -dontoptimize 7 | 8 | ## Some configurations for obfuscation 9 | #-printmapping out.map 10 | #-keepparameternames 11 | -keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod 12 | 13 | ## Repackage all shadowed classes 14 | #-repackageclasses shadow.ru.endlesscode.rpginventory 15 | 16 | ## We need to keep all plugin's classes. 17 | -keep class ru.endlesscode.rpginventory.* 18 | 19 | ## Keep events listeners 20 | -keep class * implements org.bukkit.event.Listener { 21 | @org.bukkit.event.EventHandler public void *; 22 | } 23 | 24 | -keep class * implements org.bukkit.entity.Entity { 25 | ** getHandle(); 26 | } 27 | 28 | ## Rules for Inspector 29 | -keep class * extends org.bukkit.event.Event { org.bukkit.event.HandlerList getHandlerList(); } 30 | 31 | ## Some common rules 32 | -keepclassmembernames class * { 33 | java.lang.Class class$(java.lang.String); 34 | java.lang.Class class$(java.lang.String, boolean); 35 | } 36 | 37 | -keepclasseswithmembernames,includedescriptorclasses class * { 38 | native ; 39 | } 40 | 41 | -keepclassmembers enum * { 42 | public static **[] values(); 43 | public static ** valueOf(java.lang.String); 44 | } 45 | 46 | -keepclassmembers class * implements java.io.Serializable { 47 | static final long serialVersionUID; 48 | private static final java.io.ObjectStreamField[] serialPersistentFields; 49 | private void writeObject(java.io.ObjectOutputStream); 50 | private void readObject(java.io.ObjectInputStream); 51 | java.lang.Object writeReplace(); 52 | java.lang.Object readResolve(); 53 | } 54 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'rpginventory' 2 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/RPGInventoryPlugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2018 EndlessCode Group and contributors 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory; 20 | 21 | import ru.endlesscode.inspector.bukkit.plugin.TrackedPlugin; 22 | import ru.endlesscode.inspector.bukkit.report.BukkitEnvironment; 23 | import ru.endlesscode.inspector.report.*; 24 | import ru.endlesscode.inspector.sentry.bukkit.SentryBukkitIntegration; 25 | import ru.endlesscode.rpginventory.utils.Log; 26 | 27 | import java.util.Arrays; 28 | import java.util.List; 29 | 30 | @SuppressWarnings("unused") 31 | public class RPGInventoryPlugin extends TrackedPlugin { 32 | 33 | private static final List INTEREST_PLUGINS = Arrays.asList( 34 | "ProtocolLib", "Vault", "Mimic", "BattleLevels", "Skills", "Heroes", "RacesAndClasses", 35 | "SkillAPI", "MyPet", "RPGPlayerLeveling", "PlaceholderAPI", "MMOItems", "QuantumRPG", 36 | "MMOCore", "MMOInventory" 37 | ); 38 | 39 | public RPGInventoryPlugin() { 40 | super(RPGInventory.class, new BukkitEnvironment.Properties(INTEREST_PLUGINS)); 41 | } 42 | 43 | @Override 44 | protected final Reporter createReporter() { 45 | String dsn = "@sentry_dsn@"; 46 | // Token will be replaced in compile time, so it can be empty 47 | // noinspection ConstantConditions 48 | if (dsn.isEmpty()) { 49 | Log.w("It is unofficial build of RPGInventory."); 50 | return null; 51 | } 52 | 53 | return new SentryReporter.Builder() 54 | .setDsn(dsn) 55 | .addIntegration(new SentryBukkitIntegration(this)) 56 | .focusOn(this) 57 | .build(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/api/InventoryAPI.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.api; 20 | 21 | import org.bukkit.entity.Player; 22 | import org.bukkit.inventory.Inventory; 23 | import org.bukkit.inventory.InventoryHolder; 24 | import org.bukkit.inventory.ItemStack; 25 | import org.jetbrains.annotations.NotNull; 26 | import org.jetbrains.annotations.Nullable; 27 | import ru.endlesscode.rpginventory.inventory.InventoryManager; 28 | import ru.endlesscode.rpginventory.inventory.PlayerWrapper; 29 | import ru.endlesscode.rpginventory.inventory.slot.Slot; 30 | import ru.endlesscode.rpginventory.inventory.slot.SlotManager; 31 | import ru.endlesscode.rpginventory.utils.ItemUtils; 32 | 33 | import java.util.ArrayList; 34 | import java.util.List; 35 | 36 | /** 37 | * Created by OsipXD on 03.09.2015 38 | * It is part of the RpgInventory. 39 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 40 | */ 41 | @SuppressWarnings({"unused"}) 42 | public class InventoryAPI { 43 | /** 44 | * Checks if opened inventory is RPGInventory. 45 | * 46 | * @param inventory - opened inventory 47 | * @return true - if opened RPGInventory, false - otherwise 48 | */ 49 | public static boolean isRPGInventory(@NotNull Inventory inventory) { 50 | InventoryHolder holder = inventory.getHolder(); 51 | return holder instanceof PlayerWrapper; 52 | } 53 | 54 | /** 55 | * Get all passive item from RPGInventory of specific player. 56 | * 57 | * @param player - the player 58 | * @return List of not null passive item 59 | */ 60 | @NotNull 61 | public static List getPassiveItems(@Nullable Player player) { 62 | List passiveItems = new ArrayList<>(); 63 | 64 | if (!InventoryManager.playerIsLoaded(player)) { 65 | return passiveItems; 66 | } 67 | 68 | Inventory inventory = InventoryManager.get(player).getInventory(); 69 | for (Slot slot : SlotManager.instance().getPassiveSlots()) { 70 | for (int slotId : slot.getSlotIds()) { 71 | ItemStack item = inventory.getItem(slotId); 72 | if (ItemUtils.isNotEmpty(item) && !InventoryManager.isEmptySlot(item)) { 73 | passiveItems.add(item); 74 | } 75 | } 76 | } 77 | 78 | return passiveItems; 79 | } 80 | 81 | /** 82 | * Get all active item from RPGInventory of specific player. 83 | * 84 | * @param player - the player 85 | * @return List of not null active item 86 | */ 87 | @NotNull 88 | public static List getActiveItems(@Nullable Player player) { 89 | List activeItems = new ArrayList<>(); 90 | 91 | if (!InventoryManager.playerIsLoaded(player)) { 92 | return activeItems; 93 | } 94 | 95 | Inventory inventory = InventoryManager.get(player).getInventory(); 96 | for (Slot slot : SlotManager.instance().getActiveSlots()) { 97 | ItemStack item = inventory.getItem(slot.getSlotId()); 98 | 99 | if (ItemUtils.isNotEmpty(item) && !InventoryManager.isQuickEmptySlot(item)) { 100 | activeItems.add(item); 101 | } 102 | } 103 | 104 | return activeItems; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/api/PetAPI.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.api; 20 | 21 | import org.bukkit.entity.Player; 22 | import org.bukkit.inventory.ItemStack; 23 | import org.jetbrains.annotations.Nullable; 24 | import ru.endlesscode.rpginventory.inventory.InventoryManager; 25 | import ru.endlesscode.rpginventory.inventory.PlayerWrapper; 26 | import ru.endlesscode.rpginventory.pet.PetManager; 27 | import ru.endlesscode.rpginventory.pet.PetType; 28 | import ru.endlesscode.rpginventory.utils.ItemUtils; 29 | 30 | /** 31 | * Created by OsipXD on 03.09.2015 32 | * It is part of the RpgInventory. 33 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 34 | */ 35 | @SuppressWarnings({"unused", "WeakerAccess"}) 36 | public class PetAPI { 37 | /** 38 | * Get pet spawn item from RPGInventory of specific player. 39 | * 40 | * @param player - not null player 41 | * @return ItemStack if player have pet spawn item, null - otherwise 42 | */ 43 | @Nullable 44 | public static ItemStack getPetItem(Player player) { 45 | if (!InventoryManager.playerIsLoaded(player) || !PetManager.isEnabled()) { 46 | return null; 47 | } 48 | 49 | PlayerWrapper playerWrapper = InventoryManager.get(player); 50 | ItemStack petItem = playerWrapper.getInventory().getItem(PetManager.getPetSlotId()); 51 | 52 | return ItemUtils.isEmpty(petItem) ? null : petItem; 53 | } 54 | 55 | /** 56 | * Get Pet of specific player. 57 | * 58 | * @param player - not null player 59 | * @return Pet if player have pet, null - otherwise 60 | */ 61 | @Nullable 62 | public static PetType getPet(Player player) { 63 | return PetManager.getPetFromItem(PetAPI.getPetItem(player)); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/compat/MaterialCompat.java: -------------------------------------------------------------------------------- 1 | package ru.endlesscode.rpginventory.compat; 2 | 3 | import org.bukkit.Material; 4 | import org.jetbrains.annotations.NotNull; 5 | import org.jetbrains.annotations.Nullable; 6 | 7 | import java.util.Objects; 8 | 9 | public class MaterialCompat { 10 | @NotNull 11 | public static Material getMaterial(String name) { 12 | return Objects.requireNonNull(getMaterialOrNull(name)); 13 | } 14 | 15 | @NotNull 16 | public static Material getMaterialOrAir(String name) { 17 | Material material = getMaterialOrNull(name); 18 | if (material == null) { 19 | return Material.AIR; 20 | } else { 21 | return material; 22 | } 23 | } 24 | 25 | @Nullable 26 | public static Material getMaterialOrNull(String name) { 27 | Material material = Material.getMaterial(name); 28 | if (material == null && !VersionHandler.isLegacy()) { 29 | material = Material.getMaterial(name, true); 30 | } 31 | 32 | return material; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/compat/PlayerCompat.java: -------------------------------------------------------------------------------- 1 | package ru.endlesscode.rpginventory.compat; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | public final class PlayerCompat { 6 | 7 | private static boolean isGetWidthMethodAvailable = VersionHandler.getVersionCode() >= VersionHandler.VERSION_1_11; 8 | 9 | private PlayerCompat() { 10 | } 11 | 12 | public static double getWidth(Player player) { 13 | double playerWidth = 0.6D; 14 | if (isGetWidthMethodAvailable) { 15 | try { 16 | playerWidth = player.getWidth(); 17 | } catch (NoSuchMethodError ex) { 18 | isGetWidthMethodAvailable = false; 19 | } 20 | } 21 | return playerWidth; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/compat/VersionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.compat; 20 | 21 | import org.bukkit.Bukkit; 22 | import ru.endlesscode.rpginventory.utils.Version; 23 | 24 | import java.util.regex.Matcher; 25 | import java.util.regex.Pattern; 26 | 27 | /** 28 | * Created by OsipXD on 29.08.2015 29 | * It is part of the RpgInventory. 30 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 31 | */ 32 | public class VersionHandler { 33 | 34 | public static final int VERSION_1_11 = 1_11_00; 35 | public static final int VERSION_1_12 = 1_12_00; 36 | public static final int VERSION_1_13 = 1_13_00; 37 | public static final int VERSION_1_14 = 1_14_00; 38 | public static final int VERSION_1_15 = 1_15_00; 39 | public static final int VERSION_1_16 = 1_16_00; 40 | public static final int VERSION_1_17 = 1_17_00; 41 | public static final int VERSION_1_18 = 1_18_00; 42 | public static final int VERSION_1_19 = 1_19_00; 43 | 44 | private static final Pattern pattern = Pattern.compile("(?\\d\\.\\d{1,2}(\\.\\d)?)-.*"); 45 | 46 | private static int versionCode = -1; 47 | 48 | public static boolean isNotSupportedVersion() { 49 | return getVersionCode() < VERSION_1_14 || getVersionCode() >= VERSION_1_19; 50 | } 51 | 52 | public static boolean isExperimentalSupport() { 53 | return getVersionCode() == VERSION_1_18; 54 | } 55 | 56 | public static boolean isLegacy() { 57 | return getVersionCode() < VERSION_1_13; 58 | } 59 | 60 | public static int getVersionCode() { 61 | if (versionCode == -1) { 62 | initVersionCode(); 63 | } 64 | 65 | return versionCode; 66 | } 67 | 68 | private static void initVersionCode() { 69 | Matcher matcher = pattern.matcher(Bukkit.getBukkitVersion()); 70 | if (matcher.find()) { 71 | String versionString = matcher.group("version"); 72 | versionCode = Version.parseVersion(versionString).getVersionCode(); 73 | } else { 74 | versionCode = 0; 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/compat/mimic/RPGInventoryItemsRegistry.java: -------------------------------------------------------------------------------- 1 | package ru.endlesscode.rpginventory.compat.mimic; 2 | 3 | import org.bukkit.Material; 4 | import org.bukkit.inventory.ItemStack; 5 | import org.jetbrains.annotations.NotNull; 6 | import org.jetbrains.annotations.Nullable; 7 | import ru.endlesscode.mimic.items.BukkitItemsRegistry; 8 | import ru.endlesscode.rpginventory.item.CustomItem; 9 | import ru.endlesscode.rpginventory.item.ItemManager; 10 | 11 | import java.util.Collection; 12 | 13 | public class RPGInventoryItemsRegistry implements BukkitItemsRegistry { 14 | 15 | @NotNull 16 | @Override 17 | public Collection getKnownIds() { 18 | return ItemManager.getItemList(); 19 | } 20 | 21 | @Nullable 22 | @Override 23 | public ItemStack getItem(@NotNull String itemId, @Nullable Object payload, int amount) { 24 | ItemStack item = ItemManager.getItem(itemId); 25 | if (item.getType() != Material.AIR) { 26 | item.setAmount(amount); 27 | return item; 28 | } else { 29 | return null; 30 | } 31 | } 32 | 33 | @Nullable 34 | @Override 35 | public String getItemId(@NotNull ItemStack item) { 36 | CustomItem customItem = ItemManager.getCustomItem(item); 37 | if (customItem != null) { 38 | return customItem.getId(); 39 | } else { 40 | return null; 41 | } 42 | } 43 | 44 | @Override 45 | public boolean isItemExists(@NotNull String itemId) { 46 | return ItemManager.hasItem(itemId); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/compat/mimic/RPGInventoryPlayerInventory.java: -------------------------------------------------------------------------------- 1 | package ru.endlesscode.rpginventory.compat.mimic; 2 | 3 | import org.bukkit.entity.Player; 4 | import org.bukkit.inventory.ItemStack; 5 | import org.jetbrains.annotations.NotNull; 6 | import ru.endlesscode.mimic.inventory.BukkitPlayerInventory; 7 | import ru.endlesscode.rpginventory.api.InventoryAPI; 8 | import ru.endlesscode.rpginventory.inventory.slot.Slot; 9 | import ru.endlesscode.rpginventory.inventory.slot.SlotManager; 10 | 11 | import java.util.List; 12 | import java.util.stream.Collectors; 13 | 14 | @SuppressWarnings("UnstableApiUsage") 15 | public class RPGInventoryPlayerInventory extends BukkitPlayerInventory { 16 | 17 | public RPGInventoryPlayerInventory(@NotNull Player player) { 18 | super(player); 19 | } 20 | 21 | @NotNull 22 | @Override 23 | public List getEquippedItems() { 24 | List passiveItems = InventoryAPI.getPassiveItems(getPlayer()); 25 | return collectEquippedItems(passiveItems); 26 | } 27 | 28 | @NotNull 29 | @Override 30 | public List getStoredItems() { 31 | List quickSlots = SlotManager.instance().getQuickSlots(); 32 | 33 | return collectStoredItems() 34 | .stream() 35 | .filter(item -> quickSlots.stream().noneMatch(slot -> slot.isCup(item))) 36 | .collect(Collectors.toList()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/event/ItemCommandEvent.java: -------------------------------------------------------------------------------- 1 | package ru.endlesscode.rpginventory.event; 2 | 3 | import org.bukkit.entity.Player; 4 | import org.bukkit.event.Cancellable; 5 | import org.bukkit.event.HandlerList; 6 | import org.bukkit.event.player.PlayerEvent; 7 | import org.bukkit.inventory.ItemStack; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | public class ItemCommandEvent extends PlayerEvent implements Cancellable { 11 | 12 | private static final HandlerList handlers = new HandlerList(); 13 | private boolean cancelled; 14 | 15 | private ItemStack item; 16 | 17 | public ItemCommandEvent(Player player, ItemStack item) { 18 | super(player); 19 | this.item = item; 20 | } 21 | 22 | public ItemStack getItem() { 23 | return item; 24 | } 25 | 26 | public void setItem(ItemStack item) { 27 | this.item = item; 28 | } 29 | 30 | @Override 31 | public boolean isCancelled() { 32 | return cancelled; 33 | } 34 | 35 | @Override 36 | public void setCancelled(boolean cancelled) { 37 | this.cancelled = cancelled; 38 | } 39 | 40 | @NotNull 41 | @Override 42 | public HandlerList getHandlers() { 43 | return handlers; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/event/PetEquipEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.event; 20 | 21 | import org.bukkit.entity.Player; 22 | import org.bukkit.event.Cancellable; 23 | import org.bukkit.event.HandlerList; 24 | import org.bukkit.event.player.PlayerEvent; 25 | import org.bukkit.inventory.ItemStack; 26 | import org.jetbrains.annotations.NotNull; 27 | 28 | /** 29 | * Created by OsipXD on 26.08.2015 30 | * It is part of the RpgInventory. 31 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 32 | */ 33 | public class PetEquipEvent extends PlayerEvent implements Cancellable { 34 | private static final HandlerList handlers = new HandlerList(); 35 | private final ItemStack petItem; 36 | 37 | private boolean cancelled; 38 | 39 | public PetEquipEvent(Player player, ItemStack petItem) { 40 | super(player); 41 | this.petItem = petItem; 42 | } 43 | 44 | @NotNull 45 | @SuppressWarnings("unused") 46 | public static HandlerList getHandlerList() { 47 | return handlers; 48 | } 49 | 50 | public ItemStack getPetItem() { 51 | return petItem; 52 | } 53 | 54 | @NotNull 55 | @Override 56 | public HandlerList getHandlers() { 57 | return handlers; 58 | } 59 | 60 | @Override 61 | public boolean isCancelled() { 62 | return this.cancelled; 63 | } 64 | 65 | @Override 66 | public void setCancelled(boolean cancelled) { 67 | this.cancelled = cancelled; 68 | } 69 | } 70 | 71 | 72 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/event/PetUnequipEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.event; 20 | 21 | import org.bukkit.entity.Player; 22 | import org.bukkit.event.HandlerList; 23 | import org.bukkit.event.player.PlayerEvent; 24 | import org.jetbrains.annotations.NotNull; 25 | 26 | /** 27 | * Created by OsipXD on 26.08.2015 28 | * It is part of the RpgInventory. 29 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 30 | */ 31 | public class PetUnequipEvent extends PlayerEvent { 32 | private static final HandlerList handlers = new HandlerList(); 33 | 34 | public PetUnequipEvent(Player player) { 35 | super(player); 36 | } 37 | 38 | @NotNull 39 | @SuppressWarnings("unused") 40 | public static HandlerList getHandlerList() { 41 | return handlers; 42 | } 43 | 44 | @NotNull 45 | public HandlerList getHandlers() { 46 | return handlers; 47 | } 48 | } -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/event/PlayerInventoryLoadEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.event; 20 | 21 | import org.bukkit.entity.Player; 22 | import org.bukkit.event.Cancellable; 23 | import org.bukkit.event.HandlerList; 24 | import org.bukkit.event.player.PlayerEvent; 25 | import org.jetbrains.annotations.NotNull; 26 | 27 | /** 28 | * Created by OsipXD on 11.09.2015 29 | * It is part of the RpgInventory. 30 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 31 | */ 32 | public class PlayerInventoryLoadEvent extends PlayerEvent { 33 | private static final HandlerList handlers = new HandlerList(); 34 | 35 | private PlayerInventoryLoadEvent(Player who) { 36 | super(who); 37 | } 38 | 39 | @NotNull 40 | @SuppressWarnings("unused") 41 | public static HandlerList getHandlerList() { 42 | return handlers; 43 | } 44 | 45 | @NotNull 46 | @Override 47 | public HandlerList getHandlers() { 48 | return handlers; 49 | } 50 | 51 | public static class Pre extends PlayerInventoryLoadEvent implements Cancellable { 52 | private boolean cancelled = false; 53 | 54 | public Pre(Player who) { 55 | super(who); 56 | } 57 | 58 | @Override 59 | public boolean isCancelled() { 60 | return this.cancelled; 61 | } 62 | 63 | @Override 64 | public void setCancelled(boolean cancelled) { 65 | this.cancelled = cancelled; 66 | } 67 | } 68 | 69 | public static class Post extends PlayerInventoryLoadEvent { 70 | public Post(Player who) { 71 | super(who); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/event/PlayerInventoryUnloadEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.event; 20 | 21 | import org.bukkit.entity.Player; 22 | import org.bukkit.event.HandlerList; 23 | import org.bukkit.event.player.PlayerEvent; 24 | import org.jetbrains.annotations.NotNull; 25 | 26 | /** 27 | * Created by OsipXD on 11.09.2015 28 | * It is part of the RpgInventory. 29 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 30 | */ 31 | public class PlayerInventoryUnloadEvent extends PlayerEvent { 32 | private static final HandlerList handlers = new HandlerList(); 33 | 34 | private PlayerInventoryUnloadEvent(Player who) { 35 | super(who); 36 | } 37 | 38 | @NotNull 39 | @SuppressWarnings("unused") 40 | public static HandlerList getHandlerList() { 41 | return handlers; 42 | } 43 | 44 | @NotNull 45 | @Override 46 | public HandlerList getHandlers() { 47 | return handlers; 48 | } 49 | 50 | @SuppressWarnings("unused") 51 | private static class Pre extends PlayerInventoryUnloadEvent { 52 | public Pre(Player who) { 53 | super(who); 54 | } 55 | } 56 | 57 | public static class Post extends PlayerInventoryUnloadEvent { 58 | public Post(Player who) { 59 | super(who); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/event/listener/ElytraListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.event.listener; 20 | 21 | import org.bukkit.Material; 22 | import org.bukkit.entity.EntityType; 23 | import org.bukkit.entity.Player; 24 | import org.bukkit.event.EventHandler; 25 | import org.bukkit.event.Listener; 26 | import org.bukkit.event.entity.EntityToggleGlideEvent; 27 | import org.bukkit.event.player.PlayerMoveEvent; 28 | import org.jetbrains.annotations.NotNull; 29 | import ru.endlesscode.rpginventory.compat.PlayerCompat; 30 | import ru.endlesscode.rpginventory.inventory.InventoryManager; 31 | import ru.endlesscode.rpginventory.inventory.PlayerWrapper; 32 | import ru.endlesscode.rpginventory.utils.LocationUtils; 33 | 34 | /** 35 | * Created by OsipXD on 08.04.2016 36 | * It is part of the RpgInventory. 37 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 38 | */ 39 | public class ElytraListener implements Listener { 40 | 41 | @EventHandler(ignoreCancelled = true) 42 | public void onPlayerFall(@NotNull PlayerMoveEvent event) { 43 | Player player = event.getPlayer(); 44 | if (!InventoryManager.playerIsLoaded(player) || player.isFlying() 45 | || player.getVehicle() != null) { 46 | return; 47 | } 48 | 49 | PlayerWrapper playerWrapper = InventoryManager.get(player); 50 | boolean endFalling = false; 51 | if (!player.isOnGround()) { 52 | if (playerIsSneakOnLadder(player) || isPlayerCanFall(player)) { 53 | playerWrapper.onFall(); 54 | } else if (!player.isGliding()) { 55 | endFalling = true; 56 | } 57 | } else if (playerWrapper.isFalling()) { 58 | endFalling = true; 59 | } 60 | 61 | if (endFalling) { 62 | playerWrapper.setFalling(false); 63 | } 64 | } 65 | 66 | @EventHandler(ignoreCancelled = true) 67 | public void onEntityToggleGlide(@NotNull EntityToggleGlideEvent event) { 68 | if (event.getEntityType() != EntityType.PLAYER) { 69 | return; 70 | } 71 | 72 | Player player = (Player) event.getEntity(); 73 | if (!InventoryManager.playerIsLoaded(player)) { 74 | return; 75 | } 76 | 77 | if (event.isGliding()) { 78 | PlayerWrapper playerWrapper = InventoryManager.get(player); 79 | playerWrapper.onStartGliding(); 80 | } 81 | } 82 | 83 | private boolean isPlayerCanFall(@NotNull Player player) { 84 | double playerWidth = PlayerCompat.getWidth(player); 85 | return !LocationUtils.isUnderAnyBlockHonestly(player.getLocation(), playerWidth, 3) 86 | && !playerIsOnLadder(player); 87 | } 88 | 89 | private boolean playerIsSneakOnLadder(Player player) { 90 | return player.isSneaking() && playerIsOnLadder(player); 91 | } 92 | 93 | private boolean playerIsOnLadder(Player player) { 94 | return player.getLocation().getBlock().getType() == Material.LADDER; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/event/listener/HandSwapListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.event.listener; 20 | 21 | import org.bukkit.entity.Player; 22 | import org.bukkit.event.EventHandler; 23 | import org.bukkit.event.EventPriority; 24 | import org.bukkit.event.Listener; 25 | import org.bukkit.event.inventory.InventoryType; 26 | import org.bukkit.event.player.PlayerSwapHandItemsEvent; 27 | import org.bukkit.inventory.ItemStack; 28 | import org.jetbrains.annotations.NotNull; 29 | import ru.endlesscode.rpginventory.inventory.ActionType; 30 | import ru.endlesscode.rpginventory.inventory.InventoryManager; 31 | import ru.endlesscode.rpginventory.inventory.slot.Slot; 32 | import ru.endlesscode.rpginventory.inventory.slot.SlotManager; 33 | import ru.endlesscode.rpginventory.item.ItemManager; 34 | import ru.endlesscode.rpginventory.utils.ItemUtils; 35 | 36 | /** 37 | * Created by OsipXD on 07.04.2016 38 | * It is part of the RpgInventory. 39 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 40 | */ 41 | public class HandSwapListener implements Listener { 42 | @EventHandler 43 | public void onHandSwap(@NotNull PlayerSwapHandItemsEvent event) { 44 | Player player = event.getPlayer(); 45 | 46 | Slot offHandSlot = SlotManager.instance().getShieldSlot(); 47 | Slot mainHandSlot = SlotManager.instance().getSlot(player.getInventory().getHeldItemSlot(), InventoryType.SlotType.QUICKBAR); 48 | ItemStack newOffHandItem = event.getOffHandItem(); 49 | ItemStack newMainHandItem = event.getMainHandItem(); 50 | 51 | if (offHandSlot == null && mainHandSlot == null) { 52 | return; 53 | } 54 | 55 | if (offHandSlot != null) { 56 | if (ItemUtils.isNotEmpty(newOffHandItem) 57 | && !InventoryManager.validateUpdate(player, ActionType.SET, offHandSlot, newOffHandItem)) { 58 | event.setCancelled(true); 59 | return; 60 | } 61 | } 62 | 63 | if (mainHandSlot != null) { 64 | if (ItemUtils.isNotEmpty(newOffHandItem) && mainHandSlot.isCup(newOffHandItem)) { 65 | event.setCancelled(true); 66 | return; 67 | } 68 | 69 | if (!InventoryManager.validateUpdate(player, ActionType.SET, mainHandSlot, newMainHandItem)) { 70 | event.setCancelled(true); 71 | } 72 | } 73 | } 74 | 75 | @EventHandler(priority = EventPriority.MONITOR) 76 | public void afterHandSwap(@NotNull PlayerSwapHandItemsEvent event) { 77 | ItemManager.updateStats(event.getPlayer()); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/event/listener/LockerListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.event.listener; 20 | 21 | import org.bukkit.GameMode; 22 | import org.bukkit.Material; 23 | import org.bukkit.entity.Player; 24 | import org.bukkit.event.EventHandler; 25 | import org.bukkit.event.EventPriority; 26 | import org.bukkit.event.Listener; 27 | import org.bukkit.event.entity.PlayerDeathEvent; 28 | import org.bukkit.event.inventory.InventoryClickEvent; 29 | import org.bukkit.event.player.PlayerGameModeChangeEvent; 30 | import org.bukkit.inventory.ItemStack; 31 | import org.jetbrains.annotations.NotNull; 32 | import ru.endlesscode.rpginventory.RPGInventory; 33 | import ru.endlesscode.rpginventory.inventory.InventoryLocker; 34 | import ru.endlesscode.rpginventory.inventory.InventoryManager; 35 | import ru.endlesscode.rpginventory.utils.ItemUtils; 36 | import ru.endlesscode.rpginventory.utils.PlayerUtils; 37 | 38 | import java.util.List; 39 | 40 | /** 41 | * Created by OsipXD on 18.09.2015 42 | * It is part of the RpgInventory. 43 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 44 | */ 45 | public class LockerListener implements Listener { 46 | @EventHandler 47 | public void onGameModeSwitch(@NotNull PlayerGameModeChangeEvent event) { 48 | Player player = event.getPlayer(); 49 | 50 | if (!InventoryManager.playerIsLoaded(player)) { 51 | return; 52 | } 53 | 54 | if (event.getNewGameMode() == GameMode.CREATIVE) { 55 | InventoryLocker.unlockSlots(player); 56 | } else if (event.getPlayer().getGameMode() == GameMode.CREATIVE) { 57 | InventoryLocker.lockSlots(player, true); 58 | } 59 | } 60 | 61 | @EventHandler 62 | public void onInventoryClick(@NotNull InventoryClickEvent event) { 63 | Player player = (Player) event.getWhoClicked(); 64 | ItemStack currentItem = event.getCurrentItem(); 65 | 66 | if (!InventoryManager.playerIsLoaded(player)) { 67 | return; 68 | } 69 | 70 | if (ItemUtils.isNotEmpty(currentItem) && InventoryLocker.isLockedSlot(currentItem)) { 71 | int slot = event.getSlot(); 72 | int line = InventoryLocker.getLine(slot); 73 | if (InventoryLocker.isBuyableSlot(currentItem, line)) { 74 | if (InventoryLocker.canBuySlot((Player) event.getWhoClicked(), line) && InventoryLocker.buySlot(player, line)) { 75 | player.getInventory().setItem(slot, null); 76 | event.setCurrentItem(null); 77 | 78 | if (slot < 35) { 79 | player.getInventory().setItem(slot + 1, InventoryLocker.getBuyableSlotForLine(InventoryLocker.getLine(slot + 1))); 80 | } 81 | 82 | InventoryManager.get(player).setBuyedSlots(InventoryManager.get(player).getBuyedGenericSlots() + 1); 83 | } else { 84 | event.setCancelled(true); 85 | } 86 | } else { 87 | PlayerUtils.sendMessage(player, RPGInventory.getLanguage().getMessage("error.previous")); 88 | event.setCancelled(true); 89 | } 90 | } 91 | } 92 | 93 | @EventHandler(priority = EventPriority.LOWEST) 94 | public void onPlayerDeath(@NotNull PlayerDeathEvent event) { 95 | if (!InventoryManager.playerIsLoaded(event.getEntity())) { 96 | return; 97 | } 98 | 99 | List drops = event.getDrops(); 100 | for (int i = 0; i < drops.size(); i++) { 101 | ItemStack drop = drops.get(i); 102 | if (drop != null && (InventoryLocker.isLockedSlot(drop) || InventoryManager.isEmptySlot(drop))) { 103 | event.getDrops().set(i, new ItemStack(Material.AIR)); 104 | } 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/event/listener/PlayerListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.event.listener; 20 | 21 | import org.bukkit.entity.Player; 22 | import org.bukkit.event.EventHandler; 23 | import org.bukkit.event.EventPriority; 24 | import org.bukkit.event.Listener; 25 | import org.bukkit.event.entity.PlayerDeathEvent; 26 | import org.bukkit.event.player.PlayerCommandPreprocessEvent; 27 | import org.bukkit.event.player.PlayerRespawnEvent; 28 | import org.jetbrains.annotations.NotNull; 29 | import ru.endlesscode.rpginventory.RPGInventory; 30 | import ru.endlesscode.rpginventory.inventory.InventoryManager; 31 | import ru.endlesscode.rpginventory.inventory.InventorySaver; 32 | import ru.endlesscode.rpginventory.utils.PlayerUtils; 33 | 34 | /** 35 | * Created by OsipXD on 02.09.2016 36 | * It is part of the RpgInventory. 37 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 38 | */ 39 | public class PlayerListener implements Listener { 40 | @EventHandler 41 | public void onCommand(@NotNull PlayerCommandPreprocessEvent event) { 42 | Player player = event.getPlayer(); 43 | if (InventoryManager.isAllowedWorld(player.getWorld()) && !InventoryManager.playerIsLoaded(player)) { 44 | PlayerUtils.sendMessage(player, RPGInventory.getLanguage().getMessage("error.rp.denied")); 45 | event.setCancelled(true); 46 | } 47 | } 48 | 49 | @EventHandler(priority = EventPriority.LOW) 50 | public void onPlayerDead(@NotNull PlayerDeathEvent event) { 51 | Player player = event.getEntity(); 52 | if (InventoryManager.playerIsLoaded(player)) { 53 | InventorySaver.save(player, event.getDrops(), 54 | RPGInventory.getPermissions().has(player, "rpginventory.keep.items") || event.getKeepInventory(), 55 | RPGInventory.getPermissions().has(player, "rpginventory.keep.armor") || event.getKeepInventory(), 56 | RPGInventory.getPermissions().has(player, "rpginventory.keep.rpginv") || event.getKeepInventory()); 57 | } 58 | } 59 | 60 | @EventHandler(priority = EventPriority.LOW) 61 | public void onPlayerRespawn(@NotNull PlayerRespawnEvent event) { 62 | Player player = event.getPlayer(); 63 | if (InventoryManager.playerIsLoaded(player)) { 64 | InventorySaver.restore(player); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/event/listener/WorldListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.event.listener; 20 | 21 | import org.bukkit.Bukkit; 22 | import org.bukkit.entity.Player; 23 | import org.bukkit.event.EventHandler; 24 | import org.bukkit.event.Listener; 25 | import org.bukkit.event.world.WorldSaveEvent; 26 | import org.jetbrains.annotations.NotNull; 27 | import ru.endlesscode.rpginventory.inventory.InventoryManager; 28 | import ru.endlesscode.rpginventory.inventory.backpack.BackpackManager; 29 | 30 | /** 31 | * Created by OsipXD on 24.11.2015 32 | * It is part of the RpgInventory. 33 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 34 | */ 35 | public class WorldListener implements Listener { 36 | @EventHandler 37 | public void onWorldSave(@NotNull WorldSaveEvent event) { 38 | if (!event.getWorld().equals(Bukkit.getWorlds().get(0))) { 39 | return; 40 | } 41 | 42 | BackpackManager.saveBackpacks(); 43 | 44 | for (Player player : Bukkit.getServer().getOnlinePlayers()) { 45 | InventoryManager.savePlayerInventory(player); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/event/updater/StatsUpdater.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.event.updater; 20 | 21 | import org.bukkit.attribute.Attribute; 22 | import org.bukkit.attribute.AttributeInstance; 23 | import org.bukkit.attribute.AttributeModifier; 24 | import org.bukkit.entity.Player; 25 | import ru.endlesscode.inspector.bukkit.scheduler.TrackedBukkitRunnable; 26 | import ru.endlesscode.rpginventory.inventory.InventoryManager; 27 | import ru.endlesscode.rpginventory.inventory.PlayerWrapper; 28 | import ru.endlesscode.rpginventory.item.ItemManager; 29 | import ru.endlesscode.rpginventory.item.ItemStat; 30 | import ru.endlesscode.rpginventory.pet.Attributes; 31 | 32 | /** 33 | * Created by OsipXD on 21.09.2015 34 | * It is part of the RpgInventory. 35 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 36 | */ 37 | public class StatsUpdater extends TrackedBukkitRunnable { 38 | private final Player player; 39 | 40 | public StatsUpdater(Player player) { 41 | this.player = player; 42 | } 43 | 44 | @Override 45 | public void run() { 46 | if (!InventoryManager.playerIsLoaded(this.player)) { 47 | return; 48 | } 49 | 50 | PlayerWrapper playerWrapper = InventoryManager.get(this.player); 51 | playerWrapper.updatePermissions(); 52 | 53 | // Update speed 54 | AttributeInstance speedAttribute = this.player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED); 55 | assert speedAttribute != null; 56 | AttributeModifier rpgInvModifier = null; 57 | for (AttributeModifier modifier : speedAttribute.getModifiers()) { 58 | if (modifier.getUniqueId().compareTo(Attributes.SPEED_MODIFIER_ID) == 0) { 59 | rpgInvModifier = modifier; 60 | } 61 | } 62 | 63 | if (rpgInvModifier != null) { 64 | speedAttribute.removeModifier(rpgInvModifier); 65 | } 66 | 67 | rpgInvModifier = new AttributeModifier( 68 | Attributes.SPEED_MODIFIER_ID, Attributes.SPEED_MODIFIER, 69 | ItemManager.getModifier(this.player, ItemStat.StatType.SPEED).getMultiplier() - 1, 70 | AttributeModifier.Operation.MULTIPLY_SCALAR_1 71 | ); 72 | 73 | speedAttribute.addModifier(rpgInvModifier); 74 | 75 | // Update info slots 76 | if (playerWrapper.isOpened()) { 77 | InventoryManager.syncInfoSlots(playerWrapper); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/inventory/ActionType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.inventory; 20 | 21 | import org.bukkit.event.inventory.InventoryAction; 22 | import org.jetbrains.annotations.Contract; 23 | import org.jetbrains.annotations.NotNull; 24 | 25 | /** 26 | * Created by OsipXD on 09.04.2016 27 | * It is part of the RpgInventory. 28 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 29 | */ 30 | public enum ActionType { 31 | SET, 32 | GET, 33 | DROP, 34 | OTHER; 35 | 36 | @NotNull 37 | @Contract(pure = true) 38 | public static ActionType getTypeOfAction(InventoryAction action) { 39 | if (action == InventoryAction.PLACE_ALL || action == InventoryAction.PLACE_ONE 40 | || action == InventoryAction.PLACE_SOME || action == InventoryAction.SWAP_WITH_CURSOR) { 41 | return SET; 42 | } 43 | 44 | if (action == InventoryAction.MOVE_TO_OTHER_INVENTORY || action == InventoryAction.PICKUP_ALL 45 | || action == InventoryAction.PICKUP_ONE || action == InventoryAction.PICKUP_SOME 46 | || action == InventoryAction.PICKUP_HALF || action == InventoryAction.COLLECT_TO_CURSOR) { 47 | return GET; 48 | } 49 | 50 | if (action == InventoryAction.DROP_ALL_CURSOR || action == InventoryAction.DROP_ALL_SLOT 51 | || action == InventoryAction.DROP_ONE_CURSOR || action == InventoryAction.DROP_ONE_SLOT) { 52 | return DROP; 53 | } 54 | 55 | return OTHER; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/inventory/ArmorType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.inventory; 20 | 21 | import org.bukkit.Material; 22 | import org.bukkit.entity.Player; 23 | import org.bukkit.inventory.EntityEquipment; 24 | import org.bukkit.inventory.ItemStack; 25 | import org.jetbrains.annotations.NotNull; 26 | import org.jetbrains.annotations.Nullable; 27 | import ru.endlesscode.rpginventory.inventory.slot.Slot; 28 | import ru.endlesscode.rpginventory.inventory.slot.SlotManager; 29 | import ru.endlesscode.rpginventory.utils.ItemUtils; 30 | 31 | /** 32 | * Created by OsipXD on 08.04.2016 33 | * It is part of the RpgInventory. 34 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 35 | */ 36 | public enum ArmorType { 37 | HELMET, 38 | CHESTPLATE, 39 | LEGGINGS, 40 | BOOTS, 41 | UNKNOWN; 42 | 43 | @NotNull 44 | public static ArmorType matchType(ItemStack item) { 45 | if (ItemUtils.isEmpty(item)) { 46 | return UNKNOWN; 47 | } 48 | 49 | if (item.getType() == Material.ELYTRA) { 50 | return CHESTPLATE; 51 | } 52 | 53 | String[] typeParts = item.getType().name().split("_"); 54 | String armorType = typeParts[typeParts.length - 1]; 55 | 56 | try { 57 | return ArmorType.valueOf(armorType); 58 | } catch (IllegalArgumentException exception) { 59 | return UNKNOWN; 60 | } 61 | } 62 | 63 | @Nullable 64 | public static Slot getArmorSlotById(int id) { 65 | switch (id) { 66 | case 5: 67 | return SlotManager.instance().getSlot("helmet"); 68 | case 6: 69 | return SlotManager.instance().getSlot("chestplate"); 70 | case 7: 71 | return SlotManager.instance().getSlot("leggings"); 72 | case 8: 73 | return SlotManager.instance().getSlot("boots"); 74 | default: 75 | return null; 76 | } 77 | } 78 | 79 | @Nullable 80 | public ItemStack getItem(@NotNull Player player) { 81 | EntityEquipment equipment = player.getEquipment(); 82 | if (equipment == null) { 83 | return null; 84 | } 85 | 86 | switch (this) { 87 | case HELMET: 88 | return equipment.getHelmet(); 89 | case CHESTPLATE: 90 | return equipment.getChestplate(); 91 | case LEGGINGS: 92 | return equipment.getLeggings(); 93 | case BOOTS: 94 | return equipment.getBoots(); 95 | default: 96 | return null; 97 | } 98 | } 99 | 100 | public int getSlot() { 101 | Slot temp = null; 102 | switch (this) { 103 | case HELMET: 104 | temp = SlotManager.instance().getSlot("helmet"); 105 | break; 106 | case CHESTPLATE: 107 | temp = SlotManager.instance().getSlot("chestplate"); 108 | break; 109 | case LEGGINGS: 110 | temp = SlotManager.instance().getSlot("leggings"); 111 | break; 112 | case BOOTS: 113 | temp = SlotManager.instance().getSlot("boots"); 114 | } 115 | 116 | return temp == null ? -1 : temp.getSlotId(); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/inventory/backpack/Backpack.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.inventory.backpack; 20 | 21 | import org.bukkit.Bukkit; 22 | import org.bukkit.configuration.serialization.ConfigurationSerializable; 23 | import org.bukkit.entity.Player; 24 | import org.bukkit.inventory.Inventory; 25 | import org.bukkit.inventory.ItemStack; 26 | import org.jetbrains.annotations.NotNull; 27 | import ru.endlesscode.rpginventory.inventory.InventoryManager; 28 | import ru.endlesscode.rpginventory.misc.config.Config; 29 | import ru.endlesscode.rpginventory.utils.Log; 30 | 31 | import java.util.*; 32 | 33 | /** 34 | * Created by OsipXD on 19.10.2015 35 | * It is part of the RpgInventory. 36 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 37 | */ 38 | public class Backpack implements ConfigurationSerializable { 39 | 40 | private static final String BP_ID = "id"; 41 | private static final String BP_TYPE = "type"; 42 | private static final String BP_CONTENTS = "contents"; 43 | private static final String BP_LAST_USE = "last-use"; 44 | 45 | private final UUID id; 46 | @NotNull 47 | private final BackpackType backpackType; 48 | 49 | private long lastUse; 50 | private ItemStack[] contents; 51 | 52 | public Backpack(@NotNull BackpackType backpackType) { 53 | this(backpackType, UUID.randomUUID()); 54 | } 55 | 56 | public Backpack(@NotNull BackpackType backpackType, UUID uuid) { 57 | this.id = uuid; 58 | this.backpackType = backpackType; 59 | this.contents = new ItemStack[backpackType.getSize()]; 60 | } 61 | 62 | @SuppressWarnings("unused") // Should be implemented because of ConfigurationSerializable 63 | @NotNull 64 | public static Backpack deserialize(@NotNull Map map) { 65 | UUID id = UUID.fromString((String) map.get(BP_ID)); 66 | BackpackType type = BackpackManager.getBackpackType((String) map.get(BP_TYPE)); 67 | List contents = (List) map.getOrDefault(BP_CONTENTS, Collections.emptyList()); 68 | long lastUse = (long) map.getOrDefault(BP_LAST_USE, 0L); 69 | 70 | Backpack backpack = new Backpack(type, id); 71 | backpack.setContents(contents.toArray(new ItemStack[0])); 72 | backpack.setLastUse(lastUse); 73 | 74 | return backpack; 75 | } 76 | 77 | @NotNull 78 | @Override 79 | public Map serialize() { 80 | final Map serializedBackpack = new LinkedHashMap<>(); 81 | serializedBackpack.put(BP_ID, this.id.toString()); 82 | serializedBackpack.put(BP_TYPE, this.backpackType.getId()); 83 | serializedBackpack.put(BP_CONTENTS, this.contents); 84 | serializedBackpack.put(BP_LAST_USE, this.lastUse); 85 | 86 | return serializedBackpack; 87 | } 88 | 89 | UUID getUniqueId() { 90 | return this.id; 91 | } 92 | 93 | @NotNull 94 | public BackpackType getType() { 95 | return backpackType; 96 | } 97 | 98 | void open(@NotNull Player player) { 99 | int realSize = (int) Math.ceil(this.backpackType.getSize() / 9.0) * 9; 100 | if (realSize > 54) { 101 | realSize = 54; 102 | Log.w("Backpack can''t contain more than 54 slots. So it was trimmed downto 54."); 103 | } 104 | BackpackHolder holder = new BackpackHolder(); 105 | Inventory inventory = Bukkit.createInventory(holder, realSize, backpackType.getTitle()); 106 | holder.setInventory(inventory); 107 | 108 | for (int i = 0; i < realSize; i++) { 109 | if (i < this.backpackType.getSize()) { 110 | if (this.contents[i] != null) { 111 | inventory.setItem(i, this.contents[i]); 112 | } 113 | } else { 114 | inventory.setItem(i, InventoryManager.getFillSlot()); 115 | } 116 | } 117 | 118 | player.openInventory(inventory); 119 | InventoryManager.get(player).setBackpack(this); 120 | } 121 | 122 | public void setContents(ItemStack[] contents) { 123 | this.contents = contents; 124 | } 125 | 126 | public void onUse() { 127 | this.lastUse = System.currentTimeMillis(); 128 | } 129 | 130 | public void setLastUse(long lastUse) { 131 | this.lastUse = lastUse; 132 | } 133 | 134 | boolean isOverdue() { 135 | int lifeTime = Config.getConfig().getInt("backpacks.expiration-time", 0); 136 | return lifeTime != 0 && (System.currentTimeMillis() - this.lastUse) / (1_000 * 60 * 60 * 24) > lifeTime; 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/inventory/backpack/BackpackHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.inventory.backpack; 20 | 21 | import org.bukkit.inventory.Inventory; 22 | import org.bukkit.inventory.InventoryHolder; 23 | import org.jetbrains.annotations.NotNull; 24 | 25 | /** 26 | * Created by OsipXD on 20.11.2015 27 | * It is part of the RpgInventory. 28 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 29 | */ 30 | public class BackpackHolder implements InventoryHolder { 31 | private Inventory inventory; 32 | 33 | @NotNull 34 | @Override 35 | public Inventory getInventory() { 36 | return this.inventory; 37 | } 38 | 39 | public void setInventory(Inventory inventory) { 40 | this.inventory = inventory; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/inventory/backpack/BackpackType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.inventory.backpack; 20 | 21 | import org.bukkit.configuration.ConfigurationSection; 22 | import org.bukkit.inventory.ItemStack; 23 | import org.bukkit.inventory.meta.ItemMeta; 24 | import org.jetbrains.annotations.NotNull; 25 | import ru.endlesscode.rpginventory.RPGInventory; 26 | import ru.endlesscode.rpginventory.item.Texture; 27 | import ru.endlesscode.rpginventory.item.TexturedItem; 28 | import ru.endlesscode.rpginventory.misc.FileLanguage; 29 | import ru.endlesscode.rpginventory.utils.ItemUtils; 30 | import ru.endlesscode.rpginventory.utils.StringUtils; 31 | 32 | import java.util.ArrayList; 33 | import java.util.Arrays; 34 | import java.util.List; 35 | import java.util.UUID; 36 | 37 | /** 38 | * Created by OsipXD on 05.10.2015 39 | * It is part of the RpgInventory. 40 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 41 | */ 42 | public class BackpackType extends TexturedItem { 43 | private final String id; 44 | @NotNull 45 | private final String name; 46 | @NotNull 47 | private final List lore; 48 | private final int size; 49 | 50 | private ItemStack item; 51 | 52 | BackpackType(Texture texture, ConfigurationSection config) { 53 | super(texture); 54 | 55 | this.id = config.getName(); 56 | this.name = StringUtils.coloredLine(config.getString("name", id)); 57 | this.lore = StringUtils.coloredLines(config.getStringList("lore")); 58 | this.size = config.getInt("size", 56) < 56 ? config.getInt("size") : 56; 59 | 60 | this.createItem(); 61 | } 62 | 63 | private void createItem() { 64 | ItemStack spawnItem = this.texture.getItemStack(); 65 | 66 | ItemMeta meta = spawnItem.getItemMeta(); 67 | if (meta != null) { 68 | meta.setDisplayName(this.name); 69 | 70 | FileLanguage lang = RPGInventory.getLanguage(); 71 | List lore = new ArrayList<>(); 72 | lore.addAll(Arrays.asList(lang.getMessage("backpack.desc").split("\n"))); 73 | lore.addAll(this.lore); 74 | lore.add(lang.getMessage("backpack.size", this.size)); 75 | 76 | meta.setLore(lore); 77 | spawnItem.setItemMeta(meta); 78 | } 79 | 80 | this.item = ItemUtils.setTag(spawnItem, ItemUtils.BACKPACK_TAG, this.id); 81 | } 82 | 83 | @NotNull Backpack createBackpack(UUID uuid) { 84 | return new Backpack(this, uuid); 85 | } 86 | 87 | @NotNull Backpack createBackpack() { 88 | return new Backpack(this); 89 | } 90 | 91 | public int getSize() { 92 | return this.size; 93 | } 94 | 95 | @NotNull String getTitle() { 96 | return this.name; 97 | } 98 | 99 | public ItemStack getItem() { 100 | return this.item; 101 | } 102 | 103 | public String getId() { 104 | return this.id; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/inventory/backpack/BackpackUpdater.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.inventory.backpack; 20 | 21 | import org.bukkit.inventory.Inventory; 22 | import org.bukkit.scheduler.BukkitRunnable; 23 | import ru.endlesscode.rpginventory.RPGInventory; 24 | 25 | import java.util.Arrays; 26 | 27 | /** 28 | * Created by OsipXD on 26.08.2016 29 | * It is part of the RpgInventory. 30 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 31 | */ 32 | public class BackpackUpdater extends BukkitRunnable { 33 | private final Inventory inventory; 34 | private final Backpack backpack; 35 | 36 | private static final int DELAY = 2; 37 | 38 | private BackpackUpdater(Inventory inventory, Backpack backpack) { 39 | this.inventory = inventory; 40 | this.backpack = backpack; 41 | } 42 | 43 | public static void update(Inventory inventory, Backpack backpack) { 44 | new BackpackUpdater(inventory, backpack).runTaskLater(RPGInventory.getInstance(), DELAY); 45 | } 46 | 47 | @Override 48 | public void run() { 49 | backpack.onUse(); 50 | 51 | int backpackSize = backpack.getType().getSize(); 52 | backpack.setContents(Arrays.copyOfRange(inventory.getContents(), 0, backpackSize)); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/inventory/craft/CraftExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.inventory.craft; 20 | 21 | import org.bukkit.configuration.ConfigurationSection; 22 | import org.bukkit.entity.Player; 23 | import org.bukkit.inventory.ItemStack; 24 | import org.bukkit.inventory.meta.ItemMeta; 25 | import org.jetbrains.annotations.NotNull; 26 | import org.jetbrains.annotations.Nullable; 27 | import ru.endlesscode.rpginventory.RPGInventory; 28 | import ru.endlesscode.rpginventory.utils.StringUtils; 29 | 30 | import java.util.ArrayList; 31 | import java.util.List; 32 | 33 | /** 34 | * Created by OsipXD on 29.08.2016 35 | * It is part of the RpgInventory. 36 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 37 | */ 38 | public class CraftExtension { 39 | private final String name; 40 | private final ItemStack capItem; 41 | private final List slots; 42 | @Nullable 43 | private final List includes; 44 | 45 | CraftExtension(String name, ConfigurationSection config) { 46 | this.name = name; 47 | this.capItem = initCapItem(config); 48 | 49 | this.slots = config.getIntegerList("slots"); 50 | 51 | if (config.contains("includes")) { 52 | this.includes = new ArrayList<>(); 53 | 54 | for (String childName : config.getStringList("includes")) { 55 | CraftExtension child = CraftManager.getByName(childName); 56 | if (child != null) { 57 | includes.add(child); 58 | } 59 | } 60 | } else { 61 | this.includes = null; 62 | } 63 | } 64 | 65 | private ItemStack initCapItem(@NotNull ConfigurationSection config) { 66 | ItemStack capItem = CraftManager.getTextureOfExtendable().getItemStack(); 67 | ItemMeta meta = capItem.getItemMeta(); 68 | if (meta != null) { 69 | meta.setDisplayName(StringUtils.coloredLine(config.getString("name", name))); 70 | if (config.contains("lore")) { 71 | meta.setLore(StringUtils.coloredLines(config.getStringList("lore"))); 72 | } 73 | capItem.setItemMeta(meta); 74 | } 75 | 76 | return capItem; 77 | } 78 | 79 | public ItemStack getCapItem() { 80 | return capItem; 81 | } 82 | 83 | public String getName() { 84 | return name; 85 | } 86 | 87 | public List getSlots() { 88 | return slots; 89 | } 90 | 91 | boolean isUnlockedForPlayer(@NotNull Player player) { 92 | return RPGInventory.getPermissions().has(player, "rpginventory.craft." + this.name); 93 | } 94 | 95 | void registerExtension(@NotNull List extensions) { 96 | extensions.remove(this); 97 | 98 | if (this.includes == null) { 99 | return; 100 | } 101 | 102 | for (CraftExtension extension : this.includes) { 103 | extension.registerExtension(extensions); 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/inventory/craft/CraftManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.inventory.craft; 20 | 21 | import com.comphenix.protocol.PacketType; 22 | import com.comphenix.protocol.ProtocolLibrary; 23 | import com.comphenix.protocol.events.PacketAdapter; 24 | import com.comphenix.protocol.events.PacketEvent; 25 | import org.bukkit.configuration.ConfigurationSection; 26 | import org.bukkit.configuration.MemorySection; 27 | import org.bukkit.entity.Player; 28 | import org.jetbrains.annotations.NotNull; 29 | import org.jetbrains.annotations.Nullable; 30 | import ru.endlesscode.rpginventory.RPGInventory; 31 | import ru.endlesscode.rpginventory.compat.VersionHandler; 32 | import ru.endlesscode.rpginventory.event.listener.CraftListener; 33 | import ru.endlesscode.rpginventory.item.Texture; 34 | import ru.endlesscode.rpginventory.misc.config.Config; 35 | import ru.endlesscode.rpginventory.utils.Log; 36 | 37 | import java.util.ArrayList; 38 | import java.util.List; 39 | 40 | /** 41 | * Created by OsipXD on 29.08.2016 42 | * It is part of the RpgInventory. 43 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 44 | */ 45 | public class CraftManager { 46 | @NotNull 47 | private static final List EXTENSIONS = new ArrayList<>(); 48 | private static Texture textureOfExtendable; 49 | 50 | private CraftManager() { 51 | } 52 | 53 | public static boolean init(@NotNull RPGInventory instance) { 54 | MemorySection config = (MemorySection) Config.getConfig().get("craft"); 55 | 56 | if (config == null) { 57 | Log.w("Section ''craft'' not found in config.yml"); 58 | return false; 59 | } 60 | 61 | if (!config.getBoolean("enabled")) { 62 | Log.i("Craft system is disabled in config"); 63 | return false; 64 | } 65 | 66 | try { 67 | Texture texture = Texture.parseTexture(config.getString("extendable")); 68 | if (texture.isEmpty()) { 69 | Log.s("Invalid texture in ''craft.extendable''"); 70 | return false; 71 | } 72 | textureOfExtendable = texture; 73 | 74 | @Nullable final ConfigurationSection extensions = config.getConfigurationSection("extensions"); 75 | if (extensions == null) { 76 | Log.s("Section ''craft.extensions'' not found in config.yml"); 77 | return false; 78 | } 79 | 80 | EXTENSIONS.clear(); 81 | for (String extensionName : extensions.getKeys(false)) { 82 | EXTENSIONS.add(new CraftExtension(extensionName, extensions.getConfigurationSection(extensionName))); 83 | } 84 | 85 | // Register listeners 86 | ProtocolLibrary.getProtocolManager().addPacketListener(new CraftListener(instance)); 87 | 88 | // Disable recipe book if need 89 | if (VersionHandler.getVersionCode() >= VersionHandler.VERSION_1_12) { 90 | disableRecipeBook(); 91 | } 92 | 93 | return true; 94 | } catch (Exception e) { 95 | instance.getReporter().report("Error on CraftManager initialization", e); 96 | return false; 97 | } 98 | } 99 | 100 | private static void disableRecipeBook() { 101 | ProtocolLibrary.getProtocolManager().addPacketListener( 102 | new PacketAdapter(RPGInventory.getInstance(), PacketType.Play.Server.RECIPES) { 103 | @Override 104 | public void onPacketSending(@NotNull PacketEvent event) { 105 | event.setCancelled(true); 106 | } 107 | }); 108 | Log.i("Recipe book conflicts with craft extensions and was disabled"); 109 | } 110 | 111 | @NotNull 112 | public static List getExtensions(Player player) { 113 | List extensions = new ArrayList<>(EXTENSIONS); 114 | for (CraftExtension extension : EXTENSIONS) { 115 | if (extension.isUnlockedForPlayer(player)) { 116 | extension.registerExtension(extensions); 117 | } 118 | } 119 | 120 | return extensions; 121 | } 122 | 123 | public static Texture getTextureOfExtendable() { 124 | return textureOfExtendable; 125 | } 126 | 127 | @Nullable 128 | static CraftExtension getByName(String childName) { 129 | for (CraftExtension extension : EXTENSIONS) { 130 | if (extension.getName().equals(childName)) { 131 | return extension; 132 | } 133 | } 134 | 135 | return null; 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/inventory/slot/ActionSlot.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.inventory.slot; 20 | 21 | import org.bukkit.configuration.ConfigurationSection; 22 | import org.bukkit.entity.Player; 23 | import org.jetbrains.annotations.NotNull; 24 | import ru.endlesscode.rpginventory.inventory.InventoryManager; 25 | import ru.endlesscode.rpginventory.utils.SafeEnums; 26 | 27 | /** 28 | * Created by OsipXD on 06.09.2015 29 | * It is part of the RpgInventory. 30 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 31 | */ 32 | public class ActionSlot extends Slot { 33 | private final ActionType actionType; 34 | private final String command; 35 | private final boolean isGui; 36 | 37 | ActionSlot(String name, @NotNull ConfigurationSection config) { 38 | super(name, SlotType.ACTION, config); 39 | 40 | this.actionType = SafeEnums.valueOf(ActionType.class, config.getString("action"), "action type"); 41 | this.command = config.getString("command"); 42 | this.isGui = config.getBoolean("gui", false); 43 | } 44 | 45 | public void preformAction(@NotNull Player player) { 46 | if (this.isGui) { 47 | player.closeInventory(); 48 | } 49 | 50 | if (this.actionType == ActionType.WORKBENCH) { 51 | InventoryManager.get(player).openWorkbench(); 52 | } else if (this.actionType == ActionType.ENDERCHEST) { 53 | player.openInventory(player.getEnderChest()); 54 | } else if (this.actionType == ActionType.COMMAND && command != null) { 55 | player.performCommand(command); 56 | } 57 | } 58 | 59 | private enum ActionType { 60 | WORKBENCH, 61 | ENDERCHEST, 62 | COMMAND 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/item/ClassedItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.item; 20 | 21 | import org.bukkit.configuration.ConfigurationSection; 22 | import org.jetbrains.annotations.NotNull; 23 | import org.jetbrains.annotations.Nullable; 24 | 25 | import java.util.List; 26 | 27 | /** 28 | * Created by OsipXD on 27.08.2016 29 | * It is part of the RpgInventory. 30 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 31 | */ 32 | public class ClassedItem extends TexturedItem { 33 | private final int level; 34 | @Nullable 35 | private final List classes; 36 | 37 | protected ClassedItem(Texture texture, ConfigurationSection config) { 38 | super(texture); 39 | 40 | this.level = config.getInt("level", -1); 41 | this.classes = config.contains("classes") ? config.getStringList("classes") : null; 42 | } 43 | 44 | public int getLevel() { 45 | return this.level; 46 | } 47 | 48 | @Nullable 49 | protected List getClasses() { 50 | return this.classes; 51 | } 52 | 53 | @NotNull 54 | protected String getClassesString() { 55 | if (this.classes == null) { 56 | return ""; 57 | } 58 | 59 | StringBuilder classesString = new StringBuilder(); 60 | for (String theClass : this.classes) { 61 | if (classesString.length() > 0) { 62 | classesString.append(", "); 63 | } 64 | 65 | classesString.append(theClass); 66 | } 67 | 68 | return classesString.toString(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/item/ItemAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.item; 20 | 21 | import org.bukkit.configuration.ConfigurationSection; 22 | import org.bukkit.entity.Player; 23 | import org.jetbrains.annotations.NotNull; 24 | import ru.endlesscode.rpginventory.utils.CommandUtils; 25 | import ru.endlesscode.rpginventory.utils.PlayerUtils; 26 | import ru.endlesscode.rpginventory.utils.StringUtils; 27 | 28 | /** 29 | * Created by OsipXD on 12.04.2016 30 | * It is part of the RpgInventory. 31 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 32 | */ 33 | class ItemAction { 34 | private final String command; 35 | private final String caption; 36 | private final String message; 37 | private final boolean asOp; 38 | 39 | ItemAction(@NotNull ConfigurationSection config) { 40 | this.command = config.getString("command"); 41 | this.caption = config.getString("lore"); 42 | this.message = config.getString("message"); 43 | this.asOp = config.getBoolean("op", false); 44 | } 45 | 46 | void doAction(Player player) { 47 | CommandUtils.sendCommand(player, command, asOp); 48 | if (message != null) { 49 | PlayerUtils.sendMessage(player, StringUtils.coloredLine(message)); 50 | } 51 | } 52 | 53 | public String getCaption() { 54 | return caption; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/item/ItemStat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 osipf 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.item; 20 | 21 | import org.jetbrains.annotations.NotNull; 22 | import ru.endlesscode.rpginventory.utils.StringUtils; 23 | 24 | /** 25 | * Created by OsipXD on 19.09.2015 26 | * It is part of the RpgInventory. 27 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 28 | */ 29 | public class ItemStat { 30 | private final StatType type; 31 | @NotNull 32 | private final OperationType operationType; 33 | private final boolean percentage; 34 | private final double minValue; 35 | private final double maxValue; 36 | 37 | ItemStat(StatType type, String value) { 38 | this.type = type; 39 | this.operationType = OperationType.valueOf(value.charAt(0)); 40 | this.percentage = this.type.isOnlyPercentage() || value.endsWith("%"); 41 | 42 | value = value.substring(1).replaceAll("%", ""); 43 | if (value.contains("-")) { 44 | this.minValue = Double.parseDouble(value.split("-")[0]); 45 | this.maxValue = Double.parseDouble(value.split("-")[1]); 46 | } else { 47 | this.minValue = Double.parseDouble(value); 48 | this.maxValue = -1; 49 | } 50 | } 51 | 52 | @NotNull String getStringValue() { 53 | String value = this.operationType.getOperation() + StringUtils.doubleToString(this.minValue); 54 | 55 | if (this.maxValue != -1) { 56 | value += "-" + StringUtils.doubleToString(this.maxValue); 57 | } 58 | 59 | if (this.percentage) { 60 | value += "%"; 61 | } 62 | 63 | return value; 64 | } 65 | 66 | public double getMinValue() { 67 | return minValue; 68 | } 69 | 70 | public double getMaxValue() { 71 | return isRanged() ? this.maxValue : this.minValue; 72 | } 73 | 74 | private boolean isRanged() { 75 | return this.maxValue != -1; 76 | } 77 | 78 | public double getValue() { 79 | double value = this.minValue; 80 | 81 | if (maxValue != -1) { 82 | value += (this.maxValue - this.minValue) * Math.random(); 83 | } 84 | 85 | return value; 86 | } 87 | 88 | boolean isPercentage() { 89 | return percentage; 90 | } 91 | 92 | @NotNull OperationType getOperationType() { 93 | return operationType; 94 | } 95 | 96 | public StatType getType() { 97 | return type; 98 | } 99 | 100 | 101 | enum OperationType { 102 | PLUS('+'), 103 | MINUS('-'); 104 | 105 | private final char operation; 106 | 107 | OperationType(char operation) { 108 | this.operation = operation; 109 | } 110 | 111 | @NotNull 112 | public static OperationType valueOf(char operation) { 113 | for (OperationType operationType : OperationType.values()) { 114 | if (operationType.getOperation() == operation) { 115 | return operationType; 116 | } 117 | } 118 | 119 | return PLUS; 120 | } 121 | 122 | public char getOperation() { 123 | return operation; 124 | } 125 | } 126 | 127 | @SuppressWarnings("unused") 128 | public enum StatType { 129 | DAMAGE, 130 | BOW_DAMAGE, 131 | HAND_DAMAGE, 132 | ARMOR, 133 | JUMP, 134 | CRIT_CHANCE(true), 135 | CRIT_DAMAGE(true), 136 | SPEED(true); 137 | 138 | private final boolean onlyPercentage; 139 | 140 | StatType() { 141 | this(false); 142 | } 143 | 144 | StatType(boolean onlyPercentage) { 145 | this.onlyPercentage = onlyPercentage; 146 | } 147 | 148 | public boolean isOnlyPercentage() { 149 | return this.onlyPercentage; 150 | } 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/item/Modifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.item; 20 | 21 | import ru.endlesscode.rpginventory.RPGInventory; 22 | import ru.endlesscode.rpginventory.utils.Utils; 23 | 24 | /** 25 | * Created by OsipXD on 21.09.2015 26 | * It is part of the RpgInventory. 27 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 28 | */ 29 | public class Modifier { 30 | public static final Modifier EMPTY = new Modifier(); 31 | 32 | private final double minBonus; 33 | private final double maxBonus; 34 | private final double minMultiplier; 35 | private final double maxMultiplier; 36 | 37 | private Modifier() { 38 | this(0, 0, 1, 1); 39 | } 40 | 41 | Modifier(double minBonus, double maxBonus, double minMultiplier, double maxMultiplier) { 42 | if (minBonus > maxBonus) { 43 | minBonus += maxBonus; 44 | maxBonus = minBonus - maxBonus; 45 | minBonus -= maxBonus; 46 | } 47 | 48 | this.minBonus = minBonus; 49 | this.maxBonus = maxBonus; 50 | 51 | if (minMultiplier <= 0) { 52 | minMultiplier = 0.1; 53 | } 54 | 55 | if (maxMultiplier <= 0) { 56 | maxMultiplier = 0.1; 57 | } 58 | 59 | if (minMultiplier > maxMultiplier) { 60 | minMultiplier += maxMultiplier; 61 | maxMultiplier = minMultiplier - maxMultiplier; 62 | minMultiplier -= maxMultiplier; 63 | } 64 | 65 | this.minMultiplier = Utils.round(minMultiplier, 3); 66 | this.maxMultiplier = Utils.round(maxMultiplier, 3); 67 | } 68 | 69 | private double getMinBonus() { 70 | return minBonus; 71 | } 72 | 73 | private double getMaxBonus() { 74 | return maxBonus; 75 | } 76 | 77 | private double getMinMultiplier() { 78 | return minMultiplier; 79 | } 80 | 81 | private double getMaxMultiplier() { 82 | return maxMultiplier; 83 | } 84 | 85 | public double getBonus() { 86 | return Utils.round(this.minBonus + (this.maxBonus - this.minBonus) * Math.random(), 1); 87 | } 88 | 89 | public double getMultiplier() { 90 | return Utils.round(this.minMultiplier + (this.maxMultiplier - this.minMultiplier) * Math.random(), 1); 91 | } 92 | 93 | @Override 94 | public String toString() { 95 | if (this.equals(EMPTY)) { 96 | return RPGInventory.getLanguage().getMessage("stat.message.no_bonus"); 97 | } 98 | 99 | String str = ""; 100 | 101 | if (this.minBonus != 0 && this.maxBonus != 0) { 102 | double minBonus = this.minBonus; 103 | double maxBonus = this.maxBonus; 104 | 105 | if ((maxBonus <= 0 || minBonus >= 0) && Math.abs(minBonus) > Math.abs(maxBonus)) { 106 | minBonus += maxBonus; 107 | maxBonus = minBonus - maxBonus; 108 | minBonus -= maxBonus; 109 | } 110 | 111 | if (minBonus >= 0) { 112 | str += "+"; 113 | } 114 | str += minBonus; 115 | 116 | if (minBonus != maxBonus) { 117 | str += "-" + (minBonus * maxBonus >= 0 ? Double.valueOf(Math.abs(maxBonus)) : "(+" + maxBonus + ")"); 118 | } 119 | } 120 | 121 | if (this.minMultiplier != 1 && this.maxMultiplier != 1) { 122 | double minMultiplier = Utils.round(this.minMultiplier * 100 - 100, 1); 123 | double maxMultiplier = Utils.round(this.maxMultiplier * 100 - 100, 1); 124 | 125 | if ((maxMultiplier <= 0 || minMultiplier >= 0) && Math.abs(minMultiplier) > Math.abs(maxMultiplier)) { 126 | minMultiplier += maxMultiplier; 127 | maxMultiplier = minMultiplier - maxMultiplier; 128 | minMultiplier -= maxMultiplier; 129 | } 130 | 131 | if (minMultiplier >= 0) { 132 | str += "+"; 133 | } 134 | str += minMultiplier; 135 | 136 | if (minMultiplier != maxMultiplier) { 137 | str += "-" + (minMultiplier * maxMultiplier >= 0 ? Double.valueOf(Math.abs(maxMultiplier)) : "(+" + maxMultiplier + ")"); 138 | } 139 | str += "%"; 140 | } 141 | 142 | return str; 143 | } 144 | 145 | @Override 146 | public int hashCode() { 147 | assert false : "hashCode not designed"; 148 | return 42; 149 | } 150 | 151 | @Override 152 | public boolean equals(Object obj) { 153 | if (!(obj instanceof Modifier)) { 154 | return false; 155 | } 156 | 157 | Modifier other = (Modifier) obj; 158 | return other.getMinBonus() == this.minBonus && other.getMinMultiplier() == this.minMultiplier && 159 | other.getMaxBonus() == this.maxBonus && other.getMaxMultiplier() == this.maxMultiplier; 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/item/TexturedItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.item; 20 | 21 | /** 22 | * Created by OsipXD on 28.08.2016 23 | * It is part of the RpgInventory. 24 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 25 | */ 26 | public class TexturedItem { 27 | protected final Texture texture; 28 | 29 | protected TexturedItem(Texture texture) { 30 | this.texture = texture; 31 | } 32 | 33 | public int getTextureData() { 34 | return texture.getData(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/misc/config/Config.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2018 EndlessCode Group and contributors 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.misc.config; 20 | 21 | import org.bukkit.configuration.InvalidConfigurationException; 22 | import org.bukkit.configuration.file.FileConfiguration; 23 | import org.bukkit.configuration.file.YamlConfiguration; 24 | import org.jetbrains.annotations.NotNull; 25 | import ru.endlesscode.rpginventory.RPGInventory; 26 | import ru.endlesscode.rpginventory.utils.Log; 27 | 28 | import java.io.IOException; 29 | import java.io.InputStream; 30 | import java.nio.file.Files; 31 | import java.nio.file.Path; 32 | import java.nio.file.StandardCopyOption; 33 | 34 | public class Config { 35 | 36 | /* Config options */ 37 | public static VanillaSlotAction craftSlotsAction = VanillaSlotAction.RPGINV; 38 | public static VanillaSlotAction armorSlotsAction = VanillaSlotAction.DEFAULT; 39 | 40 | public static TexturesType texturesType = TexturesType.DAMAGE; 41 | 42 | private static final FileConfiguration config = new YamlConfiguration(); 43 | private static Path configFile; 44 | 45 | public static void init(RPGInventory plugin) { 46 | configFile = plugin.getDataPath().resolve("config.yml"); 47 | plugin.saveDefaultConfig(); 48 | 49 | final InputStream defaultConfigStream = plugin.getResource("config.yml"); 50 | if (defaultConfigStream != null) { 51 | loadDefaultConfig(defaultConfigStream); 52 | } 53 | 54 | reload(); 55 | } 56 | 57 | public static FileConfiguration getConfig() { 58 | return config; 59 | } 60 | 61 | public static void reload() { 62 | try { 63 | config.load(configFile.toFile()); 64 | } catch (IOException | InvalidConfigurationException e) { 65 | Log.w(e, "Error on load config.yml"); 66 | } 67 | 68 | copyOptionsFromConfig(); 69 | save(); 70 | } 71 | 72 | public static void save() { 73 | try { 74 | config.save(configFile.toFile()); 75 | } catch (IOException e) { 76 | Log.w(e, "Error on save config.yml"); 77 | } 78 | } 79 | 80 | private static void loadDefaultConfig(@NotNull InputStream defaultConfigStream) { 81 | final Path exampleConfigPath = configFile.getParent().resolve("config-example.yml"); 82 | 83 | // Update example config 84 | try (final InputStream stream = defaultConfigStream) { 85 | Files.copy(stream, exampleConfigPath, StandardCopyOption.REPLACE_EXISTING); 86 | } catch (IOException e) { 87 | Log.w(e, "Error on copying config-example.yml"); 88 | } 89 | 90 | config.setDefaults(YamlConfiguration.loadConfiguration(exampleConfigPath.toFile())); 91 | config.options().copyDefaults(true); 92 | } 93 | 94 | private static void copyOptionsFromConfig() { 95 | craftSlotsAction = VanillaSlotAction.parseString(config.getString("craft-slots-action")); 96 | armorSlotsAction = VanillaSlotAction.parseString(config.getString("armor-slots-action")); 97 | 98 | texturesType = TexturesType.parseString(config.getString("textures-type")); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/misc/config/TexturesType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2020 EndlessCode Group and contributors 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.misc.config; 20 | 21 | import ru.endlesscode.rpginventory.utils.SafeEnums; 22 | 23 | @SuppressWarnings("unused") 24 | public enum TexturesType { 25 | DAMAGE, 26 | CUSTOM_MODEL_DATA; 27 | 28 | static TexturesType parseString(String stringValue) { 29 | return SafeEnums.valueOfOrDefault(TexturesType.class, stringValue, DAMAGE, "textures type"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/misc/config/VanillaSlotAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2018 EndlessCode Group and contributors 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.misc.config; 20 | 21 | import ru.endlesscode.rpginventory.utils.SafeEnums; 22 | 23 | public enum VanillaSlotAction { 24 | 25 | /** 26 | * Do vanilla action. 27 | */ 28 | DEFAULT, 29 | 30 | /** 31 | * Open RPG inventory. 32 | */ 33 | RPGINV; 34 | 35 | 36 | static VanillaSlotAction parseString(String stringValue) { 37 | return SafeEnums.valueOfOrDefault(VanillaSlotAction.class, stringValue, DEFAULT, "slot action"); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/misc/serialization/InventorySnapshot.java: -------------------------------------------------------------------------------- 1 | package ru.endlesscode.rpginventory.misc.serialization; 2 | 3 | import org.bukkit.configuration.serialization.ConfigurationSerializable; 4 | import org.bukkit.entity.Player; 5 | import org.jetbrains.annotations.NotNull; 6 | import ru.endlesscode.rpginventory.inventory.PlayerWrapper; 7 | import ru.endlesscode.rpginventory.inventory.slot.Slot; 8 | import ru.endlesscode.rpginventory.inventory.slot.SlotManager; 9 | 10 | import java.util.Collections; 11 | import java.util.LinkedHashMap; 12 | import java.util.Map; 13 | import java.util.function.Function; 14 | import java.util.stream.Collectors; 15 | 16 | public class InventorySnapshot implements ConfigurationSerializable { 17 | 18 | private static final String INV_SLOTS = "slots"; 19 | private static final String INV_BOUGHT_SLOTS = "bought-slots"; 20 | 21 | private final Map slots; 22 | private final int boughtSlots; 23 | 24 | 25 | private InventorySnapshot(@NotNull Map slots, int boughtSlots) { 26 | this.slots = slots; 27 | this.boughtSlots = boughtSlots; 28 | } 29 | 30 | @NotNull 31 | public static InventorySnapshot create(@NotNull PlayerWrapper playerWrapper) { 32 | final Map slots = SlotManager.instance().getSlots().stream() 33 | .filter(slot -> slot.getSlotType() != Slot.SlotType.ARMOR) 34 | .map(slot -> SlotSnapshot.create(slot, playerWrapper)) 35 | .filter(SlotSnapshot::shouldBeSaved) 36 | .collect(Collectors.toMap(SlotSnapshot::getName, Function.identity())); 37 | 38 | return new InventorySnapshot(slots, playerWrapper.getBuyedGenericSlots()); 39 | } 40 | 41 | @SuppressWarnings("unused") // Should be implemented because of ConfigurationSerializable 42 | @NotNull 43 | public static InventorySnapshot deserialize(@NotNull Map map) { 44 | final Map slots = (Map) map.getOrDefault(INV_SLOTS, Collections.emptyMap()); 45 | int boughtSlots = (Integer) map.getOrDefault(INV_BOUGHT_SLOTS, 0); 46 | 47 | return new InventorySnapshot(slots, boughtSlots); 48 | } 49 | 50 | @NotNull 51 | @Override 52 | public Map serialize() { 53 | final Map serializedInventory = new LinkedHashMap<>(); 54 | 55 | serializedInventory.put(INV_BOUGHT_SLOTS, boughtSlots); 56 | serializedInventory.put(INV_SLOTS, slots); 57 | 58 | return serializedInventory; 59 | } 60 | 61 | public PlayerWrapper restore(@NotNull Player player) { 62 | final PlayerWrapper playerWrapper = new PlayerWrapper(player); 63 | playerWrapper.setBuyedSlots(boughtSlots); 64 | 65 | SlotManager.instance().getSlots().stream() 66 | .filter(slot -> slots.containsKey(slot.getName())) 67 | .forEach(slot -> slots.get(slot.getName()).restore(playerWrapper, slot)); 68 | 69 | return playerWrapper; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/misc/serialization/LegacySerialization.java: -------------------------------------------------------------------------------- 1 | package ru.endlesscode.rpginventory.misc.serialization; 2 | 3 | import com.comphenix.protocol.wrappers.nbt.NbtCompound; 4 | import com.comphenix.protocol.wrappers.nbt.io.NbtBinarySerializer; 5 | import org.bukkit.Material; 6 | import org.bukkit.entity.Player; 7 | import org.bukkit.inventory.Inventory; 8 | import org.bukkit.inventory.ItemStack; 9 | import org.jetbrains.annotations.NotNull; 10 | import org.jetbrains.annotations.Nullable; 11 | import ru.endlesscode.rpginventory.compat.MaterialCompat; 12 | import ru.endlesscode.rpginventory.inventory.PlayerWrapper; 13 | import ru.endlesscode.rpginventory.inventory.backpack.Backpack; 14 | import ru.endlesscode.rpginventory.inventory.backpack.BackpackManager; 15 | import ru.endlesscode.rpginventory.inventory.backpack.BackpackType; 16 | import ru.endlesscode.rpginventory.inventory.slot.Slot; 17 | import ru.endlesscode.rpginventory.inventory.slot.SlotManager; 18 | import ru.endlesscode.rpginventory.utils.FileUtils; 19 | import ru.endlesscode.rpginventory.utils.ItemUtils; 20 | import ru.endlesscode.rpginventory.utils.NbtFactoryMirror; 21 | 22 | import java.io.DataInputStream; 23 | import java.io.IOException; 24 | import java.nio.file.Files; 25 | import java.nio.file.Path; 26 | import java.util.ArrayList; 27 | import java.util.List; 28 | import java.util.UUID; 29 | import java.util.zip.GZIPInputStream; 30 | 31 | /** 32 | * Legacy serialization for back compatibility. 33 | */ 34 | @Deprecated 35 | class LegacySerialization { 36 | 37 | @NotNull 38 | static PlayerWrapper loadPlayer(Player player, @NotNull Path file) throws IOException { 39 | PlayerWrapper playerWrapper = new PlayerWrapper(player); 40 | Inventory inventory = playerWrapper.getInventory(); 41 | 42 | try (DataInputStream dataInput = new DataInputStream(new GZIPInputStream(Files.newInputStream(file)))) { 43 | NbtCompound playerNbt = NbtBinarySerializer.DEFAULT.deserializeCompound(dataInput); 44 | 45 | playerWrapper.setBuyedSlots(playerNbt.getInteger("buyed-slots")); 46 | playerNbt.remove("buyed-slots"); 47 | 48 | NbtCompound itemsNbt = playerNbt.containsKey("slots") ? playerNbt.getCompound("slots") : playerNbt; 49 | 50 | for (Slot slot : SlotManager.instance().getSlots()) { 51 | if (itemsNbt.containsKey(slot.getName())) { 52 | NbtCompound slotNbt = itemsNbt.getCompound(slot.getName()); 53 | if (slot.getSlotType() != Slot.SlotType.valueOf(slotNbt.getString("type"))) { 54 | continue; 55 | } 56 | 57 | if (slotNbt.containsKey("buyed")) { 58 | playerWrapper.setBuyedSlots(slot.getName()); 59 | } 60 | 61 | NbtCompound itemListNbt = slotNbt.getCompound("items"); 62 | List itemList = new ArrayList<>(); 63 | for (String key : itemListNbt.getKeys()) { 64 | itemList.add(nbtToItemStack(itemListNbt.getCompound(key))); 65 | } 66 | 67 | List slotIds = slot.getSlotIds(); 68 | for (int i = 0; i < slotIds.size(); i++) { 69 | if (itemList.size() > i) { 70 | inventory.setItem(slotIds.get(i), itemList.get(i)); 71 | } 72 | } 73 | } 74 | } 75 | } 76 | 77 | return playerWrapper; 78 | } 79 | 80 | @Nullable 81 | static Backpack loadBackpack(@NotNull Path file) throws IOException { 82 | Backpack backpack; 83 | try (DataInputStream dataInput = new DataInputStream(new GZIPInputStream(Files.newInputStream(file)))) { 84 | NbtCompound nbtList = NbtBinarySerializer.DEFAULT.deserializeCompound(dataInput); 85 | 86 | BackpackType type = BackpackManager.getBackpackType(nbtList.getString("type")); 87 | if (type == null) { 88 | return null; 89 | } 90 | 91 | long lastUse = (nbtList.containsKey("last-use")) ? nbtList.getLong("last-use") : System.currentTimeMillis(); 92 | backpack = new Backpack(type, UUID.fromString(FileUtils.stripExtension(file.getFileName().toString()))); 93 | backpack.setLastUse(lastUse); 94 | NbtCompound itemList = nbtList.getCompound("contents"); 95 | ItemStack[] contents = new ItemStack[type.getSize()]; 96 | for (int i = 0; i < type.getSize() && itemList.containsKey(i + ""); i++) { 97 | NbtCompound compound = itemList.getCompound(i + ""); 98 | contents[i] = compound == null ? new ItemStack(Material.AIR) : nbtToItemStack(compound); 99 | } 100 | 101 | backpack.setContents(contents); 102 | } 103 | 104 | return backpack; 105 | } 106 | 107 | 108 | @NotNull 109 | private static ItemStack nbtToItemStack(NbtCompound nbt) { 110 | ItemStack item = new ItemStack(MaterialCompat.getMaterialOrAir(nbt.getString("material"))); 111 | 112 | if (ItemUtils.isNotEmpty(item)) { 113 | item.setAmount(nbt.getInteger("amount")); 114 | item.setDurability(nbt.getShort("data")); 115 | 116 | if (nbt.containsKey("tag")) { 117 | item = ItemUtils.toBukkitItemStack(item); 118 | if (ItemUtils.isNotEmpty(item)) { 119 | NbtFactoryMirror.setItemTag(item, nbt.getCompound("tag")); 120 | } 121 | } 122 | } 123 | 124 | return item; 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/misc/serialization/Serialization.java: -------------------------------------------------------------------------------- 1 | package ru.endlesscode.rpginventory.misc.serialization; 2 | 3 | import org.bukkit.configuration.InvalidConfigurationException; 4 | import org.bukkit.configuration.file.FileConfiguration; 5 | import org.bukkit.configuration.file.YamlConfiguration; 6 | import org.bukkit.configuration.serialization.ConfigurationSerialization; 7 | import org.bukkit.entity.Player; 8 | import org.jetbrains.annotations.NotNull; 9 | import org.jetbrains.annotations.Nullable; 10 | import org.yaml.snakeyaml.reader.ReaderException; 11 | import ru.endlesscode.rpginventory.inventory.PlayerWrapper; 12 | import ru.endlesscode.rpginventory.inventory.backpack.Backpack; 13 | import ru.endlesscode.rpginventory.utils.FileUtils; 14 | import ru.endlesscode.rpginventory.utils.Log; 15 | 16 | import java.io.IOException; 17 | import java.io.InputStreamReader; 18 | import java.io.OutputStreamWriter; 19 | import java.nio.charset.StandardCharsets; 20 | import java.nio.file.Files; 21 | import java.nio.file.Path; 22 | import java.nio.file.StandardCopyOption; 23 | import java.util.Objects; 24 | import java.util.zip.GZIPInputStream; 25 | import java.util.zip.GZIPOutputStream; 26 | 27 | public class Serialization { 28 | 29 | private static final String ROOT_TAG = "data"; 30 | 31 | public static void registerTypes() { 32 | ConfigurationSerialization.registerClass(InventorySnapshot.class); 33 | ConfigurationSerialization.registerClass(SlotSnapshot.class); 34 | ConfigurationSerialization.registerClass(Backpack.class); 35 | } 36 | 37 | @Nullable 38 | public static PlayerWrapper loadPlayerOrNull(Player player, @NotNull Path file) { 39 | PlayerWrapper playerWrapper; 40 | try { 41 | playerWrapper = loadPlayer(player, file); 42 | } catch (IOException | InvalidConfigurationException e) { 43 | Log.w(e); 44 | FileUtils.resolveException(file); 45 | playerWrapper = null; 46 | } 47 | return playerWrapper; 48 | } 49 | 50 | @NotNull 51 | private static PlayerWrapper loadPlayer(Player player, @NotNull Path file) 52 | throws IOException, InvalidConfigurationException { 53 | PlayerWrapper playerWrapper; 54 | try { 55 | InventorySnapshot inventorySnapshot = (InventorySnapshot) load(file); 56 | playerWrapper = inventorySnapshot.restore(player); 57 | } catch (InvalidConfigurationException e) { 58 | if (e.getCause() instanceof ReaderException) { 59 | Log.w("Can''t load {0}''s inventory. Trying to use legacy loader...", player.getName()); 60 | playerWrapper = LegacySerialization.loadPlayer(player, file); 61 | } else { 62 | throw e; 63 | } 64 | } 65 | return playerWrapper; 66 | } 67 | 68 | public static Backpack loadBackpack(@NotNull Path file) throws IOException, InvalidConfigurationException { 69 | Backpack backpack; 70 | try { 71 | backpack = (Backpack) load(file); 72 | } catch (InvalidConfigurationException e) { 73 | if (e.getCause() instanceof ReaderException) { 74 | Log.w("Can''t load backpack {0}. Trying to use legacy loader...", file.getFileName().toString()); 75 | backpack = LegacySerialization.loadBackpack(file); 76 | } else { 77 | throw e; 78 | } 79 | } 80 | 81 | return backpack; 82 | } 83 | 84 | public static void save(@NotNull Object data, @NotNull Path file) throws IOException { 85 | final FileConfiguration serializedData = new YamlConfiguration(); 86 | serializedData.set(ROOT_TAG, data); 87 | 88 | Path tempFile = Files.createTempFile(file.getParent(), file.getFileName().toString(), null); 89 | try (OutputStreamWriter stream = new OutputStreamWriter(new GZIPOutputStream(Files.newOutputStream(tempFile)), StandardCharsets.UTF_8)) { 90 | stream.write(serializedData.saveToString()); 91 | } 92 | Files.move(tempFile, file, StandardCopyOption.REPLACE_EXISTING); 93 | } 94 | 95 | @NotNull 96 | private static Object load(@NotNull Path file) 97 | throws IOException, InvalidConfigurationException { 98 | final FileConfiguration serializedData = new YamlConfiguration(); 99 | try (InputStreamReader reader = new InputStreamReader(new GZIPInputStream(Files.newInputStream(file)), StandardCharsets.UTF_8)) { 100 | serializedData.load(reader); 101 | } 102 | 103 | return Objects.requireNonNull(serializedData.get(ROOT_TAG), "Serialized data not found"); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/misc/serialization/SlotSnapshot.java: -------------------------------------------------------------------------------- 1 | package ru.endlesscode.rpginventory.misc.serialization; 2 | 3 | import org.bukkit.configuration.serialization.ConfigurationSerializable; 4 | import org.bukkit.inventory.Inventory; 5 | import org.bukkit.inventory.ItemStack; 6 | import org.jetbrains.annotations.NotNull; 7 | import ru.endlesscode.rpginventory.inventory.PlayerWrapper; 8 | import ru.endlesscode.rpginventory.inventory.slot.Slot; 9 | import ru.endlesscode.rpginventory.utils.ItemUtils; 10 | import ru.endlesscode.rpginventory.utils.Log; 11 | 12 | import java.util.Collections; 13 | import java.util.LinkedHashMap; 14 | import java.util.List; 15 | import java.util.Map; 16 | import java.util.stream.Collectors; 17 | 18 | public class SlotSnapshot implements ConfigurationSerializable { 19 | 20 | private static final String SLOT_TYPE = "type"; 21 | private static final String SLOT_BOUGHT = "bought"; 22 | private static final String SLOT_ITEMS = "items"; 23 | 24 | private final String name; 25 | private final String type; 26 | private final boolean bought; 27 | private final List items; 28 | 29 | private SlotSnapshot(@NotNull String name, @NotNull String type, boolean bought, @NotNull List items) { 30 | this.name = name; 31 | this.type = type; 32 | this.bought = bought; 33 | this.items = items; 34 | } 35 | 36 | @NotNull 37 | public static SlotSnapshot create(@NotNull Slot slot, @NotNull PlayerWrapper playerWrapper) { 38 | boolean bought = playerWrapper.isBuyedSlot(slot.getName()); 39 | 40 | final Inventory inventory = playerWrapper.getInventory(); 41 | final List items = slot.getSlotIds().stream() 42 | .map(inventory::getItem) 43 | .filter(stack -> ItemUtils.isNotEmpty(stack) && !slot.isCup(stack)) 44 | .collect(Collectors.toList()); 45 | 46 | return new SlotSnapshot(slot.getName(), slot.getSlotType().name(), bought, items); 47 | } 48 | 49 | @SuppressWarnings("unused") // Should be implemented because of ConfigurationSerializable 50 | @NotNull 51 | public static SlotSnapshot deserialize(@NotNull Map map) { 52 | String type = (String) map.getOrDefault(SLOT_TYPE, "{missing}"); 53 | boolean bought = map.containsKey(SLOT_BOUGHT); 54 | List items = (List) map.getOrDefault(SLOT_ITEMS, Collections.emptyList()); 55 | 56 | return new SlotSnapshot("", type, bought, items); 57 | } 58 | 59 | @NotNull 60 | @Override 61 | public Map serialize() { 62 | final Map serializedSlot = new LinkedHashMap<>(); 63 | serializedSlot.put(SLOT_TYPE, this.type); 64 | serializedSlot.put(SLOT_ITEMS, this.items); 65 | if (this.bought) { 66 | serializedSlot.put(SLOT_BOUGHT, true); 67 | } 68 | 69 | return serializedSlot; 70 | } 71 | 72 | void restore(@NotNull PlayerWrapper playerWrapper, @NotNull Slot slot) { 73 | if (!slot.getSlotType().name().equals(type)) { 74 | Log.w("Slot ''{0}'' skipped. Wrong type of saved slot: {1}", slot.getName(), type); 75 | return; 76 | } 77 | 78 | if (bought) { 79 | playerWrapper.setBuyedSlots(slot.getName()); 80 | } 81 | 82 | final Inventory inventory = playerWrapper.getInventory(); 83 | final List slotIds = slot.getSlotIds(); 84 | for (int i = 0; i < Math.min(slotIds.size(), items.size()); i++) { 85 | inventory.setItem(slotIds.get(i), items.get(i)); 86 | } 87 | } 88 | 89 | boolean shouldBeSaved() { 90 | return !items.isEmpty() || bought; 91 | } 92 | 93 | public String getName() { 94 | return name; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/pet/Attributes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.pet; 20 | 21 | import java.util.UUID; 22 | 23 | public class Attributes { 24 | public static final String SPEED_MODIFIER = "RPGInventory Speed Bonus"; 25 | public static final UUID SPEED_MODIFIER_ID = UUID.fromString("2deaf4fc-1673-4c5b-ac4f-25e37e08760f"); 26 | 27 | static final double ONE_BPS = 0.10638297872; 28 | static final double GALLOP_MULTIPLIER = 4.46808510803; 29 | 30 | private Attributes() { 31 | // Shouldn't be instantiated 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/pet/CooldownTimer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.pet; 20 | 21 | import org.bukkit.entity.Player; 22 | import org.bukkit.inventory.Inventory; 23 | import org.bukkit.inventory.ItemStack; 24 | import org.bukkit.inventory.meta.ItemMeta; 25 | import org.bukkit.scheduler.BukkitRunnable; 26 | import ru.endlesscode.rpginventory.RPGInventory; 27 | import ru.endlesscode.rpginventory.inventory.InventoryManager; 28 | import ru.endlesscode.rpginventory.inventory.slot.Slot; 29 | import ru.endlesscode.rpginventory.inventory.slot.SlotManager; 30 | import ru.endlesscode.rpginventory.utils.ItemUtils; 31 | 32 | import java.util.Objects; 33 | 34 | /** 35 | * Created by OsipXD on 27.08.2015 36 | * It is part of the RpgInventory. 37 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 38 | */ 39 | @Deprecated 40 | class CooldownTimer extends BukkitRunnable { 41 | private final Player player; 42 | private final ItemStack petItem; 43 | 44 | @Deprecated 45 | public CooldownTimer(Player player, ItemStack petItem) { 46 | this.player = player; 47 | this.petItem = petItem; 48 | } 49 | 50 | @Override 51 | public void run() { 52 | if (!InventoryManager.playerIsLoaded(this.player)) { 53 | this.cancel(); 54 | return; 55 | } 56 | 57 | Inventory inventory = InventoryManager.get(this.player).getInventory(); 58 | final boolean playerIsAlive = !this.player.isOnline() || this.player.isDead(); 59 | final boolean playerHasNotPetItem = inventory.getItem(PetManager.getPetSlotId()) == null; 60 | if (playerIsAlive || !PetManager.isEnabled() || playerHasNotPetItem) { 61 | this.cancel(); 62 | return; 63 | } 64 | 65 | int cooldown = PetManager.getCooldown(this.petItem); 66 | 67 | if (cooldown > 1) { 68 | ItemStack item = this.petItem.clone(); 69 | if (cooldown < 60) { 70 | item.setAmount(cooldown); 71 | } 72 | 73 | ItemMeta itemMeta = item.getItemMeta(); 74 | if (itemMeta != null) { 75 | itemMeta.setDisplayName(itemMeta.getDisplayName() 76 | + RPGInventory.getLanguage().getMessage("pet.cooldown", cooldown)); 77 | PetManager.addGlow(itemMeta); 78 | item.setItemMeta(itemMeta); 79 | } 80 | String itemTag = ItemUtils.getTag(this.petItem, ItemUtils.PET_TAG); 81 | 82 | if (itemTag.isEmpty()) { 83 | Slot petSlot = Objects.requireNonNull(SlotManager.instance().getPetSlot(), "Pet slot can't be null!"); 84 | inventory.setItem(PetManager.getPetSlotId(), petSlot.getCup()); 85 | this.cancel(); 86 | } else { 87 | ItemUtils.setTag(item, ItemUtils.PET_TAG, itemTag); 88 | inventory.setItem(PetManager.getPetSlotId(), item); 89 | } 90 | } else { 91 | PetManager.respawnPet(this.player, this.petItem); 92 | inventory.setItem(PetManager.getPetSlotId(), this.petItem); 93 | this.cancel(); 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/pet/PetFood.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.pet; 20 | 21 | import org.bukkit.configuration.ConfigurationSection; 22 | import org.bukkit.entity.LivingEntity; 23 | import org.bukkit.inventory.ItemStack; 24 | import org.bukkit.inventory.meta.ItemMeta; 25 | import org.jetbrains.annotations.Contract; 26 | import org.jetbrains.annotations.NotNull; 27 | import ru.endlesscode.rpginventory.RPGInventory; 28 | import ru.endlesscode.rpginventory.item.Texture; 29 | import ru.endlesscode.rpginventory.item.TexturedItem; 30 | import ru.endlesscode.rpginventory.misc.FileLanguage; 31 | import ru.endlesscode.rpginventory.utils.ItemUtils; 32 | import ru.endlesscode.rpginventory.utils.StringUtils; 33 | 34 | import java.util.ArrayList; 35 | import java.util.List; 36 | 37 | /** 38 | * Created by OsipXD on 28.08.2015 39 | * It is part of the RpgInventory. 40 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 41 | */ 42 | public class PetFood extends TexturedItem { 43 | @NotNull 44 | private final String name; 45 | @NotNull 46 | private final List lore; 47 | 48 | private final double value; 49 | private final List eaters; 50 | 51 | private ItemStack foodItem; 52 | 53 | PetFood(Texture texture, @NotNull ConfigurationSection config) { 54 | super(texture); 55 | 56 | this.name = StringUtils.coloredLine(config.getString("name")); 57 | this.lore = StringUtils.coloredLines(config.getStringList("lore")); 58 | this.value = config.getDouble("value"); 59 | this.eaters = config.getStringList("eaters"); 60 | 61 | this.createFoodItem(config.getName()); 62 | } 63 | 64 | @Contract("null -> false") 65 | public static boolean isFoodItem(ItemStack itemStack) { 66 | return ItemUtils.isNotEmpty(itemStack) && ItemUtils.hasTag(itemStack, ItemUtils.FOOD_TAG); 67 | } 68 | 69 | private void createFoodItem(String id) { 70 | // Set texture 71 | ItemStack spawnItem = this.texture.getItemStack(); 72 | 73 | // Set lore and display itemName 74 | ItemMeta meta = spawnItem.getItemMeta(); 75 | meta.setDisplayName(this.name); 76 | 77 | FileLanguage lang = RPGInventory.getLanguage(); 78 | List lore = new ArrayList<>(this.lore); 79 | lore.add(lang.getMessage("pet.food.value", (int) (this.value))); 80 | meta.setLore(lore); 81 | spawnItem.setItemMeta(meta); 82 | 83 | this.foodItem = ItemUtils.setTag(spawnItem, ItemUtils.FOOD_TAG, id); 84 | } 85 | 86 | public ItemStack getFoodItem() { 87 | return this.foodItem; 88 | } 89 | 90 | public double getValue() { 91 | return value; 92 | } 93 | 94 | public boolean canBeEaten(@NotNull LivingEntity pet) { 95 | String petType = pet.getType().toString(); 96 | return petType != null && this.eaters.contains(petType); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/utils/CommandUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.utils; 20 | 21 | import org.bukkit.Bukkit; 22 | import org.bukkit.entity.Player; 23 | import org.jetbrains.annotations.NotNull; 24 | 25 | /** 26 | * Created by OsipXD on 16.11.2015 27 | * It is part of the RpgInventory. 28 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 29 | */ 30 | public class CommandUtils { 31 | /** 32 | * Execute command from player to server 33 | * 34 | * @param player The player 35 | * @param command The command 36 | * @param runFromOp If true, command will be run from OP 37 | */ 38 | public static void sendCommand(@NotNull Player player, String command, boolean runFromOp) { 39 | command = StringUtils.setPlaceholders(player, command); 40 | 41 | if (runFromOp) { 42 | Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command); 43 | } else { 44 | player.performCommand(command); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/utils/EntityUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.utils; 20 | 21 | import com.comphenix.protocol.utility.MinecraftReflection; 22 | import org.bukkit.Location; 23 | import org.bukkit.entity.LivingEntity; 24 | import org.bukkit.entity.Player; 25 | import org.jetbrains.annotations.NotNull; 26 | import ru.endlesscode.inspector.report.Reporter; 27 | import ru.endlesscode.rpginventory.RPGInventory; 28 | import ru.endlesscode.rpginventory.inventory.InventoryManager; 29 | import ru.endlesscode.rpginventory.pet.PetManager; 30 | import ru.endlesscode.rpginventory.pet.PetType; 31 | 32 | import java.lang.reflect.InvocationTargetException; 33 | import java.lang.reflect.Method; 34 | 35 | /** 36 | * Created by OsipXD on 02.12.2015 37 | * It is part of the RpgInventory. 38 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 39 | */ 40 | public class EntityUtils { 41 | 42 | private static Method craftEntity_getHandle; 43 | private static Method navigationAbstract_a; 44 | private static Method entityInsentient_getNavigation; 45 | private static final Class entityInsentientClass = MinecraftReflection.getMinecraftClass("EntityInsentient"); 46 | 47 | private static final Reporter reporter = RPGInventory.getInstance().getReporter(); 48 | 49 | static { 50 | try { 51 | craftEntity_getHandle = MinecraftReflection.getCraftEntityClass().getDeclaredMethod("getHandle"); 52 | entityInsentient_getNavigation = entityInsentientClass.getDeclaredMethod("getNavigation"); 53 | navigationAbstract_a = MinecraftReflection.getMinecraftClass("NavigationAbstract") 54 | .getDeclaredMethod("a", double.class, double.class, double.class, double.class); 55 | } catch (NoSuchMethodException e) { 56 | reporter.report("Error on EntityUtils initialization", e); 57 | } 58 | } 59 | 60 | public static void goPetToPlayer(@NotNull final Player player, @NotNull final LivingEntity entity) { 61 | if (!InventoryManager.playerIsLoaded(player) || !player.isOnline() || entity.isDead()) { 62 | return; 63 | } 64 | 65 | //Issue #120, by 12 Feb 18 : https://github.com/EndlessCodeGroup/RPGInventory/issues/120#issuecomment-364834420 66 | if (!player.getWorld().getName().equals(entity.getWorld().getName())) { 67 | PetManager.teleportPet(player, null); 68 | return; 69 | } 70 | 71 | Location target = player.getLocation(); 72 | final double distance = target.distance(entity.getLocation()); 73 | if (distance > 20D && LocationUtils.isSafeLocation(target)) { 74 | PetManager.teleportPet(player, null); 75 | } else if (distance < 4D) { 76 | return; 77 | } 78 | 79 | PetType petType = PetManager.getPetFromEntity(entity, player); 80 | double speedModifier = petType == null ? 1.0 : 0.4 / petType.getSpeed(); 81 | 82 | try { 83 | Object insentient = entityInsentientClass.cast(craftEntity_getHandle.invoke(entity)); 84 | Object navigation = entityInsentient_getNavigation.invoke(insentient); 85 | navigationAbstract_a.invoke(navigation, target.getX(), target.getY(), target.getZ(), speedModifier); 86 | } catch (IllegalAccessException | InvocationTargetException e) { 87 | reporter.report("Error on going pet to player", e); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/utils/FileUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.utils; 20 | 21 | import org.jetbrains.annotations.NotNull; 22 | 23 | import java.io.IOException; 24 | import java.nio.file.Files; 25 | import java.nio.file.Path; 26 | import java.nio.file.StandardCopyOption; 27 | 28 | /** 29 | * Created by OsipXD on 07.12.2015 30 | * It is part of the RpgInventory. 31 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 32 | */ 33 | public class FileUtils { 34 | 35 | @NotNull 36 | public static String stripExtension(String fileName) { 37 | return fileName.substring(0, fileName.lastIndexOf('.')); 38 | } 39 | 40 | public static void resolveException(Path path) { 41 | try { 42 | final byte[] bytes = Files.readAllBytes(path); 43 | boolean isAllBytesAreZero = true; 44 | for (byte b : bytes) { 45 | if (b != 0) { 46 | isAllBytesAreZero = false; 47 | break; 48 | } 49 | } 50 | 51 | String newFileName = path.getFileName().toString().concat(isAllBytesAreZero ? ".gone" : ".broken"); 52 | Files.move(path, path.getParent().resolve(newFileName), StandardCopyOption.REPLACE_EXISTING); 53 | } catch (IOException ignored) { 54 | } 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/utils/InventoryUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 osipf 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.utils; 20 | 21 | import org.bukkit.entity.Player; 22 | import org.bukkit.inventory.EntityEquipment; 23 | import org.bukkit.inventory.ItemStack; 24 | import org.jetbrains.annotations.Contract; 25 | import org.jetbrains.annotations.NotNull; 26 | import ru.endlesscode.rpginventory.api.InventoryAPI; 27 | import ru.endlesscode.rpginventory.inventory.ArmorType; 28 | import ru.endlesscode.rpginventory.inventory.InventoryManager; 29 | import ru.endlesscode.rpginventory.inventory.slot.Slot; 30 | import ru.endlesscode.rpginventory.item.CustomItem; 31 | import ru.endlesscode.rpginventory.item.ItemManager; 32 | 33 | import java.util.ArrayList; 34 | import java.util.Collections; 35 | import java.util.List; 36 | 37 | public class InventoryUtils { 38 | public static void heldFreeSlot(@NotNull Player player, int start, SearchType type) { 39 | if (type == SearchType.NEXT) { 40 | for (int i = start + 1; i < start + 9; i++) { 41 | int index = i % 9; 42 | if (!InventoryManager.isQuickEmptySlot(player.getInventory().getItem(index))) { 43 | player.getInventory().setHeldItemSlot(index); 44 | return; 45 | } 46 | } 47 | } else { 48 | for (int i = start - 1; i > start - 9; i--) { 49 | int index = (i + 9) % 9; 50 | if (!InventoryManager.isQuickEmptySlot(player.getInventory().getItem(index))) { 51 | player.getInventory().setHeldItemSlot(index); 52 | return; 53 | } 54 | } 55 | } 56 | } 57 | 58 | @Contract(pure = true) 59 | public static int getQuickSlot(int slotId) { 60 | return slotId % 9; 61 | } 62 | 63 | public static boolean playerNeedArmor(Player player, ArmorType armorType) { 64 | ItemStack armorItem = armorType.getItem(player); 65 | return ItemUtils.isEmpty(armorItem) && armorType != ArmorType.UNKNOWN; 66 | } 67 | 68 | public static int getArmorSlotId(Slot slot) { 69 | switch (slot.getName()) { 70 | case "helmet": 71 | return 5; 72 | case "chestplate": 73 | return 6; 74 | case "leggings": 75 | return 7; 76 | default: 77 | return 8; 78 | } 79 | } 80 | 81 | @NotNull 82 | public static List collectEffectiveItems(@NotNull Player player, boolean notifyPlayer) { 83 | List items = new ArrayList<>(InventoryAPI.getPassiveItems(player)); 84 | Collections.addAll(items, player.getInventory().getArmorContents()); 85 | 86 | EntityEquipment equipment = player.getEquipment(); 87 | assert equipment != null; 88 | 89 | ItemStack itemInHand = equipment.getItemInMainHand(); 90 | if (CustomItem.isCustomItem(itemInHand) && ItemManager.allowedForPlayer(player, itemInHand, notifyPlayer)) { 91 | items.add(itemInHand); 92 | } 93 | 94 | itemInHand = equipment.getItemInOffHand(); 95 | if (CustomItem.isCustomItem(itemInHand) && ItemManager.allowedForPlayer(player, itemInHand, notifyPlayer)) { 96 | items.add(itemInHand); 97 | } 98 | 99 | return items; 100 | } 101 | 102 | public enum SearchType { 103 | NEXT, 104 | PREV 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/utils/Log.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2018 EndlessCode Group and contributors 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.utils; 20 | 21 | import org.jetbrains.annotations.NotNull; 22 | 23 | import java.text.MessageFormat; 24 | import java.util.logging.Level; 25 | import java.util.logging.Logger; 26 | 27 | @SuppressWarnings("CheckStyle") 28 | public final class Log { 29 | 30 | private static Logger logger; 31 | 32 | private Log() { 33 | // static class 34 | } 35 | 36 | public static void init(@NotNull Logger logger) { 37 | Log.logger = logger; 38 | } 39 | 40 | public static void i(@NotNull String message, Object... args) { 41 | logger.info(prepareMessage(message, args)); 42 | } 43 | 44 | public static void w(Throwable t) { 45 | logger.log(Level.WARNING, t.getMessage(), t); 46 | } 47 | 48 | public static void w(@NotNull String message, Object... args) { 49 | logger.warning(prepareMessage(message, args)); 50 | } 51 | 52 | public static void w(Throwable t, @NotNull String message, Object... args) { 53 | logger.log(Level.WARNING, prepareMessage(message, args), t); 54 | } 55 | 56 | public static void d(Throwable t) { 57 | logger.log(Level.FINE, "", t); 58 | } 59 | 60 | public static void s(@NotNull String message, Object... args) { 61 | logger.severe(prepareMessage(message, args)); 62 | } 63 | 64 | private static String prepareMessage(String message, Object... args) { 65 | return MessageFormat.format(message, args); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/utils/NbtFactoryMirror.java: -------------------------------------------------------------------------------- 1 | package ru.endlesscode.rpginventory.utils; 2 | 3 | import com.comphenix.protocol.reflect.StructureModifier; 4 | import com.comphenix.protocol.utility.MinecraftReflection; 5 | import com.comphenix.protocol.wrappers.BukkitConverters; 6 | import com.comphenix.protocol.wrappers.nbt.NbtBase; 7 | import com.comphenix.protocol.wrappers.nbt.NbtCompound; 8 | import com.comphenix.protocol.wrappers.nbt.NbtFactory; 9 | import com.comphenix.protocol.wrappers.nbt.NbtWrapper; 10 | import org.bukkit.Material; 11 | import org.bukkit.inventory.ItemStack; 12 | 13 | /** 14 | * For some kind of shit, ProtocolLib's method works wrong in version 4.4.0 But if I just copy 15 | * their code to my class it works fine. Recompiling of ProtocolLib also helps. (╯°□°)╯︵ ┻━┻ 16 | * TODO: Remove when new version of ProtocolLib will be released. 17 | * Track progress of the issue here: https://github.com/dmulloy2/ProtocolLib/issues/587 18 | */ 19 | public final class NbtFactoryMirror { 20 | 21 | private static StructureModifier itemStackModifier; 22 | 23 | private NbtFactoryMirror() { 24 | } 25 | 26 | public static NbtCompound fromItemCompound(ItemStack stack) { 27 | return NbtFactory.asCompound(fromItemTag(stack)); 28 | } 29 | 30 | public static void setItemTag(ItemStack stack, NbtCompound compound) { 31 | checkItemStack(stack); 32 | StructureModifier> modifier = getStackModifier(stack); 33 | modifier.write(0, compound); 34 | } 35 | 36 | private static NbtWrapper fromItemTag(ItemStack stack) { 37 | checkItemStack(stack); 38 | StructureModifier> modifier = getStackModifier(stack); 39 | NbtBase result = modifier.read(0); 40 | if (result == null) { 41 | result = com.comphenix.protocol.wrappers.nbt.NbtFactory.ofCompound("tag"); 42 | modifier.write(0, result); 43 | } 44 | 45 | return NbtFactory.fromBase((NbtBase) result); 46 | } 47 | 48 | private static void checkItemStack(ItemStack stack) { 49 | if (stack == null) { 50 | throw new IllegalArgumentException("Stack cannot be NULL."); 51 | } else if (!MinecraftReflection.isCraftItemStack(stack)) { 52 | throw new IllegalArgumentException("Stack must be a CraftItemStack."); 53 | } else if (stack.getType() == Material.AIR) { 54 | throw new IllegalArgumentException("ItemStacks representing air cannot store NMS information."); 55 | } 56 | } 57 | 58 | private static StructureModifier> getStackModifier(ItemStack stack) { 59 | Object nmsStack = MinecraftReflection.getMinecraftItemStack(stack); 60 | if (itemStackModifier == null) { 61 | itemStackModifier = new StructureModifier<>(nmsStack.getClass(), Object.class, false); 62 | } 63 | 64 | return itemStackModifier.withTarget(nmsStack).withType(MinecraftReflection.getNBTBaseClass(), BukkitConverters.getNbtConverter()); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/utils/PlayerUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.utils; 20 | 21 | import org.bukkit.entity.Player; 22 | import org.jetbrains.annotations.NotNull; 23 | import ru.endlesscode.inspector.bukkit.scheduler.TrackedBukkitRunnable; 24 | import ru.endlesscode.mimic.classes.BukkitClassSystem; 25 | import ru.endlesscode.mimic.level.BukkitLevelSystem; 26 | import ru.endlesscode.rpginventory.RPGInventory; 27 | import ru.endlesscode.rpginventory.inventory.InventoryManager; 28 | import ru.endlesscode.rpginventory.inventory.PlayerWrapper; 29 | 30 | import java.util.List; 31 | 32 | /** 33 | * Created by OsipXD on 09.11.2015 34 | * It is part of the RpgInventory. 35 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 36 | */ 37 | public class PlayerUtils { 38 | @SuppressWarnings("BooleanMethodIsAlwaysInverted") 39 | public static boolean checkLevel(@NotNull Player player, int required) { 40 | BukkitLevelSystem levelSystem = RPGInventory.getLevelSystem(player); 41 | return levelSystem.didReachLevel(required); 42 | } 43 | 44 | public static boolean checkClass(@NotNull Player player, @NotNull List classes) { 45 | BukkitClassSystem classSystem = RPGInventory.getClassSystem(player); 46 | return classSystem.hasAnyOfClasses(classes); 47 | } 48 | 49 | @SuppressWarnings("BooleanMethodIsAlwaysInverted") 50 | public static boolean checkMoney(@NotNull Player player, double cost) { 51 | double balance = (RPGInventory.economyConnected() ? RPGInventory.getEconomy().getBalance(player) : 0); 52 | if (balance < cost) { 53 | PlayerUtils.sendMessage(player, RPGInventory.getLanguage().getMessage("error.money", StringUtils.doubleToString(cost - balance))); 54 | return false; 55 | } 56 | 57 | return true; 58 | } 59 | 60 | public static void updateInventory(@NotNull final Player player) { 61 | new TrackedBukkitRunnable() { 62 | @Override 63 | public void run() { 64 | player.updateInventory(); 65 | } 66 | }.runTaskLater(RPGInventory.getInstance(), 1); 67 | } 68 | 69 | public static void sendMessage(@NotNull Player player, String message) { 70 | if (InventoryManager.playerIsLoaded(player)) { 71 | PlayerWrapper wrapper = InventoryManager.get(player); 72 | 73 | if (wrapper.getLastMessage().equals(message)) { 74 | return; 75 | } 76 | 77 | wrapper.setLastMessage(message); 78 | } 79 | 80 | player.sendMessage(message); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/utils/SafeEnums.java: -------------------------------------------------------------------------------- 1 | package ru.endlesscode.rpginventory.utils; 2 | 3 | import org.bukkit.DyeColor; 4 | import org.bukkit.entity.Cat; 5 | import org.bukkit.entity.Horse; 6 | import org.jetbrains.annotations.NotNull; 7 | import org.jetbrains.annotations.Nullable; 8 | 9 | import java.util.Arrays; 10 | 11 | public class SafeEnums { 12 | 13 | private SafeEnums() { 14 | // Shouldn't be instantiated 15 | } 16 | 17 | @Nullable 18 | public static DyeColor getDyeColor(String name) { 19 | return valueOf(DyeColor.class, name, "color"); 20 | } 21 | 22 | @Nullable 23 | public static Horse.Color getHorseColor(String name) { 24 | return valueOf(Horse.Color.class, name, "horse color"); 25 | } 26 | 27 | @Nullable 28 | public static Horse.Style getHorseStyle(String name) { 29 | return valueOf(Horse.Style.class, name, "horse style"); 30 | } 31 | 32 | @Nullable 33 | public static Cat.Type getCatType(String name) { 34 | return valueOf(Cat.Type.class, name, "cat type"); 35 | } 36 | 37 | @NotNull 38 | public static > T valueOfOrDefault(Class enumClass, String name, T defaultValue) { 39 | return valueOfOrDefault(enumClass, name, defaultValue, enumClass.getSimpleName()); 40 | } 41 | 42 | @NotNull 43 | public static > T valueOfOrDefault(Class enumClass, String name, T defaultValue, String alias) { 44 | T value = valueOf(enumClass, name, alias); 45 | if (value != null) { 46 | return value; 47 | } else { 48 | Log.w("Used {0} {1} by default.", defaultValue.name(), alias); 49 | return defaultValue; 50 | } 51 | } 52 | 53 | @Nullable 54 | public static > T valueOf(Class enumClass, String name, String alias) { 55 | if (name == null) { 56 | return null; 57 | } 58 | 59 | try { 60 | return Enum.valueOf(enumClass, name.toUpperCase()); 61 | } catch (IllegalArgumentException e) { 62 | Log.w("Unknown {0}: {1}. Available values: {2}", alias, name, Arrays.toString(enumClass.getEnumConstants())); 63 | return null; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/ru/endlesscode/rpginventory/utils/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2015-2017 Osip Fatkullin 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.utils; 20 | 21 | import java.math.BigDecimal; 22 | 23 | /** 24 | * Created by OsipXD on 20.05.2016 25 | * It is part of the RpgInventory. 26 | * All rights reserved 2014 - 2016 © «EndlessCode Group» 27 | */ 28 | public class Utils { 29 | public static double round(double a, int scale) { 30 | return new BigDecimal(a).setScale(scale, BigDecimal.ROUND_HALF_UP).doubleValue(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/resources/backpacks.yml: -------------------------------------------------------------------------------- 1 | backpacks: 2 | small: 3 | item: DIAMOND_HOE:20 4 | name: "&7Small backpack" 5 | lore: 6 | - "&e&oIt seems a trifle, but useful" 7 | size: 5 8 | medium: 9 | item: DIAMOND_HOE:21 10 | name: "&6Medium backpack" 11 | lore: 12 | - "&e&oHere your text" 13 | size: 10 14 | large: 15 | item: DIAMOND_HOE:22 16 | name: "&5Large backpack" 17 | lore: 18 | - "&e&oOh, its really big!" 19 | size: 15 20 | -------------------------------------------------------------------------------- /src/main/resources/items.yml: -------------------------------------------------------------------------------- 1 | items: 2 | assassin-gloves: 3 | texture: DIAMOND_HOE:24 4 | name: "Assassin gloves" 5 | lore: 6 | - "&e&oFaster than the wind..." 7 | rarity: RARE 8 | unbreakable: true 9 | level: 4 10 | classes: 11 | - Assassin 12 | stats: 13 | - DAMAGE +5-10 14 | - BOW_DAMAGE +2 15 | - HAND_DAMAGE +3 16 | - CRIT_CHANCE +2% 17 | - SPEED +30% 18 | - JUMP +4 19 | ring-of-gods: 20 | texture: DIAMOND_HOE:23 21 | name: "Ring of Gods" 22 | lore: 23 | - "&e&oWith this ring the Gods" 24 | - "&e&orule the world!" 25 | rarity: LEGENDARY 26 | drop: false 27 | abilities: 28 | permissions: 29 | - essentials.gamemode 30 | right-click: 31 | op: true 32 | command: "time set day" 33 | lore: "Set day" 34 | message: "Good day!" 35 | left-click: 36 | op: true 37 | command: "weather clear" 38 | lore: "Clear weather" 39 | message: "Sunshine!" 40 | mysterious-amulet: 41 | texture: DIAMOND_HOE:25 42 | name: "Mysterious amulet" 43 | lore: 44 | - "&e&oNobody knows how it works..." 45 | rarity: UNCOMMON 46 | hide-stats: true 47 | stats: 48 | - CRIT_DAMAGE +30-40% 49 | - ARMOR +50% 50 | artifact-of-knowledge: 51 | texture: DIAMOND_HOE:26 52 | name: "Artifact of Knowledge" 53 | lore: 54 | - "&e&oWow, how many new recipes!" 55 | rarity: MYTHICAL 56 | abilities: 57 | permissions: 58 | - rpginventory.craft.journeyman 59 | -------------------------------------------------------------------------------- /src/main/resources/lang/cs.lang: -------------------------------------------------------------------------------- 1 | #version: 2.0 | Do not remove this line! 2 | title: RPG Inventar 3 | 4 | locked.name: &cZamceny slot 5 | locked.lore: &6&oNejdrive musis odemknout predchozi slot 6 | 7 | buyable.name: &aDostupny slot 8 | buyable.lore: &6&oAby si odemkl slot musis: 9 | buyable.money: &6&o• mit {0} goldu 10 | buyable.level: &6&o• byt {0} lvl 11 | 12 | error.fall: &cYou can''t do it while you are flying 13 | error.money: &6Aby si mohl odemknout slot jeste potrebujes {0} gold 14 | error.level: &6Aby si mohl odemknout slot potrebujes {0} lvlu 15 | error.buyable: &6Odemknuti tohoto slotu te bude stat {0} gold. Klikni na to znova do 10 vterin aby si potvrdil odemceni. 16 | error.previous: &6Nejdrive odemkni predchozi sloty 17 | error.rp.denied: &cMusis povolit stazeni resource-packu! 18 | error.item.level: &6Vyzaduje &c{0} &6level 19 | error.item.class: &6Vyzaduje tridu &c{0} 20 | error.mount.owner: &6Zvire patri % 21 | error.creative: &4RPGInventory can''t be used in CREATIVE game mode. Please switch to SURVIVAL. 22 | 23 | message.buyed: &aUspesne jsi zakoupil slot 24 | message.perms: &cYou don''t have permission to use this command 25 | 26 | pet.name: {0} &f[{1}] 27 | pet.health: &cZivoty: &7{0} 28 | pet.damage: &cUtok: &7{0} 29 | pet.speed: &cRychlost: &7{0} block/s 30 | pet.revival.yes: &bOzivovaci doba: &7{0}s 31 | pet.revival.no: &bNeozivuje se 32 | pet.cooldown: &a&o({0}s) 33 | pet.food.value: &aObnovi: {0} Zivota 34 | pet.role.companion: Spolecnik 35 | pet.role.mount: Jezdec 36 | mypet.egg: MyPet Egg: {0} 37 | 38 | item.level: &fVyzaduje {0} level 39 | item.class: &fJen pro &b{0} 40 | item.nodrop: &7Nevypadne pri smrti 41 | item.left-click: &aLMB - {0} 42 | item.right-click: &aRMB - {0} 43 | item.hide: &7&oItem stats are hidden 44 | item.unbreakable: &7Unbreakable item 45 | 46 | stat.message.no_bonus: No bonus 47 | stat.damage: &cUtok: &7{0} 48 | stat.bow_damage: &cUtok (na dalku): &7{0} 49 | stat.hand_damage: &cUtok (na blizko): &7{0} 50 | stat.armor: &3Brneni: &7{0} 51 | stat.crit_chance: &6Sance na kriticky utok: &7{0} 52 | stat.crit_damage: &6Poskozeni kritickym utokem: &7{0} 53 | stat.speed: &9Rychlost: &7{0} 54 | stat.jump: &9Skoky: &7{0} 55 | 56 | backpack.desc: &8&oPrendej ho do spravneho slotu v RPG inventari 57 | backpack.size: &aKapacita: &7{0} 58 | backpack.limit: &cYou can''t have more than {0} backpack! 59 | -------------------------------------------------------------------------------- /src/main/resources/lang/de.lang: -------------------------------------------------------------------------------- 1 | #version: 2.0 | Do not remove this line! 2 | title: RPG Inventory 3 | 4 | locked.name: &cGesperrter Slot 5 | locked.lore: &6&oSchalte zuerst vorherige Slots frei 6 | 7 | buyable.name: &aSlot freischaltbar 8 | buyable.lore: &6&oVorraussetzungen für diesen Slot: 9 | buyable.money: &6&o• {0} Gold 10 | buyable.level: &6&o• Level {0} 11 | 12 | error.fall: &cDu kannst das nicht tun während du fliegst. 13 | error.money: &6Um weitere Slots freizuschalten benötigst du noch {0} Gold 14 | error.level: &6Um weitere Slots freizuschalten must du Level {0} erreicht haben. 15 | error.buyable: &6Um diesen Slot freizuschalten benötigst du {0} Gold. Klicke zum Bestätigen innerhalb von 10 Sekunden erneut. 16 | error.previous: &6Du musst zuerst die vorherigen Slots freischalten. 17 | error.rp.denied: &cDu musst dem Download des Resource-Packs zustimmen! 18 | error.item.level: &6Benötigtes &c{0} &6Level 19 | error.item.class: &6Benötigte Klasse &c{0} 20 | error.mount.owner: &6Dieses Reittier gehört: {0} 21 | error.creative: &4RPGInventory can''t be used in CREATIVE game mode. Please switch to SURVIVAL. 22 | 23 | message.buyed: &aDu hast den Slot erfolgreich freigeschaltet 24 | message.perms: &cYou don''t have permission to use this command 25 | 26 | pet.name: {0} &f[{1}] 27 | pet.health: &cLeben: &7{0} 28 | pet.damage: &cSChaden: &7{0} 29 | pet.speed: &cGeschwindigkeit: &7{0} block/s 30 | pet.revival.yes: &bAbklingzeit: &7{0}s 31 | pet.revival.no: &bWird nicht wiederbelebt 32 | pet.cooldown: &a&o({0}s) 33 | pet.food.value: &aStellt {0} LP wieder her 34 | pet.role.companion: Begleiter 35 | pet.role.mount: Reittier 36 | mypet.egg: MyPet Egg: {0} 37 | 38 | item.level: &fBenötigt {0} Level 39 | item.class: &fNur für &b{0} 40 | item.nodrop: &7Dropt nicht beim Tod 41 | item.left-click: &aLMB - {0} 42 | item.right-click: &aRMB - {0} 43 | item.hide: &7&oGegenstandstwerte nicht sichtbar 44 | item.unbreakable: &7Unzerstörbarer Gegenstand 45 | 46 | stat.message.no_bonus: Kein Bonus 47 | stat.damage: &cSchaden: &7{0} 48 | stat.bow_damage: &cSchaden (Bogen): &7{0} 49 | stat.hand_damage: &cSchaden (Hand): &7{0} 50 | stat.armor: &3Rüstung: &7{0} 51 | stat.crit_chance: &6Krit. Chance: &7{0} 52 | stat.crit_damage: &6Krit. Damage: &7{0} 53 | stat.speed: &9Geschwindigkeit: &7{0} 54 | stat.jump: &9Sprung: &7{0} 55 | 56 | backpack.desc: &8&oPlatzieren in den dafür vorgesehenen Slot und drücke &fRMB 57 | backpack.size: &aGröße: &7{0} 58 | backpack.limit: &cYou can''t have more than {0} backpack! 59 | -------------------------------------------------------------------------------- /src/main/resources/lang/en.lang: -------------------------------------------------------------------------------- 1 | #version: 2.0 | Do not remove this line! 2 | title: RPG Inventory 3 | 4 | locked.name: &cLocked slot 5 | locked.lore: &6&oYou need to unlock the previous slots first 6 | 7 | buyable.name: &aAvailable slot 8 | buyable.lore: &6&oTo purchase a slot, you must: 9 | buyable.money: &6&o• Have {0} gold 10 | buyable.level: &6&o• Be {0} lvl 11 | 12 | error.fall: &cYou can''t do it while you are flying 13 | error.money: &6To purchase slots you still need {0} gold 14 | error.level: &6To purchase slots you need {0} lvl 15 | error.buyable: &6To purchase this slots you need {0} gold. Click on it again in the next 10 seconds to confirm the purchase. 16 | error.previous: &6First unlock previous slots 17 | error.rp.denied: &cYou must allow downloading the resource-pack! 18 | error.item.level: &6Required &c{0} &6level 19 | error.item.class: &6Required class &c{0} 20 | error.mount.owner: &6Mount belongs to {0} 21 | error.creative: &4RPGInventory can''t be used in CREATIVE game mode. Please switch to SURVIVAL. 22 | 23 | message.buyed: &aYou have successfully purchased the slot 24 | message.perms: &cYou don''t have permission to use this command 25 | 26 | pet.name: {0} &f[{1}] 27 | pet.health: &cHealth: &7{0} 28 | pet.damage: &cDamage: &7{0} 29 | pet.speed: &cSpeed: &7{0} block/s 30 | pet.revival.yes: &bCooldown: &7{0}s 31 | pet.revival.no: &bDon''t revives 32 | pet.cooldown: &a&o({0}s) 33 | pet.food.value: &aRestores: {0} HP 34 | pet.role.companion: Companion 35 | pet.role.mount: Mount 36 | mypet.egg: MyPet Egg: {0} 37 | 38 | item.level: &fRequires {0} level 39 | item.class: &fOnly for &b{0} 40 | item.nodrop: &7Doesn''t drop on death 41 | item.left-click: &aLMB - {0} 42 | item.right-click: &aRMB - {0} 43 | item.hide: &7&oItem stats are hidden 44 | item.unbreakable: &7Unbreakable item 45 | 46 | stat.message.no_bonus: No bonus 47 | stat.damage: &cDamage: &7{0} 48 | stat.bow_damage: &cDamage (shoot): &7{0} 49 | stat.hand_damage: &cDamage (hand): &7{0} 50 | stat.armor: &3Armor: &7{0} 51 | stat.crit_chance: &6Crit Chance: &7{0} 52 | stat.crit_damage: &6Crit Damage: &7{0} 53 | stat.speed: &9Speed: &7{0} 54 | stat.jump: &9Jump: &7{0} 55 | 56 | backpack.desc: &8&oPut it in specified slot and click &fRMB 57 | backpack.size: &aSize: &7{0} 58 | backpack.limit: &cYou can''t have more than {0} backpack! 59 | -------------------------------------------------------------------------------- /src/main/resources/lang/es.lang: -------------------------------------------------------------------------------- 1 | #version: 2.0 | Do not remove this line! 2 | title: RPG Inventory 3 | 4 | locked.name: &cEspacio bloqueado 5 | locked.lore: &6&oDebes desbloquear el espacio anterior 6 | 7 | buyable.name: &aEspacio disponible 8 | buyable.lore: &6&oPara obtener este espacio debes: 9 | buyable.money: &6&o• tener {0} monedas 10 | buyable.level: &6&o• tener {0} niveles de experiencia 11 | 12 | error.fall: &cNo puedes hacer esto mientras vuelas 13 | error.money: &6Aún necesitas {0} monedas 14 | error.level: &6Aún necesitas {0} niveles de experiencia 15 | error.buyable: &6Necesitas {0} monedas para comprar este espacio. Haz click nuevamente en los próximos 10 segundos para confirmar. 16 | error.previous: &6Desbloquea el espacio previo 17 | error.rp.denied: &cDebes habilitar la descarga del pack de recursos! 18 | error.item.level: &6Nivel &c{0} &6requerido 19 | error.item.class: &6Clase &c{0} &6requerida 20 | error.mount.owner: &6La montura pertenece a {0} 21 | error.creative: &4RPGInventory can''t be used in CREATIVE game mode. Please switch to SURVIVAL. 22 | 23 | message.buyed: &aYa haz comprado el espacio 24 | message.perms: &cYou don''t have permission to use this command 25 | 26 | pet.name: {0} &f[{1}] 27 | pet.health: &cVida: &7{0} 28 | pet.damage: &cDaño: &7{0} 29 | pet.speed: &cVelocidad: &7{0} bloques/segundo 30 | pet.revival.yes: &bTiempo de espera: &7{0}s 31 | pet.revival.no: &bNo resucitará 32 | pet.cooldown: &a&o({0}s) 33 | pet.food.value: &aRestaura: {0} de vida 34 | pet.role.companion: Acompañante 35 | pet.role.mount: Montura 36 | mypet.egg: MyPet Egg: {0} 37 | 38 | item.level: &fRequiere nivel {0} 39 | item.class: &fExclusivo para &b{0} 40 | item.nodrop: &7No se dropea en la muete 41 | item.left-click: &aClick Izquierdo - {0} 42 | item.right-click: &aClick Derecho - {0} 43 | item.hide: &7&oEstadísticas del item ocultas 44 | item.unbreakable: &7Item irrompible 45 | 46 | stat.message.no_bonus: Sin bonus 47 | stat.damage: &cDaño: &7{0} 48 | stat.bow_damage: &cDaño (flecha): &7{0} 49 | stat.hand_damage: &cDaño (mano): &7{0} 50 | stat.armor: &3Armadura: &7{0} 51 | stat.crit_chance: &6Chance de golpe crítico: &7{0} 52 | stat.crit_damage: &6Daño de golpe crítico: &7{0} 53 | stat.speed: &9Velocidad: &7{0} 54 | stat.jump: &9Salto: &7{0} 55 | 56 | backpack.desc: &8&oColócala en el espacio indicado y haz &fClick Derecho 57 | backpack.size: &aTamaño: &7{0} 58 | backpack.limit: &cYou can''t have more than {0} backpack! 59 | -------------------------------------------------------------------------------- /src/main/resources/lang/jp.lang: -------------------------------------------------------------------------------- 1 | #version: 2.0 | Do not remove this line! 2 | title: RPG Inventory 3 | 4 | locked.name: &cロックされたのスペース 5 | locked.lore: &6&o以前のロックから解除する必要があります 6 | 7 | buyable.name: &a使用可能なスペース 8 | buyable.lore: &6&oのスペースを購入するには、次の条件: 9 | buyable.money: &6&o• {0} ほどの貨幣が必要である 10 | buyable.level: &6&o• {0} ほどのレベルが必要である 11 | 12 | error.fall: &c空中で使用できません 13 | error.money: &6{0}ほどのお金が必要になります 14 | error.level: &6{0}ほどのレベルが必要です 15 | error.buyable: &6このスペースを購入するには,{0}だけのゴールドが必要になります。購入を確認するため、10秒以内に再度クリックして下さい 16 | error.previous: &6以前スペースのロックを解除する必要があります 17 | error.rp.denied: &cリソースパックを使用に変えてください! 18 | error.item.level: &6それは&c{0}&6レベルが必要になります 19 | error.item.class: &6それはクラスが必要になります &c{0} 20 | error.mount.owner: &6主人に帰属しています {0} 21 | error.creative: &4RPGInventory can''t be used in CREATIVE game mode. Please switch to SURVIVAL. 22 | 23 | message.buyed: &a正常にスペースを購入しました 24 | message.perms: &c権限がありません 25 | 26 | pet.name: {0} &f[{1}] 27 | pet.health: &c健康: &7{0} 28 | pet.damage: &c被害: &7{0} 29 | pet.speed: &c速度: &7{0} block/s 30 | pet.revival.yes: &bクールタイム: &7{0}s 31 | pet.revival.no: &b復活なし 32 | pet.cooldown: &a&o({0}s) 33 | pet.food.value: &a回復: {0} HP 34 | pet.role.companion: ヘルパー 35 | pet.role.mount: 搭乗 36 | mypet.egg: MyPet Egg: {0} 37 | 38 | item.level: &f{0}ほどのレベルが必要になります 39 | item.class: &fそれは&bクラス{0}のみ使用可能です 40 | item.nodrop: &7死んだの後で落とさない 41 | item.left-click: &a左クリック - {0} 42 | item.right-click: &a右クリック - {0} 43 | item.hide: &7&o隠されたアイテム 44 | item.unbreakable: &7耐久 45 | 46 | stat.message.no_bonus: なし 47 | stat.damage: &c被害: &7{0} 48 | stat.bow_damage: &c被害 (弓): &7{0} 49 | stat.hand_damage: &c被害 (手): &7{0} 50 | stat.armor: &3被害減少: &7{0} 51 | stat.crit_chance: &6クリティカル確率: &7{0} 52 | stat.crit_damage: &6クリティカル被害: &7{0} 53 | stat.speed: &9速度: &7{0} 54 | stat.jump: &9ジャンプ: &7{0} 55 | 56 | backpack.desc: &8&o追加のスペースを使用するには、クリックしてください&f右クリック 57 | backpack.size: &aサイズ: &7{0} 58 | backpack.limit: &c所持可能な限度を超えています 59 | -------------------------------------------------------------------------------- /src/main/resources/lang/kr.lang: -------------------------------------------------------------------------------- 1 | #version: 2.0 | Do not remove this line! 2 | title: 인벤토리 3 | 4 | locked.name: &c잠긴 슬릇 5 | locked.lore: &6&o이전 슬릇부터 해제해야 합니다 6 | 7 | buyable.name: &a구매 가능한 슬릇 8 | buyable.lore: &6&o슬릇을 구입할려면 다음의 조건: 9 | buyable.money: &6• {0} 만큼의 화폐가 필요합니다 10 | buyable.level: &6• {0} 만큼의 레벨이 필요합니다 11 | 12 | error.fall: &c공중에서 사용할 수 없습니다 13 | error.money: &6{0} 만큼의 돈이 더 필요합니다 14 | error.level: &6{0} 만큼의 레벨이 더 필요합니다 15 | error.buyable: &6당신이 이 슬릇을 구입할려면 {0} 만큼의 골드가 필요합니다. 구입 확인을 위해 10 초 이내로 다시 클릭해주시길 바랍니다. 16 | error.previous: &6이전 슬릇의 잠금을 해제해야 합니다 17 | error.rp.denied: &c리소스 팩이 필요합니다! 18 | error.item.level: &6그것은 &c{0} &6레벨이 필요합니다 19 | error.item.class: &6그것은 클래스가 필요합니다 &c{0} 20 | error.mount.owner: &6주인에게 귀속되어 있습니다 {0} 21 | error.creative: &4RPGInventory can''t be used in CREATIVE game mode. Please switch to SURVIVAL. 22 | 23 | message.buyed: &a성공적으로 슬릇을 구입했습니다 24 | message.perms: &c권한이 없습니다 25 | 26 | pet.name: {0} &f[{1}] 27 | pet.health: &c체력: &7{0} 28 | pet.damage: &c데미지: &7{0} 29 | pet.speed: &c스피드: &7{0} block/s 30 | pet.revival.yes: &b쿨타임: &7{0}s 31 | pet.revival.no: &b부활하지 않습니다 32 | pet.cooldown: &a&o({0}s) 33 | pet.food.value: &a회복: {0} HP 34 | pet.role.companion: 도우미 35 | pet.role.mount: 탑승 36 | mypet.egg: MyPet Egg: {0} 37 | 38 | item.level: &f{0} 레벨이 필요합니다 39 | item.class: &f그것은 &b{0} 클래스만 사용이 가능합니다 40 | item.nodrop: &7죽을 때 떨어트리지 않습니다 41 | item.left-click: &a왼 클릭 - {0} 42 | item.right-click: &a우 클릭 - {0} 43 | item.hide: &7알 수 없음 44 | item.unbreakable: &7내구성 45 | 46 | stat.message.no_bonus: 없음 47 | stat.damage: &c데미지: &7{0} 48 | stat.bow_damage: &c데미지 (활): &7{0} 49 | stat.hand_damage: &c데미지 (손): &7{0} 50 | stat.armor: &3피해 감소: &7{0} 51 | stat.crit_chance: &6크리티컬 확률: &7{0} 52 | stat.crit_damage: &6크리티컬 데미지: &7{0} 53 | stat.speed: &9스피드: &7{0} 54 | stat.jump: &9도약: &7{0} 55 | 56 | backpack.desc: &8&o추가 슬릇을 사용할려면 클릭하세요 &f우클릭 57 | backpack.size: &a크기: &7{0} 58 | backpack.limit: &c소유 가능한 한도를 초과하였습니다 59 | -------------------------------------------------------------------------------- /src/main/resources/lang/pt.lang: -------------------------------------------------------------------------------- 1 | #version: 2.0 | Do not remove this line! 2 | title: RPG Inventory 3 | 4 | locked.name: &cEspaço bloqueado 5 | locked.lore: &6&oDeve desbloquear o espaço anterior 6 | 7 | buyable.name: &aEspaço disponivel 8 | buyable.lore: &6&oPara obter este espaco deve: 9 | buyable.money: &6&o• ter {0} moedas 10 | buyable.level: &6&o• ter {0} nivel(s) de experiencia 11 | 12 | error.fall: &cNão pode fazer isso enquanto esta voando!! 13 | error.money: &6Ainda precisa de {0} moedas 14 | error.level: &6Ainda precisa de {0} niveis 15 | error.buyable: &6Precisa de {0} moedas para comprar esse espaço. Faça um click novamente nos proximos 10seg para confirmar. 16 | error.previous: &6Desbloqueie o espaço previo 17 | error.rp.denied: &cDeve habilitar o download do pacote de recursos! 18 | error.item.level: &6Nivel &c{0} &6requerido 19 | error.item.class: &6Classe &c{0} &6requerida 20 | error.mount.owner: &6A moldura pertence a {0} 21 | error.creative: &4RPGInventory can''t be used in CREATIVE game mode. Please switch to SURVIVAL. 22 | 23 | message.buyed: &a&Você já comprou o espaço 24 | message.perms: &cYou don''t have permission to use this command 25 | 26 | pet.name: {0} &f[{1}] 27 | pet.health: &cVida: &7{0} 28 | pet.damage: &cDano: &7{0} 29 | pet.speed: &cVelocidade: &7{0} blocos/segundo 30 | pet.revival.yes: &bTempo de espera: &7{0}s 31 | pet.revival.no: &bNão resucitará 32 | pet.cooldown: &a&o({0}s) 33 | pet.food.value: &aRestaurou: {0} de vida 34 | pet.role.companion: Acompanhante 35 | pet.role.mount: Monte 36 | mypet.egg: MyPet Egg: {0} 37 | 38 | item.level: &fRequer nivel {0} 39 | item.class: &fExclusivo para &b{0} 40 | item.nodrop: &7Não se dropa ena morte. 41 | item.left-click: &aClick esquerdo - {0} 42 | item.right-click: &aClick direito - {0} 43 | item.hide: &7&oEstadísticas do item ocultas 44 | item.unbreakable: &7Item inquebravel 45 | 46 | stat.message.no_bonus: Sem bonus 47 | stat.damage: &cDano: &7{0} 48 | stat.bow_damage: &cDano (flecha): &7{0} 49 | stat.hand_damage: &cDano (mão): &7{0} 50 | stat.armor: &3Armadura: &7{0} 51 | stat.crit_chance: &6Chance de golpe crítico: &7{0} 52 | stat.crit_damage: &6Dano de golpe crítico: &7{0} 53 | stat.speed: &9Velocidade: &7{0} 54 | stat.jump: &9Pulo: &7{0} 55 | 56 | backpack.desc: &8&oColoque-o no espaço fornecido e clique &fClique com o botão direito 57 | backpack.size: &aTamanho: &7{0} 58 | backpack.limit: &cYou can''t have more than {0} backpack! 59 | -------------------------------------------------------------------------------- /src/main/resources/lang/rs.lang: -------------------------------------------------------------------------------- 1 | #version: 2.0 | Do not remove this line! 2 | title: RPG Inventory 3 | 4 | locked.name: &cZakljucan slot 5 | locked.lore: &6Moras prvo da otkljucas prethodni slot! 6 | 7 | buyable.name: &aDostupan slot 8 | buyable.lore: &6Da kupis slot moras imati: 9 | buyable.money: &6 {0} para 10 | buyable.level: &6 {0} lvl 11 | 12 | error.fall: &cNe mozes to raditi dok letis! 13 | error.money: &6Da kupis ovaj slot moras imati &e{0} &6para 14 | error.level: &6Da kupis ovaj slot moras imati&e {0} &6lvl 15 | error.buyable: &6Da kupis ovaj slot moras imati {0} para. Klikni u narednih 10 sekundi da potvrdis! 16 | error.previous: &6Prvo odkljucaj prethodni slot! 17 | error.rp.denied: &cMoras dozvoliti skidanje teksture! 18 | error.item.level: &6Potrebno &c{0} &6levela 19 | error.item.class: &6Potrebna klasa &c{0} 20 | error.mount.owner: &6Mount je od {0} 21 | error.creative: &4RPGInventory can''t be used in CREATIVE game mode. Please switch to SURVIVAL. 22 | 23 | message.buyed: &aUspesno ste kupili slot 24 | message.perms: &cYou don''t have permission to use this command 25 | 26 | pet.name: &6{0} &7[&b{1}&7] 27 | pet.health: &cZivoti: &7{0} 28 | pet.damage: &cUdarac: &7{0} 29 | pet.speed: &cBrzina: &7{0} block/s 30 | pet.revival.yes: &bCooldown: &7{0}s 31 | pet.revival.no: &bDon''t revives 32 | pet.cooldown: &a({0}s) 33 | pet.food.value: &aPunjenje: {0} HP 34 | pet.role.companion: Pratilac 35 | pet.role.mount: Mount 36 | mypet.egg: MyPet Egg: {0} 37 | 38 | item.level: &fPotrebno {0} level 39 | item.class: &fSamo za &b{0} 40 | item.nodrop: &7Ne gubi se na smrti 41 | item.left-click: &aLevi klik - {0} 42 | item.right-click: &aDesni klik - {0} 43 | item.hide: &7Statusi itema su sakriveni 44 | item.unbreakable: &7Neunistivi item 45 | 46 | stat.message.no_bonus: No bonus 47 | stat.damage: &cDamage: &7{0} 48 | stat.bow_damage: &cDamage (shoot): &7{0} 49 | stat.hand_damage: &cDamage (hand): &7{0} 50 | stat.armor: &3Armor: &7{0} 51 | stat.crit_chance: &6Crit Chance: &7{0} 52 | stat.crit_damage: &6Crit Damage: &7{0} 53 | stat.speed: &9Speed: &7{0} 54 | stat.jump: &9Jump: &7{0} 55 | 56 | backpack.desc: &8&oPut it in specified slot and click &fRMB 57 | backpack.size: &aSize: &7{0} 58 | backpack.limit: &cYou can''t have more than {0} backpack! 59 | -------------------------------------------------------------------------------- /src/main/resources/lang/ru.lang: -------------------------------------------------------------------------------- 1 | #version: 2.0 | Do not remove this line! 2 | title: RPG Inventory 3 | 4 | locked.name: &cЗаблокированный слот 5 | locked.lore: &6&oСначала разблокируйте предыдущие слоты 6 | 7 | buyable.name: &aДоступный слот 8 | buyable.lore: &6&oЧтобы приобрести слот, нужно: 9 | buyable.money: &6&o• Иметь {0} золота 10 | buyable.level: &6&o• Быть {0} уровня 11 | 12 | error.fall: &6Нельзя изменять этот слот, пока вы в полёте 13 | error.money: &6Для покупки слота не хватает {0} золота 14 | error.level: &6Для покупки слота нужен {0} уровень 15 | error.buyable: &6Этот слот стоит {0} золота, чтобы подтвердить его покупку, нажмите на него еще раз в течение 10 секунд 16 | error.previous: &6Сначала разблокируйте предыдущие слоты 17 | error.rp.denied: &cДля игры на сервере нужно cогласиться на загрузку текстур! 18 | error.item.level: &6Требуется &c{0} &6уровень 19 | error.item.class: &6Требуется класс &c{0} 20 | error.mount.owner: &6Скакун принадлежит {0} 21 | error.creative: &4RPGInventory нельзя использовать в режиме CREATIVE. Пожалуйста, переключитесь в SURVIVAL. 22 | 23 | message.buyed: &aВы успешно приобрели слот 24 | message.perms: &cУ вас нет прав на использование этой команды 25 | 26 | pet.name: {0} &f[{1}] 27 | pet.health: &cЗдоровье: &7{0} 28 | pet.damage: &cУрон: &7{0} 29 | pet.speed: &cСкорость: &7{0} блок./сек 30 | pet.revival.yes: &bВремя возрождения: &7{0}с 31 | pet.revival.no: &bНе возрождается 32 | pet.cooldown: &a&o({0}с) 33 | pet.food.value: &aВосстанавливает: {0} HP 34 | pet.role.companion: Компаньон 35 | pet.role.mount: Ездовое животное 36 | mypet.egg: Яйцо призыва: {0} 37 | 38 | item.level: &fТребуется {0} уровень 39 | item.class: &fТолько для &b{0} 40 | item.nodrop: &7Не выпадает при смерти 41 | item.left-click: &aЛКМ - {0} 42 | item.right-click: &aПКМ - {0} 43 | item.hide: &7&oСвойства скрыты 44 | item.unbreakable: &7Не ломается 45 | 46 | stat.message.no_bonus: Нет бонуса 47 | stat.damage: &cУрон: &7{0} 48 | stat.bow_damage: &cУрон (выстрел): &7{0} 49 | stat.hand_damage: &cУрон (рука): &7{0} 50 | stat.armor: &3Броня: &7{0} 51 | stat.crit_chance: &6Шанс крит.: &7{0} 52 | stat.crit_damage: &6Крит. урон: &7{0} 53 | stat.speed: &9Скорость: &7{0} 54 | stat.jump: &9Прыжок: &7{0} 55 | 56 | backpack.desc: &8&oПоместите в слот рюкзака и нажмите &fПКМ 57 | backpack.size: &aРазмер: &7{0} 58 | backpack.limit: &cУ вас не может быть рюкзаков больше чем {0}! 59 | -------------------------------------------------------------------------------- /src/main/resources/lang/tr.lang: -------------------------------------------------------------------------------- 1 | #version: 2.0 | Do not remove this line! 2 | title: RPG Envanteri 3 | 4 | locked.name: &cKilitli Bölme 5 | locked.lore: &6&oÖnce bir önceki bölmeyi alman gerek 6 | 7 | buyable.name: &aMevcut Bölmeler 8 | buyable.lore: &6&oBunu alabilmek için, bunlara sahip olmalısın: 9 | buyable.money: &6&o• {0} Altın 10 | buyable.level: &6&o• {0} Seviye 11 | 12 | error.fall: &cUçarken bunu yapamazsın 13 | error.money: &6Bunu alabilmek için {0} altına ihtiyacin var 14 | error.level: &6Bunu alabilmek için {0} seviyeye ihtiyacın var 15 | error.buyable: &6Bu slotu alabilmek için {0} altına ihtiyacın olacak! 10 saniye içinde tekrar tıklarsan satın almayı onaylarsın. 16 | error.previous: &6İlk olarak önceki sekmeyi açman gerek! 17 | error.rp.denied: &cKaynak paketi yüklemeyi devreye sokman gerek! 18 | error.item.level: &c{0} &6Seviye lazım! 19 | error.item.class: &6Gereken Irk: &c{0} 20 | error.mount.owner: &6Bineğin sahibi {0} 21 | error.creative: &4RPGInventory can''t be used in CREATIVE game mode. Please switch to SURVIVAL. 22 | 23 | message.buyed: &aBu bölmeyi başarıyla aldın! 24 | message.perms: &cYou don''t have permission to use this command 25 | 26 | pet.name: {0} &f[{1}] 27 | pet.health: &cCan: &7{0} 28 | pet.damage: &cHasar: &7{0} 29 | pet.speed: &cHız: &7{0} blok/saniye 30 | pet.revival.yes: &bBekleme Süresi: &7{0}s 31 | pet.revival.no: &bCanlandırma Yok! 32 | pet.cooldown: &a&o({0}s) 33 | pet.food.value: &aYenileme: {0} Can 34 | pet.role.companion: Yoldaş 35 | pet.role.mount: Binek 36 | mypet.egg: MyPet Egg: {0} 37 | 38 | item.level: &f{0} Seviye gerektirir! 39 | item.class: &b{0} &fIrkına özel! 40 | item.nodrop: &7Ölünce eşya düşmez! 41 | item.left-click: &aSol Tıkla - {0} 42 | item.right-click: &aSağ Tıkla - {0} 43 | item.hide: &7&oEşya istatistikleri gizlendi 44 | item.unbreakable: &7Kırılmaz eşya 45 | 46 | stat.message.no_bonus: Bonus yok 47 | stat.damage: &cHasar: &7{0} 48 | stat.bow_damage: &cHasar: (Vurus): &7{0} 49 | stat.hand_damage: &cHasar: (El): &7{0} 50 | stat.armor: &3Zırh: &7{0} 51 | stat.crit_chance: &6Kritik şansı: &7{0} 52 | stat.crit_damage: &6Kritik hasarı: &7{0} 53 | stat.speed: &9Hız: &7{0} 54 | stat.jump: &9Zıplama: &7{0} 55 | 56 | backpack.desc: &8&oBelirtilen bölmeye koyup &fSağ tuşa &8tikla! 57 | backpack.size: &aBoyut: &7{0} 58 | backpack.limit: &cYou can''t have more than {0} backpack! 59 | -------------------------------------------------------------------------------- /src/main/resources/lang/zh.lang: -------------------------------------------------------------------------------- 1 | #version: 2.0 | Do not remove this line! 2 | title: &b装备菜单 3 | 4 | locked.name: &c未解锁凹槽 5 | locked.lore: &6你必须先解锁上一个凹槽 6 | 7 | buyable.name: &a可用槽 8 | buyable.lore: &6要解锁一个凹槽,你必须: 9 | buyable.money: &6拥有 {0} 金币 10 | buyable.level: &6拥有 {0} 级 11 | 12 | error.fall: &c你无法在飞行中做这个. 13 | error.money: &6你只有 {0} 金币. 14 | error.level: &6你只有 {0} 级. 15 | error.buyable: &6解锁此凹槽需要 {0} 金币. 10秒内再次点击凹槽确认解锁. 16 | error.previous: &6你必须先解锁上一个凹槽 17 | error.rp.denied: &c你必须启用服务器材质包才可进行游戏! 18 | error.item.level: &6需要 &c{0} &6级. 19 | error.item.class: &6你的种族必须为 &c{0} 20 | error.mount.owner: &6坐骑的主人为 {0} 21 | error.creative: &4RPGInventory can''t be used in CREATIVE game mode. Please switch to SURVIVAL. 22 | 23 | message.buyed: &a你成功解锁了一个凹槽! 24 | message.perms: &cYou don''t have permission to use this command 25 | 26 | pet.name: {0} &f[{1}] 27 | pet.health: &c血量: &7{0} 28 | pet.damage: &c伤害: &7{0} 29 | pet.speed: &c移速: &7{0} block/s 30 | pet.revival.yes: &b冷却时间: &7{0}s 31 | pet.revival.no: &b不返回 32 | pet.cooldown: &a&o({0}s) 33 | pet.food.value: &a恢复: {0} HP 34 | pet.role.companion: 同伴 35 | pet.role.mount: 坐骑 36 | mypet.egg: MyPet Egg: {0} 37 | 38 | item.level: &f需要 {0} 级 39 | item.class: &f职业限制: &b{0} 40 | item.nodrop: &7死亡无法掉落 41 | item.left-click: &a左键点击 - {0} 42 | item.right-click: &a右键点击 - {0} 43 | item.hide: &7物品杂项说明已隐藏 44 | item.unbreakable: &7无法破坏 45 | 46 | stat.message.no_bonus: 0 47 | stat.damage: &c附加伤害: &7{0} 48 | stat.bow_damage: &c附加伤害 (弓箭): &7{0} 49 | stat.hand_damage: &c附加伤害 (空手): &7{0} 50 | stat.armor: &3护甲: &7{0} 51 | stat.crit_chance: &6暴击率: &7{0} 52 | stat.crit_damage: &6暴击伤害: &7{0} 53 | stat.speed: &9移速: &7{0} 54 | stat.jump: &9跳跃: &7{0} 55 | 56 | backpack.desc: &8请将背包放入背包凹槽,并右键点击打开 57 | backpack.size: &a容量: &7{0} 58 | backpack.limit: &cYou can''t have more than {0} backpack! 59 | -------------------------------------------------------------------------------- /src/main/resources/pets.yml: -------------------------------------------------------------------------------- 1 | pets: 2 | kitty: 3 | name: "&7&lKitty" 4 | item-name: "&7&lKitty's Summoning Stone" 5 | lore: 6 | - "&e&oMeow! Meow! Meow!" 7 | item: GHAST_SPAWN_EGG 8 | type: COMPANION 9 | health: 20 10 | damage: 3 11 | speed: 3.5 12 | attack-mobs: false 13 | attack-players: false 14 | revival: true 15 | cooldown: 60 16 | skin: CAT 17 | features: 18 | - "BABY: TRUE" 19 | - "TYPE: ALL_BLACK" 20 | - "COLLAR: BLUE" 21 | puppy: 22 | name: "&7&lPuppy" 23 | item-name: "&7&lPuppy's Summoning Stone" 24 | lore: 25 | - "&e&oWoof! Woof! Woof!" 26 | item: GHAST_SPAWN_EGG 27 | type: COMPANION 28 | health: 20 29 | damage: 3 30 | speed: 3.5 31 | attack-mobs: true 32 | attack-players: false 33 | revival: true 34 | cooldown: 60 35 | features: 36 | - "BABY: TRUE" 37 | - "COLLAR: BLACK" 38 | rare-wolf: 39 | name: "&9&lWolf" 40 | item-name: "&9&lWolf's Summoning Stone" 41 | lore: 42 | - "&e&oBest friend - a proven friend" 43 | item: SKELETON_SPAWN_EGG 44 | type: COMPANION 45 | health: 30 46 | damage: 5 47 | speed: 4 48 | attack-mobs: false 49 | attack-players: true 50 | revival: true 51 | cooldown: 45 52 | features: 53 | - "COLLAR: BLUE" 54 | legendary-wolf: 55 | name: "&5&lGrand Wolf" 56 | item-name: "&5&lGrand Wolf's Summoning Stone" 57 | lore: 58 | - "&e&o...but only a few become legends..." 59 | item: SILVERFISH_SPAWN_EGG 60 | type: COMPANION 61 | level: 10 62 | classes: 63 | - Mage 64 | - Warrior 65 | health: 50 66 | damage: 10 67 | speed: 6 68 | mount: true 69 | attack-mobs: true 70 | attack-players: true 71 | revival: true 72 | cooldown: 30 73 | features: 74 | - "COLLAR: PURPLE" 75 | horse: 76 | name: "&6&lHorse" 77 | item-name: "&5&lHorse's Summoning Stone" 78 | lore: 79 | - "&e&oRide like the wind!" 80 | item: ZOMBIE_SPAWN_EGG 81 | type: MOUNT 82 | health: 100 83 | speed: 10 84 | revival: true 85 | cooldown: 30 86 | features: 87 | - "CHEST: FALSE" 88 | - "ARMOR: IRON_BARDING" 89 | - "COLOR: DARK_BROWN" 90 | - "STYLE: WHITE" 91 | pig: 92 | name: "&6&lPig" 93 | item-name: "&5&lPig's Summoning Stone" 94 | lore: 95 | - "&e&oRide faster than wind!" 96 | - "&e&oBut... where my carrot?" 97 | item: PIG_SPAWN_EGG 98 | type: MOUNT 99 | health: 100 100 | speed: 12.5 101 | revival: true 102 | cooldown: 60 103 | skin: PIG 104 | food: 105 | bone: 106 | name: "&f&lBone" 107 | lore: 108 | - "&e&o- Rex, come here!" 109 | - "&e&o- Woof! Woof! Woof!" 110 | item: BONE 111 | eaters: 112 | - WOLF 113 | value: 5 114 | -------------------------------------------------------------------------------- /src/main/resources/pets.yml.legacy: -------------------------------------------------------------------------------- 1 | pets: 2 | kitty: 3 | name: "&7&lKitty" 4 | item-name: "&7&lKitty's Summoning Stone" 5 | lore: 6 | - "&e&oMeow! Meow! Meow!" 7 | item: MONSTER_EGG:Ghast 8 | type: COMPANION 9 | health: 20 10 | damage: 3 11 | speed: 3.5 12 | attack-mobs: false 13 | attack-players: false 14 | revival: true 15 | cooldown: 60 16 | skin: OCELOT 17 | features: 18 | - "BABY: TRUE" 19 | - "TYPE: BLACK_CAT" 20 | puppy: 21 | name: "&7&lPuppy" 22 | item-name: "&7&lPuppy's Summoning Stone" 23 | lore: 24 | - "&e&oWoof! Woof! Woof!" 25 | item: MONSTER_EGG:Ghast 26 | type: COMPANION 27 | health: 20 28 | damage: 3 29 | speed: 3.5 30 | attack-mobs: true 31 | attack-players: false 32 | revival: true 33 | cooldown: 60 34 | features: 35 | - "BABY: TRUE" 36 | - "COLLAR: BLACK" 37 | rare-wolf: 38 | name: "&9&lWolf" 39 | item-name: "&9&lWolf's Summoning Stone" 40 | lore: 41 | - "&e&oBest friend - a proven friend" 42 | item: MONSTER_EGG:Skeleton 43 | type: COMPANION 44 | health: 30 45 | damage: 5 46 | speed: 4 47 | attack-mobs: false 48 | attack-players: true 49 | revival: true 50 | cooldown: 45 51 | features: 52 | - "COLLAR: BLUE" 53 | legendary-wolf: 54 | name: "&5&lGrand Wolf" 55 | item-name: "&5&lGrand Wolf's Summoning Stone" 56 | lore: 57 | - "&e&o...but only a few become legends..." 58 | item: MONSTER_EGG:Silverfish 59 | type: COMPANION 60 | level: 10 61 | classes: 62 | - Mage 63 | - Warrior 64 | health: 50 65 | damage: 10 66 | speed: 6 67 | mount: true 68 | attack-mobs: true 69 | attack-players: true 70 | revival: true 71 | cooldown: 30 72 | features: 73 | - "COLLAR: PURPLE" 74 | horse: 75 | name: "&6&lHorse" 76 | item-name: "&5&lHorse's Summoning Stone" 77 | lore: 78 | - "&e&oRide like the wind!" 79 | item: MONSTER_EGG:Zombie 80 | type: MOUNT 81 | health: 100 82 | speed: 10 83 | revival: true 84 | cooldown: 30 85 | features: 86 | - "CHEST: FALSE" 87 | - "ARMOR: IRON_BARDING" 88 | - "COLOR: DARK_BROWN" 89 | - "STYLE: WHITE" 90 | pig: 91 | name: "&6&lPig" 92 | item-name: "&5&lPig's Summoning Stone" 93 | lore: 94 | - "&e&oRide faster than wind!" 95 | - "&e&oBut... where my carrot?" 96 | item: MONSTER_EGG:Pig 97 | type: MOUNT 98 | health: 100 99 | speed: 12.5 100 | revival: true 101 | cooldown: 60 102 | skin: PIG 103 | food: 104 | bone: 105 | name: "&f&lBone" 106 | lore: 107 | - "&e&o- Rex, come here!" 108 | - "&e&o- Woof! Woof! Woof!" 109 | item: BONE 110 | eaters: 111 | - WOLF 112 | value: 5 113 | -------------------------------------------------------------------------------- /src/main/resources/plugin.yml: -------------------------------------------------------------------------------- 1 | depend: 2 | - ProtocolLib 3 | - Vault 4 | softdepend: 5 | - Mimic 6 | - MyPet 7 | - PlaceholderAPI 8 | 9 | commands: 10 | rpginventory: 11 | description: RPGInventory command. 12 | aliases: [rpginv] 13 | usage: / 14 | 15 | permissions: 16 | rpginventory.admin: 17 | description: Gives access to all RPGInventory commands 18 | default: op 19 | children: 20 | rpginventory.user: true 21 | rpginventory.open.others: true 22 | rpginventory.user: 23 | description: Gives access to all user commands 24 | default: true 25 | children: 26 | rpginventory.open: true 27 | rpginventory.open: 28 | description: Allows you to open inventory by command 29 | default: true 30 | rpginventory.open.others: 31 | description: Allows you to open your or other player's inventory by command 32 | default: op 33 | children: 34 | rpginventory.open: true 35 | rpginventory.keep.items: 36 | description: Player with this permission will not lose any items on dead 37 | default: op 38 | rpginventory.keep.armor: 39 | description: Player with this permission will not lose armor on dead 40 | default: op 41 | rpginventory.keep.rpginv: 42 | description: Player with this permission will not lose items from RPGInventory on dead 43 | default: op 44 | -------------------------------------------------------------------------------- /src/main/resources/slots.yml: -------------------------------------------------------------------------------- 1 | slots: 2 | helmet: 3 | type: ARMOR 4 | slot: 4 5 | holder: 6 | item: DIAMOND_HOE:4 7 | name: "&a&lHelmet slot" 8 | lore: 9 | - "&6&oHere possible to put only helmet" 10 | items: 11 | - LEATHER_HELMET 12 | - CHAINMAIL_HELMET 13 | - IRON_HELMET 14 | - GOLD_HELMET 15 | - GOLDEN_HELMET 16 | - DIAMOND_HELMET 17 | - NETHERITE_HELMET 18 | - TURTLE_HELMET 19 | chestplate: 20 | type: ARMOR 21 | slot: 13 22 | holder: 23 | item: DIAMOND_HOE:5 24 | name: "&a&lChestplate slot" 25 | lore: 26 | - "&6&oHere possible to put only chestplate" 27 | items: 28 | - LEATHER_CHESTPLATE 29 | - CHAINMAIL_CHESTPLATE 30 | - IRON_CHESTPLATE 31 | - GOLD_CHESTPLATE 32 | - GOLDEN_CHESTPLATE 33 | - DIAMOND_CHESTPLATE 34 | - NETHERITE_CHESTPLATE 35 | leggings: 36 | type: ARMOR 37 | slot: 22 38 | holder: 39 | item: DIAMOND_HOE:6 40 | name: "&a&lLeggings slot" 41 | lore: 42 | - "&6&oHere possible to put only leggings" 43 | items: 44 | - LEATHER_LEGGINGS 45 | - CHAINMAIL_LEGGINGS 46 | - IRON_LEGGINGS 47 | - GOLD_LEGGINGS 48 | - GOLDEN_LEGGINGS 49 | - DIAMOND_LEGGINGS 50 | - NETHERITE_LEGGINGS 51 | boots: 52 | type: ARMOR 53 | slot: 31 54 | holder: 55 | item: DIAMOND_HOE:7 56 | name: "&a&lBoots slot" 57 | lore: 58 | - "&6&oHere possible to put only boots" 59 | items: 60 | - LEATHER_BOOTS 61 | - CHAINMAIL_BOOTS 62 | - IRON_BOOTS 63 | - GOLD_BOOTS 64 | - GOLDEN_BOOTS 65 | - DIAMOND_BOOTS 66 | - NETHERITE_BOOTS 67 | weapon: 68 | type: ACTIVE 69 | slot: 12 70 | quickbar: 0 71 | holder: 72 | item: DIAMOND_HOE:9 73 | name: "&a&lWeapon slot" 74 | lore: 75 | - "&6&oHere possible to put only weapon" 76 | items: 77 | - WOOD_SWORD 78 | - STONE_SWORD 79 | - IRON_SWORD 80 | - GOLD_SWORD 81 | - GOLDEN_SWORD 82 | - DIAMOND_SWORD 83 | - NETHERITE_SWORD 84 | - WOOD_AXE 85 | - STONE_AXE 86 | - IRON_AXE 87 | - GOLD_AXE 88 | - GOLDEN_AXE 89 | - DIAMOND_AXE 90 | - NETHERITE_AXE 91 | - BOW 92 | - TRIDENT 93 | - CROSSBOW 94 | gloves: 95 | type: PASSIVE 96 | slot: 14 97 | holder: 98 | item: DIAMOND_HOE:8 99 | name: "&a&lGloves slot" 100 | lore: 101 | - "&6&oHere possible to put only gloves" 102 | items: 103 | - DIAMOND_HOE:24 104 | rings: 105 | type: PASSIVE 106 | slot: [10, 28] 107 | holder: 108 | item: DIAMOND_HOE:12 109 | name: "&a&lRing slot" 110 | lore: 111 | - "&6&oHere possible to put only ring" 112 | items: 113 | - DIAMOND_HOE:23 114 | amulet: 115 | type: PASSIVE 116 | slot: 19 117 | cost: 118 | required-level: 4 119 | money: 1000 120 | holder: 121 | item: DIAMOND_HOE:13 122 | name: "&a&lAmulet slot" 123 | lore: 124 | - "&6&oHere possible to put only amulet" 125 | items: 126 | - DIAMOND_HOE:25 127 | artifacts: 128 | type: PASSIVE 129 | slot: [47, 48, 49, 50, 51] 130 | holder: 131 | item: DIAMOND_HOE:16 132 | name: "&a&lArtifact slot" 133 | lore: 134 | - "&6&oHere possible to put only artifacts" 135 | items: 136 | - DIAMOND_HOE:26 137 | shield: 138 | type: SHIELD 139 | slot: 21 140 | holder: 141 | item: DIAMOND_HOE:10 142 | name: "&a&lShield slot" 143 | lore: 144 | - "&6&oHere possible to put only shield" 145 | items: 146 | - SHIELD 147 | elytra: 148 | type: ELYTRA 149 | slot: 30 150 | holder: 151 | item: DIAMOND_HOE:11 152 | name: "&a&lElytra slot" 153 | lore: 154 | - "&6&oHere possible to put only elytra" 155 | pet: 156 | type: PET 157 | slot: 33 158 | holder: 159 | item: DIAMOND_HOE:14 160 | name: "&a&lPet slot" 161 | lore: 162 | - "&6&oHere possible to put only pet" 163 | backpack: 164 | type: BACKPACK 165 | slot: 34 166 | drop: false 167 | holder: 168 | item: DIAMOND_HOE:15 169 | name: "&a&lBackpack slot" 170 | lore: 171 | - "&6&oHere possible to put only backpack" 172 | craft: 173 | type: ACTION 174 | slot: 16 175 | gui: true 176 | holder: 177 | item: DIAMOND_HOE:2 178 | name: "&a&lWorkbench" 179 | lore: 180 | - "&6&oClick to open workbench" 181 | action: WORKBENCH 182 | info: 183 | type: INFO 184 | slot: 5 185 | holder: 186 | item: DIAMOND_HOE:3 187 | name: "&a&lYour stats" 188 | lore: 189 | - "&cDamage: &7%rpginv_damage_bonus% &8(Weapon) &7| %rpginv_bow_damage_bonus% &8(Bow) &7| %rpginv_hand_damage_bonus% &8(Hand)" 190 | - "&6Crit Damage: &7%rpginv_crit_damage_bonus% &eCrit Chance: &7%rpginv_crit_chance%" 191 | - "&3Armor: &7%rpginv_armor_bonus%" 192 | - "&bSpeed: &7%rpginv_speed_bonus% &9Jump: &7%rpginv_jump_bonus%" 193 | -------------------------------------------------------------------------------- /src/test/java/ru/endlesscode/rpginventory/utils/LogTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2018 EndlessCode Group and contributors 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.utils; 20 | 21 | import org.junit.BeforeClass; 22 | import org.junit.Test; 23 | import org.mockito.Mockito; 24 | 25 | import java.util.logging.Level; 26 | import java.util.logging.Logger; 27 | 28 | public class LogTest { 29 | 30 | private static final Logger logger = Mockito.mock(Logger.class); 31 | 32 | @BeforeClass 33 | public static void init() { 34 | Log.init(logger); 35 | } 36 | 37 | @Test 38 | public void shouldApplyArgsToMessage() { 39 | Exception exception = new Exception("Exception message"); 40 | 41 | Log.i("Info {0}, {1}", 0, "arg1"); 42 | Mockito.verify(logger).info("Info 0, arg1"); 43 | 44 | Log.w(exception); 45 | Mockito.verify(logger).log(Level.WARNING, "Exception message", exception); 46 | 47 | Log.w("Warning {0}, {1}", 0, "arg1"); 48 | Mockito.verify(logger).warning("Warning 0, arg1"); 49 | 50 | Log.w(exception, "Warning {0}, {1}", 0, "arg1"); 51 | Mockito.verify(logger).log(Level.WARNING, "Warning 0, arg1", exception); 52 | 53 | Log.s("Severe {0}, {1}", 0, "arg1"); 54 | Mockito.verify(logger).severe("Severe 0, arg1"); 55 | } 56 | 57 | @Test 58 | public void shouldApplyArgsToMessageWithQuotes() { 59 | Log.i("Info ''{0}'', \"{1}\"", "q", "qq"); 60 | Mockito.verify(logger).info("Info 'q', \"qq\""); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/ru/endlesscode/rpginventory/utils/VersionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of RPGInventory. 3 | * Copyright (C) 2018 EndlessCode Group and contributors 4 | * 5 | * RPGInventory is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * RPGInventory is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with RPGInventory. If not, see . 17 | */ 18 | 19 | package ru.endlesscode.rpginventory.utils; 20 | 21 | import org.junit.Assert; 22 | import org.junit.Test; 23 | 24 | public class VersionTest { 25 | 26 | @Test 27 | public void shouldParseVersionInRightFormat() { 28 | Version version = Version.parseVersion("1.12.2-SNAPSHOT"); 29 | 30 | Assert.assertEquals(new Version(1, 12, 2, "SNAPSHOT"), version); 31 | Assert.assertTrue(version.hasQualifier()); 32 | } 33 | 34 | @Test 35 | public void shouldParseVersionInRightFormatWithoutQualifier() { 36 | Version version = Version.parseVersion("1.12.2"); 37 | 38 | Assert.assertEquals(new Version(1, 12, 2), version); 39 | Assert.assertFalse(version.hasQualifier()); 40 | } 41 | 42 | @Test 43 | public void shouldParseVersionInRightFormatWithoutPatchVersion() { 44 | Version version = Version.parseVersion("1.12-SNAPSHOT"); 45 | 46 | Assert.assertEquals(new Version(1, 12, 0, "SNAPSHOT"), version); 47 | Assert.assertTrue(version.hasQualifier()); 48 | } 49 | 50 | @Test 51 | public void shouldParseVersionInRightFormatWithoutPatchVersionAndQualifier() { 52 | Version version = Version.parseVersion("1.12"); 53 | 54 | Assert.assertEquals(new Version(1, 12, 0), version); 55 | Assert.assertFalse(version.hasQualifier()); 56 | } 57 | 58 | @Test 59 | public void shouldParseVersionInRightFormatWithoutMinorVersion() { 60 | Version version = Version.parseVersion("1-SNAPSHOT"); 61 | 62 | Assert.assertEquals(new Version(1, 0, 0, "SNAPSHOT"), version); 63 | Assert.assertTrue(version.hasQualifier()); 64 | } 65 | 66 | @Test 67 | public void shouldParseVersionInRightFormatWithoutMinorVersionAndQualifier() { 68 | Version version = Version.parseVersion("1"); 69 | 70 | Assert.assertEquals(new Version(1, 0, 0), version); 71 | Assert.assertFalse(version.hasQualifier()); 72 | } 73 | 74 | @Test 75 | public void shouldConvertVersionToStringRight() { 76 | Assert.assertEquals("1.2.3", new Version(1, 2, 3).toString()); 77 | Assert.assertEquals("1.2.3-q", new Version(1, 2, 3, "q").toString()); 78 | } 79 | 80 | @Test 81 | public void comparingShouldBeRight() { 82 | Version version = new Version(2, 1, 4); 83 | 84 | Assert.assertEquals(0, version.compareTo(new Version(2, 1, 4))); 85 | Assert.assertEquals(0, version.compareTo(new Version(2, 1, 4, "qualifier"))); 86 | Assert.assertEquals(-1, version.compareTo(new Version(2, 1, 5))); 87 | Assert.assertEquals(-1, version.compareTo(new Version(2, 2, 0))); 88 | Assert.assertEquals(-1, version.compareTo(new Version(3, 0, 0))); 89 | Assert.assertEquals(1, version.compareTo(new Version(2, 1, 3))); 90 | Assert.assertEquals(1, version.compareTo(new Version(2, 0, 9))); 91 | Assert.assertEquals(1, version.compareTo(new Version(1, 9, 9))); 92 | } 93 | 94 | @Test 95 | public void comparingWithStringShouldBeRight() { 96 | Version version = new Version(2, 1, 4); 97 | 98 | Assert.assertEquals(0, version.compareTo("2.1.4")); 99 | Assert.assertEquals(0, version.compareTo("2.1.4-qualifier")); 100 | Assert.assertEquals(-1, version.compareTo("2.1.5")); 101 | Assert.assertEquals(-1, version.compareTo("2.2.0")); 102 | Assert.assertEquals(-1, version.compareTo("3.0.0")); 103 | Assert.assertEquals(1, version.compareTo("2.1.3")); 104 | Assert.assertEquals(1, version.compareTo("2.0.9")); 105 | Assert.assertEquals(1, version.compareTo("1.9.9")); 106 | } 107 | 108 | @Test(expected = IllegalArgumentException.class) 109 | public void shouldThrowExceptionWhenPassedWrongString() { 110 | Version.parseVersion("1.0.0.0"); 111 | } 112 | 113 | @Test(expected = IllegalArgumentException.class) 114 | public void shouldThrowExceptionWhenPassedEmptyString() { 115 | Version.parseVersion(""); 116 | } 117 | 118 | @Test(expected = IllegalArgumentException.class) 119 | public void shouldThrowExceptionWhenPassedOnlyQualifier() { 120 | Version.parseVersion("-SNAPSHOT"); 121 | } 122 | 123 | @Test(expected = IllegalArgumentException.class) 124 | public void shouldThrowExceptionWhenPassedNegativeNumbers() { 125 | new Version(1, 0, -1); 126 | } 127 | 128 | @Test(expected = NullPointerException.class) 129 | public void shouldThrowExceptionWhenPassedNullQualifier() { 130 | //noinspection ConstantConditions 131 | new Version(1, 0, 0, null); 132 | } 133 | } 134 | --------------------------------------------------------------------------------