Initial commit

This commit is contained in:
Auxilor 2020-08-28 16:14:36 +01:00
commit d0f72ac3d1
447 changed files with 22506 additions and 0 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
# Project exclude paths
/API/target/
/Plugin/target/
/v1_15_R1/target/
/v1_16_R1/target/
/v1_16_R2/target/

30
API/API.iml Normal file
View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>SPIGOT</platformType>
</autoDetectTypes>
</configuration>
</facet>
</component>
<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/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spigotmc:spigot-api:1.16.1-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.google.guava:guava:21.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.8.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.md-5:bungeecord-chat:1.16-R0.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.26" level="project" />
</component>
</module>

30
API/pom.xml Normal file
View File

@ -0,0 +1,30 @@
<?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>parent</artifactId>
<groupId>com.willfp.ecoenchants</groupId>
<version>4.1.0-pre10</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<artifactId>API</artifactId>
<name>EcoEnchants API</name>
<packaging>jar</packaging>
<version>${project.parent.version}</version>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,8 @@
package com.willfp.ecoenchants.API;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
public interface BlockBreakWrapper {
public void breakBlock(Player player, Block block);
}

View File

@ -0,0 +1,7 @@
package com.willfp.ecoenchants.API;
import org.bukkit.entity.Player;
public interface CooldownWrapper {
double getAttackCooldown(Player player);
}

View File

@ -0,0 +1,8 @@
package com.willfp.ecoenchants.API;
import org.bukkit.enchantments.Enchantment;
public interface NMSEnchantManagerWrapper {
void init(Enchantment enchantment);
void debug();
}

View File

@ -0,0 +1,29 @@
package com.willfp.ecoenchants.API;
import org.bukkit.Material;
import java.util.HashSet;
import java.util.Set;
public interface TargetWrapper {
Set<Material> TOOL = new HashSet<>();
Set<Material> ROD = new HashSet<>();
Set<Material> ARMOR = new HashSet<>();
Set<Material> ALL = new HashSet<>();
Set<Material> AXE = new HashSet<>();
Set<Material> BOOK = new HashSet<>();
Set<Material> PICKAXE = new HashSet<>();
Set<Material> HOE = new HashSet<>();
Set<Material> SHOVEL = new HashSet<>();
Set<Material> SWORD = new HashSet<>();
Set<Material> HELMET = new HashSet<>();
Set<Material> CHESTPLATE = new HashSet<>();
Set<Material> LEGGINGS = new HashSet<>();
Set<Material> BOOTS = new HashSet<>();
Set<Material> ELYTRA = new HashSet<>();
Set<Material> BOW = new HashSet<>();
Set<Material> CROSSBOW = new HashSet<>();
Set<Material> SHEARS = new HashSet<>();
Set<Material> TRIDENT = new HashSet<>();
Set<Material> SHIELD = new HashSet<>();
}

View File

@ -0,0 +1,8 @@
package com.willfp.ecoenchants.API;
import org.bukkit.entity.Trident;
import org.bukkit.inventory.ItemStack;
public interface TridentStackWrapper {
ItemStack getTridentStack(Trident trident);
}

129
Plugin/plugin.iml Normal file
View File

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>SPIGOT</platformType>
</autoDetectTypes>
</configuration>
</facet>
</component>
<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$/../Expansions/src/main/java">
<sourceFolder url="file://$MODULE_DIR$/../Expansions/src/main/java" isTestSource="false" />
</content>
<content url="file://$MODULE_DIR$/../Expansions/src/main/resources">
<sourceFolder url="file://$MODULE_DIR$/../Expansions/src/main/resources" type="java-resource" />
</content>
<content url="file://$MODULE_DIR$/../Expansions/src/test/java">
<sourceFolder url="file://$MODULE_DIR$/../Expansions/src/test/java" isTestSource="true" />
</content>
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="API" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spigotmc:spigot-api:1.15-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.google.guava:guava:21.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.md-5:bungeecord-chat:1.13-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.25" level="project" />
<orderEntry type="library" name="Maven: com.willfp.ecoenchants:API:4.1.0-pre10" level="project" />
<orderEntry type="module" module-name="v1_15_R1" />
<orderEntry type="module" module-name="v1_16_R1" />
<orderEntry type="module" module-name="v1_16_R2" />
<orderEntry type="library" name="Maven: org.apache.maven:maven-artifact:3.0.3" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.plexus:plexus-utils:2.0.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.worldguard:worldguard-bukkit:7.0.4-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.worldedit:worldedit-bukkit:7.2.0-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.worldguard:worldguard-core:7.0.4-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.worldguard.worldguard-libs:core:7.0.4-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.worldedit:worldedit-core:7.2.0-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.worldedit.worldedit-libs:core:7.2.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: net.java.truevfs:truevfs-profile-default_2.13:0.12.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.scala-lang:scala-library:2.13.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truevfs:truevfs-driver-http:0.12.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truevfs:truevfs-kernel-spec:0.12.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truecommons:truecommons-annotations:2.5.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.findbugs:annotations:3.0.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truecommons:truecommons-cio:2.5.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truecommons:truecommons-io:2.5.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truecommons:truecommons-services:2.5.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truecommons:truecommons-logging:2.5.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.inject:javax.inject:1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.slf4j:jcl-over-slf4j:1.7.28" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truevfs:truevfs-driver-odf:0.12.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truevfs:truevfs-comp-zipdriver:0.12.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truevfs:truevfs-comp-zip:0.12.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bouncycastle:bcprov-jdk15on:1.63" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truevfs:truevfs-driver-tar:0.12.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truevfs:truevfs-comp-tardriver:0.12.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.commons:commons-compress:1.19" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truevfs:truevfs-driver-tar-bzip2:0.12.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truevfs:truevfs-driver-tar-gzip:0.12.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truevfs:truevfs-driver-tar-xz:0.12.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.tukaani:xz:1.8" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truevfs:truevfs-driver-zip-raes:0.12.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truevfs:truevfs-profile-base_2.13:0.12.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truevfs:truevfs-access-swing:0.12.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truevfs:truevfs-access:0.12.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truevfs:truevfs-driver-file:0.12.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truevfs:truevfs-driver-jar:0.12.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truevfs:truevfs-driver-zip:0.12.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truevfs:truevfs-comp-ibm437:0.12.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truevfs:truevfs-kernel-impl_2.13:0.12.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truecommons:truecommons-key-console:2.5.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truecommons:truecommons-key-default:2.5.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truecommons:truecommons-key-swing:2.5.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truecommons:truecommons-key-macosx:2.5.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truecommons:truecommons-key-spec:2.5.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.truecommons:truecommons-shed:2.5.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.java.dev.jna:jna:4.1.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.mozilla:rhino-runtime:1.7.12" 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: org.slf4j:slf4j-api:1.7.26" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: it.unimi.dsi:fastutil:8.2.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.antlr:antlr4-runtime:4.7.2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.flywaydb:flyway-core:3.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: io.papermc:paperlib:1.0.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:commandbook:2.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bstats:bstats-bukkit:1.7" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.TechFortress:GriefPrevention:16.14.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.massivecraft:Factions:1.6.9.5-U0.5.13" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.massivecraft:Factions-Legacy:1.6.9.5-U0.5.13" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: mkremins:fanciful:0.4.0-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.darkblade12:particleeffect:1.8.0-fuuid" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: me.lucko:commodore:1.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.mojang:brigadier:1.0.14" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spongepowered:configurate-hocon:3.6.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spongepowered:configurate-core:3.6.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.typesafe:config:1.3.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.kitteh:paste-gg-api:0.9.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.httpcomponents:fluent-hc:4.5.5" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.httpcomponents:httpclient:4.5.5" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.httpcomponents:httpcore:4.4.9" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-codec:commons-codec:1.10" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-logging:commons-logging:1.2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.TownyAdvanced:Towny:0.96.2.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.angeschossen:LandsAPI:4.7.3" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains:annotations:19.0.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: n3kas.ae:aeapi:1.0.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: fr.neatmonster:nocheatplus:3.16.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: de.janmm14:aac-api:4.2.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.jiangdashao:matrix-api-repo:317d4635fd" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: me.vagdedes:SpartanAPI:1.0.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.8.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.comphenix.protocol:ProtocolLib:4.5.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: cglib:cglib-nodep:3.2.5" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.comphenix.executors:BukkitExecutors:1.1-SNAPSHOT" level="project" />
</component>
</module>

236
Plugin/pom.xml Normal file
View File

@ -0,0 +1,236 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>parent</artifactId>
<groupId>com.willfp.ecoenchants</groupId>
<version>4.1.0-pre10</version>
</parent>
<artifactId>plugin</artifactId>
<packaging>jar</packaging>
<name>EcoEnchants</name>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<defaultGoal>clean package install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<excludePackageNames>com.willfp.ecoenchants.enchantments.ecoenchants.*</excludePackageNames>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>install-external-non-maven1-jar</id>
<phase>clean</phase>
<configuration>
<repositoryLayout>default</repositoryLayout>
<groupId>n3kas.ae</groupId>
<artifactId>aeapi</artifactId>
<version>1.0.0</version>
<file>${project.parent.basedir}/lib/AdvancedEnchantments.jar</file>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
<goals>
<goal>install-file</goal>
</goals>
</execution>
<execution>
<id>install-external-non-maven2-jar</id>
<phase>clean</phase>
<configuration>
<repositoryLayout>default</repositoryLayout>
<groupId>me.vagdedes</groupId>
<artifactId>SpartanAPI</artifactId>
<version>1.0.0</version>
<file>${project.parent.basedir}/lib/SpartanAPI.jar</file>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
<goals>
<goal>install-file</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.15-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.willfp.ecoenchants</groupId>
<artifactId>API</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.willfp.ecoenchants</groupId>
<artifactId>v1_15_R1</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.willfp.ecoenchants</groupId>
<artifactId>v1_16_R1</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.willfp.ecoenchants</groupId>
<artifactId>v1_16_R2</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId>
<version>7.0.4-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>com.destroystokyo.paper</groupId>
<artifactId>paper-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.TechFortress</groupId>
<artifactId>GriefPrevention</artifactId>
<version>16.14.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.massivecraft</groupId>
<artifactId>Factions</artifactId>
<version>1.6.9.5-U0.5.13</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.TownyAdvanced</groupId>
<artifactId>Towny</artifactId>
<version>0.96.2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.angeschossen</groupId>
<artifactId>LandsAPI</artifactId>
<version>4.7.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>19.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>n3kas.ae</groupId>
<artifactId>aeapi</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>fr.neatmonster</groupId>
<artifactId>nocheatplus</artifactId>
<version>3.16.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.janmm14</groupId>
<artifactId>aac-api</artifactId>
<version>4.2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.jiangdashao</groupId>
<artifactId>matrix-api-repo</artifactId>
<version>317d4635fd</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.vagdedes</groupId>
<artifactId>SpartanAPI</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>4.5.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,96 @@
package com.willfp.ecoenchants;
import com.comphenix.protocol.ProtocolManager;
import com.willfp.ecoenchants.loader.Loader;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.HashMap;
/**
* The Main class for EcoEnchants
*/
public class Main extends JavaPlugin {
private static Main instance;
/**
* Config versions for config.yml and lang.yml
*/
public static final HashMap<String, Double> configVersions = new HashMap<String, Double>() {{
put("config", 4.1);
put("lang", 4.01);
}};
/**
* Is the plugin outdated
*/
public static boolean outdated;
/**
* Newest available plugin version
*/
public static String newVersion;
/**
* Has worldguard?
*/
public static boolean hasWG;
/**
* Has GriefPrevention?
*/
public static boolean hasGP;
/**
* Has FactionsUUID?
*/
public static boolean hasFactionsUUID;
/**
* Has Towny?
*/
public static boolean hasTowny;
/**
* Has Lands?
*/
public static boolean hasLands;
/**
* Has AdvancedEnchantments?
*/
public static boolean hasAE;
/**
* ProtocolLib
*/
public ProtocolManager protocolManager;
/**
* Calls {@link Loader#load()}
*/
public void onEnable() {
Loader.load();
}
/**
* Calls {@link Loader#unload()}
*/
public void onDisable() {
Loader.unload();
}
/**
* Sets instance
*/
public void onLoad() {
instance = this;
}
/**
* Get plugin instance
* @return Plugin instance
*/
public static Main getInstance() {
return instance;
}
}

View File

@ -0,0 +1,30 @@
package com.willfp.ecoenchants.anticheat;
import com.willfp.ecoenchants.Main;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class AnticheatManager {
private static final Set<AnticheatWrapper> anticheats = new HashSet<>();
public static void registerAnticheat(AnticheatWrapper anticheat) {
if(anticheat instanceof Listener) {
Bukkit.getPluginManager().registerEvents((Listener) anticheat, Main.getInstance());
}
anticheats.add(anticheat);
}
public static void exemptPlayer(Player player) {
anticheats.forEach(anticheat -> anticheat.exempt(player));
}
public static void unexemptPlayer(Player player) {
anticheats.forEach(anticheat -> anticheat.unexempt(player));
}
}

View File

@ -0,0 +1,23 @@
package com.willfp.ecoenchants.anticheat;
import org.bukkit.entity.Player;
public interface AnticheatWrapper {
/**
* Get the name of anticheat
* @return The name
*/
String getPluginName();
/**
* Exempt a player from checks
* @param player The player to exempt
*/
void exempt(Player player);
/**
* Unexempt a player from checks
* @param player The player to unexempt
*/
void unexempt(Player player);
}

View File

@ -0,0 +1,40 @@
package com.willfp.ecoenchants.anticheat.anticheats;
import com.willfp.ecoenchants.anticheat.AnticheatWrapper;
import me.konsolas.aac.api.PlayerViolationEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
public final class AnticheatAAC implements AnticheatWrapper, Listener {
private final Set<UUID> exempt = new HashSet<>();
@Override
public String getPluginName() {
return "AAC";
}
@Override
public void exempt(Player player) {
this.exempt.add(player.getUniqueId());
}
@Override
public void unexempt(Player player) {
this.exempt.remove(player.getUniqueId());
}
@EventHandler(priority = EventPriority.LOWEST)
private void onViolate(PlayerViolationEvent event) {
if (!exempt.contains(event.getPlayer().getUniqueId())) {
return;
}
event.setCancelled(true);
}
}

View File

@ -0,0 +1,40 @@
package com.willfp.ecoenchants.anticheat.anticheats;
import com.willfp.ecoenchants.anticheat.AnticheatWrapper;
import me.rerere.matrix.api.events.PlayerViolationEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
public final class AnticheatMatrix implements AnticheatWrapper, Listener {
private final Set<UUID> exempt = new HashSet<>();
@Override
public String getPluginName() {
return "Matrix";
}
@Override
public void exempt(Player player) {
this.exempt.add(player.getUniqueId());
}
@Override
public void unexempt(Player player) {
this.exempt.remove(player.getUniqueId());
}
@EventHandler(priority = EventPriority.LOWEST)
private void onViolate(PlayerViolationEvent event) {
if (!exempt.contains(event.getPlayer().getUniqueId())) {
return;
}
event.setCancelled(true);
}
}

View File

@ -0,0 +1,37 @@
package com.willfp.ecoenchants.anticheat.anticheats;
import com.willfp.ecoenchants.anticheat.AnticheatWrapper;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager;
import org.bukkit.entity.Player;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
public final class AnticheatNCP implements AnticheatWrapper {
private final Set<UUID> exempt = new HashSet<>();
@Override
public String getPluginName() {
return "NCP";
}
@Override
public void exempt(Player player) {
if (!NCPExemptionManager.isExempted(player, CheckType.ALL)) {
return;
}
if (exempt.add(player.getUniqueId())) {
NCPExemptionManager.exemptPermanently(player, CheckType.ALL);
}
}
@Override
public void unexempt(Player player) {
if (exempt.remove(player.getUniqueId())) {
NCPExemptionManager.unexempt(player, CheckType.ALL);
}
}
}

View File

@ -0,0 +1,40 @@
package com.willfp.ecoenchants.anticheat.anticheats;
import com.willfp.ecoenchants.anticheat.AnticheatWrapper;
import me.vagdedes.spartan.api.PlayerViolationEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
public final class AnticheatSpartan implements AnticheatWrapper, Listener {
private final Set<UUID> exempt = new HashSet<>();
@Override
public String getPluginName() {
return "Spartan";
}
@Override
public void exempt(Player player) {
this.exempt.add(player.getUniqueId());
}
@Override
public void unexempt(Player player) {
this.exempt.remove(player.getUniqueId());
}
@EventHandler(priority = EventPriority.LOWEST)
private void onViolate(PlayerViolationEvent event) {
if (!exempt.contains(event.getPlayer().getUniqueId())) {
return;
}
event.setCancelled(true);
}
}

View File

@ -0,0 +1,52 @@
package com.willfp.ecoenchants.anvil;
import com.willfp.ecoenchants.Main;
import com.willfp.ecoenchants.util.Pair;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.PrepareAnvilEvent;
import org.bukkit.inventory.ItemStack;
public class AnvilListeners implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onAnvilPrepare(PrepareAnvilEvent event) {
ItemStack left = event.getInventory().getItem(0);
ItemStack right = event.getInventory().getItem(1);
ItemStack out = event.getResult();
String name = event.getInventory().getRenameText();
event.setResult(null);
event.getInventory().setItem(2, null);
if(event.getViewers().isEmpty()) return; // Prevent ArrayIndexOutOfBoundsException when using AnvilGUI
Player player = (Player) event.getViewers().get(0);
Pair<ItemStack, Integer> newOut = AnvilMerge.doMerge(left, right, out, name);
if(newOut.getKey() == null) {
newOut.setKey(new ItemStack(Material.AIR, 0));
}
int modCost;
if(newOut.getValue() == null) {
modCost = 0;
} else {
modCost = newOut.getValue();
}
final int cost = modCost + event.getInventory().getRepairCost();
Bukkit.getScheduler().runTask(Main.getInstance(), () -> {
event.getInventory().setRepairCost(cost);
event.setResult(newOut.getKey());
event.getInventory().setItem(2, newOut.getKey());
player.updateInventory();
});
}
}

View File

