3.0.0a - Updated

This commit is contained in:
AMinecraftDev 2018-03-08 23:37:06 +08:00
parent 869e16a0e7
commit b13a57d773
99 changed files with 1153 additions and 5953 deletions

View File

@ -2,29 +2,16 @@
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Annotation profile for PluginAPI" enabled="true">
<sourceOutputDir name="../../../../target/generated-sources/annotations" />
<sourceTestOutputDir name="../../../../target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="PluginAPI" />
</profile>
<profile name="Annotation profile for FactionsUUID" enabled="true">
<sourceOutputDir name="../../../../target/generated-sources/annotations" />
<sourceTestOutputDir name="../../../../target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="FactionsUUID" />
</profile>
<profile name="Annotation profile for FactionsOne" enabled="true">
<sourceOutputDir name="../../../../target/generated-sources/annotations" />
<sourceTestOutputDir name="../../../../target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="FactionsOne" />
</profile>
<profile name="Annotation profile for FactionsM" enabled="true">
<sourceOutputDir name="../../../../target/generated-sources/annotations" />
<sourceTestOutputDir name="../../../../target/generated-test-sources/test-annotations" />
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="FactionHelper" />
<module name="FactionsM" />
<module name="FactionsOne" />
<module name="FactionsUUID" />
<module name="LegacyFactions" />
<module name="PluginAPI" />
</profile>
<profile name="Annotation profile for CustomBosses" enabled="true">
<sourceOutputDir name="../../target/generated-sources/annotations" />
@ -34,12 +21,14 @@
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="Core" target="1.5" />
<module name="Core" target="1.8" />
<module name="custombosses" target="1.5" />
<module name="FactionsM" target="1.5" />
<module name="FactionsOne" target="1.5" />
<module name="FactionsUUID" target="1.5" />
<module name="PluginAPI" target="1.5" />
<module name="FactionHelper" target="1.8" />
<module name="FactionsM" target="1.8" />
<module name="FactionsOne" target="1.8" />
<module name="FactionsUUID" target="1.8" />
<module name="LegacyFactions" target="1.8" />
<module name="PluginAPI" target="1.8" />
</bytecodeTargetLevel>
</component>
</project>

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: com.massivecraft:FactionsOne:1.2.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/massivecraft/FactionsOne/1.2.1/FactionsOne-1.2.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/massivecraft/FactionsOne/1.2.1/FactionsOne-1.2.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/massivecraft/FactionsOne/1.2.1/FactionsOne-1.2.1-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: com.massivecraft.factions:FactionsUUID:1.6.9.5-U0.1.21">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/massivecraft/factions/FactionsUUID/1.6.9.5-U0.1.21/FactionsUUID-1.6.9.5-U0.1.21.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/massivecraft/factions/FactionsUUID/1.6.9.5-U0.1.21/FactionsUUID-1.6.9.5-U0.1.21-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/massivecraft/factions/FactionsUUID/1.6.9.5-U0.1.21/FactionsUUID-1.6.9.5-U0.1.21-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: com.massivecraft.factions:Factions:2.9.1-SNAPSHOT">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/massivecraft/factions/Factions/2.9.1-SNAPSHOT/Factions-2.9.1-SNAPSHOT.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/massivecraft/factions/Factions/2.9.1-SNAPSHOT/Factions-2.9.1-SNAPSHOT-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/massivecraft/factions/Factions/2.9.1-SNAPSHOT/Factions-2.9.1-SNAPSHOT-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: com.massivecraft.massivecore:MassiveCore:2.9.1-SNAPSHOT">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/massivecraft/massivecore/MassiveCore/2.9.1-SNAPSHOT/MassiveCore-2.9.1-SNAPSHOT.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/massivecraft/massivecore/MassiveCore/2.9.1-SNAPSHOT/MassiveCore-2.9.1-SNAPSHOT-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/massivecraft/massivecore/MassiveCore/2.9.1-SNAPSHOT/MassiveCore-2.9.1-SNAPSHOT-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: net.redstoneore.legacyfactions:LegacyFactions:1.4.7">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/net/redstoneore/legacyfactions/LegacyFactions/1.4.7/LegacyFactions-1.4.7.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/net/redstoneore/legacyfactions/LegacyFactions/1.4.7/LegacyFactions-1.4.7-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/net/redstoneore/legacyfactions/LegacyFactions/1.4.7/LegacyFactions-1.4.7-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="Maven: org.bukkit:bukkit:1.8.6-R0.1-SNAPSHOT">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/bukkit/bukkit/1.8.6-R0.1-SNAPSHOT/bukkit-1.8.6-R0.1-20150605.095643-24.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/bukkit/bukkit/1.8.6-R0.1-SNAPSHOT/bukkit-1.8.6-R0.1-20150605.095643-24-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/bukkit/bukkit/1.8.6-R0.1-SNAPSHOT/bukkit-1.8.6-R0.1-20150605.095643-24-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.bukkit:bukkit:1.9-R0.1-SNAPSHOT">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/bukkit/bukkit/1.9-R0.1-SNAPSHOT/bukkit-1.9-R0.1-20160330.160319-146.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/bukkit/bukkit/1.9-R0.1-SNAPSHOT/bukkit-1.9-R0.1-20160330.160319-146-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/bukkit/bukkit/1.9-R0.1-SNAPSHOT/bukkit-1.9-R0.1-20160330.160319-146-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -1,13 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.yaml:snakeyaml:1.14">
<library name="Maven: org.yaml:snakeyaml:1.15">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/yaml/snakeyaml/1.14/snakeyaml-1.14.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/yaml/snakeyaml/1.15/snakeyaml-1.15.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/yaml/snakeyaml/1.14/snakeyaml-1.14-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/yaml/snakeyaml/1.15/snakeyaml-1.15-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/yaml/snakeyaml/1.14/snakeyaml-1.14-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/yaml/snakeyaml/1.15/snakeyaml-1.15-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -3,9 +3,11 @@
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/plugin-modules/Core/Core.iml" filepath="$PROJECT_DIR$/plugin-modules/Core/Core.iml" />
<module fileurl="file://$PROJECT_DIR$/plugin-modules/FactionHelper/FactionHelper.iml" filepath="$PROJECT_DIR$/plugin-modules/FactionHelper/FactionHelper.iml" />
<module fileurl="file://$PROJECT_DIR$/api-modules/FactionsM/FactionsM.iml" filepath="$PROJECT_DIR$/api-modules/FactionsM/FactionsM.iml" />
<module fileurl="file://$PROJECT_DIR$/api-modules/FactionsOne/FactionsOne.iml" filepath="$PROJECT_DIR$/api-modules/FactionsOne/FactionsOne.iml" />
<module fileurl="file://$PROJECT_DIR$/api-modules/FactionsUUID/FactionsUUID.iml" filepath="$PROJECT_DIR$/api-modules/FactionsUUID/FactionsUUID.iml" />
<module fileurl="file://$PROJECT_DIR$/api-modules/LegacyFactions/LegacyFactions.iml" filepath="$PROJECT_DIR$/api-modules/LegacyFactions/LegacyFactions.iml" />
<module fileurl="file://$PROJECT_DIR$/api-modules/PluginAPI/PluginAPI.iml" filepath="$PROJECT_DIR$/api-modules/PluginAPI/PluginAPI.iml" />
<module fileurl="file://$PROJECT_DIR$/custombosses.iml" filepath="$PROJECT_DIR$/custombosses.iml" />
</modules>

View File

@ -1,13 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
<output url="file://C:/target/classes" />
<output-test url="file://C:/target/test-classes" />
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="FactionHelper" scope="PROVIDED" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.massivecraft.factions:Factions:2.9.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.massivecraft.massivecore:MassiveCore:2.9.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.spigotmc:spigot:1.11.2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.milkbowl.vault:VaultAPI:1.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:bukkit:1.9-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-lang:commons-lang:2.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: junit:junit:4.10" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.2.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.avaje:ebean:2.8.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.persistence:persistence-api:1.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.15" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:worldguard:6.0.0-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.spigot:bukkit-classloader-check:1.8-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:commandbook:2.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.sf.opencsv:opencsv:2.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:worldedit:6.0.0-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: de.schlichtherle:truezip:6.8.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: rhino:js:1.7R2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:10.0.1" level="project" />
</component>
</module>

View File

@ -16,7 +16,7 @@
<dependencies>
<dependency>
<groupId>net.aminecraftdev.custombosses</groupId>
<artifactId>PluginAPI</artifactId>
<artifactId>FactionHelper</artifactId>
<version>3.0.0.0</version>
<scope>provided</scope>
</dependency>
@ -36,8 +36,8 @@
<build>
<defaultGoal>clean package install</defaultGoal>
<directory>/target</directory>
<finalName>${project.artifactId}-${project.version}</finalName>
<directory>target</directory>
<finalName>${project.artifactId}-${plugin.version}</finalName>
<sourceDirectory>${basedir}/src/</sourceDirectory>
<plugins>
<plugin>
@ -66,5 +66,4 @@
</plugin>
</plugins>
</build>
</project>

View File