@ -0,0 +1,219 @@
package com.willfp.ecoenchants.anvil;
import com.willfp.ecoenchants.config.ConfigManager;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.lore.EnchantLore;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.Pair;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
public class AnvilMerge {
/**
* Merge items in anvil
*
* @param left The {@link ItemStack} on the left of the anvil
* @param right The {@link ItemStack} in the middle of the anvil
* @param old The previous {@link ItemStack} result
* @param name The anvil display name
* @return The result, stored as a {@link Pair} of {@link ItemStack} and {@link Integer}.
*/
public static Pair<ItemStack, Integer> doMerge(ItemStack left, ItemStack right, ItemStack old, String name) {
// Here so it can be accessed later (scope)
int outDamage = -1;
if(old != null) {
if (old.getItemMeta() instanceof Damageable) {
outDamage = ((Damageable) old.getItemMeta()).getDamage();
}
}
if(left == null) return new Pair<>(null, null);
if(left.getEnchantments().containsKey(EcoEnchants.PERMANENCE_CURSE)) return new Pair<>(null, null);
if(!Target.Applicable.ALL.getMaterials().contains(left.getType()) || right == null || !Target.Applicable.ALL.getMaterials().contains(right.getType())) {
ItemStack out = left.clone();
ItemMeta outMeta = out.getItemMeta();
outMeta.setDisplayName(name);
if(left.getItemMeta().getDisplayName().equals(name)) {
if(left.getItemMeta() instanceof Damageable) {
int leftDamage = ((Damageable) left.getItemMeta()).getDamage();
if(outDamage >= leftDamage || outDamage == -1) {
return new Pair<>(null, null);
} else {
((Damageable) outMeta).setDamage(outDamage);
}
} else {
return new Pair<>(null, null);
}
if(right == null) {
return new Pair<>(null, null);
}
}
out.setItemMeta(outMeta);
if(out.equals(left)) return new Pair<>(null, null);
return new Pair<>(out, 0);
}
if(left.getItemMeta() instanceof Damageable && right.getItemMeta() instanceof EnchantmentStorageMeta) {
outDamage = ((Damageable) left.getItemMeta()).getDamage();
}
if(!left.getType().equals(right.getType()) && !(right.getItemMeta() instanceof EnchantmentStorageMeta)) return new Pair<>(null, null);
HashMap<Enchantment, Integer> leftEnchants = new HashMap<>();
HashMap<Enchantment, Integer> rightEnchants = new HashMap<>();
Map<Enchantment, Integer> outEnchants = new HashMap<>();
if(left.getItemMeta() instanceof EnchantmentStorageMeta) {
leftEnchants.putAll(((EnchantmentStorageMeta) left.getItemMeta()).getStoredEnchants());
} else {
leftEnchants.putAll(left.getItemMeta().getEnchants());
}
if(right.getItemMeta() instanceof EnchantmentStorageMeta) {
rightEnchants.putAll(((EnchantmentStorageMeta) right.getItemMeta()).getStoredEnchants());
} else {
rightEnchants.putAll(right.getItemMeta().getEnchants());
}
leftEnchants.forEach(((enchantment, integer) -> {
int level = integer;
if(rightEnchants.containsKey(enchantment)) {
int rightLevel = rightEnchants.get(enchantment);
if(rightLevel > level) {
level = rightLevel;
}
else if(rightLevel == level) {
if(rightLevel > enchantment.getMaxLevel() && ConfigManager.getConfig().getBool("anvil.allow-combining-unsafe")) {
level++;
} else if((rightLevel + 1) <= enchantment.getMaxLevel() || ConfigManager.getConfig().getBool("anvil.allow-unsafe-levels")) {
level++;
}
}
rightEnchants.remove(enchantment);
}
outEnchants.put(enchantment, level);
}));
rightEnchants.forEach(((enchantment, integer) -> {
AtomicBoolean doesConflict = new AtomicBoolean(false);
if(EcoEnchants.getFromEnchantment(enchantment) != null && EcoEnchants.getFromEnchantment(enchantment).getType().equals(EcoEnchant.EnchantmentType.SPECIAL) && EcoEnchants.hasAnyOfType(left, EcoEnchant.EnchantmentType.SPECIAL)) doesConflict.set(true);
if(EcoEnchants.getFromEnchantment(enchantment) != null && EcoEnchants.getFromEnchantment(enchantment).getType().equals(EcoEnchant.EnchantmentType.ARTIFACT) && EcoEnchants.hasAnyOfType(left, EcoEnchant.EnchantmentType.ARTIFACT)) doesConflict.set(true);
leftEnchants.forEach(((enchantment1, integer1) -> {
if(enchantment.conflictsWith(enchantment1)) doesConflict.set(true);
if(enchantment1.conflictsWith(enchantment)) doesConflict.set(true);
}));
boolean canEnchantItem = enchantment.canEnchantItem(left);
if(left.getItemMeta() instanceof EnchantmentStorageMeta) canEnchantItem = true;
if(canEnchantItem && !doesConflict.get()) {
outEnchants.put(enchantment, integer);
}
}));
// Test if the output is the same as left
if(outEnchants.equals(leftEnchants) && left.getItemMeta().getDisplayName().equals(name)) {
if(left.getItemMeta() instanceof Damageable) {
int leftDamage = ((Damageable) left.getItemMeta()).getDamage();
if(outDamage == leftDamage) {
return new Pair<>(null, null);
}
}
}
ItemStack output = left.clone();
if(output.getItemMeta() instanceof EnchantmentStorageMeta) {
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) output.getItemMeta();
meta.getStoredEnchants().forEach(((enchantment, integer) -> {
meta.removeStoredEnchant(enchantment);
}));
outEnchants.forEach(((enchantment, integer) -> {
meta.addStoredEnchant(enchantment, integer, ConfigManager.getConfig().getBool("anvil.allow-existing-unsafe-levels") || ConfigManager.getConfig().getBool("anvil.allow-unsafe-levels"));
}));
meta.setDisplayName(name);
output.setItemMeta(meta);
} else {
ItemMeta meta = output.getItemMeta();
meta.getEnchants().forEach(((enchantment, integer) -> {
meta.removeEnchant(enchantment);
}));
outEnchants.forEach(((enchantment, integer) -> {
meta.addEnchant(enchantment, integer, ConfigManager.getConfig().getBool("anvil.allow-existing-unsafe-levels") || ConfigManager.getConfig().getBool("anvil.allow-unsafe-levels"));
}));
if(output.getItemMeta() instanceof Damageable) {
((Damageable) meta).setDamage(outDamage);
}
meta.setDisplayName(name);
output.setItemMeta(meta);
}
// Calculate difference in enchant levels
int totalEnchantLevelDelta;
AtomicInteger outEnchantLevels = new AtomicInteger();
AtomicInteger inEnchantLevels = new AtomicInteger();
outEnchants.forEach(((enchantment, integer) -> {
if(EcoEnchants.getFromEnchantment(enchantment) != null) {
outEnchantLevels.addAndGet(integer);
}
}));
leftEnchants.forEach((((enchantment, integer) -> {
if(EcoEnchants.getFromEnchantment(enchantment) != null) {
outEnchantLevels.addAndGet(integer);
}
})));
totalEnchantLevelDelta = Math.abs(outEnchantLevels.intValue() - inEnchantLevels.intValue());
if(output.equals(left)) return new Pair<>(null, null);
if(ConfigManager.getConfig().getBool("anvil.cost-exponent.enabled")) {
double exponent = ConfigManager.getConfig().getDouble("anvil.cost-exponent.exponent");
int prevDelta = totalEnchantLevelDelta;
double costMultiplier = Math.pow(exponent, totalEnchantLevelDelta);
double modifiedCost = Math.ceil((double) totalEnchantLevelDelta * costMultiplier);
totalEnchantLevelDelta = (int) modifiedCost;
if(prevDelta > 0 && totalEnchantLevelDelta == 0) {
totalEnchantLevelDelta = prevDelta;
}
}
return new Pair<>(output, totalEnchantLevelDelta);
}
}

View File

@ -0,0 +1,727 @@
package com.willfp.ecoenchants.bstats;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.ServicePriority;
import javax.net.ssl.HttpsURLConnection;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.zip.GZIPOutputStream;
/**
* bStats collects some data for plugin authors.
* <p>
* Check out https://bStats.org/ to learn more about bStats!
*/
@SuppressWarnings({"WeakerAccess", "unused"})
public class Metrics {
static {
// You can use the property to disable the check in your test environment
if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) {
// Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D
final String defaultPackage = new String(
new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'});
final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
// We want to make sure nobody just copy & pastes the example and use the wrong package names
if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage)) {
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
}
}
}
// The version of this bStats class
public static final int B_STATS_VERSION = 1;
// The url to which the data is sent
private static final String URL = "https://bStats.org/submitData/bukkit";
// Is bStats enabled on this server?
private final boolean enabled;
// Should failed requests be logged?
private static boolean logFailedRequests;
// Should the sent data be logged?
private static boolean logSentData;
// Should the response text be logged?
private static boolean logResponseStatusText;
// The uuid of the server
private static String serverUUID;
// The plugin
private final Plugin plugin;
// The plugin id
private final int pluginId;
// A list with all custom charts
private final List<CustomChart> charts = new ArrayList<>();
/**
* Class constructor.
*
* @param plugin The plugin which stats should be submitted.
* @param pluginId The id of the plugin.
* It can be found at <a href="https://bstats.org/what-is-my-plugin-id">What is my plugin id?</a>
*/
public Metrics(Plugin plugin, int pluginId) {
if (plugin == null) {
throw new IllegalArgumentException("Plugin cannot be null!");
}
this.plugin = plugin;
this.pluginId = pluginId;
// Get the config file
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
File configFile = new File(bStatsFolder, "config.yml");
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
// Check if the config file exists
if (!config.isSet("serverUuid")) {
// Add default values
config.addDefault("enabled", true);
// Every server gets it's unique random id.
config.addDefault("serverUuid", UUID.randomUUID().toString());
// Should failed request be logged?
config.addDefault("logFailedRequests", false);
// Should the sent data be logged?
config.addDefault("logSentData", false);
// Should the response text be logged?
config.addDefault("logResponseStatusText", false);
// Inform the server owners about bStats
config.options().header(
"bStats collects some data for plugin authors like how many servers are using their plugins.\n" +
"To honor their work, you should not disable it.\n" +
"This has nearly no effect on the server performance!\n" +
"Check out https://bStats.org/ to learn more :)"
).copyDefaults(true);
try {
config.save(configFile);
} catch (IOException ignored) {
}
}
// Load the data
enabled = config.getBoolean("enabled", true);
serverUUID = config.getString("serverUuid");
logFailedRequests = config.getBoolean("logFailedRequests", false);
logSentData = config.getBoolean("logSentData", false);
logResponseStatusText = config.getBoolean("logResponseStatusText", false);
if (enabled) {
boolean found = false;
// Search for all other bStats Metrics classes to see if we are the first one
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
try {
service.getField("B_STATS_VERSION"); // Our identifier :)
found = true; // We aren't the first
break;
} catch (NoSuchFieldException ignored) {
}
}
// Register our service
Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal);
if (!found) {
// We are the first!
startSubmitting();
}
}
}
/**
* Checks if bStats is enabled.
*
* @return Whether bStats is enabled or not.
*/
public boolean isEnabled() {
return enabled;
}
/**
* Adds a custom chart.
*
* @param chart The chart to add.
*/
public void addCustomChart(CustomChart chart) {
if (chart == null) {
throw new IllegalArgumentException("Chart cannot be null!");
}
charts.add(chart);
}
/**
* Starts the Scheduler which submits our data every 30 minutes.
*/
private void startSubmitting() {
final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
if (!plugin.isEnabled()) { // Plugin was disabled
timer.cancel();
return;
}
// Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler
// Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
Bukkit.getScheduler().runTask(plugin, () -> submitData());
}
}, 1000 * 60 * 5, 1000 * 60 * 30);
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
// WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
// WARNING: Just don't do it!
}
/**
* Gets the plugin specific data.
* This method is called using Reflection.
*
* @return The plugin specific data.
*/
public JsonObject getPluginData() {
JsonObject data = new JsonObject();
String pluginName = plugin.getDescription().getName();
String pluginVersion = plugin.getDescription().getVersion();
data.addProperty("pluginName", pluginName); // Append the name of the plugin
data.addProperty("id", pluginId); // Append the id of the plugin
data.addProperty("pluginVersion", pluginVersion); // Append the version of the plugin
JsonArray customCharts = new JsonArray();
for (CustomChart customChart : charts) {
// Add the data of the custom charts
JsonObject chart = customChart.getRequestJsonObject();
if (chart == null) { // If the chart is null, we skip it
continue;
}
customCharts.add(chart);
}
data.add("customCharts", customCharts);
return data;
}
/**
* Gets the server specific data.
*
* @return The server specific data.
*/
private JsonObject getServerData() {
// Minecraft specific data
int playerAmount;
try {
// Around MC 1.8 the return type was changed to a collection from an array,
// This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
} catch (Exception e) {
playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
}
int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
String bukkitVersion = Bukkit.getVersion();
String bukkitName = Bukkit.getName();
// OS/Java specific data
String javaVersion = System.getProperty("java.version");
String osName = System.getProperty("os.name");
String osArch = System.getProperty("os.arch");
String osVersion = System.getProperty("os.version");
int coreCount = Runtime.getRuntime().availableProcessors();
JsonObject data = new JsonObject();
data.addProperty("serverUUID", serverUUID);
data.addProperty("playerAmount", playerAmount);
data.addProperty("onlineMode", onlineMode);
data.addProperty("bukkitVersion", bukkitVersion);
data.addProperty("bukkitName", bukkitName);
data.addProperty("javaVersion", javaVersion);
data.addProperty("osName", osName);
data.addProperty("osArch", osArch);
data.addProperty("osVersion", osVersion);
data.addProperty("coreCount", coreCount);
return data;
}
/**
* Collects the data and sends it afterwards.
*/
private void submitData() {
final JsonObject data = getServerData();
JsonArray pluginData = new JsonArray();
// Search for all other bStats Metrics classes to get their plugin data
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
try {
service.getField("B_STATS_VERSION"); // Our identifier :)
for (RegisteredServiceProvider<?> provider : Bukkit.getServicesManager().getRegistrations(service)) {
try {
Object plugin = provider.getService().getMethod("getPluginData").invoke(provider.getProvider());
if (plugin instanceof JsonObject) {
pluginData.add((JsonObject) plugin);
} else { // old bstats version compatibility
try {
Class<?> jsonObjectJsonSimple = Class.forName("org.json.simple.JSONObject");
if (plugin.getClass().isAssignableFrom(jsonObjectJsonSimple)) {
Method jsonStringGetter = jsonObjectJsonSimple.getDeclaredMethod("toJSONString");
jsonStringGetter.setAccessible(true);
String jsonString = (String) jsonStringGetter.invoke(plugin);
JsonObject object = new JsonParser().parse(jsonString).getAsJsonObject();
pluginData.add(object);
}
} catch (ClassNotFoundException e) {
// minecraft version 1.14+
if (logFailedRequests) {
this.plugin.getLogger().log(Level.SEVERE, "Encountered unexpected exception", e);
}
}
}
} catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {
}
}
} catch (NoSuchFieldException ignored) {
}
}
data.add("plugins", pluginData);
// Create a new thread for the connection to the bStats server
new Thread(() -> {
try {
// Send the data
sendData(plugin, data);
} catch (Exception e) {
// Something went wrong! :(
if (logFailedRequests) {
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
}
}
}).start();
}
/**
* Sends the data to the bStats server.
*
* @param plugin Any plugin. It's just used to get a logger instance.
* @param data The data to send.
*
* @throws Exception If the request failed.
*/
private static void sendData(Plugin plugin, JsonObject data) throws Exception {
if (data == null) {
throw new IllegalArgumentException("Data cannot be null!");
}
if (Bukkit.isPrimaryThread()) {
throw new IllegalAccessException("This method must not be called from the main thread!");
}
if (logSentData) {
plugin.getLogger().info("Sending data to bStats: " + data);
}
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
// Compress the data to save bandwidth
byte[] compressedData = compress(data.toString());
// Add headers
connection.setRequestMethod("POST");
connection.addRequestProperty("Accept", "application/json");
connection.addRequestProperty("Connection", "close");
connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
// Send data
connection.setDoOutput(true);
try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
outputStream.write(compressedData);
}
StringBuilder builder = new StringBuilder();
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
String line;
while ((line = bufferedReader.readLine()) != null) {
builder.append(line);
}
}
if (logResponseStatusText) {
plugin.getLogger().info("Sent data to bStats and received response: " + builder);
}
}
/**
* Gzips the given String.
*
* @param str The string to gzip.
*
* @return The gzipped String.
*
* @throws IOException If the compression failed.
*/
private static byte[] compress(final String str) throws IOException {
if (str == null) {
return null;
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) {
gzip.write(str.getBytes(StandardCharsets.UTF_8));
}
return outputStream.toByteArray();
}
/**
* Represents a custom chart.
*/
public abstract static class CustomChart {
// The id of the chart
final String chartId;
/**
* Class constructor.
*
* @param chartId The id of the chart.
*/
CustomChart(String chartId) {
if (chartId == null || chartId.isEmpty()) {
throw new IllegalArgumentException("ChartId cannot be null or empty!");
}
this.chartId = chartId;
}
private JsonObject getRequestJsonObject() {
JsonObject chart = new JsonObject();
chart.addProperty("chartId", chartId);
try {
JsonObject data = getChartData();
if (data == null) {
// If the data is null we don't send the chart.
return null;
}
chart.add("data", data);
} catch (Throwable t) {
if (logFailedRequests) {
Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t);
}
return null;
}
return chart;
}
protected abstract JsonObject getChartData() throws Exception;
}
/**
* Represents a custom simple pie.
*/
public static class SimplePie extends CustomChart {
private final Callable<String> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public SimplePie(String chartId, Callable<String> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
String value = callable.call();
if (value == null || value.isEmpty()) {
// Null = skip the chart
return null;
}
data.addProperty("value", value);
return data;
}
}
/**
* Represents a custom advanced pie.
*/
public static class AdvancedPie extends CustomChart {
private final Callable<Map<String, Integer>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public AdvancedPie(String chartId, Callable<Map<String, Integer>> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, Integer> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean allSkipped = true;
for (Map.Entry<String, Integer> entry : map.entrySet()) {
if (entry.getValue() == 0) {
continue; // Skip this invalid
}
allSkipped = false;
values.addProperty(entry.getKey(), entry.getValue());
}
if (allSkipped) {
// Null = skip the chart
return null;
}
data.add("values", values);
return data;
}
}
/**
* Represents a custom drilldown pie.
*/
public static class DrilldownPie extends CustomChart {
private final Callable<Map<String, Map<String, Integer>>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public DrilldownPie(String chartId, Callable<Map<String, Map<String, Integer>>> callable) {
super(chartId);
this.callable = callable;
}
@Override
public JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, Map<String, Integer>> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean reallyAllSkipped = true;
for (Map.Entry<String, Map<String, Integer>> entryValues : map.entrySet()) {
JsonObject value = new JsonObject();
boolean allSkipped = true;
for (Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet()) {
value.addProperty(valueEntry.getKey(), valueEntry.getValue());
allSkipped = false;
}
if (!allSkipped) {
reallyAllSkipped = false;
values.add(entryValues.getKey(), value);
}
}
if (reallyAllSkipped) {
// Null = skip the chart
return null;
}
data.add("values", values);
return data;
}
}
/**
* Represents a custom single line chart.
*/
public static class SingleLineChart extends CustomChart {
private final Callable<Integer> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public SingleLineChart(String chartId, Callable<Integer> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
int value = callable.call();
if (value == 0) {
// Null = skip the chart
return null;
}
data.addProperty("value", value);
return data;
}
}
/**
* Represents a custom multi line chart.
*/
public static class MultiLineChart extends CustomChart {
private final Callable<Map<String, Integer>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public MultiLineChart(String chartId, Callable<Map<String, Integer>> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, Integer> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean allSkipped = true;
for (Map.Entry<String, Integer> entry : map.entrySet()) {
if (entry.getValue() == 0) {
continue; // Skip this invalid
}
allSkipped = false;
values.addProperty(entry.getKey(), entry.getValue());
}
if (allSkipped) {
// Null = skip the chart
return null;
}
data.add("values", values);
return data;
}
}
/**
* Represents a custom simple bar chart.
*/
public static class SimpleBarChart extends CustomChart {
private final Callable<Map<String, Integer>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public SimpleBarChart(String chartId, Callable<Map<String, Integer>> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, Integer> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
for (Map.Entry<String, Integer> entry : map.entrySet()) {
JsonArray categoryValues = new JsonArray();
categoryValues.add(new JsonPrimitive(entry.getValue()));
values.add(entry.getKey(), categoryValues);
}
data.add("values", values);
return data;
}
}
/**
* Represents a custom advanced bar chart.
*/
public static class AdvancedBarChart extends CustomChart {
private final Callable<Map<String, int[]>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public AdvancedBarChart(String chartId, Callable<Map<String, int[]>> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, int[]> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean allSkipped = true;
for (Map.Entry<String, int[]> entry : map.entrySet()) {
if (entry.getValue().length == 0) {
continue; // Skip this invalid
}
allSkipped = false;
JsonArray categoryValues = new JsonArray();
for (int categoryValue : entry.getValue()) {
categoryValues.add(new JsonPrimitive(categoryValue));
}
values.add(entry.getKey(), categoryValues);
}
if (allSkipped) {
// Null = skip the chart
return null;
}
data.add("values", values);
return data;
}
}
}

View File

@ -0,0 +1,50 @@
package com.willfp.ecoenchants.commands;
import com.willfp.ecoenchants.Main;
import com.willfp.ecoenchants.config.ConfigManager;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Map;
public class CommandEcodebug implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (command.getName().equalsIgnoreCase("ecodebug")) {
if (!(sender instanceof Player)) {
sender.sendMessage(ConfigManager.getLang().getMessage("not-player"));
return true;
}
if (!sender.hasPermission("ecoenchants.ecodebug")) {
sender.sendMessage(ConfigManager.getLang().getNoPermission());
return true;
}
Bukkit.getLogger().info("--------------- BEGIN DEBUG ----------------");
Player player = (Player) sender;
Bukkit.getLogger().info("Running Version: " + Main.getInstance().getDescription().getVersion());
Bukkit.getLogger().info("Held Item: " + player.getInventory().getItemInMainHand().toString());
Bukkit.getLogger().info("EcoEnchants.getAll(): " + EcoEnchants.getAll().toString());
Bukkit.getLogger().info("Enchantment.values(): " + Arrays.toString(Enchantment.values()));
try {
Field byNameField = Enchantment.class.getDeclaredField("byName");
byNameField.setAccessible(true);
Map<String, Enchantment> byName = (Map<String, Enchantment>) byNameField.get(null);
Bukkit.getLogger().info("Enchantment.byName: " + byName.toString());
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
Bukkit.getLogger().info("--------------- END DEBUG ----------------");
}
return false;
}
}

View File

@ -0,0 +1,43 @@
package com.willfp.ecoenchants.commands;
import com.willfp.ecoenchants.Main;
import com.willfp.ecoenchants.config.ConfigManager;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.EnchantmentRarity;
import com.willfp.ecoenchants.lore.EnchantLore;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
public class CommandEcoreload implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (command.getName().equalsIgnoreCase("ecoreload")) {
if (sender instanceof Player) {
if (!sender.hasPermission("ecoenchants.reload")) {
sender.sendMessage(ConfigManager.getLang().getNoPermission());
return true;
}
}
ConfigManager.updateConfigs();
EnchantmentRarity.update();
EcoEnchants.update();
EnchantLore.update();
EcoEnchants.getAll().forEach((ecoEnchant -> {
HandlerList.unregisterAll(ecoEnchant);
Bukkit.getScheduler().runTaskLater(Main.getInstance(), () -> {
if(!ecoEnchant.isDisabled()) {
Bukkit.getPluginManager().registerEvents(ecoEnchant, Main.getInstance());
}
}, 1);
}));
sender.sendMessage(ConfigManager.getLang().getMessage("reloaded"));
}
return false;
}
}

View File

@ -0,0 +1,44 @@
package com.willfp.ecoenchants.commands;
import com.willfp.ecoenchants.config.ConfigManager;
import com.willfp.ecoenchants.lore.EnchantLore;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
public class CommandEcoskip implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (command.getName().equalsIgnoreCase("ecoskip")) {
if (!(sender instanceof Player)) {
sender.sendMessage(ConfigManager.getLang().getMessage("not-player"));
return true;
}
if (!sender.hasPermission("ecoenchants.skip")) {
sender.sendMessage(ConfigManager.getLang().getNoPermission());
return true;
}
Player player = (Player) sender;
ItemStack item = player.getInventory().getItemInMainHand();
ItemMeta meta = item.getItemMeta();
if(meta == null) {
return true;
}
if(meta.getPersistentDataContainer().has(EnchantLore.keySkip, PersistentDataType.INTEGER)) {
meta.getPersistentDataContainer().remove(EnchantLore.keySkip);
player.sendMessage(ConfigManager.getLang().getMessage("skip-removed"));
} else {
meta.getPersistentDataContainer().set(EnchantLore.keySkip, PersistentDataType.INTEGER, 1);
player.sendMessage(ConfigManager.getLang().getMessage("skip-added"));
}
item.setItemMeta(meta);
}
return false;
}
}

View File

@ -0,0 +1,144 @@
package com.willfp.ecoenchants.commands;
import com.willfp.ecoenchants.config.ConfigManager;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import org.apache.commons.lang.WordUtils;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class CommandEnchantinfo implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (command.getName().equalsIgnoreCase("enchantinfo")) {
if (!sender.hasPermission("ecoenchants.enchantinfo")) {
sender.sendMessage(ConfigManager.getLang().getNoPermission());
return true;
}
if(args.length == 0) {
sender.sendMessage(ConfigManager.getLang().getMessage("missing-enchant"));
return true;
}
StringBuilder nameBuilder = new StringBuilder();
Arrays.asList(args).forEach((arg) -> {
nameBuilder.append(arg).append(" ");
});
String searchName = nameBuilder.toString();
searchName = searchName.substring(0, searchName.length() - 1);
EcoEnchant enchantment = EcoEnchants.getByName(searchName);
boolean notFound = enchantment == null;
if(notFound) {
String message = ConfigManager.getLang().getMessage("not-found").replace("%name%", searchName);
sender.sendMessage(message);
return true;
}
String name;
String color;
List<String> description;
boolean isCurse = enchantment.isCursed();
boolean isSpecial = false;
boolean isArtifact = false;
if(enchantment.getType().equals(EcoEnchant.EnchantmentType.SPECIAL)) {
isSpecial = true;
}
if(enchantment.getType().equals(EcoEnchant.EnchantmentType.ARTIFACT)) {
isArtifact = true;
}
if(isCurse) color = ChatColor.translateAlternateColorCodes('&', ConfigManager.getLang().getString("curse-color"));
else if(isSpecial) color = ChatColor.translateAlternateColorCodes('&', ConfigManager.getLang().getString("special-color"));
else if(isArtifact) color = ChatColor.translateAlternateColorCodes('&', ConfigManager.getLang().getString("artifact-color"));
else color = ChatColor.translateAlternateColorCodes('&', ConfigManager.getLang().getString("not-curse-color"));
name = enchantment.getName();
description = EcoEnchants.getFromEnchantment(enchantment).getDescription();
StringBuilder descriptionBuilder = new StringBuilder();
description.forEach((line) -> {
descriptionBuilder.append(line).append(" ");
});
String desc = descriptionBuilder.toString();
Set<String> conflictNames = new HashSet<>();
Set<Enchantment> conflicts = enchantment.getConflicts();
conflicts.forEach((enchantment1 -> {
if(EcoEnchants.getFromEnchantment(enchantment1) != null) {
conflictNames.add(EcoEnchants.getFromEnchantment(enchantment1).getName());
} else {
conflictNames.add(ConfigManager.getLang().getString("vanilla." + enchantment1.getKey().getKey() + ".name"));
}
}));
StringBuilder conflictNamesBuilder = new StringBuilder();
conflictNames.forEach((name1) -> {
conflictNamesBuilder.append(name1).append(", ");
});
String allConflicts = conflictNamesBuilder.toString();
if(allConflicts.length() >= 2) {
allConflicts = allConflicts.substring(0, allConflicts.length() -2);
} else {
allConflicts = ChatColor.translateAlternateColorCodes('&', ConfigManager.getLang().getString("no-conflicts"));
}
Set<Material> targets = enchantment.getTarget();
Set<String> applicableItemsSet = new HashSet<>();
targets.forEach(material -> {
String matName = material.toString();
matName = matName.toLowerCase();
matName = matName.replaceAll("_", " ");
matName = WordUtils.capitalize(matName);
applicableItemsSet.add(matName);
});
StringBuilder targetNamesBuilder = new StringBuilder();
applicableItemsSet.forEach((name1) -> {
targetNamesBuilder.append(name1).append(", ");
});
String allTargets = targetNamesBuilder.toString();
if(allTargets.length() >= 2) {
allTargets = allTargets.substring(0, allTargets.length() - 2);
} else {
allTargets = ChatColor.translateAlternateColorCodes('&', ConfigManager.getLang().getString("no-targets"));
}
String maxLevel = String.valueOf(enchantment.getMaxLevel());
final String finalName = color + name;
final String finalDescription = desc;
final String finalTargets = allTargets;
final String finalConflicts = allConflicts;
final String finalMaxLevel = maxLevel;
Arrays.asList(ConfigManager.getLang().getMessage("enchantinfo").split("\\r?\\n")).forEach((string -> {
string = string.replaceAll("%name%", finalName)
.replaceAll("%description%", finalDescription)
.replaceAll("%target%", finalTargets)
.replaceAll("%conflicts%", finalConflicts)
.replaceAll("%maxlevel%", finalMaxLevel);
sender.sendMessage(string);
}));
}
return false;
}
}

View File

@ -0,0 +1,72 @@
package com.willfp.ecoenchants.config;
import com.willfp.ecoenchants.config.configs.Config;
import com.willfp.ecoenchants.config.configs.EnchantmentConfig;
import com.willfp.ecoenchants.config.configs.Lang;
import java.util.HashSet;
import java.util.Set;
public class ConfigManager {
private static final Lang LANG = new Lang();
private static final Config CONFIG = new Config();
private static final Set<EnchantmentConfig> enchantmentConfigs = new HashSet<>();
/**
* Update all configs
* Called on /ecoreload
*/
public static void updateConfigs() {
LANG.reload();
CONFIG.reload();
updateEnchantmentConfigs();
}
/**
* Update enchantment configs
*/
public static void updateEnchantmentConfigs() {
enchantmentConfigs.forEach((EnchantmentYamlConfig::reload));
}
/**
* Get all enchantment configs
* @return Set of all enchantment configs
*/
public static Set<EnchantmentConfig> getEnchantmentConfigs() {
return enchantmentConfigs;
}
/**
* Get EnchantmentConfig matching permission name
* @param permissionName The permission name to match
* @return The matching {@link EnchantmentConfig}
*/
public static EnchantmentConfig getEnchantmentConfig(String permissionName) {
return enchantmentConfigs.stream().filter(config -> config.getName().equalsIgnoreCase(permissionName)).findFirst().get();
}
/**
* Adds new enchantment config yml
* @param config The config to add
*/
public static void addEnchantmentConfig(EnchantmentConfig config) {
enchantmentConfigs.add(config);
}
/**
* Get lang.yml
* @return lang.yml
*/
public static Lang getLang() {
return LANG;
}
/**
* Get config.yml
* @return config.yml
*/
public static Config getConfig() {
return CONFIG;
}
}

View File

@ -0,0 +1,141 @@
package com.willfp.ecoenchants.config;
import com.willfp.ecoenchants.Main;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.*;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/**
* Class implemented by enchantment configs
*/
public abstract class EnchantmentYamlConfig {
private final String name;
public YamlConfiguration config;
private File configFile;
private final File directory;
private final double latestVersion;
private final JavaPlugin plugin = Main.getInstance();
private final Class<?> plugin2;
private final EcoEnchant.EnchantmentType type;
private File basedir = new File(this.plugin.getDataFolder(), "enchants/");
/**
* Create new config yml
*
* @param name The config name
* @param latestVersion The latest config version
* @param plugin The class of the main class of plugin or extension
* @param type The enchantment type
*/
public EnchantmentYamlConfig(String name, double latestVersion, Class<?> plugin, EcoEnchant.EnchantmentType type) {
this.name = name;
this.latestVersion = latestVersion;
this.plugin2 = plugin;
this.type = type;
if(!basedir.exists()) basedir.mkdirs();
File dir = new File(basedir, type.name().toLowerCase() + "/");
if (!dir.exists()) {
dir.mkdirs();
}
this.directory = dir;
init();
}
private void init() {
if (!new File(directory, name + ".yml").exists()) {
createFile();
}
this.configFile = new File(directory, name + ".yml");
this.config = YamlConfiguration.loadConfiguration(configFile);
checkVersion();
}
private void saveResource(boolean replace) {
String resourcePath = "/enchants/" + type.name().toLowerCase() + "/" + name + ".yml";
InputStream in = plugin2.getResourceAsStream(resourcePath);
File outFile = new File(Main.getInstance().getDataFolder(), resourcePath);
int lastIndex = resourcePath.lastIndexOf('/');
File outDir = new File(Main.getInstance().getDataFolder(), resourcePath.substring(0, Math.max(lastIndex, 0)));
if (!outDir.exists()) {
outDir.mkdirs();
}
try {
if (!outFile.exists() || replace) {
OutputStream out = new FileOutputStream(outFile);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.close();
in.close();
}
} catch (IOException ignored) {}
}
private void createFile() {
saveResource(false);
}
private void replaceFile() {
saveResource(true);
}
public void reload() {
try {
this.config.load(this.configFile);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
Bukkit.getLogger().severe("§cCould not reload " + name + ".yml - Contact Auxilor.");
}
}
private void checkVersion() {
if (latestVersion != config.getDouble("config-version")) {
Bukkit.getLogger().warning("EcoEnchants detected an older or invalid " + name + ".yml. Replacing it with the default config...");
Bukkit.getLogger().warning("If you've edited the config, copy over your changes!");
performOverwrite();
Bukkit.getLogger().info("§aReplacement complete!");
}
}
private void performOverwrite() {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss");
LocalDateTime now = LocalDateTime.now();
String dateTime = dtf.format(now);
try {
File backupDir = new File(plugin.getDataFolder(), "backup/");
if(!backupDir.exists()) backupDir.mkdirs();
File oldConf = new File(backupDir, name + "_" + dateTime + ".yml");
oldConf.createNewFile();
FileInputStream fis = new FileInputStream(directory + "/" + name + ".yml");
FileOutputStream fos = new FileOutputStream(oldConf);
byte[] buffer = new byte[1024];
int length;
while ((length = fis.read(buffer)) > 0) {
fos.write(buffer, 0, length);
}
fis.close();
fos.close();
replaceFile();
} catch (IOException e) {
e.printStackTrace();
Bukkit.getLogger().severe("§cCould not update config. Try reinstalling EcoEnchants");
}
}
}

View File

@ -0,0 +1,88 @@
package com.willfp.ecoenchants.config;
import com.willfp.ecoenchants.Main;
import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public abstract class YamlConfig {
private final String name;
public YamlConfiguration config;
private File configFile;
public YamlConfig(String name) {
this.name = name;
init();
}
private void init() {
if (!new File(Main.getInstance().getDataFolder(), name + ".yml").exists()) {
createFile();
}
this.configFile = new File(Main.getInstance().getDataFolder(), name + ".yml");
this.config = YamlConfiguration.loadConfiguration(configFile);
checkVersion();
}
private void createFile() {
Main.getInstance().saveResource(name + ".yml", false);
}
private void replaceFile() {
Main.getInstance().saveResource(name + ".yml", true);
}
public void reload() {
try {
this.config.load(this.configFile);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
Bukkit.getLogger().severe("§cCould not reload " + name + ".yml - Contact Auxilor.");
}
}
private void checkVersion() {
double latestVersion = Main.configVersions.get(this.name);
if (latestVersion != config.getDouble("config-version")) {
Bukkit.getLogger().warning("EcoEnchants detected an older or invalid " + name + ".yml. Replacing it with the default config...");
Bukkit.getLogger().warning("If you've edited the config, copy over your changes!");
performOverwrite();
Bukkit.getLogger().info("§aReplacement complete!");
}
}
private void performOverwrite() {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss");
LocalDateTime now = LocalDateTime.now();
String dateTime = dtf.format(now);
try {
File backupDir = new File(Main.getInstance().getDataFolder(), "backup/");
if(!backupDir.exists()) backupDir.mkdirs();
File oldConf = new File(backupDir, name + "_" + dateTime + ".yml");
oldConf.createNewFile();
FileInputStream fis = new FileInputStream(Main.getInstance().getDataFolder() + "/" + name + ".yml");
FileOutputStream fos = new FileOutputStream(oldConf);
byte[] buffer = new byte[1024];
int length;
while ((length = fis.read(buffer)) > 0) {
fos.write(buffer, 0, length);
}
fis.close();
fos.close();
replaceFile();
} catch (IOException e) {
e.printStackTrace();
Bukkit.getLogger().severe("§cCould not update config. Try reinstalling EcoEnchants");
}
}
}