@ -1,11 +1,11 @@
package net.aminecraftdev.custombosses.innerapi.factions;
package net.aminecraftdev.custombosses.utils.factions;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.entity.BoardColl;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.ps.PS;
import net.aminecraftdev.custombosses.innerapi.dependencies.FactionBuilder;
import net.aminecraftdev.custombosses.utils.IFactionHelper;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@ -15,7 +15,7 @@ import org.bukkit.entity.Player;
* @version 1.0.0
* @since 31-May-17
*/
public class FactionsM implements FactionBuilder {
public class FactionsM implements IFactionHelper {
@Override
public boolean isFriendly(Player a, Player b) {

View File

@ -1,13 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
<output url="file://C:/target/classes" />
<output-test url="file://C:/target/test-classes" />
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="FactionHelper" scope="PROVIDED" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.massivecraft:FactionsOne:1.2.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.spigotmc:spigot:1.11.2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.milkbowl.vault:VaultAPI:1.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:bukkit:1.9-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-lang:commons-lang:2.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: junit:junit:4.10" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.2.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.avaje:ebean:2.8.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.persistence:persistence-api:1.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.15" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:worldguard:6.0.0-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.spigot:bukkit-classloader-check:1.8-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:commandbook:2.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.sf.opencsv:opencsv:2.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:worldedit:6.0.0-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: de.schlichtherle:truezip:6.8.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: rhino:js:1.7R2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:10.0.1" level="project" />
</component>
</module>

View File

@ -16,7 +16,7 @@
<dependencies>
<dependency>
<groupId>net.aminecraftdev.custombosses</groupId>
<artifactId>PluginAPI</artifactId>
<artifactId>FactionHelper</artifactId>
<version>3.0.0.0</version>
<scope>provided</scope>
</dependency>
@ -30,8 +30,8 @@
<build>
<defaultGoal>clean package install</defaultGoal>
<directory>/target</directory>
<finalName>${project.artifactId}-${project.version}</finalName>
<directory>target</directory>
<finalName>${project.artifactId}-${plugin.version}</finalName>
<sourceDirectory>${basedir}/src/</sourceDirectory>
<plugins>
<plugin>
@ -60,5 +60,4 @@
</plugin>
</plugins>
</build>
</project>

View File

@ -1,11 +1,11 @@
package net.aminecraftdev.custombosses.innerapi.factions;
package net.aminecraftdev.custombosses.utils.factions;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Rel;
import net.aminecraftdev.custombosses.innerapi.dependencies.FactionBuilder;
import net.aminecraftdev.custombosses.utils.IFactionHelper;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@ -15,7 +15,7 @@ import org.bukkit.entity.Player;
* @version 1.0.0
* @since 31-May-17
*/
public class FactionsOne implements FactionBuilder {
public class FactionsOne implements IFactionHelper {
@Override
public boolean isFriendly(Player a, Player b) {

View File

@ -1,13 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
<output url="file://C:/target/classes" />
<output-test url="file://C:/target/test-classes" />
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="FactionHelper" scope="PROVIDED" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.massivecraft.factions:FactionsUUID:1.6.9.5-U0.1.21" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.spigotmc:spigot:1.11.2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.milkbowl.vault:VaultAPI:1.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:bukkit:1.9-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-lang:commons-lang:2.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: junit:junit:4.10" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.2.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.avaje:ebean:2.8.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.persistence:persistence-api:1.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.15" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:worldguard:6.0.0-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.spigot:bukkit-classloader-check:1.8-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:commandbook:2.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.sf.opencsv:opencsv:2.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:worldedit:6.0.0-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: de.schlichtherle:truezip:6.8.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: rhino:js:1.7R2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:10.0.1" level="project" />
</component>
</module>

View File

@ -16,22 +16,22 @@
<dependencies>
<dependency>
<groupId>net.aminecraftdev.custombosses</groupId>
<artifactId>PluginAPI</artifactId>
<artifactId>FactionHelper</artifactId>
<version>3.0.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.massivecraft</groupId>
<groupId>com.massivecraft.factions</groupId>
<artifactId>FactionsUUID</artifactId>
<version>1.6.9.5-U0.1.20</version>
<version>1.6.9.5-U0.1.21</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<defaultGoal>clean package install</defaultGoal>
<directory>/target</directory>
<finalName>${project.artifactId}-${project.version}</finalName>
<directory>target</directory>
<finalName>${project.artifactId}-${plugin.version}</finalName>
<sourceDirectory>${basedir}/src/</sourceDirectory>
<plugins>
<plugin>
@ -60,5 +60,4 @@
</plugin>
</plugins>
</build>
</project>

View File

@ -1,11 +1,11 @@
package net.aminecraftdev.custombosses.innerapi.factions;
package net.aminecraftdev.custombosses.utils.factions;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Relation;
import net.aminecraftdev.custombosses.innerapi.dependencies.FactionBuilder;
import net.aminecraftdev.custombosses.utils.IFactionHelper;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@ -15,7 +15,7 @@ import org.bukkit.entity.Player;
* @version 1.0.0
* @since 31-May-17
*/
public class FactionsUUID implements FactionBuilder {
public class FactionsUUID implements IFactionHelper {
@Override
public boolean isFriendly(Player a, Player b) {

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="FactionHelper" scope="PROVIDED" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.redstoneore.legacyfactions:LegacyFactions:1.4.7" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.spigotmc:spigot:1.11.2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.milkbowl.vault:VaultAPI:1.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:bukkit:1.9-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-lang:commons-lang:2.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: junit:junit:4.10" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.2.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.avaje:ebean:2.8.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.persistence:persistence-api:1.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.15" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:worldguard:6.0.0-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.spigot:bukkit-classloader-check:1.8-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:commandbook:2.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.sf.opencsv:opencsv:2.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:worldedit:6.0.0-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: de.schlichtherle:truezip:6.8.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: rhino:js:1.7R2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:10.0.1" level="project" />
</component>
</module>

View File

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>CustomBosses</artifactId>
<groupId>net.aminecraftdev.custombosses</groupId>
<version>3.0.0.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>LegacyFactions</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>net.aminecraftdev.custombosses</groupId>
<artifactId>FactionHelper</artifactId>
<version>3.0.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.redstoneore.legacyfactions</groupId>
<artifactId>LegacyFactions</artifactId>
<version>1.4.7</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<defaultGoal>clean package install</defaultGoal>
<directory>target</directory>
<finalName>${project.artifactId}-${plugin.version}</finalName>
<sourceDirectory>${basedir}/src/</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.4</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,59 @@
package net.aminecraftdev.custombosses.utils.factions;
import net.aminecraftdev.custombosses.utils.IFactionHelper;
import net.redstoneore.legacyfactions.Relation;
import net.redstoneore.legacyfactions.entity.Board;
import net.redstoneore.legacyfactions.entity.FPlayerColl;
import net.redstoneore.legacyfactions.entity.Faction;
import net.redstoneore.legacyfactions.locality.Locality;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 27-Oct-17
*/
public class LegacyFactions implements IFactionHelper {
@Override
public boolean isFriendly(Player a, Player b) {
Faction aFac = FPlayerColl.get(a).getFaction();
Faction bFac = FPlayerColl.get(b).getFaction();
Relation relation = aFac.getRelationTo(bFac);
if(bFac.isWilderness()) return false;
if(aFac == bFac) return true;
if(relation.isEnemy()) return false;
if(relation.isNeutral()) return false;
if(relation.isTruce()) return true;
if(relation.isAlly()) return true;
if(relation.isMember()) return true;
return false;
}
@Override
public boolean isFriendly(Player a, Location location) {
Faction aFac = FPlayerColl.get(a).getFaction();
Faction bFac = Board.get().getFactionAt(Locality.of(location));
Relation relation = aFac.getRelationTo(bFac);
if(bFac.isWilderness() || relation.isEnemy() || relation.isNeutral()) return false;
if(relation.isTruce() || relation.isAlly() || relation.isMember()) return true;
return false;
}
@Override
public boolean isInWarzone(Location location) {
Faction faction = Board.get().getFactionAt(Locality.of(location));
return faction.isWarZone();
}
@Override
public boolean isInClaimedLand(Location location) {
Faction faction = Board.get().getFactionAt(Locality.of(location));
return !(faction.isWarZone() || faction.isWilderness() || faction.isSafeZone());
}
}

View File

@ -1,13 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
<output url="file://C:/target/classes" />
<output-test url="file://C:/target/test-classes" />
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.spigotmc:spigot:1.11.2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.milkbowl.vault:VaultAPI:1.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:bukkit:1.9-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-lang:commons-lang:2.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: junit:junit:4.10" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.2.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.avaje:ebean:2.8.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.persistence:persistence-api:1.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.15" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:worldguard:6.0.0-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.spigot:bukkit-classloader-check:1.8-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:commandbook:2.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.sf.opencsv:opencsv:2.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:worldedit:6.0.0-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: de.schlichtherle:truezip:6.8.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: rhino:js:1.7R2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:10.0.1" level="project" />
</component>
</module>

View File

@ -15,8 +15,8 @@
<build>
<defaultGoal>clean package install</defaultGoal>
<directory>/target</directory>
<finalName>${project.artifactId}-${project.version}</finalName>
<directory>target</directory>
<finalName>${project.artifactId}-${plugin.version}</finalName>
<sourceDirectory>${basedir}/src/</sourceDirectory>
<plugins>
<plugin>

View File

@ -1,27 +0,0 @@
package net.aminecraftdev.custombosses.innerapi;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 31-May-17
*/
public class FileUtils {
public static final void saveFile(File file, FileConfiguration configuration) {
try {
configuration.save(file);
} catch (Exception e) {
e.printStackTrace();
}
}
public static final FileConfiguration getConf(File file) {
return YamlConfiguration.loadConfiguration(file);
}
}

View File

@ -1,66 +0,0 @@
package net.aminecraftdev.custombosses.innerapi;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.FireworkMeta;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 31-May-17
*/
public class FireworkUtils {
public static final Color getColour(String s) {
if(s.equalsIgnoreCase("AQUA")) return Color.AQUA;
if(s.equalsIgnoreCase("BLACK")) return Color.BLACK;
if(s.equalsIgnoreCase("BLUE")) return Color.BLUE;
if(s.equalsIgnoreCase("FUCHSIA")) return Color.FUCHSIA;
if(s.equalsIgnoreCase("GRAY")) return Color.GRAY;
if(s.equalsIgnoreCase("GREEN")) return Color.GREEN;
if(s.equalsIgnoreCase("LIME")) return Color.LIME;
if(s.equalsIgnoreCase("MAROON")) return Color.MAROON;
if(s.equalsIgnoreCase("NAVY")) return Color.NAVY;
if(s.equalsIgnoreCase("OLIVE")) return Color.OLIVE;
if(s.equalsIgnoreCase("ORANGE")) return Color.ORANGE;
if(s.equalsIgnoreCase("PURPLE")) return Color.PURPLE;
if(s.equalsIgnoreCase("RED")) return Color.RED;
if(s.equalsIgnoreCase("SILVER")) return Color.SILVER;
if(s.equalsIgnoreCase("TEAL")) return Color.TEAL;
if(s.equalsIgnoreCase("WHITE")) return Color.WHITE;
if(s.equalsIgnoreCase("YELLOW")) return Color.YELLOW;
return null;
}
public static final void spawnFirework(Location location, ConfigurationSection configurationSection) {
Firework firework = (Firework) location.getWorld().spawn(location, Firework.class);
String colour = configurationSection.getString("color").toUpperCase();
Color fireworkColor = getColour(colour);
int fireworkPower = configurationSection.getInt("power");
boolean fireworkFlicker = configurationSection.getBoolean("flicker");
boolean fireworkTrail = configurationSection.getBoolean("trail");
FireworkEffect.Type fireworkType = FireworkEffect.Type.valueOf(configurationSection.getString("type").toUpperCase());
FireworkMeta fireworkMeta = firework.getFireworkMeta();
fireworkMeta.addEffect(FireworkEffect.builder()
.flicker(fireworkFlicker)
.trail(fireworkTrail)
.with(fireworkType)
.withColor(fireworkColor)
.build());
fireworkMeta.setPower(fireworkPower);
firework.setFireworkMeta(fireworkMeta);
}
public static final void spawnFirework(Player player, ConfigurationSection configurationSection) {
spawnFirework(player.getLocation(), configurationSection);
}
}

View File

@ -1,53 +0,0 @@
package net.aminecraftdev.custombosses.innerapi;
import java.text.DecimalFormat;
/**
* Created by charl on 28-Apr-17.
*/
public class NumberUtils {
public static final String formatDouble(double d) {
DecimalFormat format = new DecimalFormat("###,###,###,###,###.##");
return format.format(d);
}
public static final String formatTime(int time) {
int hours = time / 3600;
int remainder = time % 3600;
int minutes = remainder / 60;
int seconds = remainder % 60;
String disHour = (hours < 10 ? "0" : "") + hours;
String disMinu = (minutes < 10 ? "0" : "") + minutes;
String disSeco = (seconds < 10 ? "0" : "") + seconds;
String formatted = "";
if(hours != 0) formatted += disHour + " hours ";
if(minutes != 0) formatted += disMinu + " minutes ";
if(seconds != 0) formatted += disSeco + " seconds.";
return formatted;
}
public static final boolean isStringInteger(String s) {
try {
Integer.valueOf(s);
} catch (NumberFormatException e) {
return false;
}
return true;
}
public static final boolean isStringDouble(String s) {
try {
Double.valueOf(s);
} catch (NumberFormatException e) {
return false;
}
return true;
}
}

View File

@ -1,38 +0,0 @@
package net.aminecraftdev.custombosses.innerapi;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 31-May-17
*/
public class PotionUtils {
public static final PotionEffect getPotionEffect(ConfigurationSection configurationSection) {
if(configurationSection.contains("enabled") && !configurationSection.getBoolean("enabled")) return null;
int level = configurationSection.getInt("level");
int duration = configurationSection.getInt("duration");
String type = configurationSection.getString("type");
if(PotionEffectType.getByName(type) == null) {
return null;
}
PotionEffectType potionEffectType = PotionEffectType.getByName(type);
if(duration == -1) {
duration = 100000;
} else {
duration *= 20;
}
level -= 1;
return new PotionEffect(potionEffectType, duration, level);
}
}

View File

@ -1,24 +0,0 @@
package net.aminecraftdev.custombosses.innerapi;
import java.util.Random;
/**
* Created by charl on 28-Apr-17.
*/
public class RandomUtils {
private static final Random RANDOM;
static {
RANDOM = new Random();
}
public static Random getRandom() {
return RANDOM;
}
public static int getRandomInt(int input) {
return RANDOM.nextInt(input);
}
}

View File

@ -1,35 +0,0 @@
package net.aminecraftdev.custombosses.innerapi;
import org.bukkit.Sound;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 31-May-17
*/
public class SoundUtils {
public static final void playSound(ConfigurationSection configurationSection, Player player) {
boolean enabled = configurationSection.getBoolean("enabled", true);
String type = configurationSection.getString("type");
int volume = configurationSection.getInt("volume");
int pitch = configurationSection.getInt("pitch");
if(!enabled) return;
player.playSound(player.getLocation(), Sound.valueOf(type.toUpperCase()), (float) volume, (float) pitch);
}
public static final Sound getSound(ConfigurationSection configurationSection) {
boolean enabled = configurationSection.getBoolean("enabled", true);
String type = configurationSection.getString("type");
if(!enabled) return null;
return Sound.valueOf(type.toUpperCase());
}
}

View File

@ -1,44 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.command;
import org.boostednetwork.factionscore.utils.NumberUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* Created by charl on 28-Apr-17.
*/
public class CommandUtils {
public static final Player strAsPlayer(String s) {
if(Bukkit.getPlayer(s) == null) return null;
return Bukkit.getPlayer(s);
}
public static final Integer strAsInteger(String s) {
if(NumberUtils.isStringInteger(s)) return Integer.valueOf(s);
return null;
}
public static final Double strAsDouble(String s) {
if(NumberUtils.isStringDouble(s)) return Double.valueOf(s);
return null;
}
public static final boolean isIntegerWithinItemStackSize(int i) {
if(i > 64) return false;
if(i < 1) return false;
return true;
}
public static final boolean isCommandSenderPlayer(CommandSender commandSender) {
if(!(commandSender instanceof Player)) return false;
return true;
}
}

View File

@ -1,24 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.command;
import org.bukkit.command.CommandSender;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 31-May-17
*/
public abstract class SubCommand<T extends CommandSender> {
private String subCommand;
public SubCommand(String subCommand) {
this.subCommand = subCommand;
}
public String getSubCommand() {
return subCommand;
}
public abstract void execute(T sender, String[] args);
}

View File

@ -1,14 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.command;
import org.bukkit.command.CommandSender;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 31-May-17
*/
public interface SubCommandBuilder<T extends CommandSender> {
void register(SubCommand<T> subCommand);
}

View File

@ -1,49 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.command.builder;
import org.bukkit.command.Command;
import org.bukkit.command.CommandMap;
import org.bukkit.command.SimpleCommandMap;
import org.bukkit.plugin.SimplePluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import java.lang.reflect.Field;
import java.util.Map;
/**
* Created by charl on 03-May-17.
*/
public final class CommandRemover {
private CommandMap map = new SimpleCommandMap(null);
/**
* Remove/un-register a command.
*/
public CommandRemover(JavaPlugin plugin, String command) {
if (plugin.getServer() != null && plugin.getServer().getPluginManager() instanceof SimplePluginManager) {
final SimplePluginManager manager = (SimplePluginManager) plugin.getServer().getPluginManager();
try {
final Field field = SimplePluginManager.class.getDeclaredField("commandMap");
field.setAccessible(true);
map = (CommandMap) field.get(manager);
final Field field2 = SimpleCommandMap.class.getDeclaredField("knownCommands");
field2.setAccessible(true);
@SuppressWarnings("unchecked")
final Map<String, Command> knownCommands = (Map<String, Command>) field2.get(map);
for (final Map.Entry<String, Command> entry : knownCommands.entrySet()) {
if (entry.getKey().equals(command)) {
entry.getValue().unregister(map);
}
}
knownCommands.remove(command);
} catch (IllegalArgumentException | NoSuchFieldException | IllegalAccessException | SecurityException e) {
e.printStackTrace();
}
}
}
}

View File

@ -1,135 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.command.builder;
import net.aminecraftdev.custombosses.innerapi.command.builder.attributes.*;
import net.aminecraftdev.custombosses.innerapi.message.MessageUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandMap;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import java.lang.reflect.Field;
import java.util.Arrays;
/**
* Created by charl on 03-May-17.
*/
public abstract class CommandService<T extends CommandSender> extends BukkitCommand {
private static CommandMap _commandMap = null;
private String _command, _description, _usage, _noPermMessage, _permission;
private String[] _aliases;
/**
* Construct a new command.
*
* @param command The command label
* @param description The command description
* @param aliases Aliases of the command
*/
public CommandService(String command, String description, String[] aliases) {
super(command);
_command = command;
_description = description;
_aliases = aliases;
}
/**
* Construct a new command.
*
* @param command The command label
* @param description The command description
*/
public CommandService(String command, String description) {
this(command, description, new String[]{});
}
/**
* Construct a new command.
*
* @param cmd The command
*/
public CommandService(Class<? extends CommandService> cmd) {
this(cmd.getAnnotation(Name.class).value(), cmd.getAnnotation(Description.class).value());
if(cmd.isAnnotationPresent(Alias.class))
_aliases = cmd.getAnnotation(Alias.class).value();
if(cmd.isAnnotationPresent(Permission.class))
_permission = cmd.getAnnotation(Permission.class).value();
if(cmd.isAnnotationPresent(Usage.class))
_usage = cmd.getAnnotation(Usage.class).value();
if(cmd.isAnnotationPresent(NoPermission.class))
_noPermMessage = cmd.getAnnotation(NoPermission.class).value();
register();
}
@Override
public final boolean execute(CommandSender commandSender, String s, String[] args) {
if(testPermission(commandSender)) return false;
try {
execute((T) commandSender, args);
} catch (ClassCastException e) {
commandSender.sendMessage(MessageUtils.translateString("&4You cannot use that command."));
return false;
}
return true;
}
/**
* This is fired when the command is executed.
*
* @param sender Sender of the command
* @param args Command arguments
*/
public abstract void execute(T sender, String[] args);
/**
* This method will register a command without the need of plugin.yml
*/
private void register() {
if (_commandMap != null) {
setFields();
_commandMap.register(_command, this);
return;
}
try {
Field field = Bukkit.getServer().getClass().getDeclaredField("commandMap");
field.setAccessible(true);
_commandMap = (CommandMap) field.get(Bukkit.getServer());
setFields();
_commandMap.register(_command, this);
}
catch (Exception e) {
e.printStackTrace();
}
}
private void setFields() {
setDescription(_description);
if(_aliases != null) setAliases(Arrays.asList(_aliases));
if(_usage != null) setUsage(_usage);
if(_permission != null) setPermission(_permission);
if(_noPermMessage != null) {
setPermissionMessage(MessageUtils.translateString(_noPermMessage));
} else {
setPermissionMessage(MessageUtils.translateString("&4You do not have <permission> for that command."));
}
}
@Override
public String getDescription() {
return _description;
}
}

View File

@ -1,15 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.command.builder.attributes;
import java.lang.annotation.*;
/**
* Created by charl on 03-May-17.
*/
@Documented
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface Alias {
String[] value();
}

View File

@ -1,15 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.command.builder.attributes;
import java.lang.annotation.*;
/**
* Created by charl on 03-May-17.
*/
@Documented
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface Description {
String value();
}

View File

@ -1,15 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.command.builder.attributes;
import java.lang.annotation.*;
/**
* Created by LukeBingham on 03/04/2017.
*/
@Documented
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface Name {
String value();
}

View File

@ -1,17 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.command.builder.attributes;
import java.lang.annotation.*;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 31-May-17
*/
@Documented
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface NoPermission {
String value();
}

View File

@ -1,15 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.command.builder.attributes;
import java.lang.annotation.*;
/**
* Created by charl on 11-May-17.
*/
@Documented
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface Permission {
String value();
}

View File

@ -1,17 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.command.builder.attributes;
import java.lang.annotation.*;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 31-May-17
*/
@Documented
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface Usage {
String value();
}

View File

@ -1,59 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.dependencies;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 31-May-17
*/
public interface FactionBuilder {
/** Used to tell if 2 players are
* friendly.
*
* @param a - The first player.
* @param b - The second player.
*
*/
boolean isFriendly(Player a, Player b);
/** Used to tell if a player is in friendly
* land, in other words to tell if they are
* in ally, truce or their own land. If not
* returns false.
*
* @param a - The player.
* @param location - The location we are checking.
*
*/
boolean isFriendly(Player a, Location location);
/** Used to check if a location is in the warzone.
* I used this in my CustomBosses plugin to check
* if the player was inside a warzone when spawning
* the boss.
*
* @param location - The location we are checking.
*
*/
boolean isInWarzone(Location location);
/** Used to check if the location is claimed by a faction
* other then Wilderness, Warzone or Safezone. If it is
* another faction it will return true, otherwise if its
* in Wilderness, Warzone or Safezone it will return false.
*
* @param location - The location that is being tested.
*
*/
boolean isInClaimedLand(Location location);
}

View File

@ -1,76 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.dependencies;
import net.milkbowl.vault.chat.Chat;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.plugin.RegisteredServiceProvider;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 25-May-17
*/
public class VaultHelper {
private static Economy economy;
private static Chat chat;
private static Permission permission;
public static final Economy getEconomy() {
return economy;
}
public static final Chat getChat() {
return chat;
}
public static final Permission getPermission() {
return permission;
}
public static boolean setupVault() {
if(!setupChat()) return false;
if(!setupPermission()) return false;
if(!setupEconomy()) return false;
return true;
}
private static boolean setupChat() {
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
return false;
}
RegisteredServiceProvider<Chat> rsp = Bukkit.getServer().getServicesManager().getRegistration(Chat.class);
if (rsp == null) {
return false;
}
chat = rsp.getProvider();
return chat != null;
}
private static boolean setupEconomy() {
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
return false;
}
RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
if (rsp == null) {
return false;
}
economy = rsp.getProvider();
return economy != null;
}
private static boolean setupPermission() {
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
return false;
}
RegisteredServiceProvider<Permission> rsp = Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
if (rsp == null) {
return false;
}
permission = rsp.getProvider();
return permission != null;
}
}

View File

@ -1,97 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.dependencies;
import com.sk89q.worldguard.bukkit.WGBukkit;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import java.util.LinkedList;
import java.util.List;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 25-May-17
*/
public class WorldGuardHelper {
private static Boolean isLoaded = null;
private static boolean isPluginLoaded() {
return isLoaded != null? isLoaded : (isLoaded = Bukkit.getServer().getPluginManager().getPlugin("WorldEdit") != null
&& Bukkit.getServer().getPluginManager().getPlugin("WorldGuard") != null);
}
public static boolean isPvPAllowed(Location loc) {
if(isPluginLoaded()) {
ApplicableRegionSet set = WGBukkit.getPlugin().getRegionManager(loc.getWorld()).getApplicableRegions(loc);
if(set.queryState(null, DefaultFlag.PVP) == StateFlag.State.DENY) return false;
}
return true;
}
public static boolean isBreakAllowed(Location loc) {
if(isPluginLoaded()) {
ApplicableRegionSet set = WGBukkit.getPlugin().getRegionManager(loc.getWorld()).getApplicableRegions(loc);
if(set.queryState(null, DefaultFlag.BLOCK_BREAK) == StateFlag.State.DENY) return false;
}
return true;
}
public static boolean allowsExplosions(Location loc) {
if(isPluginLoaded()) {
ApplicableRegionSet set = WGBukkit.getPlugin().getRegionManager(loc.getWorld()).getApplicableRegions(loc);
if(set.queryState(null, DefaultFlag.OTHER_EXPLOSION) == StateFlag.State.DENY) return false;
}
return true;
}
public static List<String> getRegionNames(Location loc) {
if(isPluginLoaded()) {
ApplicableRegionSet set = WGBukkit.getPlugin().getRegionManager(loc.getWorld()).getApplicableRegions(loc);
LinkedList<String> parentNames = new LinkedList<String>();
LinkedList<String> regions = new LinkedList<String>();
for(ProtectedRegion region : set) {
String id = region.getId();
regions.add(id);
ProtectedRegion parent = region.getParent();
while(parent != null) {
parentNames.add(parent.getId());
parent = parent.getParent();
}
}
for(String name : parentNames) {
regions.remove(name);
}
return regions;
}
return null;
}
public static boolean isMobSpawningAllowed(Location loc) {
if(isPluginLoaded()) {
ApplicableRegionSet set = WGBukkit.getPlugin().getRegionManager(loc.getWorld()).getApplicableRegions(loc);
if(set.queryState(null, DefaultFlag.MOB_SPAWNING) == StateFlag.State.DENY) return false;
}
return true;
}
}

View File

@ -1,10 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.factory;
/**
* Created by charl on 04-May-17.
*/
public interface CloneableFactory<T> {
T clone();
}

View File

@ -1,11 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.factory;
/**
* Created by charl on 04-May-17.
*/
public abstract class Factory<T> implements FactoryBuilder<T> {
protected T object;
public abstract T build();
}

View File

@ -1,11 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.factory;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 29-May-17
*/
public interface FactoryBuilder<T> {
T build();
}

View File

@ -1,997 +0,0 @@
// The MIT License (MIT)
//
// Copyright (c) 2015 Kristian Stangeland
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
// Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package net.aminecraftdev.custombosses.innerapi.factory;
import com.google.common.base.Splitter;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.Lists;
import com.google.common.collect.MapMaker;
import com.google.common.io.Closeables;
import com.google.common.io.Files;
import com.google.common.io.InputSupplier;
import com.google.common.io.OutputSupplier;
import com.google.common.primitives.Primitives;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.inventory.ItemStack;
import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.*;
import java.util.concurrent.ConcurrentMap;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
@SuppressWarnings("deprecation")
public class NbtFactory {
// Convert between NBT id and the equivalent class in java
private static final BiMap<Integer, Class<?>> NBT_CLASS = HashBiMap.create();
private static final BiMap<Integer, NbtType> NBT_ENUM = HashBiMap.create();
/**
* Whether or not to enable stream compression.
* @author Kristian
*/
public enum StreamOptions {
NO_COMPRESSION,
GZIP_COMPRESSION,
}
private enum NbtType {
TAG_END(0, Void.class),
TAG_BYTE(1, byte.class),
TAG_SHORT(2, short.class),
TAG_INT(3, int.class),
TAG_LONG(4, long.class),
TAG_FLOAT(5, float.class),
TAG_DOUBLE(6, double.class),
TAG_BYTE_ARRAY(7, byte[].class),
TAG_INT_ARRAY(11, int[].class),
TAG_STRING(8, String.class),
TAG_LIST(9, List.class),
TAG_COMPOUND(10, Map.class);
// Unique NBT id
public final int id;
private NbtType(int id, Class<?> type) {
this.id = id;
NBT_CLASS.put(id, type);
NBT_ENUM.put(id, this);
}
private String getFieldName() {
if (this == TAG_COMPOUND)
return "map";
else if (this == TAG_LIST)
return "list";
else
return "data";
}
}
// The NBT base class
private Class<?> BASE_CLASS;
private Class<?> COMPOUND_CLASS;
private Class<?> STREAM_TOOLS;
private Class<?> READ_LIMITER_CLASS;
private Method NBT_CREATE_TAG;
private Method NBT_GET_TYPE;
private Field NBT_LIST_TYPE;
private final Field[] DATA_FIELD = new Field[12];
// CraftItemStack
private Class<?> CRAFT_STACK;
private Field CRAFT_HANDLE;
private Field STACK_TAG;
// Loading/saving compounds
private LoadCompoundMethod LOAD_COMPOUND;
private Method SAVE_COMPOUND;
// Shared instance
private static NbtFactory INSTANCE;
/**
* Represents a root NBT compound.
* <p>
* All changes to this map will be reflected in the underlying NBT compound. Values may only be one of the following:
* <ul>
* <li>Primitive types</li>
* <li>{@link String String}</li>
* <li>{@link NbtList}</li>
* <li>{@link NbtCompound}</li>
* </ul>
* <p>
* See also:
* <ul>
* <li>{@link NbtFactory#createCompound()}</li>
* <li>{@link NbtFactory#fromCompound(Object)}</li>
* </ul>
* @author Kristian
*/
public final class NbtCompound extends ConvertedMap {
private NbtCompound(Object handle) {
super(handle, getDataMap(handle));
}
// Simplifiying access to each value
public Byte getByte(String key, Byte defaultValue) {
return containsKey(key) ? (Byte)get(key) : defaultValue;
}
public Short getShort(String key, Short defaultValue) {
return containsKey(key) ? (Short)get(key) : defaultValue;
}
public Integer getInteger(String key, Integer defaultValue) {
return containsKey(key) ? (Integer)get(key) : defaultValue;
}
public Long getLong(String key, Long defaultValue) {
return containsKey(key) ? (Long)get(key) : defaultValue;
}
public Float getFloat(String key, Float defaultValue) {
return containsKey(key) ? (Float)get(key) : defaultValue;
}
public Double getDouble(String key, Double defaultValue) {
return containsKey(key) ? (Double)get(key) : defaultValue;
}
public String getString(String key, String defaultValue) {
return containsKey(key) ? (String)get(key) : defaultValue;
}
public byte[] getByteArray(String key, byte[] defaultValue) {
return containsKey(key) ? (byte[])get(key) : defaultValue;
}
public int[] getIntegerArray(String key, int[] defaultValue) {
return containsKey(key) ? (int[])get(key) : defaultValue;
}
/**
* Retrieve the list by the given name.
* @param key - the name of the list.
* @param createNew - whether or not to create a new list if its missing.
* @return An existing list, a new list or NULL.
*/
public NbtList getList(String key, boolean createNew) {
NbtList list = (NbtList) get(key);
if (list == null && createNew)
put(key, list = createList());
return list;
}
/**
* Retrieve the map by the given name.
* @param key - the name of the map.
* @param createNew - whether or not to create a new map if its missing.
* @return An existing map, a new map or NULL.
*/
public NbtCompound getMap(String key, boolean createNew) {
return getMap(Arrays.asList(key), createNew);
}
// Done
/**
* Set the value of an entry at a given location.
* <p>
* Every element of the path (except the end) are assumed to be compounds, and will
* be created if they are missing.
* @param path - the path to the entry.
* @param value - the new value of this entry.
* @return This compound, for chaining.
*/
public NbtCompound putPath(String path, Object value) {
List<String> entries = getPathElements(path);
Map<String, Object> map = getMap(entries.subList(0, entries.size() - 1), true);
map.put(entries.get(entries.size() - 1), value);
return this;
}
/**
* Retrieve the value of a given entry in the tree.
* <p>
* Every element of the path (except the end) are assumed to be compounds. The
* retrieval operation will be cancelled if any of them are missing.
* @param path - path to the entry.
* @return The value, or NULL if not found.
*/
@SuppressWarnings("unchecked")
public <T> T getPath(String path) {
List<String> entries = getPathElements(path);
NbtCompound map = getMap(entries.subList(0, entries.size() - 1), false);
if (map != null) {
return (T) map.get(entries.get(entries.size() - 1));
}
return null;
}
/**
* Save the content of a NBT compound to a stream.
* <p>
* Use {@link Files#newOutputStreamSupplier(File)} to provide a stream supplier to a file.
* @param stream - the output stream.
* @param option - whether or not to compress the output.
* @throws IOException If anything went wrong.
*/
public void saveTo(OutputSupplier<? extends OutputStream> stream, StreamOptions option) throws IOException {
saveStream(this, stream, option);
}
/**
* Retrieve a map from a given path.
* @param path - path of compounds to look up.
* @param createNew - whether or not to create new compounds on the way.
* @return The map at this location.
*/
private NbtCompound getMap(Iterable<String> path, boolean createNew) {
NbtCompound current = this;
for (String entry : path) {
NbtCompound child = (NbtCompound) current.get(entry);
if (child == null) {
if (!createNew)
return null;
current.put(entry, child = createCompound());
}
current = child;
}
return current;
}
/**
* Split the path into separate elements.
* @param path - the path to split.
* @return The elements.
*/
private List<String> getPathElements(String path) {
return Lists.newArrayList(Splitter.on(".").omitEmptyStrings().split(path));
}
}
/**
* Represents a root NBT list.
* See also:
* <ul>
* <li>{@link NbtFactory#fromList(Object)}</li>
* </ul>
* @author Kristian
*/
public final class NbtList extends ConvertedList {
private NbtList(Object handle) {
super(handle, getDataList(handle));
}
}
/**
* Represents an object that provides a view of a native NMS class.
* @author Kristian
*/
public static interface Wrapper {
/**
* Retrieve the underlying native NBT tag.
* @return The underlying NBT.
*/
public Object getHandle();
}
/**
* Retrieve or construct a shared NBT factory.
* @return The factory.
*/
private static NbtFactory get() {
if (INSTANCE == null)
INSTANCE = new NbtFactory();
return INSTANCE;
}
/**
* Construct an instance of the NBT factory by deducing the class of NBTBase.
*/
private NbtFactory() {
if (BASE_CLASS == null) {
try {
// Keep in mind that I do use hard-coded field names - but it's okay as long as we're dealing
// with CraftBukkit or its derivatives. This does not work in MCPC+ however.
ClassLoader loader = NbtFactory.class.getClassLoader();
String packageName = getPackageName();
Class<?> offlinePlayer = loader.loadClass(packageName + ".CraftOfflinePlayer");
// Prepare NBT
COMPOUND_CLASS = getMethod(0, Modifier.STATIC, offlinePlayer, "getData").getReturnType();
BASE_CLASS = COMPOUND_CLASS.getSuperclass();
NBT_GET_TYPE = getMethod(0, Modifier.STATIC, BASE_CLASS, "getTypeId");
NBT_CREATE_TAG = getMethod(Modifier.STATIC, 0, BASE_CLASS, "createTag", byte.class);
// Prepare CraftItemStack
CRAFT_STACK = loader.loadClass(packageName + ".inventory.CraftItemStack");
CRAFT_HANDLE = getField(null, CRAFT_STACK, "handle");
STACK_TAG = getField(null, CRAFT_HANDLE.getType(), "tag");
// Loading/saving
String nmsPackage = BASE_CLASS.getPackage().getName();
initializeNMS(loader, nmsPackage);
LOAD_COMPOUND = READ_LIMITER_CLASS != null ?
new LoadMethodSkinUpdate(STREAM_TOOLS, READ_LIMITER_CLASS) :
new LoadMethodWorldUpdate(STREAM_TOOLS);
SAVE_COMPOUND = getMethod(Modifier.STATIC, 0, STREAM_TOOLS, null, BASE_CLASS, DataOutput.class);
} catch (ClassNotFoundException e) {
throw new IllegalStateException("Unable to find offline player.", e);
}
}
}
private void initializeNMS(ClassLoader loader, String nmsPackage) {
try {
STREAM_TOOLS = loader.loadClass(nmsPackage + ".NBTCompressedStreamTools");
READ_LIMITER_CLASS = loader.loadClass(nmsPackage + ".NBTReadLimiter");
} catch (ClassNotFoundException e) {
// Ignore - we will detect this later
}
}
private String getPackageName() {
Server server = Bukkit.getServer();
String name = server != null ? server.getClass().getPackage().getName() : null;
if (name != null && name.contains("craftbukkit")) {
return name;
} else {
// Fallback
return "org.bukkit.craftbukkit.v1_7_R3";
}
}
@SuppressWarnings("unchecked")
private Map<String, Object> getDataMap(Object handle) {
return (Map<String, Object>) getFieldValue(
getDataField(NbtType.TAG_COMPOUND, handle), handle);
}
@SuppressWarnings("unchecked")
private List<Object> getDataList(Object handle) {
return (List<Object>) getFieldValue(
getDataField(NbtType.TAG_LIST, handle), handle);
}
/**
* Construct a new NBT list of an unspecified type.
* @return The NBT list.
*/
public static NbtList createList(Object... content) {
return createList(Arrays.asList(content));
}
/**
* Construct a new NBT list of an unspecified type.
* @return The NBT list.
*/
public static NbtList createList(Iterable<? extends Object> iterable) {
NbtList list = get().new NbtList(
INSTANCE.createNbtTag(NbtType.TAG_LIST, null)
);
// Add the content as well
for (Object obj : iterable)
list.add(obj);
return list;
}
/**
* Construct a new NBT compound.
* <p>
* @return The NBT compound.
*/
public static NbtCompound createCompound() {
return get().new NbtCompound(
INSTANCE.createNbtTag(NbtType.TAG_COMPOUND, null)
);
}
/**
* Construct a new NBT wrapper from a list.
* @param nmsList - the NBT list.
* @return The wrapper.
*/
public static NbtList fromList(Object nmsList) {
return get().new NbtList(nmsList);
}
/**
* Load the content of a file from a stream.
* <p>
* Use {@link Files#newInputStreamSupplier(File)} to provide a stream from a file.
* @param stream - the stream supplier.
* @param option - whether or not to decompress the input stream.
* @return The decoded NBT compound.
* @throws IOException If anything went wrong.
*/
public static NbtCompound fromStream(InputSupplier<? extends InputStream> stream, StreamOptions option) throws IOException {
InputStream input = null;
DataInputStream data = null;
boolean suppress = true;
try {
input = stream.getInput();
data = new DataInputStream(new BufferedInputStream(
option == StreamOptions.GZIP_COMPRESSION ? new GZIPInputStream(input) : input
));
NbtCompound result = fromCompound(get().LOAD_COMPOUND.loadNbt(data));
suppress = false;
return result;
} finally {
if (data != null)
Closeables.close(data, suppress);
else if (input != null)
Closeables.close(input, suppress);
}
}
/**
* Save the content of a NBT compound to a stream.
* <p>
* Use {@link Files#newOutputStreamSupplier(File)} to provide a stream supplier to a file.
* @param source - the NBT compound to save.
* @param stream - the stream.
* @param option - whether or not to compress the output.
* @throws IOException If anything went wrong.
*/
public static void saveStream(NbtCompound source, OutputSupplier<? extends OutputStream> stream, StreamOptions option) throws IOException {
OutputStream output = null;
DataOutputStream data = null;
boolean suppress = true;
try {
output = stream.getOutput();
data = new DataOutputStream(
option == StreamOptions.GZIP_COMPRESSION ? new GZIPOutputStream(output) : output
);
invokeMethod(get().SAVE_COMPOUND, null, source.getHandle(), data);
suppress = false;
} finally {
if (data != null)
Closeables.close(data, suppress);
else if (output != null)
Closeables.close(output, suppress);
}
}
/**
* Construct a new NBT wrapper from a compound.
* @param nmsCompound - the NBT compund.
* @return The wrapper.
*/
public static NbtCompound fromCompound(Object nmsCompound) {
return get().new NbtCompound(nmsCompound);
}
/**
* Set the NBT compound tag of a given item stack.
* <p>
* The item stack must be a wrapper for a CraftItemStack. Use
* @param stack - the item stack, cannot be air.
* @param compound - the new NBT compound, or NULL to remove it.
* @throws IllegalArgumentException If the stack is not a CraftItemStack, or it represents air.
*/
public static void setItemTag(ItemStack stack, NbtCompound compound) {
checkItemStack(stack);
Object nms = getFieldValue(get().CRAFT_HANDLE, stack);
// Now update the tag compound
setFieldValue(get().STACK_TAG, nms, compound.getHandle());
}
/**
* Construct a wrapper for an NBT tag stored (in memory) in an item stack. This is where
* auxillary data such as enchanting, name and lore is stored. It does not include items
* material, damage value or count.
* <p>
* The item stack must be a wrapper for a CraftItemStack.
* @param stack - the item stack.
* @return A wrapper for its NBT tag.
*/
public static NbtCompound fromItemTag(ItemStack stack) {
checkItemStack(stack);
Object nms = getFieldValue(get().CRAFT_HANDLE, stack);
Object tag = getFieldValue(get().STACK_TAG, nms);
// Create the tag if it doesn't exist
if (tag == null) {
NbtCompound compound = createCompound();
setItemTag(stack, compound);
return compound;
}
return fromCompound(tag);
}
/**
* Retrieve a CraftItemStack version of the stack.
* @param stack - the stack to convert.
* @return The CraftItemStack version.
*/
public static ItemStack getCraftItemStack(ItemStack stack) {
// Any need to convert?
if (stack == null || get().CRAFT_STACK.isAssignableFrom(stack.getClass()))
return stack;
try {
// Call the private constructor
Constructor<?> caller = INSTANCE.CRAFT_STACK.getDeclaredConstructor(ItemStack.class);
caller.setAccessible(true);
return (ItemStack) caller.newInstance(stack);
} catch (Exception e) {
throw new IllegalStateException("Unable to convert " + stack + " + to a CraftItemStack.");
}
}
/**
* Ensure that the given stack can store arbitrary NBT information.
* @param stack - the stack to check.
*/
private static void checkItemStack(ItemStack stack) {
if (stack == null)
throw new IllegalArgumentException("Stack cannot be NULL.");
if (!get().CRAFT_STACK.isAssignableFrom(stack.getClass()))
throw new IllegalArgumentException("Stack must be a CraftItemStack.");
if (stack.getType() == Material.AIR)
throw new IllegalArgumentException("ItemStacks representing air cannot store NMS information.");
}
/**
* Convert wrapped List and Map objects into their respective NBT counterparts.
* @param value - the value of the element to create. Can be a List or a Map.
* @return The NBT element.
*/
private Object unwrapValue(Object value) {
if (value == null)
return null;
if (value instanceof Wrapper) {
return ((Wrapper) value).getHandle();
} else if (value instanceof List) {
throw new IllegalArgumentException("Can only insert a WrappedList.");
} else if (value instanceof Map) {
throw new IllegalArgumentException("Can only insert a WrappedCompound.");
} else {
return createNbtTag(getPrimitiveType(value), value);
}
}
/**
* Convert a given NBT element to a primitive wrapper or List/Map equivalent.
* <p>
* All changes to any mutable objects will be reflected in the underlying NBT element(s).
* @param nms - the NBT element.
* @return The wrapper equivalent.
*/
private Object wrapNative(Object nms) {
if (nms == null)
return null;
if (BASE_CLASS.isAssignableFrom(nms.getClass())) {
final NbtType type = getNbtType(nms);
// Handle the different types
switch (type) {
case TAG_COMPOUND:
return new NbtCompound(nms);
case TAG_LIST:
return new NbtList(nms);
default:
return getFieldValue(getDataField(type, nms), nms);
}
}
throw new IllegalArgumentException("Unexpected type: " + nms);
}
/**
* Construct a new NMS NBT tag initialized with the given value.
* @param type - the NBT type.
* @param value - the value, or NULL to keep the original value.
* @return The created tag.
*/
private Object createNbtTag(NbtType type, Object value) {
Object tag = invokeMethod(NBT_CREATE_TAG, null, (byte)type.id);
if (value != null) {
setFieldValue(getDataField(type, tag), tag, value);
}
return tag;
}
/**
* Retrieve the field where the NBT class stores its value.
* @param type - the NBT type.
* @param nms - the NBT class instance.
* @return The corresponding field.
*/
private Field getDataField(NbtType type, Object nms) {
if (DATA_FIELD[type.id] == null)
DATA_FIELD[type.id] = getField(nms, null, type.getFieldName());
return DATA_FIELD[type.id];
}
/**
* Retrieve the NBT type from a given NMS NBT tag.
* @param nms - the native NBT tag.
* @return The corresponding type.
*/
private NbtType getNbtType(Object nms) {
int type = (Byte) invokeMethod(NBT_GET_TYPE, nms);
return NBT_ENUM.get(type);
}
/**
* Retrieve the nearest NBT type for a given primitive type.
* @param primitive - the primitive type.
* @return The corresponding type.
*/
private NbtType getPrimitiveType(Object primitive) {
NbtType type = NBT_ENUM.get(NBT_CLASS.inverse().get(
Primitives.unwrap(primitive.getClass())
));
// Display the illegal value at least
if (type == null)
throw new IllegalArgumentException(String.format(
"Illegal type: %s (%s)", primitive.getClass(), primitive));
return type;
}
/**
* Invoke a method on the given target instance using the provided parameters.
* @param method - the method to invoke.
* @param target - the target.
* @param params - the parameters to supply.
* @return The result of the method.
*/
private static Object invokeMethod(Method method, Object target, Object... params) {
try {
return method.invoke(target, params);
} catch (Exception e) {
throw new RuntimeException("Unable to invoke method " + method + " for " + target, e);
}
}
private static void setFieldValue(Field field, Object target, Object value) {
try {
field.set(target, value);
} catch (Exception e) {
throw new RuntimeException("Unable to set " + field + " for " + target, e);
}
}
private static Object getFieldValue(Field field, Object target) {
try {
return field.get(target);
} catch (Exception e) {
throw new RuntimeException("Unable to retrieve " + field + " for " + target, e);
}
}
/**
* Search for the first publically and privately defined method of the given name and parameter count.
* @param requireMod - modifiers that are required.
* @param bannedMod - modifiers that are banned.
* @param clazz - a class to start with.
* @param methodName - the method name, or NULL to skip.
* @param params - the expected parameters.
* @return The first method by this name.
* @throws IllegalStateException If we cannot find this method.
*/
private static Method getMethod(int requireMod, int bannedMod, Class<?> clazz, String methodName, Class<?>... params) {
for (Method method : clazz.getDeclaredMethods()) {
// Limitation: Doesn't handle overloads
if ((method.getModifiers() & requireMod) == requireMod &&
(method.getModifiers() & bannedMod) == 0 &&
(methodName == null || method.getName().equals(methodName)) &&
Arrays.equals(method.getParameterTypes(), params)) {
method.setAccessible(true);
return method;
}
}
// Search in every superclass
if (clazz.getSuperclass() != null)
return getMethod(requireMod, bannedMod, clazz.getSuperclass(), methodName, params);
throw new IllegalStateException(String.format(
"Unable to find method %s (%s).", methodName, Arrays.asList(params)));
}
/**
* Search for the first publically and privately defined field of the given name.
* @param instance - an instance of the class with the field.
* @param clazz - an optional class to start with, or NULL to deduce it from instance.
* @param fieldName - the field name.
* @return The first field by this name.
* @throws IllegalStateException If we cannot find this field.
*/
private static Field getField(Object instance, Class<?> clazz, String fieldName) {
if (clazz == null)
clazz = instance.getClass();
// Ignore access rules
for (Field field : clazz.getDeclaredFields()) {
if (field.getName().equals(fieldName)) {
field.setAccessible(true);
return field;
}
}
// Recursively fild the correct field
if (clazz.getSuperclass() != null)
return getField(instance, clazz.getSuperclass(), fieldName);
throw new IllegalStateException("Unable to find field " + fieldName + " in " + instance);
}
/**
* Represents a class for caching wrappers.
* @author Kristian
*/
private final class CachedNativeWrapper {
// Don't recreate wrapper objects
private final ConcurrentMap<Object, Object> cache = new MapMaker().weakKeys().makeMap();
public Object wrap(Object value) {
Object current = cache.get(value);
if (current == null) {
current = wrapNative(value);
// Only cache composite objects
if (current instanceof ConvertedMap ||
current instanceof ConvertedList) {
cache.put(value, current);
}
}
return current;
}
}
/**
* Represents a map that wraps another map and automatically
* converts entries of its type and another exposed type.
* @author Kristian
*/
private class ConvertedMap extends AbstractMap<String, Object> implements Wrapper {
private final Object handle;
private final Map<String, Object> original;
private final CachedNativeWrapper cache = new CachedNativeWrapper();
public ConvertedMap(Object handle, Map<String, Object> original) {
this.handle = handle;
this.original = original;
}
// For converting back and forth
protected Object wrapOutgoing(Object value) {
return cache.wrap(value);
}
protected Object unwrapIncoming(Object wrapped) {
return unwrapValue(wrapped);
}
// Modification
@Override
public Object put(String key, Object value) {
return wrapOutgoing(original.put(
(String) key,
unwrapIncoming(value)
));
}
// Performance
@Override
public Object get(Object key) {
return wrapOutgoing(original.get(key));
}
@Override
public Object remove(Object key) {
return wrapOutgoing(original.remove(key));
}
@Override
public boolean containsKey(Object key) {
return original.containsKey(key);
}
@Override
public Set<Entry<String, Object>> entrySet() {
return new AbstractSet<Entry<String,Object>>() {
@Override
public boolean add(Entry<String, Object> e) {
String key = e.getKey();
Object value = e.getValue();
original.put(key, unwrapIncoming(value));
return true;
}
@Override
public int size() {
return original.size();
}
@Override
public Iterator<Entry<String, Object>> iterator() {
return ConvertedMap.this.iterator();
}
};
}
private Iterator<Entry<String, Object>> iterator() {
final Iterator<Entry<String, Object>> proxy = original.entrySet().iterator();
return new Iterator<Entry<String, Object>>() {
public boolean hasNext() {
return proxy.hasNext();
}
public Entry<String, Object> next() {
Entry<String, Object> entry = proxy.next();
return new SimpleEntry<String, Object>(
entry.getKey(), wrapOutgoing(entry.getValue())
);
}
public void remove() {
proxy.remove();
}
};
}
public Object getHandle() {
return handle;
}
}
/**
* Represents a list that wraps another list and converts elements
* of its type and another exposed type.
* @author Kristian
*/
private class ConvertedList extends AbstractList<Object> implements Wrapper {
private final Object handle;
private final List<Object> original;
private final CachedNativeWrapper cache = new CachedNativeWrapper();
public ConvertedList(Object handle, List<Object> original) {
if (NBT_LIST_TYPE == null)
NBT_LIST_TYPE = getField(handle, null, "type");
this.handle = handle;
this.original = original;
}
protected Object wrapOutgoing(Object value) {
return cache.wrap(value);
}
protected Object unwrapIncoming(Object wrapped) {
return unwrapValue(wrapped);
}
@Override
public Object get(int index) {
return wrapOutgoing(original.get(index));
}
@Override
public int size() {
return original.size();
}
@Override
public Object set(int index, Object element) {
return wrapOutgoing(
original.set(index, unwrapIncoming(element))
);
}
@Override
public void add(int index, Object element) {
Object nbt = unwrapIncoming(element);
// Set the list type if its the first element
if (size() == 0)
setFieldValue(NBT_LIST_TYPE, handle, (byte)getNbtType(nbt).id);
original.add(index, nbt);
}
@Override
public Object remove(int index) {
return wrapOutgoing(original.remove(index));
}
@Override
public boolean remove(Object o) {
return original.remove(unwrapIncoming(o));
}
public Object getHandle() {
return handle;
}
}
/**
* Represents a method for loading an NBT compound.
* @author Kristian
*/
private static abstract class LoadCompoundMethod {
protected Method staticMethod;
protected void setMethod(Method method) {
this.staticMethod = method;
this.staticMethod.setAccessible(true);
}
/**
* Load an NBT compound from a given stream.
* @param input - the input stream.
* @return The loaded NBT compound.
*/
public abstract Object loadNbt(DataInput input);
}
/**
* Load an NBT compound from the NBTCompressedStreamTools static method in 1.7.2 - 1.7.5
*/
private static class LoadMethodWorldUpdate extends LoadCompoundMethod {
public LoadMethodWorldUpdate(Class<?> streamClass) {
setMethod(getMethod(Modifier.STATIC, 0, streamClass, null, DataInput.class));
}
@Override
public Object loadNbt(DataInput input) {
return invokeMethod(staticMethod, null, input);
}
}
/**
* Load an NBT compound from the NBTCompressedStreamTools static method in 1.7.8
*/
private static class LoadMethodSkinUpdate extends LoadCompoundMethod {
private Object readLimiter;
public LoadMethodSkinUpdate(Class<?> streamClass, Class<?> readLimiterClass) {
setMethod(getMethod(Modifier.STATIC, 0, streamClass, null, DataInput.class, readLimiterClass));
// Find the unlimited read limiter
for (Field field : readLimiterClass.getDeclaredFields()) {
if (readLimiterClass.isAssignableFrom(field.getType())) {
try {
readLimiter = field.get(null);
} catch (Exception e) {
throw new RuntimeException("Cannot retrieve read limiter.", e);
}
}
}
}
@Override
public Object loadNbt(DataInput input) {
return invokeMethod(staticMethod, null, input, readLimiter);
}
}
}

View File

@ -1,26 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.inventory;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.Inventory;
import java.util.HashMap;
import java.util.Set;
/**
* Created by charl on 28-Apr-17.
*/
public interface IInventoryBuilder {
Panel getInventory();
Inventory getClonedInventory();
void addReplacedMap(HashMap<String, String> map);
ConfigurationSection getConfigurationSection();
ConfigurationSection getItemConfigSection();
Set<Integer> getSetOfItemSlots();
}

View File

@ -1,106 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.inventory;
import net.aminecraftdev.custombosses.innerapi.factory.FactoryBuilder;
import net.aminecraftdev.custombosses.innerapi.itemstack.ItemStackUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* Created by charl on 28-Apr-17.
*/
public class InventoryBuilder implements FactoryBuilder<Inventory>, IInventoryBuilder {
private String name;
private int slots;
private ConfigurationSection items;
private ConfigurationSection inventoryConfigSection;
private Inventory inventory;
private Set<Integer> _setOfItemSlots = new HashSet<>();
private HashMap<String, String> _map = new HashMap<>();
private Map<Integer, Integer> pageData = new HashMap<>();
private JavaPlugin javaPlugin;
public InventoryBuilder(ConfigurationSection inventory, JavaPlugin javaPlugin) {
this.name = ChatColor.translateAlternateColorCodes('&', inventory.getString("name"));
this.slots = inventory.getInt("slots");
this.items = inventory.getConfigurationSection("Items");
this.inventoryConfigSection = inventory;
this.javaPlugin = javaPlugin;
}
@Override
public Panel getInventory() {
build();
return new Panel(this.inventory, pageData, javaPlugin);
}
@Override
public Inventory getClonedInventory() {
Inventory inv = getInventory().getInventory();
Inventory inventory = Bukkit.createInventory(inv.getHolder(), inv.getSize(), inv.getTitle());
for(int i = 0; i < inv.getSize(); i++) {
if(inv.getItem(i) == null || inv.getItem(i).getType() == Material.AIR) continue;
inventory.setItem(i, inv.getItem(i));
}
return inventory;
}
@Override
public void addReplacedMap(HashMap<String, String> map) {
_map.putAll(map);
}
@Override
public ConfigurationSection getConfigurationSection() {
return inventoryConfigSection;
}
@Override
public ConfigurationSection getItemConfigSection() {
return items;
}
@Override
public Set<Integer> getSetOfItemSlots() {
return _setOfItemSlots;
}
@Override
public Inventory build() {
this.inventory = Bukkit.createInventory(null, this.slots, this.name);
for(String s : this.items.getKeys(false)) {
int slot = Integer.valueOf(s) - 1;
ConfigurationSection section = this.items.getConfigurationSection(s);
ItemStack stack = ItemStackUtils.createItemStack(section, 1, _map);
if(section.contains("NextPage")) {
boolean b = section.getBoolean("NextPage");
if(b) {
pageData.put(slot, 1);
}
} else if(section.contains("PreviousPage")) {
boolean b = section.getBoolean("PreviousPage");
if(b) {
pageData.put(slot, -1);
}
}
this.inventory.setItem(slot, stack);
_setOfItemSlots.add(slot);
}
return this.inventory;
}
}

View File

@ -1,84 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.inventory;
import net.aminecraftdev.custombosses.innerapi.factory.CloneableFactory;
import net.aminecraftdev.custombosses.innerapi.factory.Factory;
import org.bukkit.Bukkit;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.HashMap;
import java.util.Map;
/**
* Created by charl on 07-May-17.
*/
public class InventoryFactory extends Factory<Panel> implements CloneableFactory<InventoryFactory> {
private Map<Integer, ItemStack> mapOfItems = new HashMap<>();
private JavaPlugin javaPlugin;
private InventoryHolder inventoryHolder;
private String name;
private int slot;
public InventoryFactory(String name, int slot, JavaPlugin javaPlugin) {
setName(name);
setSlots(slot);
setHolder(null);
this.javaPlugin = javaPlugin;
}
public InventoryFactory setSlots(int amount) {
this.slot = amount;
return this;
}
public InventoryFactory setName(String name) {
this.name = name;
return this;
}
public InventoryFactory setHolder(InventoryHolder inventoryHolder) {
this.inventoryHolder = inventoryHolder;
return this;
}
public InventoryFactory addItem(ItemStack... itemStacks) {
for(ItemStack itemStack : itemStacks) {
for(int i = 0; i < this.slot; i++) {
if(mapOfItems.containsKey(i)) continue;
mapOfItems.put(i, itemStack);
}
}
return this;
}
public InventoryFactory setItem(ItemStack itemStack, int slot) {
mapOfItems.put(slot, itemStack);
return this;
}
@Override
public Panel build() {
Inventory inventory = Bukkit.createInventory(this.inventoryHolder, this.slot, this.name);
for(int i : this.mapOfItems.keySet()) {
inventory.setItem(i, this.mapOfItems.get(i));
}
return new Panel(inventory, javaPlugin);
}
@Override
public InventoryFactory clone() {
InventoryFactory clone = new InventoryFactory(this.name, this.slot, javaPlugin);
clone.inventoryHolder = this.inventoryHolder;
clone.mapOfItems.putAll(this.mapOfItems);
return clone;
}
}

View File

@ -1,333 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.inventory;
import net.aminecraftdev.custombosses.innerapi.inventory.base.ClickAction;
import net.aminecraftdev.custombosses.innerapi.inventory.base.PageAction;
import net.aminecraftdev.custombosses.innerapi.inventory.base.PanelCloseAction;
import net.aminecraftdev.custombosses.innerapi.message.MessageUtils;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.*;
/**
* @author Debugged
* @version 1.0
* @since 13-5-2017
*/
public class Panel {
public static List<Panel> panels = new ArrayList<>();
private static boolean registered = false;
private Inventory inventory;
public int viewers = 0;
private Map<Integer, ClickAction> actions = new HashMap<>();
private Map<Integer, Integer> pageData = new HashMap<>();
private Map<UUID, Integer> currentPages = new HashMap<>();
private Sound clickSound = null;
private boolean cancelClick = true;
private boolean destroyWhenDone = true;
private PanelCloseAction panelClose = (p) -> {};
private PageAction onPageChange = (player, currentPage, requestedPage) -> {return false;};
/**
* Creates a Panel with a title and a specific size
*
* @param title
* @param size
*/
public Panel(String title, int size, JavaPlugin javaPlugin) {
if(!registered) {
Bukkit.getPluginManager().registerEvents(getListeners(), javaPlugin);
registered = true;
}
if(size % 9 != 0 && size != 5) {
throw new UnsupportedOperationException("Inventory size must be a multiple of 9 or 5");
}
this.inventory = size % 9 == 0 ? Bukkit.createInventory(null, size, MessageUtils.translateString(title)) : Bukkit.createInventory(null, InventoryType.HOPPER, MessageUtils.translateString(title));
panels.add(this);
}
public Panel(Inventory inventory, Map<Integer, Integer> pageData, JavaPlugin javaPlugin) {
if(!registered) {
Bukkit.getPluginManager().registerEvents(getListeners(), javaPlugin);
registered = true;
}
this.inventory = inventory;
this.pageData = pageData;
panels.add(this);
}
public Panel(Inventory inventory, JavaPlugin javaPlugin) {
this(inventory, new HashMap<>(), javaPlugin);
}
/**
* Returns the listeners that are
* needed for all Panel handlers to work properly
*
* @return Listener
*/
private Listener getListeners() {
return new Listener() {
@EventHandler
public void onInvClick(InventoryClickEvent e) {
if (e.getInventory() != null && !Panel.panels.isEmpty()) {
if(e.getInventory() == null) return;
if(e.getCurrentItem() == null && e.getCursor() == null) return;
for(Panel panel : new ArrayList<>(Panel.panels)) {
if(panel != null && panel.getInventory() != null) {
if(!panel.getInventory().equals(e.getInventory())) continue;
if(panel.getClickSound() != null) {
((Player)e.getWhoClicked()).playSound(e.getWhoClicked().getLocation(), panel.getClickSound(), 3f, 1f);
}
if (panel.willCancelClick()) {
e.setCancelled(true);
}
if (panel.getInventory().equals(e.getInventory())) {
panel.executeAction(e.getRawSlot(), e);
}
}
}
}
}
@EventHandler
public void onInvClose(InventoryCloseEvent e) {
if (e.getInventory() != null && !Panel.panels.isEmpty()) {
for(Panel panel : new ArrayList<>(Panel.panels)) {
if(panel != null && panel.getInventory() != null) {
if (panel.getInventory().equals(e.getInventory())) {
panel.panelClose.onClose((Player) e.getPlayer());
panel.viewers--;
if (panel.getViewers() <= 0 && panel.willDestroyWhenDone()) {
panel.destroy();
}
}
}
}
}
}
};
}
/**
* Triggers the ClickAction interfaces
* for the specified slot
*
* @param slot int
* @param e InventoryClickEvent
*/
public void executeAction(int slot, InventoryClickEvent e) {
Player clicker = (Player) e.getWhoClicked();
if(pageData.containsKey(slot)) {
int currentPage = currentPages.getOrDefault(clicker.getUniqueId(), 0);
if(pageData.get(slot) > 0) {
if(onPageChange.onPageAction(clicker, currentPage, currentPage+1)) {
currentPages.put(clicker.getUniqueId(), currentPage+1);
}
} else {
if(currentPage != 0) {
if (onPageChange.onPageAction(clicker, currentPage, currentPage-1)) {
currentPages.put(clicker.getUniqueId(), currentPage - 1);
}
}
}
}
if(actions.containsKey(slot)) {
actions.get(slot).onClick(e);
}
}
/**
* Sets the functional interface which will be called whenever a player closes the panel
* <br>
* <b>Builder method</b>
*
* @param panelClose {@link PanelCloseAction}
* @return Panel
*/
public Panel onClose(PanelCloseAction panelClose) {
this.panelClose = panelClose;
return this;
}
/**
* Specify a ClickAction for the
* given slot number
* <br>
* <b>Builder method</b>
*
* @param slot int
* @param clickAction ClickAction
*/
public Panel setOnClick(int slot, ClickAction clickAction) {
actions.put(slot, clickAction);
return this;
}
/**
* Sets an item at the specified slot
* <br>
* <b>Builder method</b>
*
* @param slot int
* @param item ItemStack
* @return Panel
*/
public Panel setItem(int slot, ItemStack item){
inventory.setItem(slot, item);
return this;
}
/**
* Sets an item at the specified slot along with a functional interface which will<br>
* be called whenever the item gets clicked
* <br>
* <b>Builder method</b>
*
* @param slot int
* @param item ItemStack
* @param action {@link ClickAction}
* @return Panel
*/
public Panel setItem(int slot, ItemStack item, ClickAction action) {
inventory.setItem(slot, item);
actions.put(slot, action);
return this;
}
/**
* Sets the sound that will be played whenever
* an item gets clicked
*
* @param clickSound Sound
* @return Panel
*/
public Panel setClickSound(Sound clickSound) {
this.clickSound = clickSound;
return this;
}
/**
* Opens the Panel for the specified Player
* <br>
* <b>Builder method</b>
*
* @param player Player
* @return Panel
*/
public Panel openFor(Player player) {
player.openInventory(inventory);
viewers++;
return this;
}
public Panel setOnClose(PanelCloseAction panelClose) {
this.panelClose = panelClose;
return this;
}
public Panel setOnPageChange(PageAction onPageChange) {
this.onPageChange = onPageChange;
return this;
}
/**
* Makes sure the panel will cancel or not cancel click when an item was clicked
* <br>
* <b>Builder method</b>
*
* @param cancelClick boolean
* @return Panel
*/
public Panel setCancelClick(boolean cancelClick) {
this.cancelClick = cancelClick;
return this;
}
/**
* Makes sure the panel will destroy or not destroy when it has no viewers anymore
* <br>
* <b>Builder method</b>
*
* @param destroyWhenDone boolean
* @return Panel
*/
public Panel setDestroyWhenDone(boolean destroyWhenDone) {
this.destroyWhenDone = destroyWhenDone;
return this;
}
/**
* Returns whether or not the panel will destroy when there are no viewers anymore
*
* @return boolean
*/
public boolean willDestroyWhenDone() {
return destroyWhenDone;
}
/**
* Returns whether or not clicking an item in this panel will cancel the InventoryClickEvent
*
* @return boolean
*/
public boolean willCancelClick() {
return cancelClick;
}
/**
* Returns the amount of players that are viewing this panel
*
* @return int
*/
public int getViewers() {
return viewers;
}
/**
* Returns the sound that will be played
* whenever a player clicks an item
*
* @return Sound
*/
public Sound getClickSound() {
return clickSound;
}
/**
* Returns the bukkit Inventory object that corresponds to this panel
*
* @return Inventory
*/
public Inventory getInventory() {
return inventory;
}
/**
* Destroys the panel in order to block further access
*/
public void destroy() {
this.actions.clear();
this.pageData.clear();
this.currentPages.clear();
this.pageData = null;
this.currentPages = null;
this.actions = null;
this.inventory = null;
panels.remove(this);
}
}

View File

@ -1,21 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.inventory.base;
import org.bukkit.event.inventory.InventoryClickEvent;
/**
* @author Debugged
* @version 1.0
* @since 13-5-2017
*/
@FunctionalInterface
public interface ClickAction {
/**
* Called whenever the item that this
* ClickAction is associated with is triggered
*
* @param e InventoryClickEvent
*/
void onClick(InventoryClickEvent e);
}

View File

@ -1,15 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.inventory.base;
import org.bukkit.entity.Player;
/**
* @author Debugged
* @version 1.0
* @since 13-5-2017
*/
@FunctionalInterface
public interface PageAction {
boolean onPageAction(Player player, int currentPage, int requestedPage);
}

View File

@ -1,21 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.inventory.base;
import org.bukkit.entity.Player;
/**
* @author Debugged
* @version 1.0
* @since 13-5-2017
*/
@FunctionalInterface
public interface PanelCloseAction {
/**
* Called whenever a player closes the {@link net.aminecraftdev.custombosses.innerapi.inventory.Panel}
* that this PanelCloseAction is associated with
*
* @param player Player
*/
void onClose(Player player);
}

View File

@ -1,94 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.itemstack;
import net.aminecraftdev.custombosses.innerapi.factory.CloneableFactory;
import net.aminecraftdev.custombosses.innerapi.factory.Factory;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import java.util.Arrays;
import java.util.List;
/**
* Created by charl on 04-May-17.
*/
public class ItemFactory extends Factory<ItemStack> implements CloneableFactory<ItemFactory> {
private ItemMeta itemMeta;
public ItemFactory(Material material, byte data) {
this.object = new ItemStack(material, 1, (short) data);
this.itemMeta = this.object.getItemMeta();
}
public ItemFactory(Material material) {
this(material, (byte) 0);
}
public final ItemFactory setAmount(int amount) {
if(amount > 64) amount = 64;
this.object.setAmount(amount);
return this;
}
public final ItemFactory setName(String name) {
this.itemMeta.setDisplayName(name);
return this;
}
public final ItemFactory setLore(List<String> lore) {
this.itemMeta.setLore(lore);
return this;
}
public final ItemFactory setLore(String... lore) {
this.itemMeta.setLore(Arrays.asList(lore));
return this;
}
public final ItemFactory setOwner(String name) {
if(this.object.getType() == Material.SKULL_ITEM) {
SkullMeta skullMeta = (SkullMeta) this.itemMeta;
skullMeta.setOwner(name);
}
return this;
}
public final ItemFactory setDurability(short durability) {
this.object.setDurability(durability);
return this;
}
public final ItemFactory setData(byte data) {
this.object.setDurability((short) data);
return this;
}
public final ItemFactory setUnsafeEnchantment(Enchantment enchantment, int level) {
this.object.addUnsafeEnchantment(enchantment, level);
return this;
}
public final ItemFactory setEnchantment(Enchantment enchantment, int level) {
this.itemMeta.addEnchant(enchantment, level, true);
return this;
}
@Override
public final ItemStack build() {
this.object.setItemMeta(this.itemMeta);
return this.object;
}
@Override
public final ItemFactory clone() {
ItemFactory clone = new ItemFactory(this.object.getType(), this.object.getData().getData());
clone.itemMeta = this.itemMeta;
return clone;
}
}

View File

@ -1,193 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.itemstack;
import net.aminecraftdev.custombosses.innerapi.NumberUtils;
import net.aminecraftdev.custombosses.innerapi.factory.NbtFactory;
import net.aminecraftdev.custombosses.innerapi.itemstack.enchants.GlowEnchant;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by charl on 28-Apr-17.
*/
public class ItemStackUtils {
public static final ItemStack createItemStack(ConfigurationSection configurationSection) {
return createItemStack(configurationSection, 1, null);
}
public static final ItemStack createItemStack(ConfigurationSection configurationSection, int amount, Map<String, String> replacedMap) {
String type = configurationSection.getString("type");
String name = configurationSection.getString("name");
List<String> lore = configurationSection.getStringList("lore");
List<String> enchants = configurationSection.getStringList("enchants");
short durability = (short) configurationSection.getInt("durability");
Map<Enchantment, Integer> map = new HashMap<>();
List<String> newLore = new ArrayList<>();
Material mat = getType(type);
short meta = 0;
boolean addGlow = false;
if(type instanceof String) {
String sType = (String) type;
if(sType.contains(":")) {
String[] split = sType.split(":");
meta = Short.valueOf(split[1]);
}
}
if((replacedMap != null) && (name != null)) {
for(String z : replacedMap.keySet()) {
if(!name.contains(z)) continue;
name = name.replace(z, replacedMap.get(z));
}
}
if(lore != null) {
for(String z : lore) {
String y = z;
if(replacedMap != null) {
for(String x : replacedMap.keySet()) {
if(!y.contains(x)) continue;
y = y.replace(x, replacedMap.get(x));
}
}
if(y.contains("\n")) {
String[] split = y.split("\n");
for(String s2 : split) {
newLore.add(ChatColor.translateAlternateColorCodes('&', s2));
}
} else {
newLore.add(ChatColor.translateAlternateColorCodes('&', y));
}
}
}
if(enchants != null) {
for(String s : enchants) {
String[] spl = s.split(":");
String ench = spl[0];
int level = Integer.parseInt(spl[1]);
if(ench.equalsIgnoreCase("glow")) {
addGlow = true;
continue;
}
map.put(Enchantment.getByName(ench), level);
}
}
ItemStack itemStack = new ItemStack(mat, amount, meta);
ItemMeta itemMeta = itemStack.getItemMeta();
if(!newLore.isEmpty()) {
itemMeta.setLore(newLore);
}
if(name != null) {
if(!name.equals("")) {
itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
}
}
itemStack.setItemMeta(itemMeta);
if(!map.isEmpty()) {
itemStack.addUnsafeEnchantments(map);
}
if(configurationSection.contains("durability")) {
short dura = itemStack.getType().getMaxDurability();
dura -= (short) durability - 1;
itemStack.setDurability(dura);
}
if(addGlow) return addGlow(itemStack);
return itemStack;
}
public static final ItemStack replicateItem(ItemStack replicatable, int amount, Map<String, String> replaceableData, Map<String, Object> compoundData) {
ItemStack clone = replicatable.clone();
ItemMeta itemMeta = clone.getItemMeta();
String name = itemMeta.hasDisplayName()? itemMeta.getDisplayName() : "";
List<String> lore = itemMeta.hasLore()? itemMeta.getLore() : new ArrayList<>();
List<String> newLore = new ArrayList<>();
if(replaceableData != null) {
for(String line : lore) {
for(String s : replaceableData.keySet()) {
if(line.contains(s)) line = line.replace(s, replaceableData.get(s));
}
newLore.add(line);
}
for(String s : replaceableData.keySet()) {
if(name.contains(s)) name = name.replace(s, replaceableData.get(s));
}
} else {
newLore.addAll(lore);
}
itemMeta.setLore(newLore);
itemMeta.setDisplayName(name);
clone.setItemMeta(itemMeta);
clone.setAmount(amount);
if(compoundData == null) return clone;
ItemStack craftStack = NbtFactory.getCraftItemStack(clone);
NbtFactory.NbtCompound compound = NbtFactory.fromItemTag(craftStack);
for(String s : compoundData.keySet()) {
compound.put(s, compoundData.get(s));
}
return craftStack;
}
public static final Material getType(String string) {
Material material = Material.getMaterial(string);
if(material == null) {
if(NumberUtils.isStringInteger(string)) {
material = Material.getMaterial(Integer.valueOf(string));
if(material != null) return material;
return null;
} else {
String[] split = string.split(":");
material = Material.getMaterial(Integer.valueOf(split[0]));
if(material != null) return material;
return null;
}
}
return material;
}
public static final ItemStack addGlow(ItemStack itemStack) {
return GlowEnchant.addGlow(itemStack);
}
}

View File

@ -1,22 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.itemstack.enchants;
import net.aminecraftdev.custombosses.innerapi.factory.NbtFactory;
import org.bukkit.inventory.ItemStack;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 29-May-17
*/
public class GlowEnchant {
public static final ItemStack addGlow(ItemStack base) {
ItemStack craftStack = NbtFactory.getCraftItemStack(base);
NbtFactory.NbtCompound compound = NbtFactory.fromItemTag(craftStack);
NbtFactory.NbtList newList = NbtFactory.createList();
compound.put("ench", newList);
return craftStack;
}
}

View File

@ -1,133 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.message;
/**
* Created by charl on 28-Apr-17.
*/
public enum DefaultFontInfo {
A('A', 5),
a('a', 5),
B('B', 5),
b('b', 5),
C('C', 5),
c('c', 5),
D('D', 5),
d('d', 5),
E('E', 5),
e('e', 5),
F('F', 5),
f('f', 4),
G('G', 5),
g('g', 5),
H('H', 5),
h('h', 5),
I('I', 3),
i('i', 1),
J('J', 5),
j('j', 5),
K('K', 5),
k('k', 4),
L('L', 5),
l('l', 1),
M('M', 5),
m('m', 5),
N('N', 5),
n('n', 5),
O('O', 5),
o('o', 5),
P('P', 5),
p('p', 5),
Q('Q', 5),
q('q', 5),
R('R', 5),
r('r', 5),
S('S', 5),
s('s', 5),
T('T', 5),
t('t', 4),
U('U', 5),
u('u', 5),
V('V', 5),
v('v', 5),
W('W', 5),
w('w', 5),
X('X', 5),
x('x', 5),
Y('Y', 5),
y('y', 5),
Z('Z', 5),
z('z', 5),
NUM_1('1', 5),
NUM_2('2', 5),
NUM_3('3', 5),
NUM_4('4', 5),
NUM_5('5', 5),
NUM_6('6', 5),
NUM_7('7', 5),
NUM_8('8', 5),
NUM_9('9', 5),
NUM_0('0', 5),
EXCLAMATION_POINT('!', 1),
AT_SYMBOL('@', 6),
NUM_SIGN('#', 5),
DOLLAR_SIGN('$', 5),
PERCENT('%', 5),
UP_ARROW('^', 5),
AMPERSAND('&', 5),
ASTERISK('*', 5),
LEFT_PARENTHESIS('(', 4),
RIGHT_PERENTHESIS(')', 4),
MINUS('-', 5),
UNDERSCORE('_', 5),
PLUS_SIGN('+', 5),
EQUALS_SIGN('=', 5),
LEFT_CURL_BRACE('{', 4),
RIGHT_CURL_BRACE('}', 4),
LEFT_BRACKET('[', 3),
RIGHT_BRACKET(']', 3),
COLON(':', 1),
SEMI_COLON(';', 1),
DOUBLE_QUOTE('"', 3),
SINGLE_QUOTE('\'', 1),
LEFT_ARROW('<', 4),
RIGHT_ARROW('>', 4),
QUESTION_MARK('?', 5),
SLASH('/', 5),
BACK_SLASH('\\', 5),
LINE('|', 1),
TILDE('~', 5),
TICK('`', 2),
PERIOD('.', 1),
COMMA(',', 1),
SPACE(' ', 3),
DEFAULT('a', 4);
private char character;
private int length;
DefaultFontInfo(char character, int length) {
this.character = character;
this.length = length;
}
public char getCharacter(){
return this.character;
}
public int getLength(){
return this.length;
}
public int getBoldLength(){
if(this == DefaultFontInfo.SPACE) return this.getLength();
return this.length + 1;
}
public static DefaultFontInfo getDefaultFontInfo(char c){
for(DefaultFontInfo dFI : DefaultFontInfo.values()){
if(dFI.getCharacter() == c) return dFI;
}
return DefaultFontInfo.DEFAULT;
}
}

View File

@ -1,153 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.message;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
import java.util.List;
/**
* Created by charl on 28-Apr-17.
*/
public class MessageUtils {
private final static int CENTER_PX = 154;
private final static int MAX_PX = 250;
public static final int getMaxPixel() {
return MAX_PX;
}
public static final List<String> getCenteredMessage(String message) {
if(message == null || message.equals("")) return new ArrayList<>();
List<String> arrayList = new ArrayList<>();
message = translateString(message);
int messagePxSize = 0;
boolean previousCode = false;
boolean isBold = false;
int charIndex = 0;
int lastSpaceIndex = 0;
String toSendAfter = null;
String recentColorCode = "";
for(char c : message.toCharArray()) {
if(c == '§') {
previousCode = true;
continue;
} else if(previousCode) {
previousCode = false;
if(c == 'l' || c == 'L') {
isBold = true;
continue;
} else {
isBold = false;
}
} else if(c == ' ') {
lastSpaceIndex = charIndex;
} else {
DefaultFontInfo dFI = DefaultFontInfo.getDefaultFontInfo(c);
messagePxSize += isBold ? dFI.getBoldLength() : dFI.getLength();
messagePxSize++;
}
if(messagePxSize >= MAX_PX) {
toSendAfter = recentColorCode + message.substring(lastSpaceIndex + 1, message.length());
message = message.substring(0, lastSpaceIndex + 1);
break;
}
charIndex++;
}
int halvedMessageSize = messagePxSize / 2;
int toCompensate = CENTER_PX - halvedMessageSize;
int spaceLength = DefaultFontInfo.SPACE.getLength() + 1;
int compensated = 0;
StringBuilder stringBuilder = new StringBuilder();
while (compensated < toCompensate) {
stringBuilder.append(" ");
compensated += spaceLength;
}
String s = stringBuilder.toString() + message;
arrayList.add(s);
if(toSendAfter != null) {
return null;
}
return arrayList;
}
public static final void sendCenteredMessage(CommandSender player, String message) {
if(message == null || message.equals("")) player.sendMessage("");
message = translateString(message);
int messagePxSize = 0;
boolean previousCode = false;
boolean isBold = false;
int charIndex = 0;
int lastSpaceIndex = 0;
String toSendAfter = null;
String recentColorCode = "";
for(char c : message.toCharArray()) {
if(c == '§') {
previousCode = true;
continue;
} else if(previousCode) {
previousCode = false;
if(c == 'l' || c == 'L') {
isBold = true;
continue;
} else {
isBold = false;
}
} else if(c == ' ') {
lastSpaceIndex = charIndex;
} else {
DefaultFontInfo dFI = DefaultFontInfo.getDefaultFontInfo(c);
messagePxSize += isBold ? dFI.getBoldLength() : dFI.getLength();
messagePxSize++;
}
if(messagePxSize >= MAX_PX) {
toSendAfter = recentColorCode + message.substring(lastSpaceIndex + 1, message.length());
message = message.substring(0, lastSpaceIndex + 1);
break;
}
charIndex++;
}
int halvedMessageSize = messagePxSize / 2;
int toCompensate = CENTER_PX - halvedMessageSize;
int spaceLength = DefaultFontInfo.SPACE.getLength() + 1;
int compensated = 0;
StringBuilder stringBuilder = new StringBuilder();
while (compensated < toCompensate) {
stringBuilder.append(" ");
compensated += spaceLength;
}
player.sendMessage(stringBuilder.toString() + message);
if(toSendAfter != null) {
sendCenteredMessage(player, toSendAfter);
}
}
public static final String translateString(String message) {
return ChatColor.translateAlternateColorCodes('&', message);
}
}

View File

@ -1,38 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.message;
import java.util.TreeMap;
/**
* Created by charl on 07-May-17.
*/
public class RomanNumber {
private final static TreeMap<Integer, String> map = new TreeMap<Integer, String>();
static {
map.put(1000, "M");
map.put(900, "CM");
map.put(500, "D");
map.put(400, "CD");
map.put(100, "C");
map.put(90, "XC");
map.put(50, "L");
map.put(40, "XL");
map.put(10, "X");
map.put(9, "IX");
map.put(5, "V");
map.put(4, "IV");
map.put(1, "I");
}
public final static String toRoman(int number) {
int l = map.floorKey(number);
if ( number == l ) {
return map.get(number);
}
return map.get(l) + toRoman(number-l);
}
}

View File

@ -1,20 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.particles;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.List;
/**
* Created by LukeBingham on 22/03/2017.
*/
public final class ColoredParticle {
public static void send(ParticleEffect effect, Location location, List<Player> players, int r, int g, int b) {
effect.display(r / 255, g / 255, b / 255, 1, 0, location, players);
}
public static void send(ParticleEffect effect, Location location, int Distance, int r, int g, int b) {
effect.display(r / 255, g / 255, b / 255, 1, 0, location, Distance);
}
}

View File

@ -1,607 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.particles;
import org.bukkit.Bukkit;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
/**
* <b>ReflectionUtils</b>
* <p>
* This class provides useful methods which makes dealing with reflection much easier, especially when working with Bukkit
* <p>
* You are welcome to use it, modify it and redistribute it under the following conditions:
* <ul>
* <li>Don't claim this class as your own
* <li>Don't remove this disclaimer
* </ul>
* <p>
* <i>It would be nice if you provide credit to me if you use this class in a published project</i>
*
* @author DarkBlade12
* @version 1.1
*/
public final class ReflectionUtils {
// Prevent accidental construction
private ReflectionUtils() {
}
/**
* Returns the constructor of a given class with the given parameter types
*
* @param clazz Target class
* @param parameterTypes Parameter types of the desired constructor
* @return The constructor of the target class with the specified parameter types
* @throws NoSuchMethodException If the desired constructor with the specified parameter types cannot be found
* @see DataType
* @see DataType#getPrimitive(Class[])
* @see DataType#compare(Class[], Class[])
*/
public static Constructor<?> getConstructor(Class<?> clazz, Class<?>... parameterTypes) throws NoSuchMethodException {
Class<?>[] primitiveTypes = DataType.getPrimitive(parameterTypes);
for (Constructor<?> constructor : clazz.getConstructors()) {
if (!DataType.compare(DataType.getPrimitive(constructor.getParameterTypes()), primitiveTypes)) {
continue;
}
return constructor;
}
throw new NoSuchMethodException("There is no such constructor in this class with the specified parameter types");
}
/**
* Returns the constructor of a desired class with the given parameter types
*
* @param className Name of the desired target class
* @param packageType Package where the desired target class is located
* @param parameterTypes Parameter types of the desired constructor
* @return The constructor of the desired target class with the specified parameter types
* @throws NoSuchMethodException If the desired constructor with the specified parameter types cannot be found
* @throws ClassNotFoundException ClassNotFoundException If the desired target class with the specified name and package cannot be found
* @see #getConstructor(Class, Class...)
*/
public static Constructor<?> getConstructor(String className, PackageType packageType, Class<?>... parameterTypes) throws NoSuchMethodException, ClassNotFoundException {
return getConstructor(packageType.getClass(className), parameterTypes);
}
/**
* Returns an instance of a class with the given arguments
*
* @param clazz Target class
* @param arguments Arguments which are used to construct an object of the target class
* @return The instance of the target class with the specified arguments
* @throws InstantiationException If you cannot create an instance of the target class due to certain circumstances
* @throws IllegalAccessException If the desired constructor cannot be accessed due to certain circumstances
* @throws IllegalArgumentException If the types of the arguments do not match the parameter types of the constructor (this should not occur since it searches for a constructor with the types of the arguments)
* @throws InvocationTargetException If the desired constructor cannot be invoked
* @throws NoSuchMethodException If the desired constructor with the specified arguments cannot be found
*/
public static Object instantiateObject(Class<?> clazz, Object... arguments) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException {
return getConstructor(clazz, DataType.getPrimitive(arguments)).newInstance(arguments);
}
/**
* Returns an instance of a desired class with the given arguments
*
* @param className Name of the desired target class
* @param packageType Package where the desired target class is located
* @param arguments Arguments which are used to construct an object of the desired target class
* @return The instance of the desired target class with the specified arguments
* @throws InstantiationException If you cannot create an instance of the desired target class due to certain circumstances
* @throws IllegalAccessException If the desired constructor cannot be accessed due to certain circumstances
* @throws IllegalArgumentException If the types of the arguments do not match the parameter types of the constructor (this should not occur since it searches for a constructor with the types of the arguments)
* @throws InvocationTargetException If the desired constructor cannot be invoked
* @throws NoSuchMethodException If the desired constructor with the specified arguments cannot be found
* @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found
* @see #instantiateObject(Class, Object...)
*/
public static Object instantiateObject(String className, PackageType packageType, Object... arguments) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
return instantiateObject(packageType.getClass(className), arguments);
}
/**
* Returns a method of a class with the given parameter types
*
* @param clazz Target class
* @param methodName Name of the desired method
* @param parameterTypes Parameter types of the desired method
* @return The method of the target class with the specified name and parameter types
* @throws NoSuchMethodException If the desired method of the target class with the specified name and parameter types cannot be found
* @see DataType#getPrimitive(Class[])
* @see DataType#compare(Class[], Class[])
*/
public static Method getMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException {
Class<?>[] primitiveTypes = DataType.getPrimitive(parameterTypes);
for (Method method : clazz.getMethods()) {
if (!method.getName().equals(methodName) || !DataType.compare(DataType.getPrimitive(method.getParameterTypes()), primitiveTypes)) {
continue;
}
return method;
}
throw new NoSuchMethodException("There is no such method in this class with the specified name and parameter types");
}
/**
* Returns a method of a desired class with the given parameter types
*
* @param className Name of the desired target class
* @param packageType Package where the desired target class is located
* @param methodName Name of the desired method
* @param parameterTypes Parameter types of the desired method
* @return The method of the desired target class with the specified name and parameter types
* @throws NoSuchMethodException If the desired method of the desired target class with the specified name and parameter types cannot be found
* @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found
* @see #getMethod(Class, String, Class...)
*/
public static Method getMethod(String className, PackageType packageType, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException, ClassNotFoundException {
return getMethod(packageType.getClass(className), methodName, parameterTypes);
}
/**
* Invokes a method on an object with the given arguments
*
* @param instance Target object
* @param methodName Name of the desired method
* @param arguments Arguments which are used to invoke the desired method
* @return The result of invoking the desired method on the target object
* @throws IllegalAccessException If the desired method cannot be accessed due to certain circumstances
* @throws IllegalArgumentException If the types of the arguments do not match the parameter types of the method (this should not occur since it searches for a method with the types of the arguments)
* @throws InvocationTargetException If the desired method cannot be invoked on the target object
* @throws NoSuchMethodException If the desired method of the class of the target object with the specified name and arguments cannot be found
* @see #getMethod(Class, String, Class...)
* @see DataType#getPrimitive(Object[])
*/
public static Object invokeMethod(Object instance, String methodName, Object... arguments) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException {
return getMethod(instance.getClass(), methodName, DataType.getPrimitive(arguments)).invoke(instance, arguments);
}
/**
* Invokes a method of the target class on an object with the given arguments
*
* @param instance Target object
* @param clazz Target class
* @param methodName Name of the desired method
* @param arguments Arguments which are used to invoke the desired method
* @return The result of invoking the desired method on the target object
* @throws IllegalAccessException If the desired method cannot be accessed due to certain circumstances
* @throws IllegalArgumentException If the types of the arguments do not match the parameter types of the method (this should not occur since it searches for a method with the types of the arguments)
* @throws InvocationTargetException If the desired method cannot be invoked on the target object
* @throws NoSuchMethodException If the desired method of the target class with the specified name and arguments cannot be found
* @see #getMethod(Class, String, Class...)
* @see DataType#getPrimitive(Object[])
*/
public static Object invokeMethod(Object instance, Class<?> clazz, String methodName, Object... arguments) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException {
return getMethod(clazz, methodName, DataType.getPrimitive(arguments)).invoke(instance, arguments);
}
/**
* Invokes a method of a desired class on an object with the given arguments
*
* @param instance Target object
* @param className Name of the desired target class
* @param packageType Package where the desired target class is located
* @param methodName Name of the desired method
* @param arguments Arguments which are used to invoke the desired method
* @return The result of invoking the desired method on the target object
* @throws IllegalAccessException If the desired method cannot be accessed due to certain circumstances
* @throws IllegalArgumentException If the types of the arguments do not match the parameter types of the method (this should not occur since it searches for a method with the types of the arguments)
* @throws InvocationTargetException If the desired method cannot be invoked on the target object
* @throws NoSuchMethodException If the desired method of the desired target class with the specified name and arguments cannot be found
* @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found
* @see #invokeMethod(Object, Class, String, Object...)
*/
public static Object invokeMethod(Object instance, String className, PackageType packageType, String methodName, Object... arguments) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
return invokeMethod(instance, packageType.getClass(className), methodName, arguments);
}
/**
* Returns a field of the target class with the given name
*
* @param clazz Target class
* @param declared Whether the desired field is declared or not
* @param fieldName Name of the desired field
* @return The field of the target class with the specified name
* @throws NoSuchFieldException If the desired field of the given class cannot be found
* @throws SecurityException If the desired field cannot be made accessible
*/
public static Field getField(Class<?> clazz, boolean declared, String fieldName) throws NoSuchFieldException, SecurityException {
Field field = declared ? clazz.getDeclaredField(fieldName) : clazz.getField(fieldName);
field.setAccessible(true);
return field;
}
/**
* Returns a field of a desired class with the given name
*
* @param className Name of the desired target class
* @param packageType Package where the desired target class is located
* @param declared Whether the desired field is declared or not
* @param fieldName Name of the desired field
* @return The field of the desired target class with the specified name
* @throws NoSuchFieldException If the desired field of the desired class cannot be found
* @throws SecurityException If the desired field cannot be made accessible
* @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found
* @see #getField(Class, boolean, String)
*/
public static Field getField(String className, PackageType packageType, boolean declared, String fieldName) throws NoSuchFieldException, SecurityException, ClassNotFoundException {
return getField(packageType.getClass(className), declared, fieldName);
}
/**
* Returns the value of a field of the given class of an object
*
* @param instance Target object
* @param clazz Target class
* @param declared Whether the desired field is declared or not
* @param fieldName Name of the desired field
* @return The value of field of the target object
* @throws IllegalArgumentException If the target object does not feature the desired field
* @throws IllegalAccessException If the desired field cannot be accessed
* @throws NoSuchFieldException If the desired field of the target class cannot be found
* @throws SecurityException If the desired field cannot be made accessible
* @see #getField(Class, boolean, String)
*/
public static Object getValue(Object instance, Class<?> clazz, boolean declared, String fieldName) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
return getField(clazz, declared, fieldName).get(instance);
}
/**
* Returns the value of a field of a desired class of an object
*
* @param instance Target object
* @param className Name of the desired target class
* @param packageType Package where the desired target class is located
* @param declared Whether the desired field is declared or not
* @param fieldName Name of the desired field
* @return The value of field of the target object
* @throws IllegalArgumentException If the target object does not feature the desired field
* @throws IllegalAccessException If the desired field cannot be accessed
* @throws NoSuchFieldException If the desired field of the desired class cannot be found
* @throws SecurityException If the desired field cannot be made accessible
* @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found
* @see #getValue(Object, Class, boolean, String)
*/
public static Object getValue(Object instance, String className, PackageType packageType, boolean declared, String fieldName) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException, ClassNotFoundException {
return getValue(instance, packageType.getClass(className), declared, fieldName);
}
/**
* Returns the value of a field with the given name of an object
*
* @param instance Target object
* @param declared Whether the desired field is declared or not
* @param fieldName Name of the desired field
* @return The value of field of the target object
* @throws IllegalArgumentException If the target object does not feature the desired field (should not occur since it searches for a field with the given name in the class of the object)
* @throws IllegalAccessException If the desired field cannot be accessed
* @throws NoSuchFieldException If the desired field of the target object cannot be found
* @throws SecurityException If the desired field cannot be made accessible
* @see #getValue(Object, Class, boolean, String)
*/
public static Object getValue(Object instance, boolean declared, String fieldName) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
return getValue(instance, instance.getClass(), declared, fieldName);
}
/**
* Sets the value of a field of the given class of an object
*
* @param instance Target object
* @param clazz Target class
* @param declared Whether the desired field is declared or not
* @param fieldName Name of the desired field
* @param value New value
* @throws IllegalArgumentException If the type of the value does not match the type of the desired field
* @throws IllegalAccessException If the desired field cannot be accessed
* @throws NoSuchFieldException If the desired field of the target class cannot be found
* @throws SecurityException If the desired field cannot be made accessible
* @see #getField(Class, boolean, String)
*/
public static void setValue(Object instance, Class<?> clazz, boolean declared, String fieldName, Object value) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
getField(clazz, declared, fieldName).set(instance, value);
}
/**
* Sets the value of a field of a desired class of an object
*
* @param instance Target object
* @param className Name of the desired target class
* @param packageType Package where the desired target class is located
* @param declared Whether the desired field is declared or not
* @param fieldName Name of the desired field
* @param value New value
* @throws IllegalArgumentException If the type of the value does not match the type of the desired field
* @throws IllegalAccessException If the desired field cannot be accessed
* @throws NoSuchFieldException If the desired field of the desired class cannot be found
* @throws SecurityException If the desired field cannot be made accessible
* @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found
* @see #setValue(Object, Class, boolean, String, Object)
*/
public static void setValue(Object instance, String className, PackageType packageType, boolean declared, String fieldName, Object value) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException, ClassNotFoundException {
setValue(instance, packageType.getClass(className), declared, fieldName, value);
}
/**
* Sets the value of a field with the given name of an object
*
* @param instance Target object
* @param declared Whether the desired field is declared or not
* @param fieldName Name of the desired field
* @param value New value
* @throws IllegalArgumentException If the type of the value does not match the type of the desired field
* @throws IllegalAccessException If the desired field cannot be accessed
* @throws NoSuchFieldException If the desired field of the target object cannot be found
* @throws SecurityException If the desired field cannot be made accessible
* @see #setValue(Object, Class, boolean, String, Object)
*/
public static void setValue(Object instance, boolean declared, String fieldName, Object value) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
setValue(instance, instance.getClass(), declared, fieldName, value);
}
/**
* Represents an enumeration of dynamic packages of NMS and CraftBukkit
* <p>
* This class is part of the <b>ReflectionUtils</b> and follows the same usage conditions
*
* @author DarkBlade12
* @since 1.0
*/
public enum PackageType {
MINECRAFT_SERVER("net.minecraft.server." + getServerVersion()),
CRAFTBUKKIT("org.bukkit.craftbukkit." + getServerVersion()),
CRAFTBUKKIT_BLOCK(CRAFTBUKKIT, "block"),
CRAFTBUKKIT_CHUNKIO(CRAFTBUKKIT, "chunkio"),
CRAFTBUKKIT_COMMAND(CRAFTBUKKIT, "command"),
CRAFTBUKKIT_CONVERSATIONS(CRAFTBUKKIT, "conversations"),
CRAFTBUKKIT_ENCHANTMENS(CRAFTBUKKIT, "enchantments"),
CRAFTBUKKIT_ENTITY(CRAFTBUKKIT, "entity"),
CRAFTBUKKIT_EVENT(CRAFTBUKKIT, "event"),
CRAFTBUKKIT_GENERATOR(CRAFTBUKKIT, "generator"),
CRAFTBUKKIT_HELP(CRAFTBUKKIT, "help"),
CRAFTBUKKIT_INVENTORY(CRAFTBUKKIT, "inventory"),
CRAFTBUKKIT_MAP(CRAFTBUKKIT, "map"),
CRAFTBUKKIT_METADATA(CRAFTBUKKIT, "metadata"),
CRAFTBUKKIT_POTION(CRAFTBUKKIT, "potion"),
CRAFTBUKKIT_PROJECTILES(CRAFTBUKKIT, "projectiles"),
CRAFTBUKKIT_SCHEDULER(CRAFTBUKKIT, "scheduler"),
CRAFTBUKKIT_SCOREBOARD(CRAFTBUKKIT, "scoreboard"),
CRAFTBUKKIT_UPDATER(CRAFTBUKKIT, "updater"),
CRAFTBUKKIT_UTIL(CRAFTBUKKIT, "util");
private final String path;
/**
* Construct a new package type
*
* @param path Path of the package
*/
private PackageType(String path) {
this.path = path;
}
/**
* Construct a new package type
*
* @param parent Parent package of the package
* @param path Path of the package
*/
private PackageType(PackageType parent, String path) {
this(parent + "." + path);
}
/**
* Returns the path of this package type
*
* @return The path
*/
public String getPath() {
return path;
}
/**
* Returns the class with the given name
*
* @param className Name of the desired class
* @return The class with the specified name
* @throws ClassNotFoundException If the desired class with the specified name and package cannot be found
*/
public Class<?> getClass(String className) throws ClassNotFoundException {
return Class.forName(this + "." + className);
}
// Override for convenience
@Override
public String toString() {
return path;
}
/**
* Returns the version of your server
*
* @return The server version
*/
public static String getServerVersion() {
return Bukkit.getServer().getClass().getPackage().getName().substring(23);
}
}
/**
* Represents an enumeration of Java data types with corresponding classes
* <p>
* This class is part of the <b>ReflectionUtils</b> and follows the same usage conditions
*
* @author DarkBlade12
* @since 1.0
*/
public enum DataType {
BYTE(byte.class, Byte.class),
SHORT(short.class, Short.class),
INTEGER(int.class, Integer.class),
LONG(long.class, Long.class),
CHARACTER(char.class, Character.class),
FLOAT(float.class, Float.class),
DOUBLE(double.class, Double.class),
BOOLEAN(boolean.class, Boolean.class);
private static final Map<Class<?>, DataType> CLASS_MAP = new HashMap<Class<?>, DataType>();
private final Class<?> primitive;
private final Class<?> reference;
// Initialize map for quick class lookup
static {
for (DataType type : values()) {
CLASS_MAP.put(type.primitive, type);
CLASS_MAP.put(type.reference, type);
}
}
/**
* Construct a new data type
*
* @param primitive Primitive class of this data type
* @param reference Reference class of this data type
*/
private DataType(Class<?> primitive, Class<?> reference) {
this.primitive = primitive;
this.reference = reference;
}
/**
* Returns the primitive class of this data type
*
* @return The primitive class
*/
public Class<?> getPrimitive() {
return primitive;
}
/**
* Returns the reference class of this data type
*
* @return The reference class
*/
public Class<?> getReference() {
return reference;
}
/**
* Returns the data type with the given primitive/reference class
*
* @param clazz Primitive/Reference class of the data type
* @return The data type
*/
public static DataType fromClass(Class<?> clazz) {
return CLASS_MAP.get(clazz);
}
/**
* Returns the primitive class of the data type with the given reference class
*
* @param clazz Reference class of the data type
* @return The primitive class
*/
public static Class<?> getPrimitive(Class<?> clazz) {
DataType type = fromClass(clazz);
return type == null ? clazz : type.getPrimitive();
}
/**
* Returns the reference class of the data type with the given primitive class
*
* @param clazz Primitive class of the data type
* @return The reference class
*/
public static Class<?> getReference(Class<?> clazz) {
DataType type = fromClass(clazz);
return type == null ? clazz : type.getReference();
}
/**
* Returns the primitive class array of the given class array
*
* @param classes Given class array
* @return The primitive class array
*/
public static Class<?>[] getPrimitive(Class<?>[] classes) {
int length = classes == null ? 0 : classes.length;
Class<?>[] types = new Class<?>[length];
for (int index = 0; index < length; index++) {
types[index] = getPrimitive(classes[index]);
}
return types;
}
/**
* Returns the reference class array of the given class array
*
* @param classes Given class array
* @return The reference class array
*/
public static Class<?>[] getReference(Class<?>[] classes) {
int length = classes == null ? 0 : classes.length;
Class<?>[] types = new Class<?>[length];
for (int index = 0; index < length; index++) {
types[index] = getReference(classes[index]);
}
return types;
}
/**
* Returns the primitive class array of the given object array
*
* @param objects Given object array
* @return The primitive class array
*/
public static Class<?>[] getPrimitive(Object[] objects) {
int length = objects == null ? 0 : objects.length;
Class<?>[] types = new Class<?>[length];
for (int index = 0; index < length; index++) {
types[index] = getPrimitive(objects[index].getClass());
}
return types;
}
/**
* Returns the reference class array of the given object array
*
* @param objects Given object array
* @return The reference class array
*/
public static Class<?>[] getReference(Object[] objects) {
int length = objects == null ? 0 : objects.length;
Class<?>[] types = new Class<?>[length];
for (int index = 0; index < length; index++) {
types[index] = getReference(objects[index].getClass());
}
return types;
}
/**
* Compares two class arrays on equivalence
*
* @param primary Primary class array
* @param secondary Class array which is compared to the primary array
* @return Whether these arrays are equal or not
*/
public static boolean compare(Class<?>[] primary, Class<?>[] secondary) {
if (primary == null || secondary == null || primary.length != secondary.length) {
return false;
}
for (int index = 0; index < primary.length; index++) {
Class<?> primaryClass = primary[index];
Class<?> secondaryClass = secondary[index];
if (primaryClass.equals(secondaryClass) || primaryClass.isAssignableFrom(secondaryClass)) {
continue;
}
return false;
}
return true;
}
}
}

View File

@ -1,131 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.reflection;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
/**
* Created by charl on 28-Apr-17.
*/
public class ActionBarReflection extends ReflectionUtils {
private static Plugin _plugin;
private static boolean _use1_8_R1Methods = false;
private static boolean _use1_7Methods = false;
static {
if(getAPIVersion().equalsIgnoreCase("v1_8_R1")) {
_use1_8_R1Methods = true;
} else if(getAPIVersion().startsWith("v1_7_")) {
_use1_7Methods = true;
}
}
public static final Plugin getPlugin() {
return _plugin;
}
public static final Object getPlayerConnection(Player player) {
try {
Class<?> c1 = getOBCClass("entity.CraftPlayer");
Object p = c1.cast(player); // (CraftPlayer) player;
Method m1 = c1.getDeclaredMethod("getHandle"); //CraftPlayer.getHandle();
Object h = m1.invoke(p); // EntityPlayer h = ((CraftPlayer) player).getHandle();
Field f1 = h.getClass().getDeclaredField("playerConnection");
return f1.get(h);
}catch(Exception e) {
e.printStackTrace();
return null;
}
}
public static final void sendActionBar(Player player, String message) {
if(player == null) {
return;
}
if(message == null) {
return;
}
try {
Object ppoc;
Class<?> c4 = getNMSClass("PacketPlayOutChat");
Class<?> c5 = getNMSClass("Packet");
if(_use1_8_R1Methods || _use1_7Methods) {
Class<?> c2 = getNMSClass("ChatSerializer");
Class<?> c3 = getNMSClass("IChatBaseComponent");
Method m3 = c2.getDeclaredMethod("a", String.class);
Object cbc = c3.cast(m3.invoke(c2, "{\"text\": \"" + message + "\"}"));
if(_use1_8_R1Methods) {
ppoc = c4.getConstructor(new Class<?>[] {c3, byte.class}).newInstance(cbc, (byte) 2);
} else {
ppoc = c4.getConstructor(new Class<?>[] {c3}).newInstance(cbc);
}
Object playerConnection = getPlayerConnection(player); // PlayerConnection pc = h.playerConnection;
Method m5 = playerConnection.getClass().getDeclaredMethod("sendPacket", c5); // PlayerConnection.sendPacket(Packet<?> packet);
m5.invoke(playerConnection, ppoc); // pc.sendPacket(ppoc);
} else {
Class<?> c2 = getNMSClass("ChatComponentText");
Class<?> c3 = getNMSClass("IChatBaseComponent");
Object o = c2.getConstructor(new Class<?>[] {String.class}).newInstance(message);
ppoc = c4.getConstructor(new Class<?>[] {c3, byte.class}).newInstance(o, (byte) 2);
Object playerConnection = getPlayerConnection(player); // PlayerConnection pc = h.playerConnection;
Method m5 = playerConnection.getClass().getDeclaredMethod("sendPacket", c5); // PlayerConnection.sendPacket(Packet<?> packet);
m5.invoke(playerConnection, ppoc); // pc.sendPacket(ppoc);
}
} catch(Exception e) {
e.printStackTrace();
}
}
public static final void sendActionBar(final Player player, final String message, int duration, Plugin plugin) {
sendActionBar(player, message);
_plugin = plugin;
if (duration >= 0) {
// Sends empty message at the end of the duration. Allows messages shorter than 3 seconds, ensures precision.
new BukkitRunnable() {
public void run() {
sendActionBar(player, "");
}
}.runTaskLater(getPlugin(), duration + 1);
}
// Re-sends the messages every 3 seconds so it doesn't go away from the player's screen.
while (duration > 60) {
duration -= 60;
int sched = duration % 60;
new BukkitRunnable() {
public void run() {
sendActionBar(player, message);
}
}.runTaskLater(getPlugin(), (long) sched);
}
}
public static final void sendActionBarToAllPlayers(String message, Plugin plugin) {
sendActionBarToAllPlayers(message, -1, plugin);
}
public static final void sendActionBarToAllPlayers(String message, int duration, Plugin plugin) {
for(Player player : Bukkit.getOnlinePlayers()) {
sendActionBar(player, message, duration, plugin);
}
}
}

View File

@ -1,86 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.reflection;
import org.bukkit.Location;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
/**
* Created by charl on 28-Apr-17.
*/
public class ChunkReflection extends ReflectionUtils {
private static boolean _useOldMethods = false;
static {
if(getAPIVersion().startsWith("v1_8_R") || getAPIVersion().startsWith("v1_7_R")) {
_useOldMethods = true;
}
}
public static final Object getChunkProviderServer(Location location) {
try {
Class<?> c1 = getOBCClass("CraftWorld");
Object craftWorld = c1.cast(location.getWorld()); //(CraftWorld) location.getWorld();
Method m1 = c1.getDeclaredMethod("getHandle"); // CraftWorld.getHandle();
Object h1 = m1.invoke(craftWorld); // WorldServer h1 = ((CraftWorld) location.getWorld()).getHandle();
Object h2;
if(_useOldMethods) {
Field f1 = h1.getClass().getDeclaredField("chunkProviderServer"); // WorldServer.chunkProviderServer;
h2 = f1.get(h1);
} else {
Method m3 = h1.getClass().getDeclaredMethod("getChunkProviderServer"); // WorldServer.getChunkProviderServer();
h2 = m3.invoke(h1); // ChunkProviderServer h2 = h1.getChunkProviderServer();
}
return h2; // ChunkProviderServer.class
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static final boolean isChunkLoaded(Location location) {
if(location == null) return false;
if(location.getWorld() == null) return false;
int x = location.getBlockX() / 16;
int z = location.getBlockZ() / 16;
try {
Class<?> c1 = getChunkProviderServer(location).getClass();
Method m1;
Object h1 = getChunkProviderServer(location);
if(_useOldMethods) {
m1 = c1.getDeclaredMethod("isChunkLoaded", int.class, int.class); // ChunkProviderServer.isChunkLoaded(int.class, int.class);
} else {
m1 = c1.getDeclaredMethod("isLoaded", int.class, int.class); // ChunkProviderServer.isLoaded(int.class, int.class);
}
return (Boolean) m1.invoke(h1, x, z);
} catch (Exception e) {
e.printStackTrace();
return true;
}
}
public static final void loadChunk(Location location) {
if(isChunkLoaded(location)) return;
int x = location.getBlockX() / 16;
int z = location.getBlockZ() / 16;
try {
Class<?> c1 = getChunkProviderServer(location).getClass();
Object h1 = getChunkProviderServer(location);
Method m1 = c1.getDeclaredMethod("loadChunk", int.class, int.class);
m1.invoke(h1, x, z);
} catch(Exception e) {
e.printStackTrace();
}
}
}

View File

@ -1,40 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.reflection;
import org.bukkit.Bukkit;
/**
* Created by charl on 28-Apr-17.
*/
public class ReflectionUtils {
private static String _nmsVersion = null;
static {
if(_nmsVersion == null) {
_nmsVersion = Bukkit.getServer().getClass().getPackage().getName();
_nmsVersion = _nmsVersion.substring(_nmsVersion.lastIndexOf(".") + 1);
}
}
public static final String getAPIVersion() {
return _nmsVersion;
}
public static final Class<?> getNMSClass(String name) {
try {
return Class.forName("net.minecraft.server." + _nmsVersion + "." + name);
} catch(ClassNotFoundException e) {
e.printStackTrace();
return null;
}
}
public static final Class<?> getOBCClass(String name) {
try {
return Class.forName("org.bukkit.craftbukkit." + _nmsVersion + "." + name);
} catch(ClassNotFoundException e) {
e.printStackTrace();
return null;
}
}
}

View File

@ -1,35 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.serialization;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.aminecraftdev.custombosses.innerapi.serialization.helpers.LocationAdapter;
import org.bukkit.Location;
/**
* @author Debugged
* @version 1.0
* @since 18-5-2017
*/
public class BoostedGson {
private static final Gson gson = new GsonBuilder()
.setPrettyPrinting()
.excludeFieldsWithoutExposeAnnotation()
.registerTypeAdapter(Location.class, new LocationAdapter())
.create();
private static final Gson gsonFlat = new GsonBuilder()
.setPrettyPrinting()
.excludeFieldsWithoutExposeAnnotation()
.registerTypeAdapter(Location.class, new LocationAdapter())
.create();
public static Gson getGson() {
return gson;
}
public static Gson getGsonFlat() {
return gsonFlat;
}
}

View File

@ -1,40 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.serialization;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
/**
* @author Debugged
* @version 1.0
* @since 18-5-2017
*/
public class Serialize {
public static String serialize(Location location) {
return location.getWorld().getName() + ";" +
location.getX() + ";" +
location.getY() + ";" +
location.getZ() + ";" +
location.getYaw() + ";" +
location.getPitch() + ";";
}
public static Location deserializeLocation(String locationString) {
String[] split = locationString.split(";");
try {
World world = Bukkit.getWorld(split[0]);
double x = Double.parseDouble(split[1]);
double y = Double.parseDouble(split[2]);
double z = Double.parseDouble(split[3]);
float yaw = Float.parseFloat(split[4]);
float pitch = Float.parseFloat(split[5]);
return new Location(world, x, y, z, yaw, pitch);
} catch (Exception ex) {
return null;
}
}
}

View File

@ -1,28 +0,0 @@
package net.aminecraftdev.custombosses.innerapi.serialization.helpers;
import com.google.gson.*;
import net.aminecraftdev.custombosses.innerapi.serialization.Serialize;
import org.bukkit.Location;
import java.lang.reflect.Type;
/**
* @author Debugged
* @version 1.0
* @since 18-5-2017
*/
public class LocationAdapter implements JsonSerializer<Location>, JsonDeserializer<Location> {
@Override
public Location deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
return Serialize.deserializeLocation(jsonElement.getAsString());
}
@Override
public JsonElement serialize(Location location, Type type, JsonSerializationContext jsonSerializationContext) {
return new JsonPrimitive(
Serialize.serialize(location)
);
}
}

View File

@ -10,17 +10,17 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.spigotmc:spigot:1.11.2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.milkbowl.vault:VaultAPI:1.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:worldguard:6.0.0-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.spigot:bukkit-classloader-check:1.8-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:bukkit:1.9-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-lang:commons-lang:2.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: junit:junit:4.10" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.2.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.avaje:ebean:2.8.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.persistence:persistence-api:1.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.14" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:bukkit:1.8.6-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.2.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.15" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:worldguard:6.0.0-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.spigot:bukkit-classloader-check:1.8-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:commandbook:2.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.sf.opencsv:opencsv:2.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/../../target/classes" />
<output-test url="file://$MODULE_DIR$/../../target/test-classes" />
<content url="file://$MODULE_DIR$">
@ -9,5 +9,30 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="FactionHelper" />
<orderEntry type="module" module-name="FactionsM" />
<orderEntry type="module" module-name="FactionsUUID" />
<orderEntry type="module" module-name="FactionsOne" />
<orderEntry type="module" module-name="PluginAPI" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.spigotmc:spigot:1.11.2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.milkbowl.vault:VaultAPI:1.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:bukkit:1.9-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-lang:commons-lang:2.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: junit:junit:4.10" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.2.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.avaje:ebean:2.8.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.persistence:persistence-api:1.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.15" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:worldguard:6.0.0-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.spigot:bukkit-classloader-check:1.8-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:commandbook:2.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.sf.opencsv:opencsv:2.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:worldedit:6.0.0-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: de.schlichtherle:truezip:6.8.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: rhino:js:1.7R2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:10.0.1" level="project" />
</component>
</module>

View File

@ -11,15 +11,20 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>Core</artifactId>
<version>3.0.0.0</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>net.aminecraftdev.custombosses</groupId>
<artifactId>FactionHelper</artifactId>
<version>3.0.0.0</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>net.aminecraftdev.custombosses</groupId>
<artifactId>FactionsM</artifactId>
<version>3.0.0.0</version>
<type>jar</type>
<scope>compile</scope>
<optional>true</optional>
</dependency>
@ -27,7 +32,6 @@
<groupId>net.aminecraftdev.custombosses</groupId>
<artifactId>FactionsUUID</artifactId>
<version>3.0.0.0</version>
<type>jar</type>
<scope>compile</scope>
<optional>true</optional>
</dependency>
@ -35,7 +39,6 @@
<groupId>net.aminecraftdev.custombosses</groupId>
<artifactId>FactionsOne</artifactId>
<version>3.0.0.0</version>
<type>jar</type>
<scope>compile</scope>
<optional>true</optional>
</dependency>
@ -43,7 +46,6 @@
<groupId>net.aminecraftdev.custombosses</groupId>
<artifactId>PluginAPI</artifactId>
<version>3.0.0.0</version>
<type>jar</type>
<scope>compile</scope>
<optional>true</optional>
</dependency>
@ -52,14 +54,15 @@
<build>
<defaultGoal>clean package install</defaultGoal>
<directory>../../target</directory>
<finalName>CustomBosses-${project.version}</finalName>
<finalName>CustomBosses-${plugin.version}</finalName>
<sourceDirectory>${basedir}/src/</sourceDirectory>
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${basedir}/resources</directory>
<directory>${basedir}/resources/</directory>
<includes>
<include>*.json</include>
<include>*.yml</include>
</includes>
</resource>
@ -76,7 +79,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.4</version>
<version>3.1.0</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>

View File

@ -1,52 +0,0 @@
package net.aminecraftdev.custombosses.api;
import net.aminecraftdev.custombosses.handlers.BossEntity;
import net.aminecraftdev.custombosses.managers.BossManager;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 06-Sep-17
*/
public class BossAPI {
public boolean createBoss(String entityType, double health, String identifier) {
try {
EntityType.valueOf(entityType);
} catch (IllegalArgumentException ex) {
return false;
}
if(BossManager.isBossEntitySet(identifier)) return false;
EntityType eType = EntityType.valueOf(entityType);
BossEntity bossEntity = new BossEntity(eType, health, identifier);
BossManager.addBossEntity(bossEntity);
return true;
}
public LivingEntity spawnBoss(String identifier, Location location) {
if(!BossManager.isBossEntitySet(identifier)) return null;
BossEntity bossEntity = BossManager.getBossEntity(identifier);
return bossEntity.createNewBossEntity(location);
}
public LivingEntity spawnMinion(String identifier, Location location) {
if(!BossManager.isBossEntitySet(identifier)) return null;
BossEntity bossEntity = BossManager.getBossEntity(identifier);
return bossEntity.createNewMinionEntity(location);
}
public BossEntity getBoss(String identifier) {
return BossManager.getBossEntity(identifier);
}
}

View File

@ -0,0 +1,27 @@
package net.aminecraftdev.custombosses.entities;
import net.aminecraftdev.custombosses.entities.base.CustomEntity;
import net.aminecraftdev.custombosses.handlers.EntityHandler;
import net.aminecraftdev.custombosses.models.CustomEntityModel;
import org.bukkit.Location;
import java.util.ArrayList;
import java.util.List;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 06-Sep-17
*/
public class BossEntity extends CustomEntity {
private List<Location> possibleSpawns = new ArrayList<>();
private List<EntityHandler> minions = new ArrayList<>();
private boolean randomWorldSpawns = false;
public BossEntity(String identifier, CustomEntityModel customEntityModel) {
super(identifier, customEntityModel);
}
}

View File

@ -0,0 +1,111 @@
package net.aminecraftdev.custombosses.entities.base;
import net.aminecraftdev.custombosses.handlers.EntityHandler;
import net.aminecraftdev.custombosses.handlers.IIdentifier;
import net.aminecraftdev.custombosses.models.CustomEntityModel;
import net.aminecraftdev.custombosses.skills.base.CustomSkill;
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 08-Mar-18
*/
public class CustomEntity implements IIdentifier {
private List<CustomSkill> customSkills = new ArrayList<>();
private CustomEntityModel customEntityModel;
private String identifier;
public CustomEntity(String identifier, CustomEntityModel customEntityModel) {
this.identifier = identifier;
this.customEntityModel = customEntityModel;
// TODO: Convert customSkillModels into customSkills
}
@Override
public String getIdentifier() {
return this.identifier;
}
public List<CustomSkill> getCustomSkills() {
return this.customSkills;
}
public EntityHandler spawn(Location location) {
LivingEntity livingEntity = (LivingEntity) location.getWorld().spawn(location, this.customEntityModel.getEntityType().getEntityClass());
EntityEquipment entityEquipment = livingEntity.getEquipment();
/* SETTING HEALTH */
livingEntity.setMaxHealth(this.customEntityModel.getMaxHealth());
livingEntity.setHealth(this.customEntityModel.getMaxHealth());
/* SETTING DISPLAY NAME */
if(this.customEntityModel.getDisplayName() != null) {
livingEntity.setCustomName(this.customEntityModel.getDisplayName());
livingEntity.setCustomNameVisible(true);
}
/* SETTING MAIN HAND */
if(this.customEntityModel.getMainHand() != null) {
entityEquipment.setItemInMainHand(this.customEntityModel.getMainHand());
if(cannotDrop()) entityEquipment.setItemInMainHandDropChance(0);
}
/* SETTING OFF HAND */
if(this.customEntityModel.getOffHand() != null) {
entityEquipment.setItemInOffHand(this.customEntityModel.getOffHand());
if(cannotDrop()) entityEquipment.setItemInOffHandDropChance(0);
}
/* SETTING ARMOUR */
if(!this.customEntityModel.getArmor().isEmpty()) {
Map<Integer, ItemStack> equipment = this.customEntityModel.getArmor();
if(equipment.getOrDefault(0, null) != null) {
entityEquipment.setHelmet(equipment.get(0));
if(cannotDrop()) entityEquipment.setHelmetDropChance(0);
}
if(equipment.getOrDefault(1, null) != null) {
entityEquipment.setChestplate(equipment.get(1));
if(cannotDrop()) entityEquipment.setChestplateDropChance(0);
}
if(equipment.getOrDefault(2, null) != null) {
entityEquipment.setLeggings(equipment.get(2));
if(cannotDrop()) entityEquipment.setLeggingsDropChance(0);
}
if(equipment.getOrDefault(3, null) != null) {
entityEquipment.setBoots(equipment.get(3));
if(cannotDrop()) entityEquipment.setBootsDropChance(0);
}
}
/* SETTINGS POTIONS */
if(!this.customEntityModel.getPotionEffects().isEmpty()) {
livingEntity.addPotionEffects(this.customEntityModel.getPotionEffects());
}
return new EntityHandler(livingEntity, this);
}
private boolean cannotDrop() {
return !this.customEntityModel.canDropEquipment();
}
}

View File

@ -1,26 +0,0 @@
package net.aminecraftdev.custombosses.handlers;
import net.aminecraftdev.custombosses.models.CustomEntityModel;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import java.util.List;
import java.util.Map;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 06-Sep-17
*/
public class BossEntity extends CustomEntityModel {
public BossEntity(EntityType entityType, double health, String identifier) {
super(entityType, health, identifier);
}
public BossEntity(EntityType entityType, Map<Integer, ItemStack> equipment, List<String> description, List<PotionEffect> defaultPotionEffects, ItemStack itemStackInMainHand, ItemStack itemStackInOffHand, String identifier, double health, String name) {
super(entityType, equipment, description, defaultPotionEffects, itemStackInMainHand, itemStackInOffHand, identifier, health, name);
}
}

View File

@ -0,0 +1,28 @@
package net.aminecraftdev.custombosses.handlers;
import net.aminecraftdev.custombosses.entities.base.CustomEntity;
import org.bukkit.entity.LivingEntity;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 08-Mar-18
*/
public class EntityHandler {
private CustomEntity customEntity;
private LivingEntity livingEntity;
public EntityHandler(LivingEntity livingEntity, CustomEntity customEntity) {
this.customEntity = customEntity;
this.livingEntity = livingEntity;
}
public CustomEntity getCustomEntity() {
return this.customEntity;
}
public LivingEntity getLivingEntity() {
return this.livingEntity;
}
}

View File

@ -0,0 +1,12 @@
package net.aminecraftdev.custombosses.handlers;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 08-Mar-18
*/
public interface IIdentifier {
String getIdentifier();
}

View File

@ -0,0 +1,22 @@
package net.aminecraftdev.custombosses.handlers;
import net.aminecraftdev.custombosses.utils.Debug;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 08-Mar-18
*/
public class ValidationHandler {
public static boolean isNull(Object object) {
if(object == null) {
Debug.NULL_CHECK.debug();
return true;
}
return false;
}
}

View File

@ -0,0 +1,30 @@
package net.aminecraftdev.custombosses.handlers.models;
import org.bukkit.inventory.ItemStack;
import java.util.Map;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 08-Mar-18
*/
public interface IEquipmentHandler {
void setMainHand(ItemStack itemStack);
ItemStack getMainHand();
void setOffHand(ItemStack itemStack);
ItemStack getOffHand();
void setArmor(int slot, ItemStack itemStack);
Map<Integer, ItemStack> getArmor();
void setCanDropEquipment(boolean bool);
boolean canDropEquipment();
}

View File

@ -0,0 +1,18 @@
package net.aminecraftdev.custombosses.handlers.models;
import org.bukkit.potion.PotionEffect;
import java.util.List;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 08-Mar-18
*/
public interface IPotionHandler {
void addPotionEffect(PotionEffect potionEffect);
List<PotionEffect> getPotionEffects();
}

View File

@ -0,0 +1,18 @@
package net.aminecraftdev.custombosses.handlers.models;
import net.aminecraftdev.custombosses.models.CustomSkillModel;
import java.util.List;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 08-Mar-18
*/
public interface ISkillHandler {
void addSkill(CustomSkillModel skillModel);
List<CustomSkillModel> getSkills();
}

View File

@ -0,0 +1,30 @@
package net.aminecraftdev.custombosses.handlers.models;
import org.bukkit.entity.EntityType;
import java.util.List;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 08-Mar-18
*/
public interface IStatsHandler {
void setEntityType(EntityType entityType);
EntityType getEntityType();
void setMaxHealth(double health);
double getMaxHealth();
void setDisplayName(String displayName);
String getDisplayName();
void setDescription(List<String> description);
List<String> getDescription();
}

View File

@ -1,29 +0,0 @@
package net.aminecraftdev.custombosses.managers;
import net.aminecraftdev.custombosses.handlers.BossEntity;
import java.util.HashMap;
import java.util.Map;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 06-Sep-17
*/
public class BossManager {
private static final Map<String, BossEntity> MAP_OF_BOSSES = new HashMap<>();
public static boolean isBossEntitySet(String identifier) {
return MAP_OF_BOSSES.containsKey(identifier);
}
public static void addBossEntity(BossEntity bossEntity) {
MAP_OF_BOSSES.put(bossEntity.getIdentifier(), bossEntity);
}
public static BossEntity getBossEntity(String identifier) {
return MAP_OF_BOSSES.getOrDefault(identifier, null);
}
}

View File

@ -1,9 +1,12 @@
package net.aminecraftdev.custombosses.models;
import org.bukkit.Location;
import net.aminecraftdev.custombosses.handlers.IIdentifier;
import net.aminecraftdev.custombosses.handlers.ValidationHandler;
import net.aminecraftdev.custombosses.handlers.models.IEquipmentHandler;
import net.aminecraftdev.custombosses.handlers.models.IPotionHandler;
import net.aminecraftdev.custombosses.handlers.models.ISkillHandler;
import net.aminecraftdev.custombosses.handlers.models.IStatsHandler;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
@ -13,204 +16,162 @@ import java.util.*;
* @author AMinecraftDev
* @version 1.0.0
* @since 06-Sep-17
*
* TODO: Make it load messages via a messages.json file
* TODO: Make it load all custom items via. a items.json file
*/
public class CustomEntityModel {
public class CustomEntityModel implements IIdentifier, IStatsHandler, IEquipmentHandler, ISkillHandler, IPotionHandler {
private List<PotionEffect> defaultPotionEffects = new ArrayList<>();
private Map<UUID, Location> spawnedLocations = new HashMap<>();
private Map<Integer, ItemStack> equipment = new HashMap<>();
private Set<LivingEntity> minionsSpawned = new HashSet<>();
private Set<LivingEntity> bossesSpawned = new HashSet<>();
private List<CustomSkillModel> skillModels = new ArrayList<>();
private List<String> description = new ArrayList<>();
private ItemStack itemStackInMainHand;
private ItemStack itemStackInOffHand;
private String identifier, displayName;
private ItemStack mainHand, offHand;
private boolean canDropEquipment;
private EntityType entityType;
private String identifier;
private double health;
private String name;
public CustomEntityModel(EntityType entityType, double health, String identifier) {
this(entityType, null, null, null, null, null, identifier, health, null);
this(entityType, new HashMap<>(), null, new ArrayList<>(), null, null, identifier, health, null, false);
}
public CustomEntityModel(EntityType entityType, Map<Integer, ItemStack> equipment, List<String> description, List<PotionEffect> defaultPotionEffects, ItemStack itemStackInMainHand, ItemStack itemStackInOffHand, String identifier, double health, String name) {
this.entityType = entityType;
public CustomEntityModel(EntityType entityType, Map<Integer, ItemStack> equipment, List<String> description, List<PotionEffect> defaultPotionEffects, ItemStack itemStackInMainHand, ItemStack itemStackInOffHand, String identifier, double health, String name, boolean canDropEquipment) {
this.identifier = identifier;
setItemStackInMainHand(itemStackInMainHand);
setItemStackInOffHand(itemStackInOffHand);
setMaxHealth(health);
setName(name);
try {
setEntityType(entityType);
setDescription(description);
setMainHand(itemStackInMainHand);
setOffHand(itemStackInOffHand);
setMaxHealth(health);
setDisplayName(name);
setCanDropEquipment(canDropEquipment);
if(equipment != null) equipment.forEach((integer, itemStack) -> setEquipment(integer, itemStack));
if(description != null) setDescription(description);
if(this.defaultPotionEffects != null) defaultPotionEffects.forEach(potionEffect -> addDefaultPotionEffects(potionEffect));
defaultPotionEffects.forEach(this::addPotionEffect);
equipment.forEach(this::setArmor);
} catch (IllegalArgumentException ex) {}
}
public String getIdentifier() {
return identifier;
@Override
public void setMainHand(ItemStack itemStack) {
if(ValidationHandler.isNull(itemStack)) return;
this.mainHand = itemStack;
}
public List<PotionEffect> getDefaultPotionEffects() {
return new ArrayList<>(defaultPotionEffects);
@Override
public ItemStack getMainHand() {
return this.mainHand;
}
public void addDefaultPotionEffects(PotionEffect potionEffect) {
defaultPotionEffects.add(potionEffect);
@Override
public void setOffHand(ItemStack itemStack) {
if(ValidationHandler.isNull(itemStack)) return;
this.offHand = itemStack;
}
public Set<LivingEntity> getBossesSpawned() {
return new HashSet<>(bossesSpawned);
@Override
public ItemStack getOffHand() {
return this.offHand;
}
public Set<LivingEntity> getMinionsSpawned() {
return new HashSet<>(minionsSpawned);
@Override
public void setArmor(int slot, ItemStack itemStack) {
if(ValidationHandler.isNull(itemStack)) return;
this.equipment.put(slot, itemStack);
}
public Map<UUID, Location> getSpawnedLocations() {
return new HashMap<>(spawnedLocations);
}
public Map<Integer, ItemStack> getEquipment() {
return new HashMap<>(equipment);
}
public void setEquipment(int slot, ItemStack itemStack) {
if(slot > 3) return;
equipment.put(slot, itemStack);
}
public List<String> getDescription() {
return new ArrayList<>(description);
}
public void setDescription(List<String> description) {
this.description = description;
}
public void addDescription(String line) {
description.add(line);
}
public ItemStack getItemStackInMainHand() {
return itemStackInMainHand;
}
public void setItemStackInMainHand(ItemStack itemStack) {
this.itemStackInMainHand = itemStack;
}
public ItemStack getItemStackInOffHand() {
return itemStackInOffHand;
}
public void setItemStackInOffHand(ItemStack itemStack) {
this.itemStackInOffHand = itemStack;
}
public double getMaxHealth() {
return health;
}
public void setMaxHealth(double health) {
this.health = health;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public EntityType getEntityType() {
return entityType;
}
public boolean canDropEquipment() {
return canDropEquipment;
@Override
public Map<Integer, ItemStack> getArmor() {
return this.equipment;
}
@Override
public void setCanDropEquipment(boolean bool) {
this.canDropEquipment = bool;
}
public LivingEntity createNewBossEntity(Location location) {
LivingEntity livingEntity = createNewEntity(location);
bossesSpawned.add(livingEntity);
spawnedLocations.put(livingEntity.getUniqueId(), location);
return livingEntity;
@Override
public boolean canDropEquipment() {
return this.canDropEquipment;
}
public LivingEntity createNewMinionEntity(Location location) {
LivingEntity livingEntity = createNewEntity(location);
@Override
public void addPotionEffect(PotionEffect potionEffect) {
if(ValidationHandler.isNull(potionEffect)) return;
minionsSpawned.add(livingEntity);
return livingEntity;
this.defaultPotionEffects.add(potionEffect);
}
private LivingEntity createNewEntity(Location location) {
LivingEntity livingEntity = (LivingEntity) location.getWorld().spawn(location, entityType.getEntityClass());
EntityEquipment entityEquipment = livingEntity.getEquipment();
livingEntity.setMaxHealth(getMaxHealth());
livingEntity.setHealth(getMaxHealth());
if(getName() != null) {
livingEntity.setCustomName(getName());
livingEntity.setCustomNameVisible(true);
}
if(getItemStackInMainHand() != null) {
entityEquipment.setItemInMainHand(getItemStackInMainHand());
if(!canDropEquipment()) entityEquipment.setItemInMainHandDropChance(0);
}
if(getItemStackInOffHand() != null) {
entityEquipment.setItemInOffHand(getItemStackInOffHand());
if(!canDropEquipment()) entityEquipment.setItemInOffHandDropChance(0);
}
if(!getEquipment().isEmpty()) {
if(equipment.containsKey(0)) {
entityEquipment.setHelmet(equipment.get(0));
if(!canDropEquipment()) entityEquipment.setHelmetDropChance(0);
}
if(equipment.containsKey(1)) {
entityEquipment.setChestplate(equipment.get(1));
if(!canDropEquipment()) entityEquipment.setChestplateDropChance(0);
}
if(equipment.containsKey(2)) {
entityEquipment.setLeggings(equipment.get(2));
if(!canDropEquipment()) entityEquipment.setLeggingsDropChance(0);
}
if(equipment.containsKey(3)) {
entityEquipment.setBoots(equipment.get(3));
if(!canDropEquipment()) entityEquipment.setBootsDropChance(0);
}
}
if(!getDefaultPotionEffects().isEmpty()) {
livingEntity.addPotionEffects(defaultPotionEffects);
}
return livingEntity;
@Override
public List<PotionEffect> getPotionEffects() {
return this.defaultPotionEffects;
}
@Override
public void addSkill(CustomSkillModel skillModel) {
if(ValidationHandler.isNull(skillModel)) return;
this.skillModels.add(skillModel);
}
@Override
public List<CustomSkillModel> getSkills() {
return this.skillModels;
}
@Override
public String getIdentifier() {
return this.identifier;
}
@Override
public void setEntityType(EntityType entityType) {
if(ValidationHandler.isNull(entityType)) return;
this.entityType = entityType;
}
@Override
public EntityType getEntityType() {
return this.entityType;
}
@Override
public void setMaxHealth(double health) {
this.health = health;
}
@Override
public double getMaxHealth() {
return this.health;
}
@Override
public void setDisplayName(String displayName) {
if(ValidationHandler.isNull(displayName)) return;
this.displayName = displayName;
}
@Override
public String getDisplayName() {
return this.displayName;
}
@Override
public void setDescription(List<String> description) {
if(ValidationHandler.isNull(description)) return;
this.description = description;
}
@Override
public List<String> getDescription() {
return this.description;
}
}

View File

@ -0,0 +1,45 @@
package net.aminecraftdev.custombosses.models;
import net.aminecraftdev.custombosses.handlers.IIdentifier;
import net.aminecraftdev.custombosses.skills.types.SkillTarget;
import net.aminecraftdev.custombosses.skills.types.SkillType;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 08-Mar-18
*/
public class CustomSkillModel implements IIdentifier {
private SkillTarget skillTarget;
private SkillType skillType;
private String identifier;
public CustomSkillModel(String identifier, SkillTarget skillTarget, SkillType skillType) {
this.identifier = identifier;
setSkillTarget(skillTarget);
setSkillType(skillType);
}
@Override
public String getIdentifier() {
return this.identifier;
}
public SkillType getSkillType() {
return this.skillType;
}
public void setSkillType(SkillType skillType) {
this.skillType = skillType;
}
public SkillTarget getSkillTarget() {
return this.skillTarget;
}
public void setSkillTarget(SkillTarget skillTarget) {
this.skillTarget = skillTarget;
}
}

View File

@ -0,0 +1,35 @@
package net.aminecraftdev.custombosses.skills;
import net.aminecraftdev.custombosses.handlers.ValidationHandler;
import net.aminecraftdev.custombosses.models.CustomSkillModel;
import net.aminecraftdev.custombosses.skills.base.CustomSkill;
import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity;
import java.util.ArrayList;
import java.util.List;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 08-Mar-18
*/
public class CustomCommandSkill extends CustomSkill {
private List<String> commands = new ArrayList<>();
public CustomCommandSkill(String identifier, CustomSkillModel customSkillModel, List<String> commands) {
super(identifier, customSkillModel);
if(ValidationHandler.isNull(commands)) return;
this.commands.addAll(commands);
}
@Override
public void executeSkill(LivingEntity livingEntity) {
for(String command : this.commands) {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.replace("%player%", livingEntity.getName()));
}
}
}

View File

@ -0,0 +1,12 @@
package net.aminecraftdev.custombosses.skills;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 08-Mar-18
*/
public class CustomEffectSkill {
//TODO: Setup EffectSkill type
}

View File

@ -0,0 +1,12 @@
package net.aminecraftdev.custombosses.skills;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 08-Mar-18
*/
public class CustomPotionSkill {
//TODO: Setup PotionSkill type
}

View File

@ -0,0 +1,32 @@
package net.aminecraftdev.custombosses.skills.base;
import net.aminecraftdev.custombosses.handlers.IIdentifier;
import net.aminecraftdev.custombosses.models.CustomSkillModel;
import org.bukkit.entity.LivingEntity;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 08-Mar-18
*/
public abstract class CustomSkill implements IIdentifier {
private CustomSkillModel customSkillModel;
private String identifier;
public CustomSkill(String identifier, CustomSkillModel customSkillModel) {
this.identifier = identifier;
this.customSkillModel = customSkillModel;
}
@Override
public String getIdentifier() {
return this.identifier;
}
public CustomSkillModel getCustomSkillModel() {
return this.customSkillModel;
}
public abstract void executeSkill(LivingEntity livingEntity);
}

View File

@ -0,0 +1,15 @@
package net.aminecraftdev.custombosses.skills.types;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 08-Mar-18
*/
public enum SkillTarget {
BOSS,
RANDOM,
ONE,
NEARBY
}

View File

@ -0,0 +1,14 @@
package net.aminecraftdev.custombosses.skills.types;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 08-Mar-18
*/
public enum SkillType {
COMMAND,
POTION,
CUSTOM
}

View File

@ -0,0 +1,34 @@
package net.aminecraftdev.custombosses.utils;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 08-Mar-18
*/
public enum Debug {
NULL_CHECK("An object was found as null when it should not be null.");
private String message;
Debug(String message) {
this.message = message;
}
public void debug(Object... objects) {
int current = 0;
String message = this.message;
for(Object object : objects) {
String placeholder = "{" + current + "}";
message = message.replace(placeholder, object.toString());
current += 1;
}
// TODO: Check config if debug is enabled and print message
throw new IllegalArgumentException(message);
}
}

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.spigotmc:spigot:1.11.2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.milkbowl.vault:VaultAPI:1.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:bukkit:1.9-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-lang:commons-lang:2.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: junit:junit:4.10" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.2.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.avaje:ebean:2.8.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.persistence:persistence-api:1.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.15" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:worldguard:6.0.0-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.spigot:bukkit-classloader-check:1.8-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:commandbook:2.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.sf.opencsv:opencsv:2.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:worldedit:6.0.0-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: de.schlichtherle:truezip:6.8.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: rhino:js:1.7R2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:10.0.1" level="project" />
</component>
</module>

View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>CustomBosses</artifactId>
<groupId>net.aminecraftdev.custombosses</groupId>
<version>3.0.0.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>FactionHelper</artifactId>
<build>
<defaultGoal>clean package install</defaultGoal>
<directory>target</directory>
<finalName>${project.artifactId}-${project.version}</finalName>
<sourceDirectory>${basedir}/src/</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.4</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,20 @@
package net.aminecraftdev.custombosses.utils;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 08-Mar-18
*/
public interface IFactionHelper {
boolean isFriendly(Player a, Player b);
boolean isFriendly(Player a, Location location);
boolean isInWarzone(Location location);
boolean isInClaimedLand(Location location);
}

16
pom.xml
View File

@ -7,15 +7,22 @@
<groupId>net.aminecraftdev.custombosses</groupId>
<artifactId>CustomBosses</artifactId>
<packaging>pom</packaging>
<version>3.0.0.1</version>
<version>3.0.0.0</version>
<modules>
<module>api-modules/FactionsM</module>
<module>api-modules/FactionsOne</module>
<module>api-modules/FactionsUUID</module>
<module>api-modules/PluginAPI</module>
<module>api-modules/LegacyFactions</module>
<module>plugin-modules/Core</module>
<module>plugin-modules/FactionHelper</module>
</modules>
<properties>
<plugin.version>3.0.0a</plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>com.spigotmc</groupId>
@ -43,4 +50,11 @@
</dependency>
</dependencies>
<repositories>
<repository>
<id>vault-repo</id>
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
</repository>
</repositories>
</project>