View File

@ -0,0 +1,60 @@
package com.willfp.ecoenchants.config.configs;
import com.willfp.ecoenchants.config.YamlConfig;
import org.bukkit.inventory.ItemStack;
import java.util.List;
import java.util.Set;
/**
* Wrapper for config.yml
*/
public class Config extends YamlConfig {
public Config() {
super("config");
}
public int getInt(String path) {
return config.getInt(path);
}
public int getInt(String path, int def) {
return config.getInt(path, def);
}
public List<Integer> getInts(String path) {
return config.getIntegerList(path);
}
public boolean getBool(String path) {
return config.getBoolean(path);
}
public List<Boolean> getBools(String path) {
return config.getBooleanList(path);
}
public String getString(String path) {
return config.getString(path);
}
public List<String> getStrings(String path) {
return config.getStringList(path);
}
public double getDouble(String path) {
return config.getDouble(path);
}
public List<Double> getDoubles(String path) {
return config.getDoubleList(path);
}
public ItemStack getItemStack(String path) {
return config.getItemStack(path);
}
public Set<String> getRarities() {
return config.getConfigurationSection("obtaining.rarities").getKeys(false);
}
}

View File

@ -0,0 +1,99 @@
package com.willfp.ecoenchants.config.configs;
import com.willfp.ecoenchants.config.EnchantmentYamlConfig;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EnchantmentRarity;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Wrapper for enchantment-specific configs
*/
public class EnchantmentConfig extends EnchantmentYamlConfig {
private final String name;
public static String userId = "%%__USER__%%";
public EnchantmentConfig(String name, double version, Class<?> plugin, EcoEnchant.EnchantmentType type) {
super(name, version, plugin, type);
this.name = name;
}
public String getName() {
return name;
}
public int getInt(String path) {
return config.getInt(path);
}
public int getInt(String path, int def) {
return config.getInt(path, def);
}
public List<Integer> getInts(String path) {
return config.getIntegerList(path);
}
public boolean getBool(String path) {
return config.getBoolean(path);
}
public boolean getBool(String path, boolean def) {
return config.getBoolean(path, def);
}
public List<Boolean> getBools(String path) {
return config.getBooleanList(path);
}
public String getString(String path) {
return config.getString(path);
}
public List<String> getStrings(String path) {
return config.getStringList(path);
}
public double getDouble(String path) {
return config.getDouble(path);
}
public List<Double> getDoubles(String path) {
return config.getDoubleList(path);
}
public ItemStack getItemStack(String path) {
return config.getItemStack(path);
}
public Set<Enchantment> getEnchantments(String path) {
Set<Enchantment> enchantments = new HashSet<>();
List<String> enchantmentKeys = config.getStringList(path);
enchantmentKeys.forEach((key -> enchantments.add(Enchantment.getByKey(NamespacedKey.minecraft(key)))));
return enchantments;
}
public EnchantmentRarity getRarity() {
String rarityName = this.getString("obtaining.rarity");
return EnchantmentRarity.getByName(rarityName);
}
public Set<Material> getTarget(Set<Material> initialTarget) {
List<String> targetName = config.getStringList("general-config.target");
if(targetName == null || targetName.isEmpty()) return initialTarget;
Set<Material> targets = new HashSet<>();
targetName.forEach((s -> {
Material mat = Material.getMaterial(s.toUpperCase());
targets.add(mat);
}));
return targets;
}
}

View File

@ -0,0 +1,36 @@
package com.willfp.ecoenchants.config.configs;
import com.willfp.ecoenchants.config.YamlConfig;
import org.bukkit.ChatColor;
import java.util.List;
/**
* Wrapper for lang.yml
*/
public class Lang extends YamlConfig {
public Lang() {
super("lang");
}
public String getString(String path) {
return config.getString(path);
}
public List<String> getStrings(String path) {
return config.getStringList(path);
}
public String getPrefix() {
return ChatColor.translateAlternateColorCodes('&', config.getString("messages.prefix"));
}
public String getNoPermission() {
return getPrefix() + ChatColor.translateAlternateColorCodes('&', config.getString("messages.no-permission"));
}
public String getMessage(String message) {
return getPrefix() + ChatColor.translateAlternateColorCodes('&', config.getString("messages." + message));
}
}

View File

@ -0,0 +1,144 @@
package com.willfp.ecoenchants.enchantments;
import com.google.common.util.concurrent.AtomicDouble;
import com.willfp.ecoenchants.Main;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.nms.TridentStack;
import com.willfp.ecoenchants.util.HasEnchant;
import com.willfp.ecoenchants.util.Rand;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.block.Block;
import org.bukkit.entity.AbstractArrow;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Trident;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
/**
* Wrapper for Artifact enchantments
* in order to reduce copying existing code between artifacts.
*/
public abstract class Artifact extends EcoEnchant {
private final Particle particle;
private final Particle.DustOptions extra;
public Artifact(String key, double version, Particle particle) {
super(new EcoEnchantBuilder(key, EnchantmentType.ARTIFACT, new Target.Applicable[]{Target.Applicable.ELYTRA, Target.Applicable.SWORD, Target.Applicable.AXE, Target.Applicable.PICKAXE}, version));
this.particle = particle;
extra = null;
}
public Artifact(String key, double version, Particle particle, Particle.DustOptions extra) {
super(new EcoEnchantBuilder(key, EnchantmentType.ARTIFACT, new Target.Applicable[]{Target.Applicable.ELYTRA, Target.Applicable.SWORD, Target.Applicable.AXE, Target.Applicable.PICKAXE}, version));
this.particle = particle;
this.extra = extra;
}
@EventHandler
public void onBreak(BlockBreakEvent event) {
Player player = event.getPlayer();
Block block = event.getBlock();
if(!this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "on-blocks").contains(block.getType().name().toLowerCase())) return;
if (!HasEnchant.playerHeld(player, this)) return;
int amount = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "amount");
block.getWorld().spawnParticle(particle, block.getLocation().add(0.5, 0.5, 0.5), amount, 0.4, 0.4, 0.4, 0, extra, false);
}
@EventHandler
public void onElytra(PlayerMoveEvent event) {
Player player = event.getPlayer();
if(!player.isGliding()) return;
if (!HasEnchant.playerElytra(player, this)) return;
Location location = player.getLocation();
Vector direction = player.getLocation().clone().getDirection();
Vector point1 = player.getLocation().getDirection().clone();
point1.rotateAroundY(Math.toRadians(90));
point1.multiply(1.2);
Location location1 = player.getLocation().clone().add(point1);
Vector point2 = player.getLocation().getDirection().clone();
point2.rotateAroundY(Math.toRadians(-90));
point2.multiply(1.2);
Location location2 = player.getLocation().clone().add(point2);
player.getWorld().spawnParticle(particle, location1, 1, 0, 0, 0, 0, extra, true);
player.getWorld().spawnParticle(particle, location2, 1, 0, 0, 0, 0, extra, true);
}
@EventHandler
public void onHit(EntityDamageByEntityEvent event) {
if(!(event.getDamager() instanceof Player)) return;
if(!(event.getEntity() instanceof LivingEntity)) return;
Player player = (Player) event.getDamager();
LivingEntity entity = (LivingEntity) event.getEntity();
if (!HasEnchant.playerHeld(player, this)) return;
double radius = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "radius");
AtomicDouble yAtomic = new AtomicDouble(0);
double yDelta = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "y-delta");
double radiusMultiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "radius-multiplier");
double offset = Rand.randFloat(0, 0.75);
new BukkitRunnable() {
@Override
public void run() {
for(int i = 0; i<3; i++) {
if (yAtomic.get() > entity.getHeight()) this.cancel();
yAtomic.addAndGet(yDelta);
double y = yAtomic.get();
double x = radius * Math.cos((y + offset) * radiusMultiplier);
double z = radius * Math.sin((y + offset) * radiusMultiplier);
Location particleLocation = entity.getLocation();
particleLocation.add(x, y, z);
entity.getWorld().spawnParticle(particle, particleLocation, 1, 0, 0, 0, 0, extra, false);
}
}
}.runTaskTimer(Main.getInstance(), 0, 1);
}
@EventHandler
public void onShoot(ProjectileLaunchEvent event) {
if (!(event.getEntity() instanceof AbstractArrow))
return;
if(!(event.getEntity().getShooter() instanceof Player)) return;
Player player = (Player) event.getEntity().getShooter();
AbstractArrow entity = (AbstractArrow) event.getEntity();
ItemStack item = player.getInventory().getItemInMainHand();
if(entity instanceof Trident) {
item = TridentStack.getTridentStack((Trident) entity);
}
if (!HasEnchant.item(item, this)) return;
int ticks = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "particle-tick-delay");
new BukkitRunnable() {
@Override
public void run() {
if(entity.isOnGround() || entity.isInBlock() || entity.isDead()) this.cancel();
entity.getLocation().getWorld().spawnParticle(particle, entity.getLocation(), 1, 0, 0, 0, 0, extra, true);
}
}.runTaskTimer(Main.getInstance(), 4, ticks);
}
}

View File

@ -0,0 +1,321 @@
package com.willfp.ecoenchants.enchantments;
import com.willfp.ecoenchants.config.ConfigManager;
import com.willfp.ecoenchants.config.configs.EnchantmentConfig;
import com.willfp.ecoenchants.nms.Target;
import org.apache.commons.lang.WordUtils;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import java.lang.reflect.Field;
import java.util.*;
public abstract class EcoEnchant extends Enchantment implements Listener {
private String name;
private String description;
private Set<Material> target;
private final String permissionName;
private final EnchantmentType type;
private final double configVersion;
private final EnchantmentConfig config;
private boolean grindstoneable;
private boolean canGetFromTable;
private boolean canGetFromVillager;
private boolean canGetFromLoot;
private int maxLvl;
private Set<Enchantment> conflicts;
private EnchantmentRarity rarity;
private boolean disabled;
/**
* Create new EcoEnchant matching builder
*
* @param builder The {@link EcoEnchantBuilder} for enchantment
*/
protected EcoEnchant(EcoEnchantBuilder builder) {
super(NamespacedKey.minecraft(builder.key));
this.type = builder.type;
this.name = builder.name;
this.target = builder.target;
this.permissionName = builder.permission;
this.configVersion = builder.configVersion;
this.config = builder.config;
this.update();
this.add();
}
/**
* Update the enchantment based off config values
*/
public void update() {
rarity = config.getRarity();
conflicts = config.getEnchantments(EcoEnchants.GENERAL_LOCATION + "conflicts");
grindstoneable = config.getBool(EcoEnchants.GENERAL_LOCATION + "grindstoneable");
canGetFromTable = config.getBool(EcoEnchants.OBTAINING_LOCATION + "table");
canGetFromVillager = config.getBool(EcoEnchants.OBTAINING_LOCATION + "villager");
canGetFromLoot = config.getBool(EcoEnchants.OBTAINING_LOCATION + "loot");
maxLvl = config.getInt(EcoEnchants.GENERAL_LOCATION + "maximum-level", 1);
name = config.getString("name");
description = config.getString("description");
target = config.getTarget(target);
disabled = config.getBool("disabled", false);
this.register();
}
private void register() {
try {
Field byIdField = Enchantment.class.getDeclaredField("byKey");
Field byNameField = Enchantment.class.getDeclaredField("byName");
byIdField.setAccessible(true);
byNameField.setAccessible(true);
Map<NamespacedKey, Enchantment> byKey = (Map<NamespacedKey, Enchantment>) byIdField.get(null);
Map<String, Enchantment> byName = (Map<String, Enchantment>) byNameField.get(null);
byKey.remove(this.getKey());
byName.remove(this.getName());
Map<String, Enchantment> byNameClone = new HashMap<>(byName);
for (Map.Entry<String, Enchantment> entry : byNameClone.entrySet()) {
if (entry.getValue().getKey().equals(this.getKey())) {
byName.remove(entry.getKey());
}
}
Field f = Enchantment.class.getDeclaredField("acceptingNew");
f.setAccessible(true);
f.set(null, true);
f.setAccessible(false);
Enchantment.registerEnchantment(this);
} catch (NoSuchFieldException | IllegalAccessException ignored) {}
}
private void add() {
EcoEnchants.addNewEcoEnchant(this);
}
private void remove() {
EcoEnchants.removeEcoEnchant(this);
}
/**
* Get if enchantment can be removed in grindstone
* @return Whether the enchantment can be removed
*/
public boolean isGrindstoneable() {
return grindstoneable;
}
/**
* Get {@link EnchantmentType} of enchantment
* @return The {@link EnchantmentType}
*/
public EnchantmentType getType() { return this.type; }
/**
* Get a set of all conflicts
* @return Conflicts
*/
public Set<Enchantment> getConflicts() {
return this.conflicts;
}
/**
* Get if enchantment is disabled
* @return If disabled
*/
public boolean isDisabled() {
return this.disabled;
}
/**
* Get permission name of enchantment
* @return The permission name
*/
public String getPermissionName() {
return permissionName;
}
/**
* Get description of enchantment
* @return The description
*/
public List<String> getDescription() {
return Arrays.asList(WordUtils.wrap(description, ConfigManager.getConfig().getInt("lore.describe.wrap"), "\n", false).split("\\r?\\n"));
}
/**
* Get if enchantment can be obtained from an enchanting table
* @return If can be obtained
*/
public boolean canGetFromTable() {
return canGetFromTable;
}
/**
* Get if enchantment can be obtained from a villager
* @return If can be obtained
*/
public boolean canGetFromVillager() {
return canGetFromVillager;
}
/**
* Get if enchantment can be obtained from chest loot
* @return If can be obtained
*/
public boolean canGetFromLoot() {
return canGetFromLoot;
}
/**
* Get {@link EnchantmentRarity} of enchantment
* @return The enchantment rarity
*/
public EnchantmentRarity getRarity() {
return rarity;
}
/**
* If enchantment conflicts with any enchantment in set
* @param enchantments The set to test against
* @return If there are any conflicts
*/
public boolean conflictsWithAny(Set<? extends Enchantment> enchantments) {
return conflicts.stream().anyMatch(enchantments::contains);
}
/**
* Get enchantment cast to {@link Enchantment}
* @return The enchantment
*/
public Enchantment getEnchantment() {
return this;
}
/**
* Get the {@link Target} of enchantment
* @return Set of enchantable items
*/
public Set<Material> getTarget() {
return target;
}
/**
* Get latest config version
* @return The latest version
*/
public double getConfigVersion() {
return configVersion;
}
/**
* Get {@link EnchantmentConfig} of enchantment
* @return The config
*/
public EnchantmentConfig getConfig() {
return config;
}
/**
* Get display name of enchantment.
* Not deprecated, unlike {@link Enchantment#getName()}
*
* @return The display name
*/
@Override
public String getName() {
return name;
}
/**
* Get max level of enchantment
* @return The max level
*/
@Override
public int getMaxLevel() {
return maxLvl;
}
/**
* @return 1
*/
@Override
public int getStartLevel() {
return 1;
}
/**
* Do not use this method.
* Only here for compatibility with {@link Enchantment}
*
* @return Returns {@link EnchantmentTarget#ALL}. Do not use.
*
* @deprecated {@link EnchantmentTarget} is not supported due to its lack of flexibility. Use {@link EcoEnchant#getTarget()} instead.
*/
@Override
@Deprecated
public EnchantmentTarget getItemTarget() {
return EnchantmentTarget.ALL;
}
/**
* @return false
* @deprecated Treasure enchantments do not exist. Use {@link EcoEnchant#getType()} instead.
*/
@Override
@Deprecated
public boolean isTreasure() {
return false;
}
/**
* @return Returns if enchantment is cursed.
*
* @deprecated Use {@link EcoEnchant#getType()} instead.
*/
@Override
@Deprecated
public boolean isCursed() {
return this.type.equals(EnchantmentType.CURSE);
}
/**
* Get if enchantment conflicts with specified enchantment
* @param enchantment The enchantment to test against
* @return If conflicts
*/
@Override
public boolean conflictsWith(Enchantment enchantment) {
return conflicts.contains(enchantment);
}
/**
* If enchantment can be applied to item
* @param itemStack The {@link ItemStack} to test against
* @return If can be applied
*/
@Override
public boolean canEnchantItem(ItemStack itemStack) {
return target.contains(itemStack.getType()) || Target.Applicable.BOOK.getMaterials().contains(itemStack.getType());
}
/**
* The types of {@link EcoEnchant}
*/
public enum EnchantmentType {
NORMAL,
CURSE,
SPECIAL,
ARTIFACT
}
}

View File

@ -0,0 +1,129 @@
package com.willfp.ecoenchants.enchantments;
import com.willfp.ecoenchants.Main;
import com.willfp.ecoenchants.config.ConfigManager;
import com.willfp.ecoenchants.config.configs.EnchantmentConfig;
import com.willfp.ecoenchants.nms.Target;
import org.bukkit.Material;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
public class EcoEnchantBuilder {
public final String name;
public final String key;
public final String permission;
public final Set<Material> target;
public double configVersion;
public final EnchantmentConfig config;
public Class<?> plugin;
public final EcoEnchant.EnchantmentType type;
/**
* Creates new EcoEnchantBuilder
* Only used by base enchantments, do not use for extensions.
*
* @param key The enchantment key name
* @param type The enchantment type
* @param applicable The materials that the enchantment can be applied to
* @param version The config version
*/
public EcoEnchantBuilder(String key, EcoEnchant.EnchantmentType type, Target.Applicable applicable, double version) {
this(key, type, new Target.Applicable[]{applicable}, version);
}
/**
* Creates new EcoEnchantBuilder
* Use for extensions
*
* @param key The enchantment key name
* @param type The enchantment type
* @param applicable The materials that the enchantment can be applied to
* @param version The config version
* @param plugin The main class of extension
*/
public EcoEnchantBuilder(String key, EcoEnchant.EnchantmentType type, Target.Applicable applicable, double version, Class<?> plugin) {
this(key, type, new Target.Applicable[]{applicable}, version, plugin);
}
/**
* Creates new EcoEnchantBuilder
* Only used by base enchantments, do not use for extensions.
*
* @param key The enchantment key name
* @param type The enchantment type
* @param applicable The materials that the enchantment can be applied to
* @param version The config version
*/
public EcoEnchantBuilder(String key, EcoEnchant.EnchantmentType type, Target.Applicable[] applicable, double version) {
this(key, type, applicable, version, Main.class);
}
/**
* Creates new EcoEnchantBuilder for Extension
* Use for extensions
*
* @param key The enchantment key name
* @param type The enchantment type
* @param applicable The materials that the enchantment can be applied to
* @param version The config version
* @param plugin The main class of extension
*/
public EcoEnchantBuilder(String key, EcoEnchant.EnchantmentType type, Target.Applicable[] applicable, double version, Class<?> plugin) {
if(Pattern.matches("[a-z_]", key)) throw new InvalidEnchantmentException("Key must only contain lowercase letters and underscores");
this.key = key;
this.permission = key.replace("_","");
Set<Material> target = new HashSet<>();
Arrays.asList(applicable).forEach((applicable1 -> {
target.addAll(applicable1.getMaterials());
}));
this.target = target;
this.type = type;
this.plugin = plugin;
this.configVersion = version;
ConfigManager.addEnchantmentConfig(new EnchantmentConfig(permission, configVersion, plugin, this.type));
this.config = ConfigManager.getEnchantmentConfig(permission);
this.name = config.getString("name");
}
/**
* Creates new EcoEnchantBuilder for Extension
* Use for extensions
*
* @param key The enchantment key name
* @param type The enchantment type
* @param target The materials that the enchantment can be applied to
* @param version The config version
* @param plugin The main class of extension
*
* @deprecated Use {@link Target.Applicable} instead
*/
@Deprecated
public EcoEnchantBuilder(String key, EcoEnchant.EnchantmentType type, Set<Material> target, double version, Class<?> plugin) {
if(Pattern.matches("[a-z_]", key)) throw new InvalidEnchantmentException("Key must only contain lowercase letters and underscores");
this.key = key;
this.permission = key.replace("_","");
this.target = target;
this.type = type;
this.plugin = plugin;
this.configVersion = version;
ConfigManager.addEnchantmentConfig(new EnchantmentConfig(permission, configVersion, plugin, this.type));
this.config = ConfigManager.getEnchantmentConfig(permission);
this.name = config.getString("name");
}
}

View File

@ -0,0 +1,299 @@
package com.willfp.ecoenchants.enchantments;
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.*;
import com.willfp.ecoenchants.enchantments.ecoenchants.curse.*;
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.*;
import com.willfp.ecoenchants.enchantments.ecoenchants.special.*;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* Contains general methods for EcoEnchants
*/
@SuppressWarnings("unchecked")
public class EcoEnchants {
public static final String CONFIG_LOCATION = "config.";
public static final String OBTAINING_LOCATION = "obtaining.";
public static final String GENERAL_LOCATION = "general-config.";
private static final Set<EcoEnchant> ecoEnchants = new HashSet<>();
public static final EcoEnchant TELEKINESIS = new Telekinesis();
public static final EcoEnchant MARKSMAN = new Marksman();
public static final EcoEnchant INFERNAL_TOUCH = new InfernalTouch();
public static final EcoEnchant SPRING = new Spring();
public static final EcoEnchant STRAY_ASPECT = new StrayAspect();
public static final EcoEnchant ILLUSION_ASPECT = new IllusionAspect();
public static final EcoEnchant SLICING = new Slicing();
public static final EcoEnchant DEXTEROUS = new Dexterous();
public static final EcoEnchant BEHEADING = new Beheading();
public static final EcoEnchant NECROTIC = new Necrotic();
public static final EcoEnchant MAGMA_WALKER = new MagmaWalker();
public static final EcoEnchant TECTONIC = new Tectonic();
public static final EcoEnchant EVASION = new Evasion();
public static final EcoEnchant SUCCESSION = new Succession();
public static final EcoEnchant FARMHAND = new Farmhand();
public static final EcoEnchant WISDOM = new Wisdom();
public static final EcoEnchant LEECHING = new Leeching();
public static final EcoEnchant VAMPIRE_ASPECT = new VampireAspect();
public static final EcoEnchant INSTABILITY = new Instability();
public static final EcoEnchant THRIVE = new Thrive();
public static final EcoEnchant DRILL = new Drill();
public static final EcoEnchant THOR = new Thor();
public static final EcoEnchant STREAMLINING = new Streamlining();
public static final EcoEnchant FIRST_STRIKE = new FirstStrike();
public static final EcoEnchant FINISHING = new Finishing();
public static final EcoEnchant CRITICALS = new Criticals();
public static final EcoEnchant INCANDESCENCE = new Incandescence();
public static final EcoEnchant SUPERCRITICAL = new Supercritical();
public static final EcoEnchant ABRASION = new Abrasion();
public static final EcoEnchant SPLASH = new Splash();
public static final EcoEnchant EXTINGUISHING = new Extinguishing();
public static final EcoEnchant GOLIATH = new Goliath();
public static final EcoEnchant OPTICS = new Optics();
public static final EcoEnchant DEFUSION = new Defusion();
public static final EcoEnchant CEREBRAL = new Cerebral();
public static final EcoEnchant GRIT = new Grit();
public static final EcoEnchant BOSS_HUNTER = new BossHunter();
public static final EcoEnchant INVIGORATION = new Invigoration();
public static final EcoEnchant REJUVENATION = new Rejuvenation();
public static final EcoEnchant FRAGILITY_CURSE = new FragilityCurse();
public static final EcoEnchant TRIPLESHOT = new Tripleshot();
public static final EcoEnchant RAPID = new Rapid();
public static final EcoEnchant SATING = new Sating();
public static final EcoEnchant REINFORCEMENT = new Reinforcement();
public static final EcoEnchant SOULBOUND = new Soulbound();
public static final EcoEnchant RAZOR = new Razor();
public static final EcoEnchant PROSPERITY = new Prosperity();
public static final EcoEnchant PRESERVATION = new Preservation();
public static final EcoEnchant FRENZY = new Frenzy();
public static final EcoEnchant BUTCHERING = new Butchering();
public static final EcoEnchant PROXIMITY = new Proximity();
public static final EcoEnchant ENDER_SLAYER = new EnderSlayer();
public static final EcoEnchant PROTECTOR = new Protector();
public static final EcoEnchant INDESTRUCTIBILITY = new Indestructibility();
public static final EcoEnchant ENERGIZING = new Energizing();
public static final EcoEnchant INTELLECT = new Intellect();
public static final EcoEnchant DEFLECTION = new Deflection();
public static final EcoEnchant LAUNCH = new Launch();
public static final EcoEnchant PERMANENCE_CURSE = new PermanenceCurse();
public static final EcoEnchant SPEARFISHING = new Spearfishing();
public static final EcoEnchant NETHER_INFUSION = new NetherInfusion();
public static final EcoEnchant REPLENISH = new Replenish();
public static final EcoEnchant FLINCH = new Flinch();
public static final EcoEnchant ELECTROSHOCK = new Electroshock();
public static final EcoEnchant NOCTURNAL = new Nocturnal();
public static final EcoEnchant CONFUSION = new Confusion();
public static final EcoEnchant ARCANIC = new Arcanic();
public static final EcoEnchant PENTASHOT = new Pentashot();
public static final EcoEnchant LUMBERJACK = new Lumberjack();
public static final EcoEnchant STONE_SWITCHER = new StoneSwitcher();
public static final EcoEnchant MAGNETIC = new Magnetic();
public static final EcoEnchant REPAIRING = new Repairing();
public static final EcoEnchant CALLING_CURSE = new CallingCurse();
public static final EcoEnchant BLAST_MINING = new BlastMining();
public static final EcoEnchant LIQUID_SHOT = new LiquidShot();
public static final EcoEnchant GRAPPLE = new Grapple();
public static final EcoEnchant HEART_ARTIFACT = new HeartArtifact();
public static final EcoEnchant SPARKLE_ARTIFACT = new SparkleArtifact();
public static final EcoEnchant LAVA_ARTIFACT = new LavaArtifact();
public static final EcoEnchant DRAGON_ARTIFACT = new DragonArtifact();
public static final EcoEnchant ENCHANTMENT_ARTIFACT = new EnchantmentArtifact();
public static final EcoEnchant SMOKE_ARTIFACT = new SmokeArtifact();
public static final EcoEnchant FIRE_ARTIFACT = new FireArtifact();
public static final EcoEnchant EMERALD_ARTIFACT = new EmeraldArtifact();
public static final EcoEnchant NETHER_ARTIFACT = new NetherArtifact();
public static final EcoEnchant END_ARTIFACT = new EndArtifact();
public static final EcoEnchant WATER_ARTIFACT = new WaterArtifact();
public static final EcoEnchant TOTEM_ARTIFACT = new TotemArtifact();
public static final EcoEnchant REDSTONE_ARTIFACT = new RedstoneArtifact();
public static final EcoEnchant ZAP_ARTIFACT = new ZapArtifact();
public static final EcoEnchant MUSIC_ARTIFACT = new MusicArtifact();
public static final EcoEnchant SNOW_ARTIFACT = new SnowArtifact();
public static final EcoEnchant WITCH_ARTIFACT = new WitchArtifact();
public static final EcoEnchant HONEY_ARTIFACT = new HoneyArtifact();
public static final EcoEnchant DAMAGE_ARTIFACT = new DamageArtifact();
public static final EcoEnchant CLOUDS_ARTIFACT = new CloudsArtifact();
public static final EcoEnchant MAGIC_ARTIFACT = new MagicArtifact();
public static final EcoEnchant DUST_ARTIFACT = new DustArtifact();
public static final EcoEnchant MAGMA_ARTIFACT = new MagmaArtifact();
public static final EcoEnchant INK_ARTIFACT = new InkArtifact();
public static final EcoEnchant ZEUS = new Zeus();
public static final EcoEnchant KINETIC = new Kinetic();
public static final EcoEnchant FIRE_AFFINITY = new FireAffinity();
public static final EcoEnchant PARASITIC = new Parasitic();
public static final EcoEnchant PARRY = new Parry();
public static final EcoEnchant AIMING = new Aiming();
public static final EcoEnchant HOOK = new Hook();
public static final EcoEnchant BLEED = new Bleed();
public static final EcoEnchant WEAKENING = new Weakening();
public static final EcoEnchant OXYGENATE = new Oxygenate();
public static final EcoEnchant WATER_ASPECT = new WaterAspect();
public static final EcoEnchant STAMINA = new Stamina();
public static final EcoEnchant COLLATERAL = new Collateral();
public static final EcoEnchant HUNGER_CURSE = new HungerCurse();
public static final EcoEnchant PALADIN = new Paladin();
public static final EcoEnchant SERRATED = new Serrated();
public static final EcoEnchant BLADED = new Bladed();
public static final EcoEnchant INFERNO = new Inferno();
public static final EcoEnchant STAB = new Stab();
public static final EcoEnchant TORNADO = new Tornado();
public static final EcoEnchant EXTRACT = new Extract();
public static final EcoEnchant AERIAL = new Aerial();
public static final EcoEnchant FAMINE = new Famine();
public static final EcoEnchant ANNIHILATE = new Annihilate();
public static final EcoEnchant RADIANCE = new Radiance();
public static final EcoEnchant HORDE = new Horde();
public static final EcoEnchant VEIN = new Vein();
public static final EcoEnchant ICE_SHOT = new IceShot();
public static final EcoEnchant PUNCTURE = new Puncture();
public static final EcoEnchant SHOCKWAVE = new Shockwave();
public static final EcoEnchant VOLATILE = new Volatile();
public static final EcoEnchant INSTANTANEOUS = new Instantaneous();
public static final EcoEnchant FREERUNNER = new Freerunner();
public static final EcoEnchant BOLT = new Bolt();
public static final EcoEnchant DULLNESS = new Dullness();
public static final EcoEnchant IGNITE = new Ignite();
public static final EcoEnchant CLEAVE = new Cleave();
public static final EcoEnchant CARVE = new Carve();
public static final EcoEnchant TOXIC = new Toxic();
public static final EcoEnchant WATER_AFFINITY = new WaterAffinity();
public static final EcoEnchant FORCEFIELD = new Forcefield();
public static final EcoEnchant SYCOPHANT = new Sycophant();
public static final EcoEnchant CHOPLESS = new Chopless();
public static final EcoEnchant GREEN_THUMB = new GreenThumb();
public static final EcoEnchant SPIKED = new Spiked();
public static final EcoEnchant HARPOON = new Harpoon();
public static final EcoEnchant REEL = new Reel();
public static final EcoEnchant SHOT_ASSIST = new ShotAssist();
public static final EcoEnchant FROZEN = new Frozen();
public static final EcoEnchant DISAPPEAR = new Disappear();
public static final EcoEnchant HARMLESSNESS_CURSE = new HarmlessnessCurse();
public static final EcoEnchant FURY = new Fury();
public static final EcoEnchant LEVITATE = new Levitate();
public static final EcoEnchant BREAKLESSNESS_CURSE = new BreaklessnessCurse();
public static final EcoEnchant DECAY_CURSE = new DecayCurse();
public static final EcoEnchant MISFORTUNE_CURSE = new MisfortuneCurse();
public static final EcoEnchant VENOM = new Venom();
public static final EcoEnchant CRANIAL = new Cranial();
public static final EcoEnchant AQUATIC = new Aquatic();
public static final EcoEnchant BUCKSHOT = new Buckshot();
public static final EcoEnchant DIVERSE = new Diverse();
public static final EcoEnchant LIFE_STEAL = new LifeSteal();
/**
* Get all registered {@link EcoEnchant}s
*
* @return A set of all {@link EcoEnchant}s
*/
public static Set<EcoEnchant> getAll() {
return ecoEnchants;
}
/**
* Gets {@link EcoEnchant} from {@link Enchantment}
*
* @param enchantment The enchantment
* @return The matching {@link EcoEnchant}, or null if not found.
*/
public static EcoEnchant getFromEnchantment(Enchantment enchantment) {
return getByKey(enchantment.getKey());
}
/**
* Get {@link EcoEnchant} matching display name
*
* @param name The display name to search for
* @return The matching {@link EcoEnchant}, or null if not found.
*/
public static EcoEnchant getByName(String name) {
Optional<EcoEnchant> matching = getAll().stream().filter(enchant -> enchant.getName().equalsIgnoreCase(name)).findFirst();
return matching.orElse(null);
}
/**
* Get {@link EcoEnchant} matching permission name
*
* @param permissionName The permission name to search for
* @return The matching {@link EcoEnchant}, or null if not found.
*/
public static EcoEnchant getByPermission(String permissionName) {
Optional<EcoEnchant> matching = getAll().stream().filter(enchant -> enchant.getPermissionName().equalsIgnoreCase(permissionName)).findFirst();
return matching.orElse(null);
}
/**
* Get {@link EcoEnchant} matching key
*
* @param key The NamespacedKey to search for
* @return The matching {@link EcoEnchant}, or null if not found.
*/
public static EcoEnchant getByKey(NamespacedKey key) {
Optional<EcoEnchant> matching = getAll().stream().filter(enchant -> enchant.getKey().equals(key)).findFirst();
return matching.orElse(null);
}
/**
* Get if {@link ItemStack} has any {@link EcoEnchant} matching specified {@link com.willfp.ecoenchants.enchantments.EcoEnchant.EnchantmentType}
*
* @param item The {@link ItemStack} to check
* @param type The {@link com.willfp.ecoenchants.enchantments.EcoEnchant.EnchantmentType} to match
* @return True if has, false if doesn't have.
*/
public static boolean hasAnyOfType(ItemStack item, EcoEnchant.EnchantmentType type) {
if(item == null) return false;
AtomicBoolean hasOfType = new AtomicBoolean(false);
if(item.getItemMeta() instanceof EnchantmentStorageMeta) {
((EnchantmentStorageMeta) item.getItemMeta()).getStoredEnchants().forEach(((enchantment, integer) -> {
if(getFromEnchantment(enchantment) != null) {
if(getFromEnchantment(enchantment).getType().equals(type)) hasOfType.set(true);
}
}));
} else {
item.getEnchantments().forEach(((enchantment, integer) -> {
if (getFromEnchantment(enchantment) != null) {
if (getFromEnchantment(enchantment).getType().equals(type)) hasOfType.set(true);
}
}));
}
return hasOfType.get();
}
/**
* Update all {@link EcoEnchant}s
* Called on /ecoreload
*/
public static void update() {
for (EcoEnchant ecoEnchant : new HashSet<>(getAll())) {
ecoEnchant.update();
}
}
/**
* Add new {@link EcoEnchant} to EcoEnchants
* Only for internal use, enchantments are automatically added in the {@link EcoEnchant#EcoEnchant(EcoEnchantBuilder)} constructor.
*
* @param enchant The {@link EcoEnchant} to add
*/
public static void addNewEcoEnchant(EcoEnchant enchant) {
ecoEnchants.remove(enchant);
ecoEnchants.add(enchant);
}
/**
* Remove {@link EcoEnchant} from EcoEnchants
*
* @param enchant The {@link EcoEnchant} to remove
*/
public static void removeEcoEnchant(EcoEnchant enchant) {
ecoEnchants.remove(enchant);
}
}

View File

@ -0,0 +1,116 @@
package com.willfp.ecoenchants.enchantments;
import com.willfp.ecoenchants.config.ConfigManager;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
/**
* Class for storing all enchantment rarities
*/
public class EnchantmentRarity {
private static final Set<EnchantmentRarity> rarities = new HashSet<>();
private final String name;
private final double probability;
private final int minimumLevel;
private final double villagerProbability;
private final double lootProbability;
/**
* Create new EnchantmentRarity
* @param name The name of the rarity
* @param probability The probability
* @param minimumLevel The minimum xp level
* @param villagerProbability The probability of a villager obtaining an enchantment with this rarity
* @param lootProbability The probability of an item in a loot chest having an enchantment with this rarity
*/
public EnchantmentRarity(String name, double probability, int minimumLevel, double villagerProbability, double lootProbability) {
Optional<EnchantmentRarity> matching = rarities.stream().filter(rarity -> rarity.getName().equalsIgnoreCase(name)).findFirst();
matching.ifPresent(rarities::remove);
this.name = name;
this.probability = probability;
this.minimumLevel = minimumLevel;
this.villagerProbability = villagerProbability;
this.lootProbability = lootProbability;
rarities.add(this);
}
/**
* Get the name of the rarity
* @return The name
*/
public String getName() {
return this.name;
}
/**
* Get the probability of obtaining enchantment with this rarity from an enchanting table
* @return The probability as a percentage
*/
public double getProbability() {
return this.probability;
}
/**
* Get the probability of obtaining enchantment with this rarity from a villager
* @return The probability as a percentage
*/
public double getVillagerProbability() {
return this.villagerProbability;
}
/**
* Get the probability of obtaining enchantment with this rarity from a loot chest
* @return The probability as a percentage
*/
public double getLootProbability() {
return this.lootProbability;
}
/**
* Get the minimum level required to obtain enchantment with this rarity from an enchanting table
* @return The minimum level
*/
public int getMinimumLevel() {
return this.minimumLevel;
}
/**
* Get EnchantmentRarity matching name
* @param name The name to search for
* @return The matching EnchantmentRarity, or null if not found
*/
public static EnchantmentRarity getByName(String name) {
Optional<EnchantmentRarity> matching = rarities.stream().filter(rarity -> rarity.getName().equalsIgnoreCase(name)).findFirst();
return matching.orElse(null);
}
/**
* Update all rarities
* Called on /ecoreload
*/
public static void update() {
Set<String> raritiesNames = ConfigManager.getConfig().getRarities();
raritiesNames.forEach((rarity) -> {
String name = rarity;
double probability = ConfigManager.getConfig().getDouble("obtaining.rarities." + rarity + ".table-probability");
int minimumLevel = ConfigManager.getConfig().getInt("obtaining.rarities." + rarity + ".minimum-level");
double villagerProbability = ConfigManager.getConfig().getDouble("obtaining.rarities." + rarity + ".villager-probability");
double lootProbability = ConfigManager.getConfig().getDouble("obtaining.rarities." + rarity + ".loot-probability");
new EnchantmentRarity(name, probability, minimumLevel, villagerProbability, lootProbability);
});
}
/**
* Get all rarities
* @return A set of all rarities
*/
public static Set<EnchantmentRarity> getAll() {
return rarities;
}
}

View File

@ -0,0 +1,10 @@
package com.willfp.ecoenchants.enchantments;
/**
* Triggered if enchantment is invalid (for extensions)
*/
public class InvalidEnchantmentException extends RuntimeException {
public InvalidEnchantmentException(String errorMessage) {
super(errorMessage);
}
}

View File

@ -0,0 +1,17 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import org.bukkit.Color;
import org.bukkit.Particle;
@SuppressWarnings("deprecation")
public class CloudsArtifact extends Artifact {
public CloudsArtifact() {
super(
"clouds_artifact",
4.0,
Particle.REDSTONE,
new Particle.DustOptions(Color.AQUA, 1.0f)
);
}
}

View File

@ -0,0 +1,15 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import org.bukkit.Particle;
@SuppressWarnings("deprecation")
public class DamageArtifact extends Artifact {
public DamageArtifact() {
super(
"damage_artifact",
4.0,
Particle.DAMAGE_INDICATOR
);
}
}

View File

@ -0,0 +1,15 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import org.bukkit.Particle;
@SuppressWarnings("deprecation")
public class DragonArtifact extends Artifact {
public DragonArtifact() {
super(
"dragon_artifact",
4.0,
Particle.DRAGON_BREATH
);
}
}

View File

@ -0,0 +1,15 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import org.bukkit.Particle;
@SuppressWarnings("deprecation")
public class DustArtifact extends Artifact {
public DustArtifact() {
super(
"dust_artifact",
4.0,
Particle.CRIT
);
}
}

View File

@ -0,0 +1,15 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import org.bukkit.Particle;
@SuppressWarnings("deprecation")
public class EmeraldArtifact extends Artifact {
public EmeraldArtifact() {
super(
"emerald_artifact",
4.0,
Particle.COMPOSTER
);
}
}

View File

@ -0,0 +1,15 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import org.bukkit.Particle;
@SuppressWarnings("deprecation")
public class EnchantmentArtifact extends Artifact {
public EnchantmentArtifact() {
super(
"enchantment_artifact",
4.0,
Particle.ENCHANTMENT_TABLE
);
}
}

View File

@ -0,0 +1,15 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import org.bukkit.Particle;
@SuppressWarnings("deprecation")
public class EndArtifact extends Artifact {
public EndArtifact() {
super(
"end_artifact",
4.0,
Particle.END_ROD
);
}
}

View File

@ -0,0 +1,15 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import org.bukkit.Particle;
@SuppressWarnings("deprecation")
public class FireArtifact extends Artifact {
public FireArtifact() {
super(
"fire_artifact",
4.0,
Particle.FLAME
);
}
}

View File

@ -0,0 +1,15 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import org.bukkit.Particle;
@SuppressWarnings("deprecation")
public class HeartArtifact extends Artifact {
public HeartArtifact() {
super(
"heart_artifact",
4.0,
Particle.HEART
);
}
}

View File

@ -0,0 +1,15 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import org.bukkit.Particle;
@SuppressWarnings("deprecation")
public class HoneyArtifact extends Artifact {
public HoneyArtifact() {
super(
"honey_artifact",
4.0,
Particle.FALLING_HONEY
);
}
}

View File

@ -0,0 +1,15 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import org.bukkit.Particle;
@SuppressWarnings("deprecation")
public class InkArtifact extends Artifact {
public InkArtifact() {
super(
"ink_artifact",
4.0,
Particle.SQUID_INK
);
}
}

View File

@ -0,0 +1,15 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import org.bukkit.Particle;
@SuppressWarnings("deprecation")
public class LavaArtifact extends Artifact {
public LavaArtifact() {
super(
"lava_artifact",
4.0,
Particle.DRIP_LAVA
);
}
}

View File

@ -0,0 +1,15 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import org.bukkit.Particle;
@SuppressWarnings("deprecation")
public class MagicArtifact extends Artifact {
public MagicArtifact() {
super(
"magic_artifact",
4.0,
Particle.CRIT_MAGIC
);
}
}

View File

@ -0,0 +1,15 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import org.bukkit.Particle;
@SuppressWarnings("deprecation")
public class MagmaArtifact extends Artifact {
public MagmaArtifact() {
super(
"magma_artifact",
4.0,
Particle.LAVA
);
}
}

View File

@ -0,0 +1,15 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import org.bukkit.Particle;
@SuppressWarnings("deprecation")
public class MusicArtifact extends Artifact {
public MusicArtifact() {
super(
"music_artifact",
4.0,
Particle.NOTE
);
}
}

View File

@ -0,0 +1,15 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import org.bukkit.Particle;
@SuppressWarnings("deprecation")
public class NetherArtifact extends Artifact {
public NetherArtifact() {
super(
"nether_artifact",
4.0,
Particle.PORTAL
);
}
}

View File

@ -0,0 +1,17 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import org.bukkit.Color;
import org.bukkit.Particle;
@SuppressWarnings("deprecation")
public class RedstoneArtifact extends Artifact {
public RedstoneArtifact() {
super(
"redstone_artifact",
4.0,
Particle.REDSTONE,
new Particle.DustOptions(Color.RED, 1.0f)
);
}
}

View File

@ -0,0 +1,15 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import org.bukkit.Particle;
@SuppressWarnings("deprecation")
public class SmokeArtifact extends Artifact {
public SmokeArtifact() {
super(
"smoke_artifact",
4.0,
Particle.CAMPFIRE_COSY_SMOKE
);
}
}

View File

@ -0,0 +1,15 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import org.bukkit.Particle;
@SuppressWarnings("deprecation")
public class SnowArtifact extends Artifact {
public SnowArtifact() {
super(
"snow_artifact",
4.0,
Particle.SNOWBALL
);
}
}

View File

@ -0,0 +1,15 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import org.bukkit.Particle;
@SuppressWarnings("deprecation")
public class SparkleArtifact extends Artifact {
public SparkleArtifact() {
super(
"sparkle_artifact",
4.0,
Particle.FIREWORKS_SPARK
);
}
}

View File

@ -0,0 +1,15 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import org.bukkit.Particle;
@SuppressWarnings("deprecation")
public class TotemArtifact extends Artifact {
public TotemArtifact() {
super(
"totem_artifact",
4.0,
Particle.TOTEM
);
}
}

View File

@ -0,0 +1,15 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import org.bukkit.Particle;
@SuppressWarnings("deprecation")
public class WaterArtifact extends Artifact {
public WaterArtifact() {
super(
"water_artifact",
4.0,
Particle.DRIP_WATER
);
}
}

View File

@ -0,0 +1,15 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import org.bukkit.Particle;
@SuppressWarnings("deprecation")
public class WitchArtifact extends Artifact {
public WitchArtifact() {
super(
"witch_artifact",
4.0,
Particle.SPELL_WITCH
);
}
}

View File

@ -0,0 +1,17 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
import com.willfp.ecoenchants.enchantments.Artifact;
import org.bukkit.Color;
import org.bukkit.Particle;
@SuppressWarnings("deprecation")
public class ZapArtifact extends Artifact {
public ZapArtifact() {
super(
"zap_artifact",
4.0,
Particle.REDSTONE,
new Particle.DustOptions(Color.YELLOW, 1.0f)
);
}
}

View File

@ -0,0 +1,34 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.HasEnchant;
import com.willfp.ecoenchants.util.Rand;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockDamageEvent;
@SuppressWarnings("deprecation")
public class BreaklessnessCurse extends EcoEnchant {
public BreaklessnessCurse() {
super(
new EcoEnchantBuilder("breaklessness_curse", EnchantmentType.CURSE, Target.Applicable.TOOL, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onDamageBlock(BlockDamageEvent event) {
Player player = event.getPlayer();
if (!HasEnchant.playerHeld(player, this)) return;
if (Rand.randFloat(0, 1) > 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance"))
return;
event.setCancelled(true);
}
}

View File

@ -0,0 +1,51 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
import com.willfp.ecoenchants.Main;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.task.EcoRunnable;
import com.willfp.ecoenchants.util.HasEnchant;
import com.willfp.ecoenchants.util.LocationUtils;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.PigZombie;
import org.bukkit.util.Vector;
@SuppressWarnings("deprecation")
public class CallingCurse extends EcoEnchant implements EcoRunnable {
public CallingCurse() {
super(
new EcoEnchantBuilder("calling_curse", EnchantmentType.CURSE, new Target.Applicable[]{Target.Applicable.ARMOR}, 4.0)
);
}
@Override
public void run() {
Main.getInstance().getServer().getOnlinePlayers().stream().filter(player -> HasEnchant.getArmorPoints(player, EcoEnchants.CALLING_CURSE, false) > 0).forEach((player -> {
double distance = EcoEnchants.CALLING_CURSE.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "distance");
for (Entity e : player.getWorld().getNearbyEntities(player.getLocation(), distance, distance, distance)) {
if(!(e instanceof Monster)) continue;
if(e instanceof PigZombie) {
((PigZombie) e).setAngry(true);
}
((Monster) e).setTarget(player);
Vector vector = player.getLocation().toVector().clone().subtract(e.getLocation().toVector()).normalize().multiply(0.23d);
if(LocationUtils.isFinite(vector)) {
e.setVelocity(vector);
}
}
}));
}
@Override
public long getTime() {
return this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "repeat-ticks");
}
}

View File

@ -0,0 +1,51 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
import com.willfp.ecoenchants.Main;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.task.EcoRunnable;
import com.willfp.ecoenchants.util.HasEnchant;
import com.willfp.ecoenchants.util.ItemDurability;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Repairable;
import java.util.Arrays;
@SuppressWarnings("deprecation")
public class DecayCurse extends EcoEnchant implements EcoRunnable {
public DecayCurse() {
super(
new EcoEnchantBuilder("decay_curse", EnchantmentType.CURSE, Target.Applicable.ALL, 4.0)
);
}
@Override
public void run() {
Main.getInstance().getServer().getOnlinePlayers().forEach((player -> {
if(Arrays.stream(player.getInventory().getContents()).parallel().noneMatch(item2 -> HasEnchant.item(item2, EcoEnchants.DECAY_CURSE)))
return;
for(ItemStack item : player.getInventory().getContents()) {
if(!HasEnchant.item(item, EcoEnchants.DECAY_CURSE)) continue;
if(!(item.getItemMeta() instanceof Repairable)) continue;
if(player.getInventory().getItemInMainHand().equals(item)) continue;
if(player.getInventory().getItemInOffHand().equals(item)) continue;
if(player.getItemOnCursor().equals(item)) continue;
int damage = EcoEnchants.DECAY_CURSE.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "damage");
ItemDurability.damageItemNoBreak(item, damage, player);
}
}));
}
@Override
public long getTime() {
return this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "repeat-ticks");
}
}

View File

@ -0,0 +1,34 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.HasEnchant;
import com.willfp.ecoenchants.util.Rand;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerItemDamageEvent;
import org.bukkit.inventory.ItemStack;
@SuppressWarnings("deprecation")
public class FragilityCurse extends EcoEnchant {
public FragilityCurse() {
super(
new EcoEnchantBuilder("fragility_curse", EnchantmentType.CURSE, new Target.Applicable[]{Target.Applicable.ALL}, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onItemDamage(PlayerItemDamageEvent event) {
ItemStack item = event.getItem();
if (!HasEnchant.item(item, this)) return;
int min = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "minimum-extra-durability");
int max = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "maximum-extra-durability");
event.setDamage(event.getDamage() * Rand.randInt(min, max));
}
}

View File

@ -0,0 +1,44 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.HasEnchant;
import com.willfp.ecoenchants.util.Rand;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@SuppressWarnings("deprecation")
public class HarmlessnessCurse extends EcoEnchant {
public HarmlessnessCurse() {
super(
new EcoEnchantBuilder("harmlessness_curse", EnchantmentType.CURSE, new Target.Applicable[]{Target.Applicable.SWORD, Target.Applicable.AXE}, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void harmlessnessHit(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player))
return;
if (!(event.getEntity() instanceof LivingEntity))
return;
if (event.getEntity() instanceof Monster)
return;
Player player = (Player) event.getDamager();
if (!HasEnchant.playerHeld(player, this)) return;
if (Rand.randFloat(0, 1) > 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance"))
return;
event.setDamage(0);
event.setCancelled(true);
}
}

View File

@ -0,0 +1,37 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.HasEnchant;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.FoodLevelChangeEvent;
@SuppressWarnings("deprecation")
public class HungerCurse extends EcoEnchant {
public HungerCurse() {
super(
new EcoEnchantBuilder("hunger_curse", EnchantmentType.CURSE, Target.Applicable.HELMET, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onHunger(FoodLevelChangeEvent event) {
if (!(event.getEntity() instanceof Player))
return;
Player player = (Player) event.getEntity();
if(!HasEnchant.playerHelmet(player, this)) return;
if(event.getFoodLevel() > player.getFoodLevel()) return;
int delta = player.getFoodLevel() - event.getFoodLevel();
delta *= this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "times-more-hunger");
event.setFoodLevel(player.getFoodLevel() - delta);
}
}

View File

@ -0,0 +1,34 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.HasEnchant;
import com.willfp.ecoenchants.util.Rand;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockBreakEvent;
@SuppressWarnings("deprecation")
public class MisfortuneCurse extends EcoEnchant {
public MisfortuneCurse() {
super(
new EcoEnchantBuilder("misfortune_curse", EnchantmentType.CURSE, Target.Applicable.TOOL, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onBreak(BlockBreakEvent event) {
Player player = event.getPlayer();
if (!HasEnchant.playerHeld(player, this)) return;
if (Rand.randFloat(0, 1) > 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance"))
return;
event.setDropItems(false);
}
}

View File

@ -0,0 +1,18 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.nms.Target;
@SuppressWarnings("deprecation")
public class PermanenceCurse extends EcoEnchant {
public PermanenceCurse() {
super(
new EcoEnchantBuilder("permanence_curse", EnchantmentType.CURSE, Target.Applicable.ALL, 4.0)
);
}
// START OF LISTENERS
// Listeners are in anvil listeners
}

View File

@ -0,0 +1,75 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Cooldown;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.AntiGrief;
import com.willfp.ecoenchants.util.HasEnchant;
import com.willfp.ecoenchants.util.ItemDurability;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Arrays;
@SuppressWarnings("deprecation")
public class Abrasion extends EcoEnchant {
public Abrasion() {
super(
new EcoEnchantBuilder("abrasion", EnchantmentType.NORMAL, new Target.Applicable[]{Target.Applicable.SWORD, Target.Applicable.AXE}, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onHit(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player))
return;
if (!(event.getEntity() instanceof Player))
return;
if (event.isCancelled())
return;
Player player = (Player) event.getDamager();
Player victim = (Player) event.getEntity();
if(!AntiGrief.canInjurePlayer(player, victim)) return;
if (!HasEnchant.playerHeld(player, this)) return;
int level = HasEnchant.getPlayerLevel(player, this);
boolean notcharged = this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged");
if (Cooldown.getCooldown(player) != 1.0f && !notcharged)
return;
ArrayList<ItemStack> armor = new ArrayList<ItemStack>(Arrays.asList(victim.getInventory().getArmorContents()));
if (armor.isEmpty())
return;
for (ItemStack armorPiece : armor) {
if (armorPiece == null)
continue;
if (Target.Applicable.HELMET.getMaterials().contains(armorPiece.getType())) {
ItemDurability.damageItem(player, player.getInventory().getHelmet(), level, 39);
}
if (Target.Applicable.CHESTPLATE.getMaterials().contains(armorPiece.getType())) {
ItemDurability.damageItem(player, player.getInventory().getChestplate(), level, 38);
}
if (Target.Applicable.LEGGINGS.getMaterials().contains(armorPiece.getType())) {
ItemDurability.damageItem(player, player.getInventory().getLeggings(), level, 37);
}
if (Target.Applicable.BOOTS.getMaterials().contains(armorPiece.getType())) {
ItemDurability.damageItem(player, player.getInventory().getBoots(), level, 36);
}
}
}
}

View File

@ -0,0 +1,63 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.Main;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.HasEnchant;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.metadata.FixedMetadataValue;
@SuppressWarnings("deprecation")
public class Aerial extends EcoEnchant {
public Aerial() {
super(
new EcoEnchantBuilder("aerial", EnchantmentType.NORMAL, new Target.Applicable[]{Target.Applicable.BOW, Target.Applicable.CROSSBOW}, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onShoot(ProjectileLaunchEvent event) {
if (event.getEntityType() != EntityType.ARROW)
return;
if (!(event.getEntity().getShooter() instanceof Player))
return;
Player player = (Player) event.getEntity().getShooter();
if(player.isOnGround())
return;
if (!HasEnchant.playerHeld(player, this)) return;
int level = HasEnchant.getPlayerLevel(player, this);
if (!(event.getEntity() instanceof Arrow)) return;
Arrow a = (Arrow) event.getEntity();
a.setMetadata("from-aerial", new FixedMetadataValue(Main.getInstance(), level));
}
@EventHandler
public void onDamage(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Arrow))
return;
if (!event.getDamager().hasMetadata("from-aerial"))
return;
int level = event.getDamager().getMetadata("from-aerial").get(0).asInt();
double damage = event.getDamage();
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-multiplier-per-level");
double reduction = 1 + (multiplier * level);
event.setDamage(damage * reduction);
}
}

View File

@ -0,0 +1,58 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.nms.TridentStack;
import com.willfp.ecoenchants.util.HasEnchant;
import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Trident;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
@SuppressWarnings("deprecation")
public class Aquatic extends EcoEnchant {
public Aquatic() {
super(
new EcoEnchantBuilder("aquatic", EnchantmentType.NORMAL, Target.Applicable.TRIDENT, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onHit(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Trident))
return;
if(!(((Trident) event.getDamager()).getShooter() instanceof Player))
return;
if (!(event.getEntity() instanceof LivingEntity))
return;
if (event.isCancelled())
return;
Player player = (Player) ((Trident) event.getDamager()).getShooter();
Trident trident = (Trident) event.getDamager();
ItemStack item = TridentStack.getTridentStack(trident);
if(!player.getLocation().getBlock().getType().equals(Material.WATER))
return;
if (!HasEnchant.item(item, this)) return;
int level = HasEnchant.getItemLevel(item, this);
double perLevelDamage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "percent-more-per-level");
double totalDamagePercent = (100 + (perLevelDamage * level))/100;
event.setDamage(event.getDamage() * totalDamagePercent);
}
}

View File

@ -0,0 +1,44 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.HasEnchant;
import com.willfp.ecoenchants.util.Rand;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent;
@SuppressWarnings("deprecation")
public class Arcanic extends EcoEnchant {
public Arcanic() {
super(
new EcoEnchantBuilder("arcanic", EnchantmentType.NORMAL, Target.Applicable.ARMOR, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onEffect(EntityDamageEvent event) {
if (!(event.getEntity() instanceof Player))
return;
if (!(event.getCause().equals(EntityDamageEvent.DamageCause.POISON) || event.getCause().equals(EntityDamageEvent.DamageCause.WITHER)))
return;
Player player = (Player) event.getEntity();
int totalArcanicPoints = HasEnchant.getArmorPoints(player, this, false);
if (totalArcanicPoints == 0)
return;
double chance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-point");
if (Rand.randFloat(0, 1) > totalArcanicPoints * 0.01 * chance)
return;
event.setCancelled(true);
}
}

View File

@ -0,0 +1,76 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.queue.DropQueue;
import com.willfp.ecoenchants.util.HasEnchant;
import com.willfp.ecoenchants.util.Rand;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
public class Beheading extends EcoEnchant {
public Beheading() {
super(
new EcoEnchantBuilder("beheading", EnchantmentType.NORMAL, new Target.Applicable[]{Target.Applicable.SWORD, Target.Applicable.AXE}, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onDeath(EntityDeathEvent event) {
if (event.getEntity().getKiller() == null)
return;
Player player = event.getEntity().getKiller();
LivingEntity victim = event.getEntity();
if (!HasEnchant.playerHeld(player, this)) return;
int level = HasEnchant.getPlayerLevel(player, this);
double chance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level");
if (Rand.randFloat(0, 1) > level * 0.01 * chance)
return;
ItemStack item;
if(victim instanceof Player) {
item = new ItemStack(Material.PLAYER_HEAD, 1);
SkullMeta meta = (SkullMeta) item.getItemMeta();
assert meta != null;
meta.setOwningPlayer((Player) victim);
item.setItemMeta(meta);
} else {
if(event.getEntityType().equals(EntityType.ZOMBIE)) {
item = new ItemStack(Material.ZOMBIE_HEAD, 1);
}
else if(event.getEntityType().equals(EntityType.SKELETON)) {
item = new ItemStack(Material.SKELETON_SKULL, 1);
}
else if(event.getEntityType().equals(EntityType.CREEPER)) {
item = new ItemStack(Material.CREEPER_HEAD, 1);
}
else if(event.getEntityType().equals(EntityType.ENDER_DRAGON)) {
item = new ItemStack(Material.DRAGON_HEAD, 1);
}
else return;
}
new DropQueue(player)
.addItem(item)
.addXP(event.getDroppedExp())
.setLocation(victim.getLocation())
.push();
event.setDroppedExp(0);
}
}

View File

@ -0,0 +1,77 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.Main;
import com.willfp.ecoenchants.anticheat.AnticheatManager;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.BlockBreak;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.AntiGrief;
import com.willfp.ecoenchants.util.HasEnchant;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.metadata.FixedMetadataValue;
@SuppressWarnings("deprecation")
public class BlastMining extends EcoEnchant {
public BlastMining() {
super(
new EcoEnchantBuilder("blast_mining", EnchantmentType.NORMAL, Target.Applicable.PICKAXE, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onBreak(BlockBreakEvent event) {
Player player = event.getPlayer();
Block block = event.getBlock();
if (block.hasMetadata("from-drill") || block.hasMetadata("from-lumberjack") || block.hasMetadata("from-blastmining") || block.hasMetadata("from-vein")) {
return;
}
if (!HasEnchant.playerHeld(player, this)) return;
if (event.isCancelled())
return;
if (!AntiGrief.canBreakBlock(player, block)) return;
if(player.isSneaking() && this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "disable-on-sneak")) return;
boolean hasExploded = false;
AnticheatManager.exemptPlayer(player);
for(int x = -1; x <= 1; x++) {
for(int y = -1; y <= 1; y++) {
for (int z = -1; z <= 1; z++) {
if(x == 0 && y == 0 && z == 0) continue;
Block block1 = block.getWorld().getBlockAt(block.getLocation().clone().add(x, y, z));
block1.setMetadata("from-blastmining", new FixedMetadataValue(Main.getInstance(), true));
if(this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blacklisted-blocks").contains(block1.getType().name().toLowerCase())) {
continue;
}
if(block1.getType().getHardness() > block.getType().getHardness() && this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "hardness-check")) continue;
if (!AntiGrief.canBreakBlock(player, block1)) continue;
BlockBreak.breakBlock(player, block1);
if(!hasExploded) {
block.getWorld().createExplosion(block.getLocation().clone().add(0.5, 0.5, 0.5), 0, false);
hasExploded = true;
}
block1.removeMetadata("from-blastmining", Main.getInstance());
}
}
}
AnticheatManager.unexemptPlayer(player);
}
}

View File

@ -0,0 +1,74 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.Main;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Cooldown;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.AntiGrief;
import com.willfp.ecoenchants.util.HasEnchant;
import com.willfp.ecoenchants.util.Rand;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.concurrent.atomic.AtomicInteger;
@SuppressWarnings("deprecation")
public class Bleed extends EcoEnchant {
public Bleed() {
super(
new EcoEnchantBuilder("bleed", EnchantmentType.NORMAL, Target.Applicable.SWORD, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onHit(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player))
return;
if (!(event.getEntity() instanceof LivingEntity))
return;
Player player = (Player) event.getDamager();
LivingEntity victim = (LivingEntity) event.getEntity();
if(event.getEntity() instanceof Player) {
if(!AntiGrief.canInjurePlayer(player, (Player) event.getEntity())) return;
}
if (!HasEnchant.playerHeld(player, this)) return;
if (Cooldown.getCooldown(player) != 1.0f && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged"))
return;
int level = HasEnchant.getPlayerLevel(player, this);
if (Rand.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level"))
return;
double bleedDamage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "bleed-damage");
int bleedCount = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "amount-per-level");
bleedCount *= level;
final int finalBleedCount = bleedCount;
AtomicInteger currentBleedCount = new AtomicInteger(0);
new BukkitRunnable() {
@Override
public void run() {
currentBleedCount.addAndGet(1);
victim.damage(bleedDamage);
if(currentBleedCount.get() >= finalBleedCount) this.cancel();
}
}.runTaskTimer(Main.getInstance(), 0, 10);
}
}

View File

@ -0,0 +1,45 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.HasEnchant;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Boss;
import org.bukkit.entity.ElderGuardian;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@SuppressWarnings("deprecation")
public class BossHunter extends EcoEnchant {
public BossHunter() {
super(
new EcoEnchantBuilder("boss_hunter", EnchantmentType.NORMAL, new Target.Applicable[]{Target.Applicable.BOW, Target.Applicable.CROSSBOW}, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onHit(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Arrow)) return;
if (!(((Arrow) event.getDamager()).getShooter() instanceof Player)) return;
if (!(event.getEntity() instanceof Boss || event.getEntity() instanceof ElderGuardian)) return;
Player player = (Player) ((Arrow) event.getDamager()).getShooter();
Arrow arrow = (Arrow) event.getDamager();
if (!HasEnchant.playerHeld(player, this)) return;
int level = HasEnchant.getPlayerLevel(player, this);
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");
double damageMultiplier = (level * multiplier) + 1;
event.setDamage(event.getDamage() * damageMultiplier);
}
}

View File

@ -0,0 +1,62 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.HasEnchant;
import com.willfp.ecoenchants.util.Rand;
import org.bukkit.Sound;
import org.bukkit.SoundCategory;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.AbstractArrow;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.util.Vector;
@SuppressWarnings("deprecation")
public class Buckshot extends EcoEnchant {
public Buckshot() {
super(
new EcoEnchantBuilder("buckshot", EnchantmentType.NORMAL, Target.Applicable.BOW, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onShoot(EntityShootBowEvent event) {
if (event.getProjectile().getType() != EntityType.ARROW)
return;
if (!(event.getEntity() instanceof Player))
return;
Player player = (Player) event.getEntity();
if (!HasEnchant.playerHeld(player, this)) return;
int level = HasEnchant.getPlayerLevel(player, this);
event.getProjectile().remove();
player.playSound(player.getLocation(), Sound.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0f, 1.0f);
int numberPerLevel = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "amount-per-level");
int number = numberPerLevel * level;
double spread = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "spread-per-level");
spread *= level;
for (int i = 0; i < number; i += 1) {
Vector velocity = event.getProjectile().getVelocity().clone();
velocity.add(new Vector(Rand.randFloat(-spread, spread), Rand.randFloat(-spread, spread), Rand.randFloat(-spread, spread)));
Arrow arrow = player.launchProjectile(Arrow.class, velocity);
if(HasEnchant.playerHeld(player, Enchantment.ARROW_FIRE)) arrow.setFireTicks(Integer.MAX_VALUE);
arrow.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED);
}
}
}

View File

@ -0,0 +1,42 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.HasEnchant;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@SuppressWarnings("deprecation")
public class Butchering extends EcoEnchant {
public Butchering() {
super(
new EcoEnchantBuilder("butchering", EnchantmentType.NORMAL, new Target.Applicable[]{Target.Applicable.SWORD, Target.Applicable.AXE}, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void butcheringHit(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player))
return;
if (!(event.getEntity() instanceof LivingEntity))
return;
if (event.getEntity() instanceof Monster)
return;
Player player = (Player) event.getDamager();
if (!HasEnchant.playerHeld(player, this)) return;
int level = HasEnchant.getPlayerLevel(player, this);
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "bonus-per-level");
event.setDamage(event.getDamage() + (level * multiplier));
}
}

View File

@ -0,0 +1,48 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.HasEnchant;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@SuppressWarnings("deprecation")
public class Cerebral extends EcoEnchant {
public Cerebral() {
super(
new EcoEnchantBuilder("cerebral", EnchantmentType.NORMAL, new Target.Applicable[]{Target.Applicable.BOW, Target.Applicable.CROSSBOW}, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onCerebralDamage(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Arrow)) return;
if (!(((Arrow) event.getDamager()).getShooter() instanceof Player)) return;
if (!(event.getEntity() instanceof LivingEntity)) return;
Player player = (Player) ((Arrow) event.getDamager()).getShooter();
Arrow arrow = (Arrow) event.getDamager();
LivingEntity victim = (LivingEntity) event.getEntity();
if (!(arrow.getLocation().getY() >= victim.getLocation().getY() + victim.getEyeHeight() - 0.22)) return;
if (!HasEnchant.playerHeld(player, this)) return;
int level = HasEnchant.getPlayerLevel(player, this);
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");
double damageMultiplier = (level * multiplier) + 1;
event.setDamage(event.getDamage() * damageMultiplier);
}
}

View File

@ -0,0 +1,47 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.HasEnchant;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@SuppressWarnings("deprecation")
public class Chopless extends EcoEnchant {
public Chopless() {
super(
new EcoEnchantBuilder("chopless", EnchantmentType.NORMAL, Target.Applicable.ARMOR, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onPreservationHurt(EntityDamageByEntityEvent event) {
if(!(event.getDamager() instanceof Player))
return;
if (!(event.getEntity() instanceof Player))
return;
Player player = (Player) event.getEntity();
Player damager = (Player) event.getDamager();
if(!Target.Applicable.AXE.getMaterials().contains(damager.getInventory().getItemInMainHand().getType()))
return;
int totalChoplessPoints = HasEnchant.getArmorPoints(player, this, true);
if (totalChoplessPoints == 0)
return;
double reduction = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "percent-less-per-level");
double multiplier = 1 - (reduction/100 * totalChoplessPoints);
event.setDamage(event.getDamage() * multiplier);
}
}

View File

@ -0,0 +1,67 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.Main;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Cooldown;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.AntiGrief;
import com.willfp.ecoenchants.util.HasEnchant;
import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.metadata.FixedMetadataValue;
@SuppressWarnings("deprecation")
public class Cleave extends EcoEnchant {
public Cleave() {
super(
new EcoEnchantBuilder("cleave", EnchantmentType.NORMAL, Target.Applicable.AXE, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onDamage(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player))
return;
if (!(event.getEntity() instanceof LivingEntity))
return;
Player player = (Player) event.getDamager();
LivingEntity victim = (LivingEntity) event.getEntity();
if(victim.hasMetadata("cleaved"))
return;
if(event.getEntity() instanceof Player) {
if(!AntiGrief.canInjurePlayer(player, (Player) event.getEntity())) return;
}
if (!HasEnchant.playerHeld(player, this)) return;
if (Cooldown.getCooldown(player) != 1.0f && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged"))
return;
int level = HasEnchant.getPlayerLevel(player, this);
double damagePerLevel = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-percentage-per-level") * 0.01;
double radiusPerLevel = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "radius-per-level");
final double damage = damagePerLevel * level * event.getDamage();
final double radius = radiusPerLevel * level;
victim.getNearbyEntities(radius, radius, radius).stream()
.filter(entity -> entity instanceof LivingEntity)
.filter(entity -> !entity.equals(player))
.forEach(entity -> {
entity.setMetadata("cleaved", new FixedMetadataValue(Main.getInstance(), true));
((LivingEntity) entity).damage(damage, player);
Bukkit.getScheduler().runTaskLater(Main.getInstance(), () -> entity.removeMetadata("cleaved", Main.getInstance()), 5);
});
}
}

View File

@ -0,0 +1,42 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.HasEnchant;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.ProjectileLaunchEvent;
@SuppressWarnings("deprecation")
public class Collateral extends EcoEnchant {
public Collateral() {
super(
new EcoEnchantBuilder("collateral", EnchantmentType.NORMAL, Target.Applicable.BOW, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onCollateralShoot(ProjectileLaunchEvent event) {
if (event.getEntityType() != EntityType.ARROW)
return;
if (!(event.getEntity().getShooter() instanceof Player))
return;
Player player = (Player) event.getEntity().getShooter();
if (!HasEnchant.playerHeld(player, this)) return;
int level = HasEnchant.getPlayerLevel(player, this);
if (!(event.getEntity() instanceof Arrow)) return;
Arrow a = (Arrow) event.getEntity();
a.setPierceLevel(level);
}
}

View File

@ -0,0 +1,52 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.nms.TridentStack;
import com.willfp.ecoenchants.util.HasEnchant;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Trident;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
@SuppressWarnings("deprecation")
public class Cranial extends EcoEnchant {
public Cranial() {
super(
new EcoEnchantBuilder("cranial", EnchantmentType.NORMAL, Target.Applicable.TRIDENT, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onDamage(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Trident)) return;
if (!(((Trident) event.getDamager()).getShooter() instanceof Player)) return;
if (!(event.getEntity() instanceof LivingEntity)) return;
Player player = (Player) ((Trident) event.getDamager()).getShooter();
Trident trident = (Trident) event.getDamager();
LivingEntity victim = (LivingEntity) event.getEntity();
if (!(trident.getLocation().getY() >= victim.getLocation().getY() + victim.getEyeHeight() - 0.22)) return;
ItemStack item = TridentStack.getTridentStack(trident);
if (!HasEnchant.item(item, this)) return;
int level = HasEnchant.getItemLevel(item, this);
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");
double damageMultiplier = (level * multiplier) + 1;
event.setDamage(event.getDamage() * damageMultiplier);
}
}

View File

@ -0,0 +1,43 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.HasEnchant;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@SuppressWarnings("deprecation")
public class Criticals extends EcoEnchant {
public Criticals() {
super(
new EcoEnchantBuilder("criticals", EnchantmentType.NORMAL, new Target.Applicable[]{Target.Applicable.SWORD, Target.Applicable.AXE}, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void criticalHit(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player))
return;
if (!(event.getEntity() instanceof LivingEntity))
return;
Player player = (Player) event.getDamager();
LivingEntity victim = (LivingEntity) event.getEntity();
if (!HasEnchant.playerHeld(player, this)) return;
if (!(player.getFallDistance() > 0 && !player.isOnGround()))
return;
int level = HasEnchant.getPlayerLevel(player, this);
event.setDamage(event.getDamage() * ((level * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-multiplier-per-level")) + 1));
}
}

View File

@ -0,0 +1,53 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.AntiGrief;
import com.willfp.ecoenchants.util.HasEnchant;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@SuppressWarnings("deprecation")
public class Deflection extends EcoEnchant {
public Deflection() {
super(
new EcoEnchantBuilder("deflection", EnchantmentType.NORMAL, Target.Applicable.SHIELD, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onDeflect(EntityDamageByEntityEvent event) {
if (!(event.getEntity() instanceof Player))
return;
if (!(event.getDamager() instanceof LivingEntity))
return;
Player player = (Player) event.getEntity();
LivingEntity victim = (LivingEntity) event.getDamager();
if(!player.isBlocking()) return;
if(victim instanceof Player) {
if(!AntiGrief.canInjurePlayer(player, (Player) event.getEntity())) return;
}
int level;
if (!HasEnchant.playerOffhand(player, this) && !HasEnchant.playerHeld(player, this)) return;
if(HasEnchant.playerOffhand(player, this)) level = HasEnchant.getPlayerOffhandLevel(player, this);
else level = HasEnchant.getPlayerLevel(player, this);
double perlevel = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "percent-deflected-per-level");
double damagePercent = (perlevel/100) * level;
double damage = event.getDamage() * damagePercent;
victim.damage(damage, player);
}
}

View File

@ -0,0 +1,41 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.HasEnchant;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@SuppressWarnings("deprecation")
public class Defusion extends EcoEnchant {
public Defusion() {
super(
new EcoEnchantBuilder("defusion", EnchantmentType.NORMAL, new Target.Applicable[]{Target.Applicable.SWORD, Target.Applicable.AXE}, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void defusionHit(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player))
return;
if (!(event.getEntity() instanceof Creeper))
return;
Player player = (Player) event.getDamager();
Creeper victim = (Creeper) event.getEntity();
if (!HasEnchant.playerHeld(player, this)) return;
int level = HasEnchant.getPlayerLevel(player, this);
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "bonus-per-level");
event.setDamage(event.getDamage() + (level * multiplier));
}
}

View File

@ -0,0 +1,40 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.HasEnchant;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.inventory.ItemStack;
@SuppressWarnings("deprecation")
public class Dexterous extends EcoEnchant {
public Dexterous() {
super(
new EcoEnchantBuilder("dexterous", EnchantmentType.NORMAL, new Target.Applicable[]{Target.Applicable.SWORD, Target.Applicable.AXE}, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onDextHold(PlayerItemHeldEvent event) {
Player player = event.getPlayer();
ItemStack item = player.getInventory().getItem(event.getNewSlot());
if (!HasEnchant.item(item, this)) {
player.getAttribute(Attribute.GENERIC_ATTACK_SPEED).setBaseValue(4.0);
return;
}
int level = HasEnchant.getItemLevel(item, this);
double bonus = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "add-speed-per-level");
player.getAttribute(Attribute.GENERIC_ATTACK_SPEED).setBaseValue(4.0 + (level * bonus));
}
}

View File

@ -0,0 +1,47 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.Main;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.HasEnchant;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
@SuppressWarnings("deprecation")
public class Disappear extends EcoEnchant {
public Disappear() {
super(
new EcoEnchantBuilder("disappear", EnchantmentType.NORMAL, Target.Applicable.ARMOR, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onHurt(EntityDamageByEntityEvent event) {
if (!(event.getEntity() instanceof Player))
return;
Bukkit.getScheduler().runTaskLater(Main.getInstance(), () -> {
Player player = (Player) event.getEntity();
if(player.getHealth() > EcoEnchants.DISAPPEAR.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "threshold"))
return;
final int points = HasEnchant.getArmorPoints(player, this, true);
if (points == 0)
return;
int ticksPerLevel = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "ticks-per-level");
final int ticks = ticksPerLevel * points;
player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, ticks, 1, false, false, true));
}, 1);
}
}

View File

@ -0,0 +1,43 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.HasEnchant;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@SuppressWarnings("deprecation")
public class Diverse extends EcoEnchant {
public Diverse() {
super(
new EcoEnchantBuilder("diverse", EnchantmentType.NORMAL, Target.Applicable.AXE, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onHit(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player))
return;
if(!(event.getEntity() instanceof Player))
return;
Player player = (Player) event.getDamager();
Player victim = (Player) event.getEntity();
if(!Target.Applicable.SWORD.getMaterials().contains(victim.getInventory().getItemInMainHand().getType()))
return;
if (!HasEnchant.playerHeld(player, this)) return;
int level = HasEnchant.getPlayerLevel(player, this);
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "per-level-multiplier");
event.setDamage(event.getDamage() * (1 + (level * multiplier)));
}
}

View File

@ -0,0 +1,72 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.Main;
import com.willfp.ecoenchants.anticheat.AnticheatManager;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.BlockBreak;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.AntiGrief;
import com.willfp.ecoenchants.util.HasEnchant;
import com.willfp.ecoenchants.util.SimplifyVector;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.util.Vector;
@SuppressWarnings("deprecation")
public class Drill extends EcoEnchant {
public Drill() {
super(
new EcoEnchantBuilder("drill", EnchantmentType.NORMAL, Target.Applicable.TOOL, 4.0)
);
}
// START OF LISTENERS
@EventHandler(priority = EventPriority.LOW)
public void drillBreak(BlockBreakEvent event) {
Player player = event.getPlayer();
Block block = event.getBlock();
if (block.hasMetadata("from-drill") || block.hasMetadata("from-lumberjack") || block.hasMetadata("from-blastmining") || block.hasMetadata("from-vein")) {
return;
}
if (!HasEnchant.playerHeld(player, this)) return;
if (event.isCancelled())
return;
if (!AntiGrief.canBreakBlock(player, block)) return;
if(player.isSneaking() && this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "disable-on-sneak")) return;
int level = HasEnchant.getPlayerLevel(player, this) * this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "blocks-per-level");
AnticheatManager.exemptPlayer(player);
for(int i = 1; i <= level; i++) {
Vector simplified = SimplifyVector.simplifyVector(player.getLocation().getDirection().normalize()).multiply(i);
Block block1 = block.getWorld().getBlockAt(block.getLocation().clone().add(simplified));
block1.setMetadata("from-drill", new FixedMetadataValue(Main.getInstance(), true));
if(this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blacklisted-blocks").contains(block1.getType().name().toLowerCase())) {
continue;
}
if(block1.getType().getHardness() > block.getType().getHardness() && this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "hardness-check")) continue;
if (!AntiGrief.canBreakBlock(player, block1)) continue;
BlockBreak.breakBlock(player, block1);
block1.removeMetadata("from-drill", Main.getInstance());
}
AnticheatManager.unexemptPlayer(player);
}
}

View File

@ -0,0 +1,57 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Cooldown;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.AntiGrief;
import com.willfp.ecoenchants.util.HasEnchant;
import com.willfp.ecoenchants.util.Rand;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
@SuppressWarnings("deprecation")
public class Dullness extends EcoEnchant {
public Dullness() {
super(
new EcoEnchantBuilder("dullness", EnchantmentType.NORMAL, Target.Applicable.SWORD, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onHit(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player))
return;
if (!(event.getEntity() instanceof LivingEntity))
return;
Player player = (Player) event.getDamager();
LivingEntity victim = (LivingEntity) event.getEntity();
if(event.getEntity() instanceof Player) {
if(!AntiGrief.canInjurePlayer(player, (Player) event.getEntity())) return;
}
if (!HasEnchant.playerHeld(player, this)) return;
if (Cooldown.getCooldown(player) != 1.0f && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged"))
return;
int level = HasEnchant.getPlayerLevel(player, this);
if (Rand.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level"))
return;
int durationPerLevel = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "duration-per-level");
victim.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, level * durationPerLevel, level));
}
}

View File

@ -0,0 +1,57 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.AntiGrief;
import com.willfp.ecoenchants.util.HasEnchant;
import com.willfp.ecoenchants.util.Lightning;
import com.willfp.ecoenchants.util.Rand;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@SuppressWarnings("deprecation")
public class Electroshock extends EcoEnchant {
public Electroshock() {
super(
new EcoEnchantBuilder("electroshock", EnchantmentType.NORMAL, Target.Applicable.SHIELD, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onElectroshock(EntityDamageByEntityEvent event) {
if (!(event.getEntity() instanceof Player))
return;
if (!(event.getDamager() instanceof LivingEntity))
return;
Player player = (Player) event.getEntity();
LivingEntity victim = (LivingEntity) event.getDamager();
if(!player.isBlocking()) return;
if(victim instanceof Player) {
if(!AntiGrief.canInjurePlayer(player, (Player) event.getEntity())) return;
}
int level;
if (!HasEnchant.playerOffhand(player, this) && !HasEnchant.playerHeld(player, this)) return;
if(HasEnchant.playerOffhand(player, this)) level = HasEnchant.getPlayerOffhandLevel(player, this);
else level = HasEnchant.getPlayerLevel(player, this);
double chance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level");
double damage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage");
double finalChance = (chance * level)/100;
if(Rand.randFloat(0, 1) > finalChance) return;
Lightning.strike(victim, damage);
}
}

View File

@ -0,0 +1,50 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.HasEnchant;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import java.util.HashSet;
import java.util.Set;
@SuppressWarnings("deprecation")
public class EnderSlayer extends EcoEnchant {
public EnderSlayer() {
super(
new EcoEnchantBuilder("ender_slayer", EnchantmentType.NORMAL, new Target.Applicable[]{Target.Applicable.SWORD, Target.Applicable.AXE}, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void enderSlayerHit(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player))
return;
Set<EntityType> endMobs = new HashSet<EntityType>() {{
add(EntityType.ENDERMITE);
add(EntityType.ENDERMAN);
add(EntityType.ENDER_DRAGON);
add(EntityType.SHULKER);
}};
if (!endMobs.contains(event.getEntityType()))
return;
Player player = (Player) event.getDamager();
if (!HasEnchant.playerHeld(player, this)) return;
int level = HasEnchant.getPlayerLevel(player, this);
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "bonus-per-level");
event.setDamage(event.getDamage() + (level * multiplier));
}
}

View File

@ -0,0 +1,43 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.HasEnchant;
import com.willfp.ecoenchants.util.Rand;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent;
@SuppressWarnings("deprecation")
public class Evasion extends EcoEnchant {
public Evasion() {
super(
new EcoEnchantBuilder("evasion", EnchantmentType.NORMAL, Target.Applicable.ARMOR, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onEvasionHurt(EntityDamageEvent event) {
if (!(event.getEntity() instanceof Player))
return;
Player player = (Player) event.getEntity();
int totalEvasionPoints = HasEnchant.getArmorPoints(player, this, true);
if (totalEvasionPoints == 0)
return;
double chance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-point");
if (Rand.randFloat(0, 1) > totalEvasionPoints * 0.01 * chance)
return;
event.setCancelled(true);
}
}

View File

@ -0,0 +1,45 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.HasEnchant;
import com.willfp.ecoenchants.util.Rand;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent;
@SuppressWarnings("deprecation")
public class Extinguishing extends EcoEnchant {
public Extinguishing() {
super(
new EcoEnchantBuilder("extinguishing", EnchantmentType.NORMAL, Target.Applicable.ARMOR, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onExtinguishingHurt(EntityDamageEvent event) {
if (!(event.getEntity() instanceof Player))
return;
if (!event.getCause().equals(EntityDamageEvent.DamageCause.FIRE_TICK))
return;
Player player = (Player) event.getEntity();
int totalExtinguishingPoints = HasEnchant.getArmorPoints(player, this, false);
if (totalExtinguishingPoints == 0)
return;
double chance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-point");
if (Rand.randFloat(0, 1) > totalExtinguishingPoints * 0.01 * chance)
return;
player.setFireTicks(0);
}
}

View File

@ -0,0 +1,63 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.nms.TridentStack;
import com.willfp.ecoenchants.util.AntiGrief;
import com.willfp.ecoenchants.util.HasEnchant;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Trident;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
@SuppressWarnings("deprecation")
public class Extract extends EcoEnchant {
public Extract() {
super(
new EcoEnchantBuilder("extract", EnchantmentType.NORMAL, Target.Applicable.TRIDENT, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void extractHit(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Trident))
return;
if(!(((Trident) event.getDamager()).getShooter() instanceof Player))
return;
if (!(event.getEntity() instanceof LivingEntity))
return;
if (event.isCancelled())
return;
Player player = (Player) ((Trident) event.getDamager()).getShooter();
Trident trident = (Trident) event.getDamager();
ItemStack item = TridentStack.getTridentStack(trident);
if(event.getEntity() instanceof Player) {
if(!AntiGrief.canInjurePlayer(player, (Player) event.getEntity())) return;
}
if (!HasEnchant.item(item, this)) return;
int level = HasEnchant.getItemLevel(item, this);
double damage = event.getDamage();
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-multiplier-per-level");
double amountToHeal = damage * level * multiplier;
double newHealth = player.getHealth() + amountToHeal;
if (newHealth > player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()) {
newHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
}
player.setHealth(newHealth);
}
}

View File

@ -0,0 +1,56 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Cooldown;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.AntiGrief;
import com.willfp.ecoenchants.util.HasEnchant;
import com.willfp.ecoenchants.util.Rand;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
@SuppressWarnings("deprecation")
public class Famine extends EcoEnchant {
public Famine() {
super(
new EcoEnchantBuilder("famine", EnchantmentType.NORMAL, Target.Applicable.SWORD, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onHit(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player))
return;
if (!(event.getEntity() instanceof LivingEntity))
return;
Player player = (Player) event.getDamager();
LivingEntity victim = (LivingEntity) event.getEntity();
if(event.getEntity() instanceof Player) {
if(!AntiGrief.canInjurePlayer(player, (Player) event.getEntity())) return;
}
if (!HasEnchant.playerHeld(player, this)) return;
if (Cooldown.getCooldown(player) != 1.0f && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged"))
return;
int level = HasEnchant.getPlayerLevel(player, this);
if (Rand.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level"))
return;
victim.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, level * 40, level));
victim.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, level * 40, level));
}
}

View File

@ -0,0 +1,86 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.*;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
@SuppressWarnings("deprecation")
public class Farmhand extends EcoEnchant {
public Farmhand() {
super(
new EcoEnchantBuilder("farmhand", EnchantmentType.NORMAL, Target.Applicable.HOE, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void onTill(PlayerInteractEvent event) {
Player player = event.getPlayer();
if (!event.getAction().equals(Action.RIGHT_CLICK_BLOCK))
return;
if (event.getClickedBlock() == null)
return;
if (!(event.getClickedBlock().getType().equals(Material.DIRT) || event.getClickedBlock().getType().equals(Material.GRASS_BLOCK)))
return;
ItemStack item = event.getItem();
if (!HasEnchant.item(item, this)) return;
if (!(Target.Applicable.HOE.getMaterials().contains(item.getType())))
return;
if(!AntiGrief.canBreakBlock(player, event.getClickedBlock())) return;
event.getClickedBlock().setType(Material.FARMLAND);
int initial = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "initial-radius");
int levelrad = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "per-level-radius");
int radius = initial + (HasEnchant.getItemLevel(item, this) - 1) * levelrad;
Vector[] vecs;
if (this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "use-cube")) {
vecs = Cube.getCube(radius);
} else {
vecs = Square.getSquare(radius);
}
if (!this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "per-block-damage")) {
ItemDurability.damageItem(player, player.getInventory().getItemInMainHand(), 1, player.getInventory().getHeldItemSlot());
}
for (Vector vec : vecs) {
Location loc = event.getClickedBlock().getLocation().add(vec);
Block block = event.getClickedBlock().getWorld().getBlockAt(loc);
if(!AntiGrief.canBreakBlock(player, block)) continue;
if (!(block.getType().equals(Material.DIRT) || block.getType().equals(Material.GRASS_BLOCK)))
continue;
if (!block.getWorld().getBlockAt(loc.add(0, 1, 0)).getType().equals(Material.AIR))
continue;
block.setType(Material.FARMLAND);
if (this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "per-block-damage")) {
ItemDurability.damageItem(player, player.getInventory().getItemInMainHand(), 1, player.getInventory().getHeldItemSlot());
}
}
}
}

View File

@ -0,0 +1,43 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.HasEnchant;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@SuppressWarnings("deprecation")
public class Finishing extends EcoEnchant {
public Finishing() {
super(
new EcoEnchantBuilder("finishing", EnchantmentType.NORMAL, Target.Applicable.SWORD, 4.0)
);
}
// START OF LISTENERS
@EventHandler
public void finishingHit(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player))
return;
if (!(event.getEntity() instanceof LivingEntity))
return;
Player player = (Player) event.getDamager();
LivingEntity victim = (LivingEntity) event.getEntity();
if (!HasEnchant.playerHeld(player, this)) return;
int level = HasEnchant.getPlayerLevel(player, this);
double minhealth = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "minimum-health-per-level");
if (!(((LivingEntity) event.getEntity()).getHealth() <= level * minhealth))
return;
event.setDamage(10000); // cba to do this properly
}
}

View File

@ -0,0 +1,44 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.nms.Target;
import com.willfp.ecoenchants.util.HasEnchant;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@SuppressWarnings("deprecation")
public class FireAffinity extends EcoEnchant {
public FireAffinity() {
super(
new EcoEnchantBuilder("fire_affinity", EnchantmentType.NORMAL, Target.Applicable.SWORD, 4.01)
);
}
// START OF LISTENERS
@EventHandler
public void fireAffinityHit(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player))
return;
if (!(event.getEntity() instanceof LivingEntity))
return;
Player player = (Player) event.getDamager();
if (!HasEnchant.playerHeld(player, this)) return;
if(player.getFireTicks() == 0) return;
int level = HasEnchant.getPlayerLevel(player, this);
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "percent-more-per-level");
double finalMultiplier = (multiplier/100 * level) + 1;
event.setDamage(event.getDamage() * finalMultiplier);
}
}

Some files were not shown because too many files have changed in this diff Show More