diff --git a/.travis.yml b/.travis.yml index 6d6441d9..9bddb57f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: java script: mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V sudo: false jdk: - - oraclejdk8 + - openjdk8 notifications: slack: rooms: diff --git a/extras/ant/build.xml b/extras/ant/build.xml deleted file mode 100644 index c0abd91c..00000000 --- a/extras/ant/build.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/extras/eclipse/BukkitPlugin.launch b/extras/eclipse/BukkitPlugin.launch deleted file mode 100644 index 69800120..00000000 --- a/extras/eclipse/BukkitPlugin.launch +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/extras/eclipse/eclipse.importorder b/extras/eclipse/eclipse.importorder deleted file mode 100644 index b7a9b88f..00000000 --- a/extras/eclipse/eclipse.importorder +++ /dev/null @@ -1,8 +0,0 @@ -#Organize Import Order -#Sun Aug 02 18:33:53 NZST 2015 -5=javax -4=java -3=org -2=com -1= -0=\# diff --git a/extras/eclipse/eclipse_fomatter.xml b/extras/eclipse/eclipse_fomatter.xml deleted file mode 100644 index 08919ab7..00000000 --- a/extras/eclipse/eclipse_fomatter.xml +++ /dev/null @@ -1,295 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/lib/Factions 2.7.5.jar b/lib/Factions 2.7.5.jar deleted file mode 100644 index 6c5b798f..00000000 Binary files a/lib/Factions 2.7.5.jar and /dev/null differ diff --git a/lib/GLib.jar b/lib/GLib.jar deleted file mode 100644 index ffffb0ee..00000000 Binary files a/lib/GLib.jar and /dev/null differ diff --git a/lib/GriefPrevention 10.5.3.jar b/lib/GriefPrevention 10.5.3.jar deleted file mode 100644 index e9442abf..00000000 Binary files a/lib/GriefPrevention 10.5.3.jar and /dev/null differ diff --git a/lib/Kingdoms.jar b/lib/Kingdoms.jar deleted file mode 100644 index 28b4446a..00000000 Binary files a/lib/Kingdoms.jar and /dev/null differ diff --git a/lib/LWC.jar b/lib/LWC.jar deleted file mode 100644 index 05db983a..00000000 Binary files a/lib/LWC.jar and /dev/null differ diff --git a/lib/MassiveCore 2.7.5.jar b/lib/MassiveCore 2.7.5.jar deleted file mode 100644 index e23d12b6..00000000 Binary files a/lib/MassiveCore 2.7.5.jar and /dev/null differ diff --git a/lib/NoCheatPlus.jar b/lib/NoCheatPlus.jar deleted file mode 100644 index 853ec54c..00000000 Binary files a/lib/NoCheatPlus.jar and /dev/null differ diff --git a/lib/PreciousStones 10.6.1.jar b/lib/PreciousStones 10.6.1.jar deleted file mode 100644 index cb267131..00000000 Binary files a/lib/PreciousStones 10.6.1.jar and /dev/null differ diff --git a/lib/ProjectKorraItems.jar b/lib/ProjectKorraItems.jar deleted file mode 100644 index 23a5ab2b..00000000 Binary files a/lib/ProjectKorraItems.jar and /dev/null differ diff --git a/lib/ProjectKorraRPG.jar b/lib/ProjectKorraRPG.jar deleted file mode 100644 index 45825ab5..00000000 Binary files a/lib/ProjectKorraRPG.jar and /dev/null differ diff --git a/lib/ProjectKorraSpirits.jar b/lib/ProjectKorraSpirits.jar deleted file mode 100644 index 03b9fc87..00000000 Binary files a/lib/ProjectKorraSpirits.jar and /dev/null differ diff --git a/lib/Residence4.0.0.4.jar b/lib/Residence4.0.0.4.jar deleted file mode 100644 index 2e5fda79..00000000 Binary files a/lib/Residence4.0.0.4.jar and /dev/null differ diff --git a/lib/Towny.jar b/lib/Towny.jar deleted file mode 100644 index 0d3daa44..00000000 Binary files a/lib/Towny.jar and /dev/null differ diff --git a/lib/guava-18.0.jar b/lib/guava-18.0.jar deleted file mode 100644 index 8f89e490..00000000 Binary files a/lib/guava-18.0.jar and /dev/null differ diff --git a/lib/spigot-1.12.1.jar b/lib/spigot-1.12.1.jar deleted file mode 100644 index adf6ef4b..00000000 Binary files a/lib/spigot-1.12.1.jar and /dev/null differ diff --git a/lib/worldguard-6.1.jar b/lib/worldguard-6.1.jar deleted file mode 100644 index 7824963f..00000000 Binary files a/lib/worldguard-6.1.jar and /dev/null differ diff --git a/localrepo/br/net/fabiozumbi12/RedProtect/7.5.5/RedProtect-7.5.5.jar b/localrepo/br/net/fabiozumbi12/RedProtect/7.5.5/RedProtect-7.5.5.jar new file mode 100644 index 00000000..bc6c46ff Binary files /dev/null and b/localrepo/br/net/fabiozumbi12/RedProtect/7.5.5/RedProtect-7.5.5.jar differ diff --git a/localrepo/br/net/fabiozumbi12/RedProtect/7.5.5/RedProtect-7.5.5.pom b/localrepo/br/net/fabiozumbi12/RedProtect/7.5.5/RedProtect-7.5.5.pom new file mode 100644 index 00000000..faf74fcb --- /dev/null +++ b/localrepo/br/net/fabiozumbi12/RedProtect/7.5.5/RedProtect-7.5.5.pom @@ -0,0 +1,9 @@ + + + 4.0.0 + br.net.fabiozumbi12 + RedProtect + 7.5.5 + POM was created from install:install-file + diff --git a/localrepo/br/net/fabiozumbi12/RedProtect/maven-metadata-local.xml b/localrepo/br/net/fabiozumbi12/RedProtect/maven-metadata-local.xml new file mode 100644 index 00000000..e7077f45 --- /dev/null +++ b/localrepo/br/net/fabiozumbi12/RedProtect/maven-metadata-local.xml @@ -0,0 +1,12 @@ + + + br.net.fabiozumbi12 + RedProtect + + 7.5.5 + + 7.5.5 + + 20190223101710 + + diff --git a/localrepo/com/bekvon/bukkit/residence/4.8.3.1/residence-4.8.3.1.jar b/localrepo/com/bekvon/bukkit/residence/4.8.3.1/residence-4.8.3.1.jar new file mode 100644 index 00000000..dfa92702 Binary files /dev/null and b/localrepo/com/bekvon/bukkit/residence/4.8.3.1/residence-4.8.3.1.jar differ diff --git a/localrepo/com/bekvon/bukkit/residence/4.8.3.1/residence-4.8.3.1.pom b/localrepo/com/bekvon/bukkit/residence/4.8.3.1/residence-4.8.3.1.pom new file mode 100644 index 00000000..f8c03974 --- /dev/null +++ b/localrepo/com/bekvon/bukkit/residence/4.8.3.1/residence-4.8.3.1.pom @@ -0,0 +1,9 @@ + + + 4.0.0 + com.bekvon.bukkit + residence + 4.8.3.1 + POM was created from install:install-file + diff --git a/localrepo/com/bekvon/bukkit/residence/maven-metadata-local.xml b/localrepo/com/bekvon/bukkit/residence/maven-metadata-local.xml new file mode 100644 index 00000000..be2a1416 --- /dev/null +++ b/localrepo/com/bekvon/bukkit/residence/maven-metadata-local.xml @@ -0,0 +1,12 @@ + + + com.bekvon.bukkit + residence + + 4.8.3.1 + + 4.8.3.1 + + 20190223101425 + + diff --git a/localrepo/com/griefcraft/lwc/2.1.2/lwc-2.1.2.jar b/localrepo/com/griefcraft/lwc/2.1.2/lwc-2.1.2.jar new file mode 100644 index 00000000..063ac3bc Binary files /dev/null and b/localrepo/com/griefcraft/lwc/2.1.2/lwc-2.1.2.jar differ diff --git a/localrepo/com/griefcraft/lwc/2.1.2/lwc-2.1.2.pom b/localrepo/com/griefcraft/lwc/2.1.2/lwc-2.1.2.pom new file mode 100644 index 00000000..95e6db14 --- /dev/null +++ b/localrepo/com/griefcraft/lwc/2.1.2/lwc-2.1.2.pom @@ -0,0 +1,9 @@ + + + 4.0.0 + com.griefcraft + lwc + 2.1.2 + POM was created from install:install-file + diff --git a/localrepo/com/griefcraft/lwc/maven-metadata-local.xml b/localrepo/com/griefcraft/lwc/maven-metadata-local.xml new file mode 100644 index 00000000..cc7b3485 --- /dev/null +++ b/localrepo/com/griefcraft/lwc/maven-metadata-local.xml @@ -0,0 +1,12 @@ + + + com.griefcraft + lwc + + 2.1.2 + + 2.1.2 + + 20190223101300 + + diff --git a/localrepo/com/palmergames/Towny/0.93.0.0/Towny-0.93.0.0.jar b/localrepo/com/palmergames/Towny/0.93.0.0/Towny-0.93.0.0.jar new file mode 100644 index 00000000..f9a9b0fd Binary files /dev/null and b/localrepo/com/palmergames/Towny/0.93.0.0/Towny-0.93.0.0.jar differ diff --git a/localrepo/com/palmergames/Towny/0.93.0.0/Towny-0.93.0.0.pom b/localrepo/com/palmergames/Towny/0.93.0.0/Towny-0.93.0.0.pom new file mode 100644 index 00000000..837a877a --- /dev/null +++ b/localrepo/com/palmergames/Towny/0.93.0.0/Towny-0.93.0.0.pom @@ -0,0 +1,9 @@ + + + 4.0.0 + com.palmergames + Towny + 0.93.0.0 + POM was created from install:install-file + diff --git a/localrepo/com/palmergames/Towny/maven-metadata-local.xml b/localrepo/com/palmergames/Towny/maven-metadata-local.xml new file mode 100644 index 00000000..692b1aff --- /dev/null +++ b/localrepo/com/palmergames/Towny/maven-metadata-local.xml @@ -0,0 +1,12 @@ + + + com.palmergames + Towny + + 0.93.0.0 + + 0.93.0.0 + + 20190223101606 + + diff --git a/localrepo/com/songoda/kingdoms/1.2.3/kingdoms-1.2.3.jar b/localrepo/com/songoda/kingdoms/1.2.3/kingdoms-1.2.3.jar new file mode 100644 index 00000000..9635c970 Binary files /dev/null and b/localrepo/com/songoda/kingdoms/1.2.3/kingdoms-1.2.3.jar differ diff --git a/localrepo/com/songoda/kingdoms/1.2.3/kingdoms-1.2.3.pom b/localrepo/com/songoda/kingdoms/1.2.3/kingdoms-1.2.3.pom new file mode 100644 index 00000000..a0dac4bc --- /dev/null +++ b/localrepo/com/songoda/kingdoms/1.2.3/kingdoms-1.2.3.pom @@ -0,0 +1,9 @@ + + + 4.0.0 + com.songoda + kingdoms + 1.2.3 + POM was created from install:install-file + diff --git a/localrepo/com/songoda/kingdoms/maven-metadata-local.xml b/localrepo/com/songoda/kingdoms/maven-metadata-local.xml new file mode 100644 index 00000000..31130761 --- /dev/null +++ b/localrepo/com/songoda/kingdoms/maven-metadata-local.xml @@ -0,0 +1,12 @@ + + + com.songoda + kingdoms + + 1.2.3 + + 1.2.3 + + 20190223101813 + + diff --git a/localrepo/me/markeh/factionsframework/1.2.0/factionsframework-1.2.0.jar b/localrepo/me/markeh/factionsframework/1.2.0/factionsframework-1.2.0.jar new file mode 100644 index 00000000..c9b6f855 Binary files /dev/null and b/localrepo/me/markeh/factionsframework/1.2.0/factionsframework-1.2.0.jar differ diff --git a/localrepo/me/markeh/factionsframework/1.2.0/factionsframework-1.2.0.jar.md5 b/localrepo/me/markeh/factionsframework/1.2.0/factionsframework-1.2.0.jar.md5 new file mode 100644 index 00000000..6239148a --- /dev/null +++ b/localrepo/me/markeh/factionsframework/1.2.0/factionsframework-1.2.0.jar.md5 @@ -0,0 +1 @@ +333673ff2f0740caad4889dcaa4840d4 \ No newline at end of file diff --git a/localrepo/me/markeh/factionsframework/1.2.0/factionsframework-1.2.0.jar.sha1 b/localrepo/me/markeh/factionsframework/1.2.0/factionsframework-1.2.0.jar.sha1 new file mode 100644 index 00000000..1814d8a4 --- /dev/null +++ b/localrepo/me/markeh/factionsframework/1.2.0/factionsframework-1.2.0.jar.sha1 @@ -0,0 +1 @@ +3869ec4128db113162c54a11d0010a002ed3b5ee \ No newline at end of file diff --git a/localrepo/me/markeh/factionsframework/1.2.0/factionsframework-1.2.0.pom b/localrepo/me/markeh/factionsframework/1.2.0/factionsframework-1.2.0.pom new file mode 100644 index 00000000..c474924b --- /dev/null +++ b/localrepo/me/markeh/factionsframework/1.2.0/factionsframework-1.2.0.pom @@ -0,0 +1,8 @@ + + + 4.0.0 + me.markeh + factionsframework + 1.2.0 + diff --git a/localrepo/me/markeh/factionsframework/1.2.0/factionsframework-1.2.0.pom.md5 b/localrepo/me/markeh/factionsframework/1.2.0/factionsframework-1.2.0.pom.md5 new file mode 100644 index 00000000..0b82b721 --- /dev/null +++ b/localrepo/me/markeh/factionsframework/1.2.0/factionsframework-1.2.0.pom.md5 @@ -0,0 +1 @@ +1fe23316d4e93edea247dd0e49a73cee \ No newline at end of file diff --git a/localrepo/me/markeh/factionsframework/1.2.0/factionsframework-1.2.0.pom.sha1 b/localrepo/me/markeh/factionsframework/1.2.0/factionsframework-1.2.0.pom.sha1 new file mode 100644 index 00000000..3fd23435 --- /dev/null +++ b/localrepo/me/markeh/factionsframework/1.2.0/factionsframework-1.2.0.pom.sha1 @@ -0,0 +1 @@ +fa0e391fae40a538a5b3223ad3b3b01990c0afe6 \ No newline at end of file diff --git a/localrepo/me/markeh/factionsframework/maven-metadata.xml b/localrepo/me/markeh/factionsframework/maven-metadata.xml new file mode 100644 index 00000000..ed669a9e --- /dev/null +++ b/localrepo/me/markeh/factionsframework/maven-metadata.xml @@ -0,0 +1,12 @@ + + + me.markeh + factionsframework + + 1.2.0 + + 1.2.0 + + 20190223095944 + + diff --git a/localrepo/me/markeh/factionsframework/maven-metadata.xml.md5 b/localrepo/me/markeh/factionsframework/maven-metadata.xml.md5 new file mode 100644 index 00000000..8df5ad74 --- /dev/null +++ b/localrepo/me/markeh/factionsframework/maven-metadata.xml.md5 @@ -0,0 +1 @@ +f381f9c9b67641659a289a4e6ed63a25 \ No newline at end of file diff --git a/localrepo/me/markeh/factionsframework/maven-metadata.xml.sha1 b/localrepo/me/markeh/factionsframework/maven-metadata.xml.sha1 new file mode 100644 index 00000000..8a3a5e01 --- /dev/null +++ b/localrepo/me/markeh/factionsframework/maven-metadata.xml.sha1 @@ -0,0 +1 @@ +8ced509852cc7dd171ce85c9eb439969b9af1ce1 \ No newline at end of file diff --git a/pom.xml b/pom.xml index 8fed805c..fed20210 100644 --- a/pom.xml +++ b/pom.xml @@ -1,143 +1,178 @@ - + + 4.0.0 - com.projectkorra projectkorra - 1.8.7 - jar + 1.8.9 ProjectKorra - + + + project.local + project + file://${project.basedir}/localrepo/ + + + + sk89q-repo + http://maven.sk89q.com/repo/ + + + + jitpack.io + https://jitpack.io + + + + md_5-snapshots + https://repo.md-5.net/content/repositories/snapshots/ + + spigot-repo https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + aikar + http://repo.aikar.co/nexus/content/groups/aikar/ + + + + papermc + https://papermc.io/repo/repository/maven-public/ + + + + placeholderapi + http://repo.extendedclip.com/content/repositories/placeholderapi/ + - - - - org.spigotmc - Spigot-Server - LATEST - system - ${project.basedir}/lib/spigot-1.12.1.jar + + + io.papermc + paperlib + 1.0.1 + + + + co.aikar + minecraft-timings + 1.0.4 + + + + org.spigotmc + spigot-api + 1.13.2-R0.1-SNAPSHOT + provided + + + + org.apache.commons + commons-lang3 + 3.8.1 - com.massivecraft - factions - LATEST - system - ${project.basedir}/lib/Factions 2.7.5.jar - - + me.markeh + factionsframework + 1.2.0 + provided + + - me.ryanhamshire + com.github.TechFortress GriefPrevention - LATEST - system - ${project.basedir}/lib/GriefPrevention 10.5.3.jar + 16.7.1 + provided com.griefcraft lwc - LATEST - system - ${project.basedir}/lib/LWC.jar - - - - com.massivecraft - massivecore - LATEST - system - ${project.basedir}/lib/MassiveCore 2.7.5.jar + 2.1.2 + provided fr.neatmonster nocheatplus - LATEST - system - ${project.basedir}/lib/NoCheatPlus.jar + 3.16.1-SNAPSHOT + provided - - net.sacredlabyrinth.Phaed - PreciousStones - LATEST - system - ${project.basedir}/lib/PreciousStones 10.6.1.jar - - - - com.projectkorra - rpg - LATEST - system - ${project.basedir}/lib/ProjectKorraRPG.jar - - - - com.projectkorra - items - LATEST - system - ${project.basedir}/lib/ProjectKorraItems.jar - - - - com.projectkorra - spirits - LATEST - system - ${project.basedir}/lib/ProjectKorraSpirits.jar - + com.bekvon.bukkit residence - LATEST - system - ${project.basedir}/lib/Residence4.0.0.4.jar + 4.8.3.1 + provided - com.plamergames.bukkit + com.palmergames Towny - LATEST - system - ${project.basedir}/lib/Towny.jar + 0.93.0.0 + provided - + - com.sk89q - worldguard - LATEST - system - ${project.basedir}/lib/worldguard-6.1.jar + com.sk89q.worldedit + worldedit-core + 7.0.0-SNAPSHOT + provided + + + com.sk89q.worldguard + worldguard-core + 7.0.0-SNAPSHOT + provided + + + com.sk89q.worldedit + worldedit-bukkit + 7.0.0-SNAPSHOT + provided + + + com.sk89q.worldguard + worldguard-legacy + 7.0.0-SNAPSHOT + provided + + + + br.net.fabiozumbi12 + RedProtect + 7.5.5 + provided - org.kingdoms - Kingdoms - LATEST - system - ${project.basedir}/lib/Kingdoms.jar + com.songoda + kingdoms + 1.2.3 + provided - + - org.generallib - GLib - LATEST - system - ${project.basedir}/lib/GLib.jar + me.clip + placeholderapi + 2.9.2 + provided - clean package install ${project.name}-${project.version} @@ -156,29 +191,57 @@ org.apache.maven.plugins maven-compiler-plugin - 3.1 + 3.8.0 1.8 1.8 - - maven-shade-plugin - 2.3 - - - package - - shade - - - - - + + org.apache.maven.plugins + maven-jar-plugin + 3.1.1 + + ${dir} + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.1 + + ${project.build.directory}/dependency-reduced-pom.xml + + + co.aikar.timings.lib + timingslib.projectkorra + + + io.papermc.lib + paperlib.projectkorra + + + org.apache.commons + commonslang3.projectkorra + + + + + + package + + shade + + + true + + + + - + ${project.build.directory} UTF-8 diff --git a/src/com/projectkorra/projectkorra/BendingManager.java b/src/com/projectkorra/projectkorra/BendingManager.java index 58c90eb0..b75514ef 100644 --- a/src/com/projectkorra/projectkorra/BendingManager.java +++ b/src/com/projectkorra/projectkorra/BendingManager.java @@ -3,6 +3,8 @@ package com.projectkorra.projectkorra; import java.util.HashMap; import java.util.UUID; +import co.aikar.timings.lib.MCTiming; + import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.World; @@ -18,7 +20,6 @@ import com.projectkorra.projectkorra.util.RevertChecker; import com.projectkorra.projectkorra.util.TempArmor; import com.projectkorra.projectkorra.util.TempPotionEffect; import com.projectkorra.projectkorra.waterbending.blood.Bloodbending; -import com.projectkorra.rpg.RPGMethods; public class BendingManager implements Runnable { @@ -29,9 +30,19 @@ public class BendingManager implements Runnable { long interval; private final HashMap times = new HashMap(); // true if day time + private final MCTiming CORE_ABILITY_TIMING, TEMP_POTION_TIMING, DAY_NIGHT_TIMING, HORIZONTAL_VELOCITY_TRACKER_TIMING, COOLDOWN_TIMING, TEMP_ARMOR_TIMING, ACTIONBAR_STATUS_TIMING; + public BendingManager() { instance = this; this.time = System.currentTimeMillis(); + + this.CORE_ABILITY_TIMING = ProjectKorra.timing("CoreAbility#ProgressAll"); + this.TEMP_POTION_TIMING = ProjectKorra.timing("TempPotion#ProgressAll"); + this.DAY_NIGHT_TIMING = ProjectKorra.timing("HandleDayNight"); + this.HORIZONTAL_VELOCITY_TRACKER_TIMING = ProjectKorra.timing("HorizontalVelocityTracker#UpdateAll"); + this.COOLDOWN_TIMING = ProjectKorra.timing("HandleCooldowns"); + this.TEMP_ARMOR_TIMING = ProjectKorra.timing("TempArmor#Cleanup"); + this.ACTIONBAR_STATUS_TIMING = ProjectKorra.timing("ActionBarCheck"); } public static BendingManager getInstance() { @@ -58,11 +69,6 @@ public class BendingManager implements Runnable { this.times.put(world, false); } } else { - if (GeneralMethods.hasRPG()) { - if (RPGMethods.isFullMoon(world) || RPGMethods.isLunarEclipse(world) || RPGMethods.isSolarEclipse(world) || RPGMethods.isSozinsComet(world)) { - continue; - } - } if (this.times.get(world) && !ElementalAbility.isDay(world)) { // The hashmap says it is day, but it is not. this.times.put(world, false); // Sets time to night. @@ -103,19 +109,37 @@ public class BendingManager implements Runnable { @Override public void run() { - try { - this.interval = System.currentTimeMillis() - this.time; - this.time = System.currentTimeMillis(); - ProjectKorra.time_step = this.interval; + this.interval = System.currentTimeMillis() - this.time; + this.time = System.currentTimeMillis(); + ProjectKorra.time_step = this.interval; + try (MCTiming timing = this.CORE_ABILITY_TIMING.startTiming()) { CoreAbility.progressAll(); - TempPotionEffect.progressAll(); - this.handleDayNight(); - RevertChecker.revertAirBlocks(); - HorizontalVelocityTracker.updateAll(); - this.handleCooldowns(); - TempArmor.cleanup(); + } + try (MCTiming timing = this.TEMP_POTION_TIMING.startTiming()) { + TempPotionEffect.progressAll(); + } + + try (MCTiming timing = this.DAY_NIGHT_TIMING.startTiming()) { + this.handleDayNight(); + } + + RevertChecker.revertAirBlocks(); + + try (MCTiming timing = this.HORIZONTAL_VELOCITY_TRACKER_TIMING.startTiming()) { + HorizontalVelocityTracker.updateAll(); + } + + try (MCTiming timing = this.COOLDOWN_TIMING.startTiming()) { + this.handleCooldowns(); + } + + try (MCTiming timing = this.TEMP_ARMOR_TIMING.startTiming()) { + TempArmor.cleanup(); + } + + try (MCTiming timing = this.ACTIONBAR_STATUS_TIMING.startTiming()) { for (final Player player : Bukkit.getOnlinePlayers()) { if (Bloodbending.isBloodbent(player)) { ActionBar.sendActionBar(Element.BLOOD.getColor() + "* Bloodbent *", player); @@ -124,9 +148,6 @@ public class BendingManager implements Runnable { } } } - catch (final Exception e) { - e.printStackTrace(); - } } public static String getSunriseMessage() { diff --git a/src/com/projectkorra/projectkorra/BendingPlayer.java b/src/com/projectkorra/projectkorra/BendingPlayer.java index 0af3f487..ce1aed51 100644 --- a/src/com/projectkorra/projectkorra/BendingPlayer.java +++ b/src/com/projectkorra/projectkorra/BendingPlayer.java @@ -10,6 +10,9 @@ import java.util.Map.Entry; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; @@ -22,9 +25,6 @@ import com.projectkorra.projectkorra.ability.Ability; import com.projectkorra.projectkorra.ability.AvatarAbility; import com.projectkorra.projectkorra.ability.ChiAbility; import com.projectkorra.projectkorra.ability.CoreAbility; -import com.projectkorra.projectkorra.ability.ElementalAbility; -import com.projectkorra.projectkorra.ability.FireAbility; -import com.projectkorra.projectkorra.ability.WaterAbility; import com.projectkorra.projectkorra.ability.util.PassiveManager; import com.projectkorra.projectkorra.avatar.AvatarState; import com.projectkorra.projectkorra.command.Commands; @@ -34,6 +34,7 @@ import com.projectkorra.projectkorra.event.PlayerCooldownChangeEvent; import com.projectkorra.projectkorra.event.PlayerCooldownChangeEvent.Result; import com.projectkorra.projectkorra.storage.DBConnection; import com.projectkorra.projectkorra.util.Cooldown; +import com.projectkorra.projectkorra.util.DBCooldownManager; import com.projectkorra.projectkorra.waterbending.blood.Bloodbending; /** @@ -58,6 +59,7 @@ public class BendingPlayer { private final UUID uuid; private final String name; private ChiAbility stance; + private final DBCooldownManager cooldownManager; private final ArrayList elements; private final ArrayList subelements; private HashMap abilities; @@ -76,6 +78,7 @@ public class BendingPlayer { public BendingPlayer(final UUID uuid, final String playerName, final ArrayList elements, final ArrayList subelements, final HashMap abilities, final boolean permaRemoved) { this.uuid = uuid; this.name = playerName; + this.cooldownManager = Manager.getManager(DBCooldownManager.class); this.elements = elements; this.subelements = subelements; this.setAbilities(abilities); @@ -152,17 +155,18 @@ public class BendingPlayer { public Map loadCooldowns() { final Map cooldowns = new ConcurrentHashMap<>(); - try (ResultSet rs = DBConnection.sql.readQuery("SELECT * FROM pk_cooldowns WHERE uuid = '" + this.uuid.toString() + "'")) { - while (rs.next()) { - final int cooldownId = rs.getInt("cooldown_id"); - final long value = rs.getLong("value"); - final String name = ProjectKorra.cooldowns.getCooldownName(cooldownId); - cooldowns.put(name, new Cooldown(value, true)); + if (ProjectKorra.isDatabaseCooldownsEnabled()) { + try (ResultSet rs = DBConnection.sql.readQuery("SELECT * FROM pk_cooldowns WHERE uuid = '" + this.uuid.toString() + "'")) { + while (rs.next()) { + final int cooldownId = rs.getInt("cooldown_id"); + final long value = rs.getLong("value"); + final String name = this.cooldownManager.getCooldownName(cooldownId); + cooldowns.put(name, new Cooldown(value, true)); + } + } catch (final SQLException e) { + e.printStackTrace(); } } - catch (final SQLException e) { - e.printStackTrace(); - } return cooldowns; } @@ -171,15 +175,14 @@ public class BendingPlayer { for (final Entry entry : this.cooldowns.entrySet()) { final String name = entry.getKey(); final Cooldown cooldown = entry.getValue(); - final int cooldownId = ProjectKorra.cooldowns.getCooldownId(name, false); + final int cooldownId = this.cooldownManager.getCooldownId(name, false); try (ResultSet rs = DBConnection.sql.readQuery("SELECT value FROM pk_cooldowns WHERE uuid = '" + this.uuid.toString() + "' AND cooldown_id = " + cooldownId)) { if (rs.next()) { DBConnection.sql.modifyQuery("UPDATE pk_cooldowns SET value = " + cooldown.getCooldown() + " WHERE uuid = '" + this.uuid.toString() + "' AND cooldown_id = " + cooldownId, false); } else { DBConnection.sql.modifyQuery("INSERT INTO pk_cooldowns (uuid, cooldown_id, value) VALUES ('" + this.uuid.toString() + "', " + cooldownId + ", " + cooldown.getCooldown() + ")", false); } - } - catch (final SQLException e) { + } catch (final SQLException e) { e.printStackTrace(); } } @@ -275,10 +278,6 @@ public class BendingPlayer { return false; } else if (GeneralMethods.isRegionProtectedFromBuild(this.player, ability.getName(), playerLoc)) { return false; - } else if (ability instanceof FireAbility && ElementalAbility.isSolarEclipse(this.player.getWorld())) { - return false; - } else if (ability instanceof WaterAbility && ElementalAbility.isLunarEclipse(this.player.getWorld())) { - return false; } return true; @@ -913,4 +912,8 @@ public class BendingPlayer { this.chiBlocked = false; } + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); + } } diff --git a/src/com/projectkorra/projectkorra/GeneralMethods.java b/src/com/projectkorra/projectkorra/GeneralMethods.java index bd80a3c6..d16fa96d 100644 --- a/src/com/projectkorra/projectkorra/GeneralMethods.java +++ b/src/com/projectkorra/projectkorra/GeneralMethods.java @@ -25,52 +25,20 @@ import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.BlockState; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.FallingBlock; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.entity.TNTPrimed; -import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.scheduler.BukkitRunnable; -import org.bukkit.util.Vector; -import org.kingdoms.constants.StructureType; -import org.kingdoms.constants.kingdom.Kingdom; -import org.kingdoms.constants.land.Land; -import org.kingdoms.constants.land.SimpleChunkLocation; -import org.kingdoms.constants.land.SimpleLocation; -import org.kingdoms.constants.player.KingdomPlayer; -import org.kingdoms.manager.game.GameManagement; - import com.bekvon.bukkit.residence.Residence; +import com.bekvon.bukkit.residence.api.ResidenceInterface; import com.bekvon.bukkit.residence.protection.ClaimedResidence; import com.bekvon.bukkit.residence.protection.ResidencePermissions; import com.google.common.reflect.ClassPath; import com.griefcraft.lwc.LWC; import com.griefcraft.lwc.LWCPlugin; import com.griefcraft.model.Protection; -import com.massivecraft.factions.engine.EngineMain; -import com.massivecraft.massivecore.ps.PS; import com.palmergames.bukkit.towny.Towny; import com.palmergames.bukkit.towny.TownyMessaging; import com.palmergames.bukkit.towny.TownySettings; @@ -84,6 +52,42 @@ import com.palmergames.bukkit.towny.object.WorldCoord; import com.palmergames.bukkit.towny.utils.PlayerCacheUtil; import com.palmergames.bukkit.towny.war.flagwar.TownyWar; import com.palmergames.bukkit.towny.war.flagwar.TownyWarConfig; +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldguard.WorldGuard; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.protection.flags.Flags; +import com.sk89q.worldguard.protection.flags.StateFlag; +import com.songoda.kingdoms.constants.land.Land; +import com.songoda.kingdoms.constants.land.SimpleChunkLocation; +import com.songoda.kingdoms.constants.player.KingdomPlayer; +import com.songoda.kingdoms.manager.game.GameManagement; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Color; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.BlockState; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Levelled; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Entity; +import org.bukkit.entity.FallingBlock; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.MainHand; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.util.Vector; + import com.projectkorra.projectkorra.Element.SubElement; import com.projectkorra.projectkorra.ability.Ability; import com.projectkorra.projectkorra.ability.AddonAbility; @@ -110,7 +114,7 @@ import com.projectkorra.projectkorra.earthbending.EarthBlast; import com.projectkorra.projectkorra.earthbending.passive.EarthPassive; import com.projectkorra.projectkorra.event.BendingPlayerCreationEvent; import com.projectkorra.projectkorra.event.BendingReloadEvent; -import com.projectkorra.projectkorra.event.BindChangeEvent; +import com.projectkorra.projectkorra.event.PlayerBindChangeEvent; import com.projectkorra.projectkorra.firebending.FireBlast; import com.projectkorra.projectkorra.firebending.FireShield; import com.projectkorra.projectkorra.firebending.combustion.Combustion; @@ -118,6 +122,7 @@ import com.projectkorra.projectkorra.object.Preset; import com.projectkorra.projectkorra.storage.DBConnection; import com.projectkorra.projectkorra.util.ActionBar; import com.projectkorra.projectkorra.util.BlockCacheElement; +import com.projectkorra.projectkorra.util.ColoredParticle; import com.projectkorra.projectkorra.util.MovementHandler; import com.projectkorra.projectkorra.util.ParticleEffect; import com.projectkorra.projectkorra.util.ReflectionHandler; @@ -125,26 +130,26 @@ import com.projectkorra.projectkorra.util.ReflectionHandler.PackageType; import com.projectkorra.projectkorra.util.TempArmor; import com.projectkorra.projectkorra.util.TempArmorStand; import com.projectkorra.projectkorra.util.TempBlock; -import com.projectkorra.projectkorra.util.TimeUtil; import com.projectkorra.projectkorra.waterbending.WaterManipulation; import com.projectkorra.projectkorra.waterbending.WaterSpout; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.protection.flags.DefaultFlag; +import br.net.fabiozumbi12.RedProtect.Bukkit.RedProtect; +import br.net.fabiozumbi12.RedProtect.Bukkit.Region; +import br.net.fabiozumbi12.RedProtect.Bukkit.API.RedProtectAPI; +import me.markeh.factionsframework.entities.FPlayer; +import me.markeh.factionsframework.entities.FPlayers; +import me.markeh.factionsframework.entities.Faction; +import me.markeh.factionsframework.entities.Factions; +import me.markeh.factionsframework.enums.Rel; import me.ryanhamshire.GriefPrevention.Claim; import me.ryanhamshire.GriefPrevention.GriefPrevention; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.TextComponent; -import net.sacredlabyrinth.Phaed.PreciousStones.PreciousStones; -import net.sacredlabyrinth.Phaed.PreciousStones.field.FieldFlag; public class GeneralMethods { - public static final Material[] NON_OPAQUE = { Material.AIR, Material.SAPLING, Material.WATER, Material.STATIONARY_WATER, Material.LAVA, Material.STATIONARY_LAVA, Material.POWERED_RAIL, Material.DETECTOR_RAIL, Material.WEB, Material.LONG_GRASS, Material.DEAD_BUSH, Material.YELLOW_FLOWER, Material.RED_ROSE, Material.BROWN_MUSHROOM, Material.RED_MUSHROOM, Material.TORCH, Material.FIRE, Material.REDSTONE_WIRE, Material.CROPS, Material.LADDER, Material.RAILS, Material.SIGN_POST, Material.LEVER, Material.STONE_PLATE, Material.WOOD_PLATE, Material.REDSTONE_TORCH_OFF, Material.REDSTONE_TORCH_ON, Material.STONE_BUTTON, Material.SNOW, Material.SUGAR_CANE_BLOCK, Material.PORTAL, Material.DIODE_BLOCK_OFF, Material.DIODE_BLOCK_ON, Material.PUMPKIN_STEM, Material.MELON_STEM, Material.VINE, Material.WATER_LILY, Material.NETHER_STALK, Material.ENDER_PORTAL, Material.COCOA, Material.TRIPWIRE_HOOK, Material.TRIPWIRE, Material.FLOWER_POT, Material.CARROT, Material.POTATO, Material.WOOD_BUTTON, Material.GOLD_PLATE, Material.IRON_PLATE, Material.REDSTONE_COMPARATOR_OFF, Material.REDSTONE_COMPARATOR_ON, Material.DAYLIGHT_DETECTOR, Material.CARPET, Material.DOUBLE_PLANT, Material.STANDING_BANNER, Material.WALL_BANNER, Material.DAYLIGHT_DETECTOR_INVERTED, Material.END_ROD, Material.CHORUS_PLANT, Material.CHORUS_FLOWER, Material.BEETROOT_BLOCK, Material.END_GATEWAY }; - public static final Material[] INTERACTABLE_MATERIALS = { Material.ACACIA_DOOR, Material.ACACIA_FENCE_GATE, Material.ANVIL, Material.BEACON, Material.BED_BLOCK, Material.BIRCH_DOOR, Material.BIRCH_FENCE_GATE, Material.BOAT, Material.BREWING_STAND, Material.BURNING_FURNACE, Material.CAKE_BLOCK, Material.CHEST, Material.COMMAND, Material.DARK_OAK_DOOR, Material.DARK_OAK_FENCE_GATE, Material.DISPENSER, Material.DRAGON_EGG, Material.DROPPER, Material.ENCHANTMENT_TABLE, Material.ENDER_CHEST, Material.ENDER_PORTAL_FRAME, Material.FENCE_GATE, Material.FURNACE, Material.HOPPER, Material.HOPPER_MINECART, Material.COMMAND_MINECART, Material.JUKEBOX, Material.JUNGLE_DOOR, Material.JUNGLE_FENCE_GATE, Material.LEVER, Material.MINECART, Material.NOTE_BLOCK, Material.SPRUCE_DOOR, Material.SPRUCE_FENCE_GATE, Material.STONE_BUTTON, Material.TRAPPED_CHEST, Material.TRAP_DOOR, Material.WOOD_BUTTON, Material.WOOD_DOOR, Material.WORKBENCH }; - // Represents PlayerName, previously checked blocks, and whether they were true or false private static final Map> BLOCK_CACHE = new ConcurrentHashMap<>(); private static final ArrayList INVINCIBLE = new ArrayList<>(); @@ -159,8 +164,7 @@ public class GeneralMethods { try { getAbsorption = ReflectionHandler.getMethod("EntityHuman", PackageType.MINECRAFT_SERVER, "getAbsorptionHearts"); setAbsorption = ReflectionHandler.getMethod("EntityHuman", PackageType.MINECRAFT_SERVER, "setAbsorptionHearts", Float.class); - } - catch (final Exception e) { + } catch (final Exception e) { e.printStackTrace(); } } @@ -336,8 +340,13 @@ public class GeneralMethods { try { if (!rs2.next()) { // Data doesn't exist, we want a completely new player. DBConnection.sql.modifyQuery("INSERT INTO pk_players (uuid, player, slot1, slot2, slot3, slot4, slot5, slot6, slot7, slot8, slot9) VALUES ('" + uuid.toString() + "', '" + player + "', 'null', 'null', 'null', 'null', 'null', 'null', 'null', 'null', 'null')"); - new BendingPlayer(uuid, player, new ArrayList(), new ArrayList(), new HashMap(), false); - ProjectKorra.log.info("Created new BendingPlayer for " + player); + new BukkitRunnable() { + @Override + public void run() { + new BendingPlayer(uuid, player, new ArrayList(), new ArrayList(), new HashMap(), false); + ProjectKorra.log.info("Created new BendingPlayer for " + player); + } + }.runTask(ProjectKorra.plugin); } else { // The player has at least played before. final String player2 = rs2.getString("player"); @@ -530,8 +539,7 @@ public class GeneralMethods { } }.runTask(ProjectKorra.plugin); } - } - catch (final SQLException ex) { + } catch (final SQLException ex) { ex.printStackTrace(); } } @@ -556,13 +564,13 @@ public class GeneralMethods { writer.write(line + "\n"); } } - } - catch (final IOException e) { + } catch (final IOException e) { e.printStackTrace(); } } } + @Deprecated public static void displayColoredParticle(final Location loc, ParticleEffect type, final String hexVal, final float xOffset, final float yOffset, final float zOffset) { int r = 0; int g = 0; @@ -582,44 +590,46 @@ public class GeneralMethods { if (red <= 0) { red = 1 / 255.0F; } - loc.setX(loc.getX() + Math.random() * xOffset); - loc.setY(loc.getY() + Math.random() * yOffset); - loc.setZ(loc.getZ() + Math.random() * zOffset); + loc.setX(loc.getX() + (Math.random() * 2 - 1) * xOffset); + loc.setY(loc.getY() + (Math.random() * 2 - 1) * yOffset); + loc.setZ(loc.getZ() + (Math.random() * 2 - 1) * zOffset); if (type != ParticleEffect.RED_DUST && type != ParticleEffect.REDSTONE && type != ParticleEffect.SPELL_MOB && type != ParticleEffect.MOB_SPELL && type != ParticleEffect.SPELL_MOB_AMBIENT && type != ParticleEffect.MOB_SPELL_AMBIENT) { type = ParticleEffect.RED_DUST; } - type.display(red, green, blue, 1F, 0, loc, 255.0); + type.display(loc, 0, red, green, blue); } + @Deprecated public static void displayColoredParticle(final Location loc, final String hexVal) { displayColoredParticle(loc, ParticleEffect.RED_DUST, hexVal, 0, 0, 0); } + @Deprecated public static void displayColoredParticle(final Location loc, final String hexVal, final float xOffset, final float yOffset, final float zOffset) { displayColoredParticle(loc, ParticleEffect.RED_DUST, hexVal, xOffset, yOffset, zOffset); } - public static void displayParticleVector(final Location loc, final ParticleEffect type, final float xTrans, final float yTrans, final float zTrans) { - if (type == ParticleEffect.FIREWORKS_SPARK) { - ParticleEffect.FIREWORKS_SPARK.display(xTrans, yTrans, zTrans, 0.09F, 0, loc, 257D); - } else if (type == ParticleEffect.SMOKE || type == ParticleEffect.SMOKE_NORMAL) { - ParticleEffect.SMOKE.display(xTrans, yTrans, zTrans, 0.04F, 0, loc, 257D); - } else if (type == ParticleEffect.LARGE_SMOKE || type == ParticleEffect.SMOKE_LARGE) { - ParticleEffect.LARGE_SMOKE.display(xTrans, yTrans, zTrans, 0.04F, 0, loc, 257D); - } else if (type == ParticleEffect.ENCHANTMENT_TABLE) { - ParticleEffect.ENCHANTMENT_TABLE.display(xTrans, yTrans, zTrans, 0.5F, 0, loc, 257D); - } else if (type == ParticleEffect.PORTAL) { - ParticleEffect.PORTAL.display(xTrans, yTrans, zTrans, 0.5F, 0, loc, 257D); - } else if (type == ParticleEffect.FLAME) { - ParticleEffect.FLAME.display(xTrans, yTrans, zTrans, 0.04F, 0, loc, 257D); - } else if (type == ParticleEffect.CLOUD) { - ParticleEffect.CLOUD.display(xTrans, yTrans, zTrans, 0.04F, 0, loc, 257D); - } else if (type == ParticleEffect.SNOW_SHOVEL) { - ParticleEffect.SNOW_SHOVEL.display(xTrans, yTrans, zTrans, 0.2F, 0, loc, 257D); - } else { - ParticleEffect.RED_DUST.display(0, 0, 0, 0.004F, 0, loc, 257D); + public static void displayColoredParticle(String hexVal, final Location loc, final int amount, final double offsetX, final double offsetY, final double offsetZ) { + int r = 0; + int g = 0; + int b = 0; + + if (hexVal.startsWith("#")) { + hexVal = hexVal.substring(1); } + + if (hexVal.length() <= 6) { + r = Integer.valueOf(hexVal.substring(0, 2), 16).intValue(); + g = Integer.valueOf(hexVal.substring(2, 4), 16).intValue(); + b = Integer.valueOf(hexVal.substring(4, 6), 16).intValue(); + } + + new ColoredParticle(Color.fromRGB(r, g, b), 1F).display(loc, amount, offsetX, offsetY, offsetZ); + } + + public static void displayColoredParticle(final String hexVal, final Location loc) { + displayColoredParticle(hexVal, loc, 1, 0, 0, 0); } /** @@ -651,16 +661,7 @@ public class GeneralMethods { final CoreAbility ability = CoreAbility.getAbility(displayedMessage); if (ability != null && bPlayer != null) { - if (bPlayer.isOnCooldown(ability)) { - final long cooldown = bPlayer.getCooldown(ability.getName()) - System.currentTimeMillis(); - displayedMessage = ability.getElement().getColor() + "" + ChatColor.STRIKETHROUGH + ability.getName() + "" + ability.getElement().getColor() + " - " + TimeUtil.formatTime(cooldown); - } else { - if (bPlayer.getStance() != null && bPlayer.getStance().getName().equals(ability.getName())) { - displayedMessage = ability.getElement().getColor() + "" + ChatColor.UNDERLINE + ability.getName(); - } else { - displayedMessage = ability.getElement().getColor() + ability.getName(); - } - } + displayedMessage = ability.getMovePreview(player); } else if (displayedMessage == null || displayedMessage.isEmpty() || displayedMessage.equals("")) { displayedMessage = ""; } @@ -674,8 +675,7 @@ public class GeneralMethods { final Object entityplayer = ActionBar.getHandle.invoke(player); final Object hearts = getAbsorption.invoke(entityplayer); return (float) hearts; - } - catch (final Exception e) { + } catch (final Exception e) { e.printStackTrace(); } return 0; @@ -686,8 +686,7 @@ public class GeneralMethods { try { final Object entityplayer = ActionBar.getHandle.invoke(player); setAbsorption.invoke(entityplayer, hearts); - } - catch (final Exception e) { + } catch (final Exception e) { e.printStackTrace(); } } @@ -864,6 +863,50 @@ public class GeneralMethods { } return circleblocks; } + + /** + * Gets the closest entity within the specified radius around a point + * @param center point to check around + * @param radius distance from center to check within + * @return null if not found + */ + public static Entity getClosestEntity(Location center, double radius) { + Entity found = null; + Double distance = null; + + for (Entity entity : GeneralMethods.getEntitiesAroundPoint(center, radius)) { + double check = center.distanceSquared(entity.getLocation()); + + if (distance == null || check < distance) { + found = entity; + distance = check; + } + } + + return found; + } + + /** + * Gets the closest LivingEntity within the specified radius around a point + * @param center point to check around + * @param radius distance from center to check within + * @return null if not found + */ + public static LivingEntity getClosestLivingEntity(Location center, double radius) { + LivingEntity le = null; + Double distance = null; + + for (Entity entity : GeneralMethods.getEntitiesAroundPoint(center, radius)) { + double check = center.distanceSquared(entity.getLocation()); + + if (entity instanceof LivingEntity && (distance == null || check < distance)) { + le = (LivingEntity) entity; + distance = check; + } + } + + return le; + } public static String getCurrentDate() { final DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); @@ -914,10 +957,10 @@ public class GeneralMethods { * @param breakitem Unused * @return The item drops fromt the specified block */ - public static Collection getDrops(final Block block, final Material type, final byte data, final ItemStack breakitem) { + public static Collection getDrops(final Block block, final Material type, final BlockData data) { final BlockState tempstate = block.getState(); block.setType(type); - block.setData(data); + block.setBlockData(data); final Collection item = block.getDrops(); tempstate.update(true); return item; @@ -932,34 +975,7 @@ public class GeneralMethods { * @return A list of entities around a point */ public static List getEntitiesAroundPoint(final Location location, final double radius) { - final List entities = new ArrayList(); - final World world = location.getWorld(); - - // To find chunks we use chunk coordinates (not block coordinates!) - final int smallX = (int) (location.getX() - radius) >> 4; - final int bigX = (int) (location.getX() + radius) >> 4; - final int smallZ = (int) (location.getZ() - radius) >> 4; - final int bigZ = (int) (location.getZ() + radius) >> 4; - - for (int x = smallX; x <= bigX; x++) { - for (int z = smallZ; z <= bigZ; z++) { - if (world.isChunkLoaded(x, z)) { - entities.addAll(Arrays.asList(world.getChunkAt(x, z).getEntities())); - } - } - } - - final Iterator entityIterator = entities.iterator(); - while (entityIterator.hasNext()) { - final Entity e = entityIterator.next(); - if (e.getWorld().equals(location.getWorld()) && e.getLocation().distanceSquared(location) > radius * radius) { - entityIterator.remove(); - } else if (e instanceof Player && (((Player) e).isDead() || ((Player) e).getGameMode().equals(GameMode.SPECTATOR))) { - entityIterator.remove(); - } - } - - return entities; + return new ArrayList<>(location.getWorld().getNearbyEntities(location, radius, radius, radius, entity -> !(entity.isDead() || (entity instanceof Player && ((Player) entity).getGameMode().equals(GameMode.SPECTATOR))))); } public static long getGlobalCooldown() { @@ -1043,16 +1059,16 @@ public class GeneralMethods { } public static int getMaxPresets(final Player player) { + final int max = ConfigManager.getConfig().getInt("Properties.MaxPresets"); if (player.isOp()) { - return 100; + return max; } - int cap = 0; - for (int i = 0; i <= 10; i++) { + for (int i = max; i > 0; i--) { if (player.hasPermission("bending.command.preset.create." + i)) { - cap = i; + return i; } } - return cap; + return 0; } public static Vector getOrthogonalVector(final Vector axis, final double degrees, final double length) { @@ -1092,6 +1108,16 @@ public class GeneralMethods { return location.clone().subtract(new Vector(Math.cos(angle), 0, Math.sin(angle)).normalize().multiply(distance)); } + public static Location getMainHandLocation(final Player player) { + Location loc; + if (player.getMainHand() == MainHand.LEFT) { + loc = GeneralMethods.getLeftSide(player.getLocation(), .55).add(0, 1.2, 0); + } else { + loc = GeneralMethods.getRightSide(player.getLocation(), .55).add(0, 1.2, 0); + } + return loc; + } + public static Plugin getProbending() { if (hasProbending()) { return Bukkit.getServer().getPluginManager().getPlugin("Probending"); @@ -1113,12 +1139,28 @@ public class GeneralMethods { return null; } + public static BlockData getLavaData(final int level) { + final BlockData data = Material.LAVA.createBlockData(); + if (data instanceof Levelled) { + ((Levelled) data).setLevel(level); + } + return data; + } + + public static BlockData getWaterData(final int level) { + final BlockData data = Material.WATER.createBlockData(); + if (data instanceof Levelled) { + ((Levelled) data).setLevel(level); + } + return data; + } + public static Entity getTargetedEntity(final Player player, final double range, final List avoid) { double longestr = range + 1; Entity target = null; final Location origin = player.getEyeLocation(); final Vector direction = player.getEyeLocation().getDirection().normalize(); - for (final Entity entity : origin.getWorld().getEntities()) { + for (final Entity entity : getEntitiesAroundPoint(origin, range)) { if (entity instanceof Player) { if (((Player) entity).isDead() || ((Player) entity).getGameMode().equals(GameMode.SPECTATOR)) { continue; @@ -1145,34 +1187,58 @@ public class GeneralMethods { public static Entity getTargetedEntity(final Player player, final double range) { return getTargetedEntity(player, range, new ArrayList()); } - - public static Location getTargetedLocation(final Player player, final double originselectrange, final Material... nonOpaque2) { + + public static Location getTargetedLocation(final Player player, final double range, final boolean ignoreTempBlocks, final boolean checkDiagonals, final Material... nonOpaque2) { final Location origin = player.getEyeLocation(); final Vector direction = origin.getDirection(); - HashSet trans = new HashSet(); + final HashSet trans = new HashSet(); trans.add(Material.AIR); + trans.add(Material.CAVE_AIR); + trans.add(Material.VOID_AIR); - if (nonOpaque2 == null) { - trans = null; - } else { + if (nonOpaque2 != null) { for (final Material material : nonOpaque2) { trans.add(material); } } - final Block block = player.getTargetBlock(trans, (int) originselectrange + 1); - double distance = originselectrange; - if (block.getWorld().equals(origin.getWorld())) { - distance = block.getLocation().distance(origin) - 1.5; + final Location location = origin.clone(); + final Vector vec = direction.normalize().multiply(0.2); + + for (double i = 0; i < range; i += 0.2) { + location.add(vec); + + if (checkDiagonals && checkDiagonalWall(location, vec)) { + location.subtract(vec); + break; + } + + final Block block = location.getBlock(); + + if (trans.contains(block.getType())) { + continue; + } else if (ignoreTempBlocks && (TempBlock.isTempBlock(block) && !WaterAbility.isBendableWaterTempBlock(block))) { + continue; + } else { + location.subtract(vec); + break; + } } - final Location location = origin.add(direction.multiply(distance)); return location; } + public static Location getTargetedLocation(final Player player, final double range, final boolean ignoreTempBlocks, final Material... nonOpaque2) { + return getTargetedLocation(player, range, ignoreTempBlocks, true, nonOpaque2); + } + + public static Location getTargetedLocation(final Player player, final double range, final Material... nonOpaque2) { + return getTargetedLocation(player, range, false, nonOpaque2); + } + public static Location getTargetedLocation(final Player player, final int range) { - return getTargetedLocation(player, range, Material.AIR); + return getTargetedLocation(player, range, false); } public static Block getTopBlock(final Location loc, final int range) { @@ -1187,19 +1253,19 @@ public class GeneralMethods { Block blockHolder = loc.getBlock(); int y = 0; // Only one of these while statements will go - while (blockHolder.getType() != Material.AIR && Math.abs(y) < Math.abs(positiveY)) { + while (!ElementalAbility.isAir(blockHolder.getType()) && Math.abs(y) < Math.abs(positiveY)) { y++; final Block tempBlock = loc.clone().add(0, y, 0).getBlock(); - if (tempBlock.getType() == Material.AIR) { + if (ElementalAbility.isAir(tempBlock.getType())) { return blockHolder; } blockHolder = tempBlock; } - while (blockHolder.getType() == Material.AIR && Math.abs(y) < Math.abs(negativeY)) { + while (ElementalAbility.isAir(blockHolder.getType()) && Math.abs(y) < Math.abs(negativeY)) { y--; blockHolder = loc.clone().add(0, y, 0).getBlock(); - if (blockHolder.getType() != Material.AIR) { + if (!ElementalAbility.isAir(blockHolder.getType())) { return blockHolder; } } @@ -1210,20 +1276,20 @@ public class GeneralMethods { Block blockHolder = loc.getBlock(); int y = 0; // Only one of these while statements will go - while (blockHolder.getType() != Material.AIR && Math.abs(y) < Math.abs(negativeY)) { + while (!ElementalAbility.isAir(blockHolder.getType()) && Math.abs(y) < Math.abs(negativeY)) { y--; final Block tempblock = loc.clone().add(0, y, 0).getBlock(); - if (tempblock.getType() == Material.AIR) { + if (ElementalAbility.isAir(tempblock.getType())) { return blockHolder; } blockHolder = tempblock; } - while (blockHolder.getType() != Material.AIR && Math.abs(y) < Math.abs(positiveY)) { + while (!ElementalAbility.isAir(blockHolder.getType()) && Math.abs(y) < Math.abs(positiveY)) { y++; blockHolder = loc.clone().add(0, y, 0).getBlock(); - if (blockHolder.getType() == Material.AIR) { + if (ElementalAbility.isAir(blockHolder.getType())) { return blockHolder; } } @@ -1270,18 +1336,34 @@ public class GeneralMethods { } public static boolean isAdjacentToThreeOrMoreSources(final Block block) { - if (block == null || (TempBlock.isTempBlock(block) && WaterAbility.isBendableWaterTempBlock(block))) { + return isAdjacentToThreeOrMoreSources(block, false); + } + + public static boolean isAdjacentToThreeOrMoreSources(final Block block, final boolean lava) { + if (block == null || (TempBlock.isTempBlock(block) && (!lava && !WaterAbility.isBendableWaterTempBlock(block)))) { return false; } int sources = 0; - final byte full = 0x0; final BlockFace[] faces = { BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH }; for (final BlockFace face : faces) { final Block blocki = block.getRelative(face); - if ((blocki.getType() == Material.LAVA || blocki.getType() == Material.STATIONARY_LAVA) && blocki.getData() == full && EarthPassive.canPhysicsChange(blocki)) { - sources++; + if (lava) { + if (!(blocki.getType() == Material.LAVA && EarthPassive.canPhysicsChange(blocki))) { + continue; + } + } else { + if (!((ElementalAbility.isWater(blocki) || ElementalAbility.isIce(blocki)) && WaterManipulation.canPhysicsChange(blocki))) { + continue; + } } - if ((ElementalAbility.isWater(blocki) || ElementalAbility.isIce(blocki)) && blocki.getData() == full && WaterManipulation.canPhysicsChange(blocki)) { + + //At this point it should either be water or lava + if (blocki.getBlockData() instanceof Levelled) { + final Levelled level = (Levelled) blocki.getBlockData(); + if (level.getLevel() == 0) { + sources++; + } + } else { //ice sources++; } } @@ -1293,7 +1375,11 @@ public class GeneralMethods { } public static boolean isInteractable(final Block block) { - return Arrays.asList(INTERACTABLE_MATERIALS).contains(block.getType()); + return isInteractable(block.getType()); + } + + public static boolean isInteractable(final Material material) { + return material.isInteractable(); } public static boolean isObstructed(final Location location1, final Location location2) { @@ -1360,13 +1446,14 @@ public class GeneralMethods { public static boolean isRegionProtectedFromBuildPostCache(final Player player, final String ability, final Location loc) { final boolean allowHarmless = ConfigManager.defaultConfig.get().getBoolean("Properties.RegionProtection.AllowHarmlessAbilities"); final boolean respectWorldGuard = ConfigManager.defaultConfig.get().getBoolean("Properties.RegionProtection.RespectWorldGuard"); - final boolean respectPreciousStones = ConfigManager.defaultConfig.get().getBoolean("Properties.RegionProtection.RespectPreciousStones"); + //final boolean respectPreciousStones = ConfigManager.defaultConfig.get().getBoolean("Properties.RegionProtection.RespectPreciousStones"); final boolean respectFactions = ConfigManager.defaultConfig.get().getBoolean("Properties.RegionProtection.RespectFactions"); final boolean respectTowny = ConfigManager.defaultConfig.get().getBoolean("Properties.RegionProtection.RespectTowny"); final boolean respectGriefPrevention = ConfigManager.defaultConfig.get().getBoolean("Properties.RegionProtection.RespectGriefPrevention"); final boolean respectLWC = ConfigManager.defaultConfig.get().getBoolean("Properties.RegionProtection.RespectLWC"); final boolean respectResidence = ConfigManager.defaultConfig.get().getBoolean("Properties.RegionProtection.Residence.Respect"); - final boolean respectKingdoms = ConfigManager.defaultConfig.get().getBoolean("Properties.RegionProtection.Kingdoms"); + final boolean respectKingdoms = ConfigManager.defaultConfig.get().getBoolean("Properties.RegionProtection.RespectKingdoms"); + final boolean respectRedProtect = ConfigManager.defaultConfig.get().getBoolean("Properties.RegionProtection.RespectRedProtect"); boolean isIgnite = false; boolean isExplosive = false; @@ -1388,14 +1475,14 @@ public class GeneralMethods { final PluginManager pm = Bukkit.getPluginManager(); final Plugin wgp = pm.getPlugin("WorldGuard"); - final Plugin psp = pm.getPlugin("PreciousStones"); - final Plugin fcp = pm.getPlugin("Factions"); + //final Plugin psp = pm.getPlugin("PreciousStones"); + final Plugin facsfw = pm.getPlugin("FactionsFramework"); final Plugin twnp = pm.getPlugin("Towny"); final Plugin gpp = pm.getPlugin("GriefPrevention"); - final Plugin massivecore = pm.getPlugin("MassiveCore"); final Plugin lwc = pm.getPlugin("LWC"); final Plugin residence = pm.getPlugin("Residence"); final Plugin kingdoms = pm.getPlugin("Kingdoms"); + final Plugin redprotect = pm.getPlugin("RedProtect"); for (final Location location : new Location[] { loc, player.getLocation() }) { final World world = location.getWorld(); @@ -1411,53 +1498,49 @@ public class GeneralMethods { } } if (wgp != null && respectWorldGuard && !player.hasPermission("worldguard.region.bypass." + world.getName())) { - final WorldGuardPlugin wg = (WorldGuardPlugin) Bukkit.getPluginManager().getPlugin("WorldGuard"); + final WorldGuard wg = WorldGuard.getInstance(); if (!player.isOnline()) { return true; } - if (isIgnite) { - if (!wg.hasPermission(player, "worldguard.override.lighter")) { - if (wg.getGlobalStateManager().get(world).blockLighter) { + if (!player.hasPermission("worldguard.override.lighter")) { + if (wg.getPlatform().getGlobalStateManager().get(BukkitAdapter.adapt(world)).blockLighter) { return true; } } } + if (isExplosive) { - if (wg.getGlobalStateManager().get(location.getWorld()).blockTNTExplosions) { + if (wg.getPlatform().getGlobalStateManager().get(BukkitAdapter.adapt(location.getWorld())).blockTNTExplosions) { return true; } - if (!wg.getRegionContainer().createQuery().testBuild(location, player, DefaultFlag.TNT)) { + final StateFlag.State tntflag = wg.getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(location), WorldGuardPlugin.inst().wrapPlayer(player), Flags.TNT); + if (tntflag != null && tntflag.equals(StateFlag.State.DENY)) { return true; } } - - if (!wg.canBuild(player, location.getBlock())) { - return true; + final StateFlag bendingflag = (StateFlag) WorldGuard.getInstance().getFlagRegistry().get("bending"); + if (bendingflag != null) { + final StateFlag.State bendingflagstate = wg.getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(location), WorldGuardPlugin.inst().wrapPlayer(player), bendingflag); + if (bendingflagstate == null && !wg.getPlatform().getRegionContainer().createQuery().testState(BukkitAdapter.adapt(location), WorldGuardPlugin.inst().wrapPlayer(player), Flags.BUILD)) { + return true; + } + if (bendingflagstate != null && bendingflagstate.equals(StateFlag.State.DENY)) { + return true; + } + } else { + if (!wg.getPlatform().getRegionContainer().createQuery().testState(BukkitAdapter.adapt(location), WorldGuardPlugin.inst().wrapPlayer(player), Flags.BUILD)) { + return true; + } } } - if (psp != null && respectPreciousStones) { - final PreciousStones ps = (PreciousStones) psp; + if (facsfw != null && respectFactions) { + final FPlayer fPlayer = FPlayers.getBySender(player); + final Faction faction = Factions.getFactionAt(location); + final Rel relation = fPlayer.getRelationTo(faction); - if (isIgnite) { - if (ps.getForceFieldManager().hasSourceField(location, FieldFlag.PREVENT_FIRE)) { - return true; - } - } - if (isExplosive) { - if (ps.getForceFieldManager().hasSourceField(location, FieldFlag.PREVENT_EXPLOSIONS)) { - return true; - } - } - - if (!PreciousStones.API().canBreak(player, location)) { - return true; - } - } - - if (fcp != null && massivecore != null && respectFactions) { - if (!EngineMain.canPlayerBuildAt(player, PS.valueOf(loc.getBlock()), false)) { + if (!(faction.isNone() || fPlayer.getFaction().equals(faction) || relation == Rel.ALLY)) { return true; } } @@ -1470,8 +1553,7 @@ public class GeneralMethods { try { final TownyWorld tWorld = TownyUniverse.getDataSource().getWorld(world.getName()); worldCoord = new WorldCoord(tWorld.getName(), Coord.parseCoord(location)); - - final boolean bBuild = PlayerCacheUtil.getCachePermission(player, location, 3, (byte) 0, TownyPermission.ActionType.BUILD); + final boolean bBuild = PlayerCacheUtil.getCachePermission(player, location, Material.DIRT, TownyPermission.ActionType.BUILD); if (!bBuild) { final PlayerCache cache = twn.getCache(player); @@ -1480,8 +1562,7 @@ public class GeneralMethods { if (((status == TownBlockStatus.ENEMY) && TownyWarConfig.isAllowingAttacks())) { try { TownyWar.callAttackCellEvent(twn, player, location.getBlock(), worldCoord); - } - catch (final Exception e) { + } catch (final Exception e) { TownyMessaging.sendErrorMsg(player, e.getMessage()); } return true; @@ -1495,8 +1576,7 @@ public class GeneralMethods { TownyMessaging.sendErrorMsg(player, cache.getBlockErrMsg()); } } - } - catch (final Exception e1) { + } catch (final Exception e1) { TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_not_configured")); } } @@ -1516,61 +1596,85 @@ public class GeneralMethods { } if (residence != null && respectResidence) { - final ClaimedResidence res = Residence.getResidenceManager().getByLoc(loc); - if (res != null) { - final ResidencePermissions perms = res.getPermissions(); - if (perms.playerHas(player.getName(), ConfigManager.defaultConfig.get().getString("Properities.RegionProtection.Residence.Flag"), true)) { + final ResidenceInterface res = Residence.getInstance().getResidenceManagerAPI(); + final ClaimedResidence claim = res.getByLoc(location); + if (claim != null) { + final ResidencePermissions perms = claim.getPermissions(); + if (!perms.hasApplicableFlag(player.getName(), ConfigManager.getConfig().getString("Properties.RegionProtection.Residence.Flag"))) { return true; } } } if (kingdoms != null && respectKingdoms) { - final SimpleLocation location_ = new SimpleLocation(loc); - final SimpleChunkLocation chunk = location_.toSimpleChunk(); - final Land land = GameManagement.getLandManager().getOrLoadLand(chunk); - - if (land.getOwner() != null) { - final KingdomPlayer kp = GameManagement.getPlayerManager().getSession(player); - - if (!kp.isAdminMode()) { - if (land.getOwner().equals("SafeZone")) { + final KingdomPlayer kPlayer = GameManagement.getPlayerManager().getOfflineKingdomPlayer(player).getKingdomPlayer(); + if (kPlayer.getKingdom() != null) { + final SimpleChunkLocation chunkLocation = new SimpleChunkLocation(location.getChunk()); + final Land land = GameManagement.getLandManager().getOrLoadLand(chunkLocation); + final UUID owner = land.getOwnerUUID(); + if (owner != null) { + if (!kPlayer.getKingdom().getKing().equals(owner)) { return true; - } else if (kp.getKingdom() == null) { // If the player isn't in a kingdom but it's claimed land. - return true; - } else { - final Kingdom kingdom = kp.getKingdom(); - final String kingdomName = kingdom.getKingdomName(); - if (!kingdomName.equals(land.getOwner())) // If the player's kingdom doesn't match. - { - return true; - } - - // If it's within the nexus area, test for higher permission. - if (land.getStructure() != null && land.getStructure().getType() == StructureType.NEXUS) { - if (!kp.getRank().isHigherOrEqualTo(kingdom.getPermissionsInfo().getBuildInNexus())) { - return true; - } - } } } } + + } + + if (redprotect != null && respectRedProtect) { + final RedProtectAPI api = RedProtect.get().getAPI(); + final Region region = api.getRegion(location); + if (!(region != null && region.canBuild(player))) { + return true; + } } } return false; } public static boolean isSolid(final Block block) { - return !Arrays.asList(NON_OPAQUE).contains(block.getType()); + return isSolid(block.getType()); + } + + public static boolean isSolid(final Material material) { + return material.isSolid(); + } + + public static boolean isTransparent(final Block block) { + return isTransparent(block.getType()); + } + + public static boolean isTransparent(final Material material) { + return !material.isOccluding() && !material.isSolid(); } /** Checks if an entity is Undead **/ public static boolean isUndead(final Entity entity) { - return entity != null && (entity.getType() == EntityType.ZOMBIE || entity.getType() == EntityType.BLAZE || entity.getType() == EntityType.GIANT || entity.getType() == EntityType.IRON_GOLEM || entity.getType() == EntityType.MAGMA_CUBE || entity.getType() == EntityType.PIG_ZOMBIE || entity.getType() == EntityType.SKELETON || entity.getType() == EntityType.SLIME || entity.getType() == EntityType.SNOWMAN || entity.getType() == EntityType.ZOMBIE); + if (entity == null) { + return false; + } + + switch (entity.getType()) { + case SKELETON: + case STRAY: + case WITHER_SKELETON: + case WITHER: + case ZOMBIE: + case HUSK: + case ZOMBIE_VILLAGER: + case PIG_ZOMBIE: + case DROWNED: + case ZOMBIE_HORSE: + case SKELETON_HORSE: + case PHANTOM: + return true; + default: + return false; + } } public static boolean isWeapon(final Material mat) { - return mat != null && (mat == Material.WOOD_AXE || mat == Material.WOOD_PICKAXE || mat == Material.WOOD_SPADE || mat == Material.WOOD_SWORD || mat == Material.STONE_AXE || mat == Material.STONE_PICKAXE || mat == Material.STONE_SPADE || mat == Material.STONE_SWORD || mat == Material.IRON_AXE || mat == Material.IRON_PICKAXE || mat == Material.IRON_SWORD || mat == Material.IRON_SPADE || mat == Material.DIAMOND_AXE || mat == Material.DIAMOND_PICKAXE || mat == Material.DIAMOND_SWORD || mat == Material.DIAMOND_SPADE || mat == Material.GOLD_AXE || mat == Material.GOLD_HOE || mat == Material.GOLD_SWORD || mat == Material.GOLD_PICKAXE || mat == Material.GOLD_SPADE); + return mat != null && (mat == Material.WOODEN_AXE || mat == Material.WOODEN_PICKAXE || mat == Material.WOODEN_SHOVEL || mat == Material.WOODEN_SWORD || mat == Material.STONE_AXE || mat == Material.STONE_PICKAXE || mat == Material.STONE_SHOVEL || mat == Material.STONE_SWORD || mat == Material.IRON_AXE || mat == Material.IRON_PICKAXE || mat == Material.IRON_SWORD || mat == Material.IRON_SHOVEL || mat == Material.DIAMOND_AXE || mat == Material.DIAMOND_PICKAXE || mat == Material.DIAMOND_SWORD || mat == Material.DIAMOND_SHOVEL || mat == Material.GOLDEN_AXE || mat == Material.GOLDEN_HOE || mat == Material.GOLDEN_SWORD || mat == Material.GOLDEN_PICKAXE || mat == Material.GOLDEN_SHOVEL || mat == Material.TRIDENT); } public static void loadBendingPlayer(final BendingPlayer pl) { @@ -1591,13 +1695,13 @@ public class GeneralMethods { String prefix = ""; final boolean chatEnabled = ConfigManager.languageConfig.get().getBoolean("Chat.Enable"); - if (bPlayer.getElements().size() > 1) { + + prefix = ChatColor.WHITE + ChatColor.translateAlternateColorCodes('&', ConfigManager.languageConfig.get().getString("Chat.Prefixes.Nonbender")) + " "; + if (player.hasPermission("bending.avatar") || (bPlayer.hasElement(Element.AIR) && bPlayer.hasElement(Element.EARTH) && bPlayer.hasElement(Element.FIRE) && bPlayer.hasElement(Element.WATER))) { prefix = Element.AVATAR.getPrefix(); - } else if (bPlayer.getElements().size() == 1) { + } else if (bPlayer.getElements().size() > 0) { element = bPlayer.getElements().get(0); prefix = element.getPrefix(); - } else { - prefix = ChatColor.WHITE + ChatColor.translateAlternateColorCodes('&', ConfigManager.languageConfig.get().getString("Chat.Prefixes.Nonbender")) + " "; } if (chatEnabled) { @@ -1680,9 +1784,11 @@ public class GeneralMethods { } public static void removeBlock(final Block block) { - if (isAdjacentToThreeOrMoreSources(block)) { + if (isAdjacentToThreeOrMoreSources(block, false)) { block.setType(Material.WATER); - block.setData((byte) 0x0); + if (block.getBlockData() instanceof Levelled) { + ((Levelled) block.getBlockData()).setLevel(1); + } } else { block.setType(Material.AIR); } @@ -1796,15 +1902,20 @@ public class GeneralMethods { final boolean respectTowny = ConfigManager.defaultConfig.get().getBoolean("Properties.RegionProtection.RespectTowny"); final boolean respectGriefPrevention = ConfigManager.defaultConfig.get().getBoolean("Properties.RegionProtection.RespectGriefPrevention"); final boolean respectLWC = ConfigManager.defaultConfig.get().getBoolean("Properties.RegionProtection.RespectLWC"); + final boolean respectResidence = ConfigManager.defaultConfig.get().getBoolean("Properties.RegionProtection.Residence.Respect"); + final boolean respectKingdoms = ConfigManager.defaultConfig.get().getBoolean("Properties.RegionProtection.Kingdoms"); + final boolean respectRedProtect = ConfigManager.defaultConfig.get().getBoolean("Properties.RegionProtection.RedProtect"); final PluginManager pm = Bukkit.getPluginManager(); final Plugin wgp = pm.getPlugin("WorldGuard"); final Plugin psp = pm.getPlugin("PreciousStones"); - final Plugin fcp = pm.getPlugin("Factions"); + final Plugin fcp = pm.getPlugin("FactionsFramework"); final Plugin twnp = pm.getPlugin("Towny"); final Plugin gpp = pm.getPlugin("GriefPrevention"); - final Plugin massivecore = pm.getPlugin("MassiveCore"); final Plugin lwc = pm.getPlugin("LWC"); + final Plugin residence = pm.getPlugin("Residence"); + final Plugin kingdoms = pm.getPlugin("Kingdoms"); + final Plugin redprotect = pm.getPlugin("RedProtect"); if (wgp != null && respectWorldGuard) { writeToDebug("WorldGuard v" + wgp.getDescription().getVersion()); @@ -1813,10 +1924,7 @@ public class GeneralMethods { writeToDebug("PreciousStones v" + psp.getDescription().getVersion()); } if (fcp != null && respectFactions) { - writeToDebug("Factions v" + fcp.getDescription().getVersion()); - } - if (massivecore != null && respectFactions) { - writeToDebug("MassiveCore v" + massivecore.getDescription().getVersion()); + writeToDebug("FactionsFramework v" + fcp.getDescription().getVersion()); } if (twnp != null && respectTowny) { writeToDebug("Towny v" + twnp.getDescription().getVersion()); @@ -1827,6 +1935,15 @@ public class GeneralMethods { if (lwc != null && respectLWC) { writeToDebug("LWC v" + lwc.getDescription().getVersion()); } + if (residence != null && respectResidence) { + writeToDebug("Residence v" + residence.getDescription().getVersion()); + } + if (kingdoms != null && respectKingdoms) { + writeToDebug("Kingdoms v" + kingdoms.getDescription().getVersion()); + } + if (redprotect != null && respectRedProtect) { + writeToDebug("RedProtect v" + redprotect.getDescription().getVersion()); + } writeToDebug(""); writeToDebug("Plugins Hooking Into ProjectKorra (Core)"); @@ -1882,15 +1999,13 @@ public class GeneralMethods { } else if (obj instanceof Map) { writeToDebug(simpleName + ": " + field.getName() + " size=" + ((Map) obj).size()); } - } - catch (final Exception e) { + } catch (final Exception e) { } } } } - } - catch (final IOException e) { + } catch (final IOException e) { e.printStackTrace(); } @@ -1909,7 +2024,7 @@ public class GeneralMethods { } final String uuid = bPlayer.getUUIDString(); - final BindChangeEvent event = new BindChangeEvent(Bukkit.getPlayer(UUID.fromString(uuid)), ability, slot, false); + final PlayerBindChangeEvent event = new PlayerBindChangeEvent(Bukkit.getPlayer(UUID.fromString(uuid)), ability, slot, false); Bukkit.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return; @@ -2033,15 +2148,12 @@ public class GeneralMethods { public static void setVelocity(final Entity entity, final Vector velocity) { if (entity instanceof TNTPrimed) { if (ConfigManager.defaultConfig.get().getBoolean("Properties.BendingAffectFallingSand.TNT")) { - entity.setVelocity(velocity.multiply(ConfigManager.defaultConfig.get().getDouble("Properties.BendingAffectFallingSand.TNTStrengthMultiplier"))); + velocity.multiply(ConfigManager.defaultConfig.get().getDouble("Properties.BendingAffectFallingSand.TNTStrengthMultiplier")); } - return; - } - if (entity instanceof FallingBlock) { + } else if (entity instanceof FallingBlock) { if (ConfigManager.defaultConfig.get().getBoolean("Properties.BendingAffectFallingSand.Normal")) { - entity.setVelocity(velocity.multiply(ConfigManager.defaultConfig.get().getDouble("Properties.BendingAffectFallingSand.NormalStrengthMultiplier"))); + velocity.multiply(ConfigManager.defaultConfig.get().getDouble("Properties.BendingAffectFallingSand.NormalStrengthMultiplier")); } - return; } // Attempt to stop velocity from going over the packet cap. @@ -2066,28 +2178,47 @@ public class GeneralMethods { entity.setVelocity(velocity); } - public static FallingBlock spawnFallingBlock(final Location loc, final int type) { - return spawnFallingBlock(loc, type, (byte) 0); - } - - public static FallingBlock spawnFallingBlock(final Location loc, final int type, final byte data) { - return loc.getWorld().spawnFallingBlock(loc, type, data); - } - public static FallingBlock spawnFallingBlock(final Location loc, final Material type) { - return spawnFallingBlock(loc, type, (byte) 0); + return spawnFallingBlock(loc, type, type.createBlockData()); } - public static FallingBlock spawnFallingBlock(final Location loc, final Material type, final byte data) { - return loc.getWorld().spawnFallingBlock(loc, type, data); + public static FallingBlock spawnFallingBlock(final Location loc, final Material type, final BlockData data) { + return loc.getWorld().spawnFallingBlock(loc, data); + } + + public static boolean playerHeadIsInBlock(final Player player, final Block block) { + return playerHeadIsInBlock(player, block, false); + } + + public static boolean playerHeadIsInBlock(final Player player, final Block block, final boolean exact) { + double checkDistance; + if (exact) { + checkDistance = 0.5; + } else { + checkDistance = 0.75; + } + return (player.getEyeLocation().getBlockY() == block.getLocation().getBlockY() && (Math.abs(player.getEyeLocation().getX() - block.getLocation().add(0.5, 0.0, 0.5).getX()) < checkDistance) && (Math.abs(player.getEyeLocation().getZ() - block.getLocation().add(0.5, 0.0, 0.5).getZ()) < checkDistance)); + } + + public static boolean playerFeetIsInBlock(final Player player, final Block block) { + return playerFeetIsInBlock(player, block, false); + } + + public static boolean playerFeetIsInBlock(final Player player, final Block block, final boolean exact) { + double checkDistance; + if (exact) { + checkDistance = 0.5; + } else { + checkDistance = 0.75; + } + return (player.getLocation().getBlockY() == block.getLocation().getBlockY() && (Math.abs(player.getLocation().getX() - block.getLocation().add(0.5, 0.0, 0.5).getX()) < checkDistance) && (Math.abs(player.getLocation().getZ() - block.getLocation().add(0.5, 0.0, 0.5).getZ()) < checkDistance)); } public static void sendBrandingMessage(final CommandSender sender, final String message) { ChatColor color; try { color = ChatColor.valueOf(ConfigManager.languageConfig.get().getString("Chat.Branding.Color").toUpperCase()); - } - catch (final IllegalArgumentException exception) { + } catch (final IllegalArgumentException exception) { color = ChatColor.GOLD; } @@ -2193,9 +2324,30 @@ public class GeneralMethods { pw.flush(); pw.close(); - } - catch (final IOException e) { + } catch (final IOException e) { e.printStackTrace(); } } + + public static boolean locationEqualsIgnoreDirection(final Location loc1, final Location loc2) { + return loc1.getWorld().equals(loc2.getWorld()) && loc1.getX() == loc2.getX() && loc1.getY() == loc2.getY() && loc1.getZ() == loc2.getZ(); + } + + public static boolean isLightEmitting(final Material material) { + switch (material) { + case GLOWSTONE: + case TORCH: + case SEA_LANTERN: + case BEACON: + case REDSTONE_LAMP: + case REDSTONE_TORCH: + case MAGMA_BLOCK: + case LAVA: + case JACK_O_LANTERN: + case END_ROD: + return true; + default: + return false; + } + } } diff --git a/src/com/projectkorra/projectkorra/Manager.java b/src/com/projectkorra/projectkorra/Manager.java new file mode 100644 index 00000000..bb9390e0 --- /dev/null +++ b/src/com/projectkorra/projectkorra/Manager.java @@ -0,0 +1,124 @@ +package com.projectkorra.projectkorra; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.lang3.Validate; + +import org.bukkit.Bukkit; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.plugin.java.JavaPlugin; + +import com.projectkorra.projectkorra.util.DBCooldownManager; +import com.projectkorra.projectkorra.util.FlightHandler; +import com.projectkorra.projectkorra.util.StatisticsManager; + +public abstract class Manager implements Listener { + + /** + * {@link Map} containing all {@link Manager} instances by their + * {@link Class} as key + */ + private static final Map, Manager> MANAGERS = new HashMap<>(); + + /** + * Register a new {@link Manager} instance. + * + * @param managerClass {@link Class} of the {@link Manager} to be registered + * @throws NullPointerException if managerClass is null + * @throws IllegalArgumentException if managerClass has already been + * registered + */ + public static void registerManager(final Class managerClass) { + Validate.notNull(managerClass, "Manager class cannot be null"); + Validate.isTrue(!MANAGERS.containsKey(managerClass), "Manager has already been registered"); + try { + final Constructor constructor = managerClass.getDeclaredConstructor(); + final boolean accessible = constructor.isAccessible(); + constructor.setAccessible(true); + final Manager manager = constructor.newInstance(); + constructor.setAccessible(accessible); + manager.activate(); + MANAGERS.put(managerClass, manager); + } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | SecurityException | IllegalArgumentException | InvocationTargetException e) { + e.printStackTrace(); + } + } + + /** + * Get a registered {@link Manager} by its {@link Class}. + * + * @param managerClass {@link Class} of the registered {@link Manager} + * @return instance of the {@link Manager} class + * @throws NullPointerException if managerClass is null + * @throws IllegalArgumentException if managerClass has not yet been + * registered + */ + public static T getManager(final Class managerClass) { + Validate.notNull(managerClass, "Manager class cannot be null"); + Validate.isTrue(MANAGERS.containsKey(managerClass), "Manager has not yet been registered"); + final Manager registered = MANAGERS.get(managerClass); + return managerClass.cast(registered); + } + + /** + * Get this plugin instance + * + * @return {@link ProjectKorra} plugin instance + */ + protected ProjectKorra getPlugin() { + return JavaPlugin.getPlugin(ProjectKorra.class); + } + + /** + * Activate this {@link Manager} + */ + public final void activate() { + Bukkit.getPluginManager().registerEvents(this, ProjectKorra.plugin); + this.onActivate(); + } + + /** + * Overridable method to execute code when this {@link Manager} is activated + */ + public void onActivate() { + + } + + /** + * Deactivate this {@link Manager} + */ + public final void deactivate() { + HandlerList.unregisterAll(this); + this.onDeactivate(); + } + + /** + * Overridable method to execute code when this {@link Manager} is + * deactivated + */ + public void onDeactivate() { + + } + + /** + * Activates core {@link Manager} instances + */ + public static void startup() { + registerManager(StatisticsManager.class); + registerManager(DBCooldownManager.class); + registerManager(FlightHandler.class); + } + + /** + * Deactivates and clears all {@link Manager} instances + */ + public static void shutdown() { + MANAGERS.values().forEach(Manager::deactivate); + MANAGERS.clear(); + } + +} diff --git a/src/com/projectkorra/projectkorra/PKListener.java b/src/com/projectkorra/projectkorra/PKListener.java index 4f311cb0..648046b6 100644 --- a/src/com/projectkorra/projectkorra/PKListener.java +++ b/src/com/projectkorra/projectkorra/PKListener.java @@ -3,11 +3,12 @@ package com.projectkorra.projectkorra; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.UUID; +import co.aikar.timings.lib.MCTiming; + import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.GameMode; @@ -30,7 +31,10 @@ import org.bukkit.event.block.BlockFormEvent; import org.bukkit.event.block.BlockFromToEvent; import org.bukkit.event.block.BlockIgniteEvent; import org.bukkit.event.block.BlockPhysicsEvent; +import org.bukkit.event.block.BlockPistonExtendEvent; +import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.block.FluidLevelChangeEvent; import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntityCombustEvent; import org.bukkit.event.entity.EntityDamageByBlockEvent; @@ -41,18 +45,20 @@ import org.bukkit.event.entity.EntityDamageEvent.DamageModifier; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityInteractEvent; +import org.bukkit.event.entity.EntityPickupItemEvent; import org.bukkit.event.entity.EntityShootBowEvent; import org.bukkit.event.entity.EntityTargetEvent; import org.bukkit.event.entity.EntityTargetLivingEntityEvent; import org.bukkit.event.entity.EntityTeleportEvent; import org.bukkit.event.entity.EntityToggleGlideEvent; +import org.bukkit.event.entity.ItemMergeEvent; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.event.entity.SlimeSplitEvent; import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryPickupItemEvent; import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerAnimationEvent; import org.bukkit.event.player.PlayerBucketEmptyEvent; import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerGameModeChangeEvent; @@ -135,7 +141,6 @@ import com.projectkorra.projectkorra.earthbending.passive.FerroControl; import com.projectkorra.projectkorra.event.EntityBendingDeathEvent; import com.projectkorra.projectkorra.event.HorizontalVelocityChangeEvent; import com.projectkorra.projectkorra.event.PlayerChangeElementEvent; -import com.projectkorra.projectkorra.event.PlayerChangeElementEvent.Result; import com.projectkorra.projectkorra.event.PlayerJumpEvent; import com.projectkorra.projectkorra.firebending.Blaze; import com.projectkorra.projectkorra.firebending.BlazeArc; @@ -160,9 +165,11 @@ import com.projectkorra.projectkorra.object.Preset; import com.projectkorra.projectkorra.util.BlockSource; import com.projectkorra.projectkorra.util.ClickType; import com.projectkorra.projectkorra.util.DamageHandler; +import com.projectkorra.projectkorra.util.FlightHandler; import com.projectkorra.projectkorra.util.FlightHandler.Flight; import com.projectkorra.projectkorra.util.MovementHandler; import com.projectkorra.projectkorra.util.PassiveHandler; +import com.projectkorra.projectkorra.util.StatisticsManager; import com.projectkorra.projectkorra.util.StatisticsMethods; import com.projectkorra.projectkorra.util.TempArmor; import com.projectkorra.projectkorra.util.TempBlock; @@ -174,6 +181,7 @@ import com.projectkorra.projectkorra.waterbending.WaterBubble; import com.projectkorra.projectkorra.waterbending.WaterManipulation; import com.projectkorra.projectkorra.waterbending.WaterSpout; import com.projectkorra.projectkorra.waterbending.blood.Bloodbending; +import com.projectkorra.projectkorra.waterbending.combo.IceBullet; import com.projectkorra.projectkorra.waterbending.healing.HealingWaters; import com.projectkorra.projectkorra.waterbending.ice.IceBlast; import com.projectkorra.projectkorra.waterbending.ice.IceSpikeBlast; @@ -182,7 +190,6 @@ import com.projectkorra.projectkorra.waterbending.ice.PhaseChange.PhaseChangeTyp import com.projectkorra.projectkorra.waterbending.multiabilities.WaterArms; import com.projectkorra.projectkorra.waterbending.passive.FastSwim; import com.projectkorra.projectkorra.waterbending.passive.HydroSink; -import com.projectkorra.rpg.RPGMethods; public class PKListener implements Listener { ProjectKorra plugin; @@ -193,8 +200,25 @@ public class PKListener implements Listener { private static final ArrayList TOGGLED_OUT = new ArrayList<>(); // Stands for toggled = false while logging out. private static final Map JUMPS = new HashMap<>(); + private static MCTiming TimingPhysicsWaterManipulationCheck, TimingPhysicsEarthPassiveCheck, TimingPhysicsIlluminationTorchCheck, TimingPhysicsEarthAbilityCheck, TimingPhysicsAirTempBlockBelowFallingBlockCheck; + private static MCTiming TimingPlayerMoveMovementHandlerCheck, TimingPlayerMoveSpoutCheck, TimingPlayerMoveBloodbentCheck, TimingPlayerMoveAirChiPassiveCheck, TimingPlayerMoveFirePassiveCheck, TimingPlayerMoveJumpCheck; + public PKListener(final ProjectKorra plugin) { + this.plugin = plugin; + + TimingPhysicsWaterManipulationCheck = ProjectKorra.timing("PhysicsWaterManipulationCheck"); + TimingPhysicsEarthPassiveCheck = ProjectKorra.timing("PhysicsEarthPassiveCheck"); + TimingPhysicsIlluminationTorchCheck = ProjectKorra.timing("PhysicsIlluminationTorchCheck"); + TimingPhysicsEarthAbilityCheck = ProjectKorra.timing("PhysicsEarthAbilityCheck"); + TimingPhysicsAirTempBlockBelowFallingBlockCheck = ProjectKorra.timing("PhysicsAirTempBlockBelowFallingBlockCheck"); + + TimingPlayerMoveMovementHandlerCheck = ProjectKorra.timing("PlayerMoveMovementHandlerCheck"); + TimingPlayerMoveSpoutCheck = ProjectKorra.timing("PlayerMoveSpoutCheck"); + TimingPlayerMoveBloodbentCheck = ProjectKorra.timing("PlayerMoveBloodbentCheck"); + TimingPlayerMoveAirChiPassiveCheck = ProjectKorra.timing("PlayerMoveAirChiPassiveCheck"); + TimingPlayerMoveFirePassiveCheck = ProjectKorra.timing("PlayerMoveFirePassiveCheck"); + TimingPlayerMoveJumpCheck = ProjectKorra.timing("PlayerMoveJumpCheck"); } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @@ -245,6 +269,8 @@ public class PKListener implements Listener { TempBlock.revertBlock(block, Material.AIR); } else if (DensityShift.isPassiveSand(block)) { DensityShift.revertSand(block); + } else if (WaterBubble.isAir(block)) { + event.setCancelled(true); } } @@ -252,24 +278,36 @@ public class PKListener implements Listener { public void onBlockFlowTo(final BlockFromToEvent event) { final Block toblock = event.getToBlock(); final Block fromblock = event.getBlock(); - if (ElementalAbility.isLava(fromblock)) { - event.setCancelled(!EarthPassive.canFlowFromTo(fromblock, toblock)); - } - if (ElementalAbility.isWater(fromblock)) { - event.setCancelled(!WaterBubble.isAir(toblock)); - if (!event.isCancelled()) { - event.setCancelled(!WaterManipulation.canFlowFromTo(fromblock, toblock)); - } + if (TempBlock.isTempBlock(fromblock) || TempBlock.isTempBlock(toblock)) { + event.setCancelled(true); + } else { + if (ElementalAbility.isLava(fromblock)) { + event.setCancelled(!EarthPassive.canFlowFromTo(fromblock, toblock)); + } else if (ElementalAbility.isWater(fromblock)) { + event.setCancelled(WaterBubble.isAir(toblock)); + if (!event.isCancelled()) { + event.setCancelled(!WaterManipulation.canFlowFromTo(fromblock, toblock)); + } - if (!event.isCancelled()) { - if (Illumination.isIlluminationTorch(toblock)) { - toblock.setType(Material.AIR); + if (!event.isCancelled()) { + if (Illumination.isIlluminationTorch(toblock)) { + toblock.setType(Material.AIR); + } } } } } + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onFluidLevelChange(final FluidLevelChangeEvent event) { + if (TempBlock.isTempBlock(event.getBlock())) { + event.setCancelled(true); + } else if (TempBlock.isTouchingTempBlock(event.getBlock())) { + event.setCancelled(true); + } + } + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onBlockForm(final BlockFormEvent event) { if (TempBlock.isTempBlock(event.getBlock())) { @@ -290,7 +328,7 @@ public class PKListener implements Listener { boolean marked = true; for (final BlockFace face : faces) { final Block b = event.getBlock().getRelative(face); - if (b.getType() == Material.WATER || b.getType() == Material.STATIONARY_WATER) { + if (b.getType() == Material.WATER) { if (!TempBlock.isTempBlock(b)) { marked = false; // if there is any normal water around it, prevent it. break; @@ -305,8 +343,7 @@ public class PKListener implements Listener { } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onBlockIgnite(final BlockIgniteEvent event) { - } + public void onBlockIgnite(final BlockIgniteEvent event) {} @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onBlockMeltEvent(final BlockFadeEvent event) { @@ -345,13 +382,39 @@ public class PKListener implements Listener { public void onBlockPhysics(final BlockPhysicsEvent event) { final Block block = event.getBlock(); - if (!WaterManipulation.canPhysicsChange(block) || !EarthPassive.canPhysicsChange(block) || Illumination.isIlluminationTorch(block) || EarthAbility.getPreventPhysicsBlocks().contains(block)) { - event.setCancelled(true); + try (MCTiming timing = TimingPhysicsWaterManipulationCheck.startTiming()) { + if (!WaterManipulation.canPhysicsChange(block)) { + event.setCancelled(true); + return; + } + } + + try (MCTiming timing = TimingPhysicsEarthPassiveCheck.startTiming()) { + if (!EarthPassive.canPhysicsChange(block)) { + event.setCancelled(true); + return; + } + } + + try (MCTiming timing = TimingPhysicsIlluminationTorchCheck.startTiming()) { + if (Illumination.isIlluminationTorch(block)) { + event.setCancelled(true); + return; + } + } + + try (MCTiming timing = TimingPhysicsEarthAbilityCheck.startTiming()) { + if (EarthAbility.getPreventPhysicsBlocks().contains(block)) { + event.setCancelled(true); + return; + } } // If there is a TempBlock of Air bellow FallingSand blocks, prevent it from updating. - if (!event.isCancelled() && (block.getType() == Material.SAND || block.getType() == Material.GRAVEL || block.getType() == Material.ANVIL || block.getType() == Material.DRAGON_EGG) && TempBlock.isTempBlock(block.getRelative(BlockFace.DOWN)) && block.getRelative(BlockFace.DOWN).getType() == Material.AIR) { - event.setCancelled(true); + try (MCTiming timing = TimingPhysicsAirTempBlockBelowFallingBlockCheck.startTiming()) { + if ((block.getType() == Material.SAND || block.getType() == Material.RED_SAND || block.getType() == Material.GRAVEL || block.getType() == Material.ANVIL || block.getType() == Material.DRAGON_EGG) && ElementalAbility.isAir(block.getRelative(BlockFace.DOWN).getType()) && TempBlock.isTempBlock(block.getRelative(BlockFace.DOWN))) { + event.setCancelled(true); + } } } @@ -363,19 +426,8 @@ public class PKListener implements Listener { return; } - if (TempBlock.isTempBlock(event.getBlock())) { - final TempBlock tb = TempBlock.get(event.getBlock()); - tb.revertBlock(); - event.getBlock().setType(event.getItemInHand().getType()); - if (event.getPlayer().getGameMode() != GameMode.CREATIVE) { - if (event.getItemInHand().getAmount() <= 0) { - event.getItemInHand().setType(Material.AIR); - event.getItemInHand().setAmount(1); - } else { - event.getItemInHand().setAmount(event.getItemInHand().getAmount() - 1); - } - } - return; + if (TempBlock.isTempBlock(event.getBlock()) && event.getItemInHand().getType() != Material.FLINT_AND_STEEL) { + TempBlock.removeBlock(event.getBlock()); } } @@ -404,12 +456,6 @@ public class PKListener implements Listener { player.setDisplayName(player.getName()); player.setDisplayName(prefix + ChatColor.RESET + player.getDisplayName()); } - - if (event.getResult() == Result.REMOVE) { - if (GeneralMethods.hasRPG()) { - RPGMethods.revokeAvatar(player.getUniqueId()); - } - } } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @@ -437,8 +483,7 @@ public class PKListener implements Listener { } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onEntityDamageBlock(final EntityDamageByBlockEvent event) { - } + public void onEntityDamageBlock(final EntityDamageByBlockEvent event) {} @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onEntityDamageByBlock(final EntityDamageByBlockEvent event) { @@ -469,7 +514,9 @@ public class PKListener implements Listener { } if (entity instanceof LivingEntity && TempArmor.hasTempArmor((LivingEntity) entity)) { - event.setDamage(DamageModifier.ARMOR, 0); + if (event.isApplicable(DamageModifier.ARMOR)) { + event.setDamage(DamageModifier.ARMOR, 0); + } } if (entity instanceof Player) { @@ -484,6 +531,10 @@ public class PKListener implements Listener { abil.remove(); } + if (CoreAbility.getAbility(player, FireJet.class) != null && event.getCause() == DamageCause.FLY_INTO_WALL) { + event.setCancelled(true); + } + if (bPlayer.isElementToggled(Element.FIRE)) { return; } @@ -502,10 +553,12 @@ public class PKListener implements Listener { if (TempArmor.hasTempArmor(event.getEntity())) { final TempArmor armor = TempArmor.getVisibleTempArmor(event.getEntity()); - final List newDrops = armor.filterArmor(event.getDrops()); + if (armor != null) { + final List newDrops = armor.filterArmor(event.getDrops()); + event.getDrops().clear(); + event.getDrops().addAll(newDrops); + } - event.getDrops().clear(); - event.getDrops().addAll(newDrops); if (MetalClips.isControlled(event.getEntity())) { event.getDrops().add(new ItemStack(Material.IRON_INGOT, MetalClips.getTargetToAbility().get(event.getEntity()).getMetalClipsCount())); } @@ -527,22 +580,17 @@ public class PKListener implements Listener { ItemStack cooked = drops.get(i); final Material material = drops.get(i).getType(); switch (material) { - case RAW_BEEF: - cooked = new ItemStack(Material.COOKED_BEEF, 1); + case BEEF: + cooked = new ItemStack(Material.COOKED_BEEF); break; - case RAW_FISH: - final ItemStack salmon = new ItemStack(Material.RAW_FISH, 1, (short) 1); - if (drops.get(i).getDurability() == salmon.getDurability()) { - cooked = new ItemStack(Material.COOKED_FISH, 1, (short) 1); - } else { - cooked = new ItemStack(Material.COOKED_FISH, 1); - } + case SALMON: + cooked = new ItemStack(Material.COOKED_SALMON); break; - case RAW_CHICKEN: - cooked = new ItemStack(Material.COOKED_CHICKEN, 1); + case CHICKEN: + cooked = new ItemStack(Material.COOKED_CHICKEN); break; - case PORK: - cooked = new ItemStack(Material.GRILLED_PORK, 1); + case PORKCHOP: + cooked = new ItemStack(Material.COOKED_PORKCHOP); break; case MUTTON: cooked = new ItemStack(Material.COOKED_MUTTON); @@ -550,6 +598,9 @@ public class PKListener implements Listener { case RABBIT: cooked = new ItemStack(Material.COOKED_RABBIT); break; + case COD: + cooked = new ItemStack(Material.COOKED_COD); + break; default: break; } @@ -662,7 +713,7 @@ public class PKListener implements Listener { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onEntityTeleportEvent(final EntityTeleportEvent event) { final Entity entity = event.getEntity(); - if (MovementHandler.isStopped(entity) || Bloodbending.isBloodbent(entity) || Suffocate.isBreathbent(entity) || MetalClips.isControlled((LivingEntity) entity)) { + if (MovementHandler.isStopped(entity) || Bloodbending.isBloodbent(entity) || Suffocate.isBreathbent(entity) || (entity instanceof LivingEntity && MetalClips.isControlled((LivingEntity) entity))) { event.setCancelled(true); } @@ -735,10 +786,13 @@ public class PKListener implements Listener { } }.runTaskLater(ProjectKorra.plugin, 20); } - - StatisticsMethods.addStatisticAbility(event.getAttacker().getUniqueId(), CoreAbility.getAbility(event.getAbility().getName()), com.projectkorra.projectkorra.util.Statistic.PLAYER_KILLS, 1); + if (event.getAttacker() != null && ProjectKorra.isStatisticsEnabled()) { + StatisticsMethods.addStatisticAbility(event.getAttacker().getUniqueId(), CoreAbility.getAbility(event.getAbility().getName()), com.projectkorra.projectkorra.util.Statistic.PLAYER_KILLS, 1); + } + } + if (event.getAttacker() != null && ProjectKorra.isStatisticsEnabled()) { + StatisticsMethods.addStatisticAbility(event.getAttacker().getUniqueId(), CoreAbility.getAbility(event.getAbility().getName()), com.projectkorra.projectkorra.util.Statistic.TOTAL_KILLS, 1); } - StatisticsMethods.addStatisticAbility(event.getAttacker().getUniqueId(), CoreAbility.getAbility(event.getAbility().getName()), com.projectkorra.projectkorra.util.Statistic.TOTAL_KILLS, 1); } @EventHandler @@ -756,9 +810,18 @@ public class PKListener implements Listener { final Player player = event.getPlayer(); final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); - final String e = bPlayer == null || bPlayer.getElements().size() == 0 ? "Nonbender" : (bPlayer.getElements().size() > 1 ? "Avatar" : bPlayer.getElements().get(0).getName()); + String e = "Nonbender"; + ChatColor c = ChatColor.WHITE; + if (bPlayer != null) { + if (player.hasPermission("bending.avatar") || (bPlayer.hasElement(Element.AIR) && bPlayer.hasElement(Element.EARTH) && bPlayer.hasElement(Element.FIRE) && bPlayer.hasElement(Element.WATER))) { + c = Element.AVATAR.getColor(); + e = Element.AVATAR.getName(); + } else if (bPlayer.getElements().size() > 0) { + c = bPlayer.getElements().get(0).getColor(); + e = bPlayer.getElements().get(0).getName(); + } + } final String element = ConfigManager.languageConfig.get().getString("Chat.Prefixes." + e); - final ChatColor c = bPlayer == null || bPlayer.getElements().size() == 0 ? ChatColor.WHITE : (bPlayer.getElements().size() > 1 ? Element.AVATAR.getColor() : bPlayer.getElements().get(0).getColor()); event.setFormat(event.getFormat().replace("{element}", c + element + ChatColor.RESET).replace("{ELEMENT}", c + element + ChatColor.RESET).replace("{elementcolor}", c + "").replace("{ELEMENTCOLOR}", c + "")); if (!ConfigManager.languageConfig.get().getBoolean("Chat.Enable")) { @@ -771,15 +834,10 @@ public class PKListener implements Listener { return; } - if (player.hasPermission("bending.avatar") || bPlayer.getElements().size() > 1) { + if (player.hasPermission("bending.avatar") || (bPlayer.hasElement(Element.AIR) && bPlayer.hasElement(Element.EARTH) && bPlayer.hasElement(Element.FIRE) && bPlayer.hasElement(Element.WATER))) { color = ChatColor.valueOf(ConfigManager.languageConfig.get().getString("Chat.Colors.Avatar")); - } else { - for (final Element element_ : Element.getMainElements()) { - if (bPlayer.hasElement(element_)) { - color = element_.getColor(); - break; - } - } + } else if (bPlayer.getElements().size() > 0) { + color = bPlayer.getElements().get(0).getColor(); } String format = ConfigManager.languageConfig.get().getString("Chat.Format"); @@ -818,23 +876,28 @@ public class PKListener implements Listener { new AirBurst(player, true); } } + + CoreAbility gd = CoreAbility.getAbility(GracefulDescent.class); + CoreAbility ds = CoreAbility.getAbility(DensityShift.class); + CoreAbility hs = CoreAbility.getAbility(HydroSink.class); + CoreAbility ab = CoreAbility.getAbility(Acrobatics.class); - if (bPlayer.hasElement(Element.AIR) && event.getCause() == DamageCause.FALL && bPlayer.canBendPassive(CoreAbility.getAbility(GracefulDescent.class)) && bPlayer.canUsePassive(CoreAbility.getAbility(GracefulDescent.class)) && CoreAbility.getAbility(GracefulDescent.class).isEnabled() && PassiveManager.hasPassive(player, CoreAbility.getAbility(GracefulDescent.class))) { + if (gd != null && bPlayer.hasElement(Element.AIR) && event.getCause() == DamageCause.FALL && bPlayer.canBendPassive(gd) && bPlayer.canUsePassive(gd) && gd.isEnabled() && PassiveManager.hasPassive(player, gd)) { event.setDamage(0D); event.setCancelled(true); - } else if (bPlayer.hasElement(Element.EARTH) && event.getCause() == DamageCause.FALL && bPlayer.canBendPassive(CoreAbility.getAbility(DensityShift.class)) && bPlayer.canUsePassive(CoreAbility.getAbility(DensityShift.class)) && CoreAbility.getAbility(DensityShift.class).isEnabled() && PassiveManager.hasPassive(player, CoreAbility.getAbility(DensityShift.class))) { + } else if (ds != null && bPlayer.hasElement(Element.EARTH) && event.getCause() == DamageCause.FALL && bPlayer.canBendPassive(ds) && bPlayer.canUsePassive(ds) && ds.isEnabled() && PassiveManager.hasPassive(player, ds)) { if (DensityShift.softenLanding(player)) { event.setDamage(0D); event.setCancelled(true); } - } else if (bPlayer.hasElement(Element.WATER) && event.getCause() == DamageCause.FALL && bPlayer.canBendPassive(CoreAbility.getAbility(HydroSink.class)) && bPlayer.canUsePassive(CoreAbility.getAbility(HydroSink.class)) && CoreAbility.getAbility(HydroSink.class).isEnabled() && PassiveManager.hasPassive(player, CoreAbility.getAbility(HydroSink.class))) { + } else if (hs != null && bPlayer.hasElement(Element.WATER) && event.getCause() == DamageCause.FALL && bPlayer.canBendPassive(hs) && bPlayer.canUsePassive(hs) && hs.isEnabled() && PassiveManager.hasPassive(player, hs)) { if (HydroSink.applyNoFall(player)) { event.setDamage(0D); event.setCancelled(true); } } - if (bPlayer.hasElement(Element.CHI) && event.getCause() == DamageCause.FALL && bPlayer.canBendPassive(CoreAbility.getAbility(Acrobatics.class)) && bPlayer.canUsePassive(CoreAbility.getAbility(Acrobatics.class)) && CoreAbility.getAbility(Acrobatics.class).isEnabled() && PassiveManager.hasPassive(player, CoreAbility.getAbility(Acrobatics.class))) { + if (ab != null && bPlayer.hasElement(Element.CHI) && event.getCause() == DamageCause.FALL && bPlayer.canBendPassive(ab) && bPlayer.canUsePassive(ab) && ab.isEnabled() && PassiveManager.hasPassive(player, ab)) { final double initdamage = event.getDamage(); final double newdamage = event.getDamage() * Acrobatics.getFallReductionFactor(); final double finaldamage = initdamage - newdamage; @@ -845,7 +908,7 @@ public class PKListener implements Listener { } if (event.getCause() == DamageCause.FALL) { - final Flight flight = ProjectKorra.flightHandler.getInstance(player); + final Flight flight = Manager.getManager(FlightHandler.class).getInstance(player); if (flight != null) { if (flight.getPlayer() == flight.getSource()) { event.setCancelled(true); @@ -853,7 +916,9 @@ public class PKListener implements Listener { } } - if (bPlayer.canBendPassive(CoreAbility.getAbility(HeatControl.class)) && bPlayer.hasElement(Element.FIRE) && bPlayer.canUsePassive(CoreAbility.getAbility(HeatControl.class)) && (event.getCause() == DamageCause.FIRE || event.getCause() == DamageCause.FIRE_TICK)) { + CoreAbility hc = CoreAbility.getAbility(HeatControl.class); + + if (hc != null && bPlayer.hasElement(Element.FIRE) && bPlayer.canBendPassive(hc) && bPlayer.canUsePassive(hc) && (event.getCause() == DamageCause.FIRE || event.getCause() == DamageCause.FIRE_TICK)) { event.setCancelled(!HeatControl.canBurn(player)); } @@ -900,7 +965,7 @@ public class PKListener implements Listener { return; } - final String boundAbil = sourceBPlayer.getBoundAbilityName(); + final Ability boundAbil = sourceBPlayer.getBoundAbility(); if (sourceBPlayer.getBoundAbility() != null) { if (!sourceBPlayer.isOnCooldown(boundAbil)) { @@ -909,15 +974,15 @@ public class PKListener implements Listener { if (sourceBPlayer.getBoundAbility() instanceof ChiAbility) { if (sourceBPlayer.canCurrentlyBendWithWeapons()) { if (sourceBPlayer.isElementToggled(Element.CHI)) { - if (boundAbil.equalsIgnoreCase("Paralyze")) { + if (boundAbil.equals(CoreAbility.getAbility(Paralyze.class))) { new Paralyze(sourcePlayer, entity); - } else if (boundAbil.equalsIgnoreCase("QuickStrike")) { + } else if (boundAbil.equals(CoreAbility.getAbility(QuickStrike.class))) { new QuickStrike(sourcePlayer, entity); e.setCancelled(true); - } else if (boundAbil.equalsIgnoreCase("SwiftKick")) { + } else if (boundAbil.equals(CoreAbility.getAbility(SwiftKick.class))) { new SwiftKick(sourcePlayer, entity); e.setCancelled(true); - } else if (boundAbil.equalsIgnoreCase("RapidPunch")) { + } else if (boundAbil.equals(CoreAbility.getAbility(RapidPunch.class))) { new RapidPunch(sourcePlayer, entity); e.setCancelled(true); } @@ -1035,6 +1100,14 @@ public class PKListener implements Listener { } } + if (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR) { + if (bPlayer.getBoundAbilityName().equalsIgnoreCase("IceBlast")) { + if (CoreAbility.hasAbility(player, IceBullet.class)) { + CoreAbility.getAbility(player, IceBullet.class).doRightClick(); + } + } + } + if (MovementHandler.isStopped(player) || Bloodbending.isBloodbent(player) || Suffocate.isBreathbent(player)) { event.setCancelled(true); } @@ -1074,6 +1147,7 @@ public class PKListener implements Listener { return; } } + if (!RIGHT_CLICK_INTERACT.contains(player.getUniqueId())) { if (event.getRightClicked() instanceof Player) { final Player target = (Player) event.getRightClicked(); @@ -1116,32 +1190,25 @@ public class PKListener implements Listener { GeneralMethods.createBendingPlayer(player.getUniqueId(), player.getName()); if (ProjectKorra.isStatisticsEnabled()) { - ProjectKorra.statistics.load(player.getUniqueId()); + Manager.getManager(StatisticsManager.class).load(player.getUniqueId()); } - Bukkit.getScheduler().runTaskLater(ProjectKorra.plugin, new Runnable() { - - @Override - public void run() { - PassiveManager.registerPassives(player); - GeneralMethods.removeUnusableAbilities(player.getName()); - } + Bukkit.getScheduler().runTaskLater(ProjectKorra.plugin, (Runnable) () -> { + PassiveManager.registerPassives(player); + GeneralMethods.removeUnusableAbilities(player.getName()); }, 5); if (ConfigManager.languageConfig.get().getBoolean("Chat.Branding.JoinMessage.Enabled")) { - Bukkit.getScheduler().runTaskLater(ProjectKorra.plugin, new Runnable() { - @Override - public void run() { - ChatColor color = ChatColor.valueOf(ConfigManager.languageConfig.get().getString("Chat.Branding.Color").toUpperCase()); - color = color == null ? ChatColor.GOLD : color; - final String topBorder = ConfigManager.languageConfig.get().getString("Chat.Branding.Borders.TopBorder"); - final String bottomBorder = ConfigManager.languageConfig.get().getString("Chat.Branding.Borders.BottomBorder"); - if (!topBorder.isEmpty()) { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', topBorder)); - } - player.sendMessage(color + "This server is running ProjectKorra version " + ProjectKorra.plugin.getDescription().getVersion() + " for bending! Find out more at http://www.projectkorra.com!"); - if (!bottomBorder.isEmpty()) { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', bottomBorder)); - } + Bukkit.getScheduler().runTaskLater(ProjectKorra.plugin, (Runnable) () -> { + ChatColor color = ChatColor.valueOf(ConfigManager.languageConfig.get().getString("Chat.Branding.Color").toUpperCase()); + color = color == null ? ChatColor.GOLD : color; + final String topBorder = ConfigManager.languageConfig.get().getString("Chat.Branding.Borders.TopBorder"); + final String bottomBorder = ConfigManager.languageConfig.get().getString("Chat.Branding.Borders.BottomBorder"); + if (!topBorder.isEmpty()) { + player.sendMessage(ChatColor.translateAlternateColorCodes('&', topBorder)); + } + player.sendMessage(color + "This server is running ProjectKorra version " + ProjectKorra.plugin.getDescription().getVersion() + " for bending! Find out more at http://www.projectkorra.com!"); + if (!bottomBorder.isEmpty()) { + player.sendMessage(ChatColor.translateAlternateColorCodes('&', bottomBorder)); } }, 20 * 4); } @@ -1159,75 +1226,86 @@ public class PKListener implements Listener { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onPlayerMove(final PlayerMoveEvent event) { + if (event.getTo().getX() == event.getFrom().getX() && event.getTo().getY() == event.getFrom().getY() && event.getTo().getZ() == event.getFrom().getZ()) { + return; + } + final Player player = event.getPlayer(); final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); - if (MovementHandler.isStopped(player)) { - if (event.getTo().getX() != event.getFrom().getX() || event.getTo().getZ() != event.getFrom().getZ() || event.getTo().getY() > event.getFrom().getY()) { - event.setCancelled(true); + + try (MCTiming timing = TimingPlayerMoveMovementHandlerCheck.startTiming()) { + if (MovementHandler.isStopped(player)) { + if (event.getTo().getX() != event.getFrom().getX() || event.getTo().getZ() != event.getFrom().getZ() || event.getTo().getY() > event.getFrom().getY()) { + event.setCancelled(true); + } return; } - } else if (CoreAbility.hasAbility(player, WaterSpout.class) || CoreAbility.hasAbility(player, AirSpout.class)) { - Vector vel = new Vector(); - vel.setX(event.getTo().getX() - event.getFrom().getX()); - vel.setZ(event.getTo().getZ() - event.getFrom().getZ()); + } - final double currspeed = vel.length(); - final double maxspeed = .2; - if (currspeed > maxspeed) { - // apply only if moving set a factor - vel = vel.normalize().multiply(maxspeed); - // apply the new velocity - event.getPlayer().setVelocity(vel); - } - } else if (Bloodbending.isBloodbent(player)) { - final BendingPlayer bender = Bloodbending.getBloodbender(player); - if (bender.isAvatarState()) { - event.setCancelled(true); + try (MCTiming timing = TimingPlayerMoveSpoutCheck.startTiming()) { + if (CoreAbility.hasAbility(player, WaterSpout.class) || CoreAbility.hasAbility(player, AirSpout.class)) { + Vector vel = new Vector(); + vel.setX(event.getTo().getX() - event.getFrom().getX()); + vel.setZ(event.getTo().getZ() - event.getFrom().getZ()); + + final double currspeed = vel.length(); + final double maxspeed = .2; + if (currspeed > maxspeed) { + // apply only if moving set a factor + vel = vel.normalize().multiply(maxspeed); + // apply the new velocity + event.getPlayer().setVelocity(vel); + } return; } + } - double distance1 = 0; - double distance2 = 0; - final Location loc = Bloodbending.getBloodbendingLocation(player); - if (player.getWorld().equals(loc.getWorld())) { - distance1 = event.getFrom().distanceSquared(loc); - distance2 = event.getTo().distanceSquared(loc); - } - - if (distance1 == 0 && distance2 == 0) { - return; - } else if (distance1 > distance2 || distance1 < distance2) { - if (!player.getVelocity().equals(Bloodbending.getBloodbendingVector(player))) { - player.setVelocity(Bloodbending.getBloodbendingVector(player)); + try (MCTiming timing = TimingPlayerMoveBloodbentCheck.startTiming()) { + if (Bloodbending.isBloodbent(player)) { + final BendingPlayer bender = Bloodbending.getBloodbender(player); + if (bender.isAvatarState()) { + event.setCancelled(true); return; } - } - } else { - if (bPlayer != null) { - if (event.getTo().getX() != event.getFrom().getX() || event.getTo().getY() != event.getFrom().getY() || event.getTo().getZ() != event.getFrom().getZ()) { - if (bPlayer.hasElement(Element.AIR) || bPlayer.hasElement(Element.CHI)) { - PassiveHandler.checkExhaustionPassives(player); + + final Location loc = Bloodbending.getBloodbendingLocation(player); + if (player.getWorld().equals(loc.getWorld())) { + if (!player.getVelocity().equals(Bloodbending.getBloodbendingVector(player))) { + player.setVelocity(Bloodbending.getBloodbendingVector(player)); } } + return; + } + } + if (bPlayer != null) { + try (MCTiming timing = TimingPlayerMoveAirChiPassiveCheck) { + if (bPlayer.hasElement(Element.AIR) || bPlayer.hasElement(Element.CHI)) { + PassiveHandler.checkExhaustionPassives(player); + } + } + + try (MCTiming timing = TimingPlayerMoveFirePassiveCheck.startTiming()) { if (event.getTo().getBlock() != event.getFrom().getBlock()) { FirePassive.handle(player); } } } - if (event.getTo().getY() > event.getFrom().getY()) { - if (!(player.getLocation().getBlock().getType() == Material.VINE) && !(player.getLocation().getBlock().getType() == Material.LADDER)) { - final int current = player.getStatistic(Statistic.JUMP); - final int last = JUMPS.get(player); + try (MCTiming timing = TimingPlayerMoveJumpCheck.startTiming()) { + if (event.getTo().getY() > event.getFrom().getY()) { + if (!(player.getLocation().getBlock().getType() == Material.VINE) && !(player.getLocation().getBlock().getType() == Material.LADDER)) { + final int current = player.getStatistic(Statistic.JUMP); + final int last = JUMPS.get(player); - if (last != current) { - JUMPS.put(player, current); + if (last != current) { + JUMPS.put(player, current); - final double yDif = event.getTo().getY() - event.getFrom().getY(); + final double yDif = event.getTo().getY() - event.getFrom().getY(); - if ((yDif < 0.035 || yDif > 0.037) && (yDif < 0.116 || yDif > 0.118)) { - Bukkit.getServer().getPluginManager().callEvent(new PlayerJumpEvent(player, yDif)); + if ((yDif < 0.035 || yDif > 0.037) && (yDif < 0.116 || yDif > 0.118)) { + Bukkit.getServer().getPluginManager().callEvent(new PlayerJumpEvent(player, yDif)); + } } } } @@ -1253,10 +1331,12 @@ public class PKListener implements Listener { final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); if (ProjectKorra.isStatisticsEnabled()) { - ProjectKorra.statistics.store(player.getUniqueId()); + Manager.getManager(StatisticsManager.class).store(player.getUniqueId()); } if (bPlayer != null) { - bPlayer.saveCooldowns(); + if (ProjectKorra.isDatabaseCooldownsEnabled()) { + bPlayer.saveCooldowns(); + } if (TOGGLED_OUT.contains(player.getUniqueId()) && bPlayer.isToggled()) { TOGGLED_OUT.remove(player.getUniqueId()); @@ -1335,18 +1415,22 @@ public class PKListener implements Listener { BlockSource.update(player, ClickType.SHIFT_DOWN); } - if (PassiveManager.hasPassive(player, CoreAbility.getAbility(FerroControl.class))) { - new FerroControl(player); - } else if (PassiveManager.hasPassive(player, CoreAbility.getAbility(FastSwim.class))) { - new FastSwim(player); - } - AirScooter.check(player); final CoreAbility coreAbil = bPlayer.getBoundAbility(); final String abil = bPlayer.getBoundAbilityName(); - if (coreAbil == null) { + if (coreAbil == null || !coreAbil.isSneakAbility()) { + if (PassiveManager.hasPassive(player, CoreAbility.getAbility(FerroControl.class))) { + new FerroControl(player); + } + + if (PassiveManager.hasPassive(player, CoreAbility.getAbility(FastSwim.class))) { + new FastSwim(player); + } + } + + if (coreAbil == null) { return; } @@ -1364,7 +1448,7 @@ public class PKListener implements Listener { } else if (abil.equalsIgnoreCase("AirBurst")) { new AirBurst(player, false); } else if (abil.equalsIgnoreCase("AirSuction")) { - AirSuction.setOrigin(player); + new AirSuction(player); } else if (abil.equalsIgnoreCase("AirSwipe")) { new AirSwipe(player, true); } else if (abil.equalsIgnoreCase("AirShield")) { @@ -1506,9 +1590,18 @@ public class PKListener implements Listener { } } - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onPlayerSwing(final PlayerAnimationEvent event) { + @EventHandler(priority = EventPriority.NORMAL) + public void onPlayerSwing(final PlayerInteractEvent event) { final Player player = event.getPlayer(); + if (event.getHand() != EquipmentSlot.HAND) { + return; + } + if (event.getAction() != Action.LEFT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_AIR) { + return; + } + if (event.getAction() == Action.LEFT_CLICK_BLOCK && event.isCancelled()) { + return; + } final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); if (bPlayer == null) { return; @@ -1543,11 +1636,6 @@ public class PKListener implements Listener { } else if (bPlayer.isChiBlocked()) { event.setCancelled(true); return; - } else if (GeneralMethods.isInteractable(player.getTargetBlock(new HashSet(), 5))) { - event.setCancelled(true); - return; - } else if (player.getInventory().getItemInMainHand().getType() == Material.FISHING_ROD) { - return; } BlockSource.update(player, ClickType.LEFT_CLICK); @@ -1568,7 +1656,7 @@ public class PKListener implements Listener { if (abil.equalsIgnoreCase("AirBlast")) { new AirBlast(player); } else if (abil.equalsIgnoreCase("AirSuction")) { - new AirSuction(player); + AirSuction.shoot(player); } else if (abil.equalsIgnoreCase("AirBurst")) { AirBurst.coneBurst(player); } else if (abil.equalsIgnoreCase("AirScooter")) { @@ -1589,7 +1677,11 @@ public class PKListener implements Listener { if (abil.equalsIgnoreCase("Bloodbending")) { Bloodbending.launch(player); } else if (abil.equalsIgnoreCase("IceBlast")) { - IceBlast.activate(player); + if (CoreAbility.hasAbility(player, IceBullet.class)) { + CoreAbility.getAbility(player, IceBullet.class).doLeftClick(); + } else { + IceBlast.activate(player); + } } else if (abil.equalsIgnoreCase("IceSpike")) { IceSpikeBlast.activate(player); } else if (abil.equalsIgnoreCase("OctopusForm")) { @@ -1754,6 +1846,11 @@ public class PKListener implements Listener { return; } } + if (ConfigManager.getConfig().getBoolean("Abilities.Fire.FireJet.ShowGliding")) { + if (CoreAbility.getAbility(player, FireJet.class) != null) { + event.setCancelled(true); + } + } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @@ -1771,6 +1868,53 @@ public class PKListener implements Listener { } } + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onPickupItem(final EntityPickupItemEvent event) { + for (final MetalClips metalClips : CoreAbility.getAbilities(MetalClips.class)) { + if (metalClips.getTrackedIngots().contains(event.getItem())) { + event.setCancelled(true); + } + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onInventoryPickupItem(final InventoryPickupItemEvent event) { + for (final MetalClips metalClips : CoreAbility.getAbilities(MetalClips.class)) { + if (metalClips.getTrackedIngots().contains(event.getItem())) { + event.setCancelled(true); + } + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onItemMerge(final ItemMergeEvent event) { + for (final MetalClips metalClips : CoreAbility.getAbilities(MetalClips.class)) { + if (metalClips.getTrackedIngots().contains(event.getEntity()) || metalClips.getTrackedIngots().contains(event.getTarget())) { + event.setCancelled(true); + } + } + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void onBlockPistonExtendEvent(final BlockPistonExtendEvent event) { + for (final Block b : event.getBlocks()) { + if (TempBlock.isTempBlock(b)) { + event.setCancelled(true); + break; + } + } + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void onBlockPistonRetractEvent(final BlockPistonRetractEvent event) { + for (final Block b : event.getBlocks()) { + if (TempBlock.isTempBlock(b)) { + event.setCancelled(true); + break; + } + } + } + public static HashMap getBendingPlayerDeath() { return BENDING_PLAYER_DEATH; } diff --git a/src/com/projectkorra/projectkorra/ProjectKorra.java b/src/com/projectkorra/projectkorra/ProjectKorra.java index 72f695b3..4ddfe988 100644 --- a/src/com/projectkorra/projectkorra/ProjectKorra.java +++ b/src/com/projectkorra/projectkorra/ProjectKorra.java @@ -3,13 +3,18 @@ package com.projectkorra.projectkorra; import java.util.HashMap; import java.util.logging.Logger; +import com.bekvon.bukkit.residence.protection.FlagPermissions; + +import co.aikar.timings.lib.MCTiming; +import co.aikar.timings.lib.TimingManager; + import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Statistic; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitTask; -import com.bekvon.bukkit.residence.protection.FlagPermissions; import com.projectkorra.projectkorra.ability.CoreAbility; import com.projectkorra.projectkorra.ability.util.CollisionInitializer; import com.projectkorra.projectkorra.ability.util.CollisionManager; @@ -22,10 +27,10 @@ import com.projectkorra.projectkorra.command.Commands; import com.projectkorra.projectkorra.configuration.ConfigManager; import com.projectkorra.projectkorra.earthbending.util.EarthbendingManager; import com.projectkorra.projectkorra.firebending.util.FirebendingManager; +import com.projectkorra.projectkorra.hooks.PlaceholderAPIHook; +import com.projectkorra.projectkorra.hooks.WorldGuardFlag; import com.projectkorra.projectkorra.object.Preset; import com.projectkorra.projectkorra.storage.DBConnection; -import com.projectkorra.projectkorra.util.DBCooldownManager; -import com.projectkorra.projectkorra.util.FlightHandler; import com.projectkorra.projectkorra.util.Metrics; import com.projectkorra.projectkorra.util.RevertChecker; import com.projectkorra.projectkorra.util.StatisticsManager; @@ -39,17 +44,18 @@ public class ProjectKorra extends JavaPlugin { public static Logger log; public static CollisionManager collisionManager; public static CollisionInitializer collisionInitializer; - public static StatisticsManager statistics; - public static DBCooldownManager cooldowns; - public static FlightHandler flightHandler; public static long time_step = 1; public Updater updater; + private BukkitTask revertChecker; + private static TimingManager timingManager; @Override public void onEnable() { plugin = this; ProjectKorra.log = this.getLogger(); + timingManager = TimingManager.of(this); + new ConfigManager(); new GeneralMethods(this); final boolean checkUpdateOnStartup = ConfigManager.getConfig().getBoolean("Properties.UpdateChecker"); @@ -70,9 +76,7 @@ public class ProjectKorra extends JavaPlugin { return; } - statistics = new StatisticsManager(); - cooldowns = new DBCooldownManager(); - flightHandler = new FlightHandler(); + Manager.startup(); this.getServer().getPluginManager().registerEvents(new PKListener(this), this); this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new BendingManager(), 0, 1); @@ -81,22 +85,19 @@ public class ProjectKorra extends JavaPlugin { this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new EarthbendingManager(this), 0, 1); this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new FirebendingManager(this), 0, 1); this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new ChiblockingManager(this), 0, 1); - this.getServer().getScheduler().runTaskTimerAsynchronously(this, new RevertChecker(this), 0, 200); + this.revertChecker = this.getServer().getScheduler().runTaskTimerAsynchronously(this, new RevertChecker(this), 0, 200); if (ConfigManager.languageConfig.get().getBoolean("Chat.Branding.AutoAnnouncer.Enabled")) { - this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { - @Override - public void run() { - ChatColor color = ChatColor.valueOf(ConfigManager.languageConfig.get().getString("Chat.Branding" + ".Color").toUpperCase()); - color = color == null ? ChatColor.GOLD : color; - final String topBorder = ConfigManager.languageConfig.get().getString("Chat.Branding.Borders.TopBorder"); - final String bottomBorder = ConfigManager.languageConfig.get().getString("Chat.Branding.Borders" + ".BottomBorder"); - if (!topBorder.isEmpty()) { - Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', topBorder)); - } - Bukkit.broadcastMessage(color + "This server is running ProjectKorra version " + ProjectKorra.plugin.getDescription().getVersion() + " for bending! Find out more at http://www" + ".projectkorra.com!"); - if (!bottomBorder.isEmpty()) { - Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', bottomBorder)); - } + this.getServer().getScheduler().scheduleSyncRepeatingTask(this, () -> { + ChatColor color = ChatColor.valueOf(ConfigManager.languageConfig.get().getString("Chat.Branding" + ".Color").toUpperCase()); + color = color == null ? ChatColor.GOLD : color; + final String topBorder = ConfigManager.languageConfig.get().getString("Chat.Branding.Borders.TopBorder"); + final String bottomBorder = ConfigManager.languageConfig.get().getString("Chat.Branding.Borders" + ".BottomBorder"); + if (!topBorder.isEmpty()) { + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', topBorder)); + } + Bukkit.broadcastMessage(color + "This server is running ProjectKorra version " + ProjectKorra.plugin.getDescription().getVersion() + " for bending! Find out more at http://www" + ".projectkorra.com!"); + if (!bottomBorder.isEmpty()) { + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', bottomBorder)); } }, (long) (ConfigManager.languageConfig.get().getDouble("Chat.Branding.AutoAnnouncer.Interval") * 60 * 20), (long) (ConfigManager.languageConfig.get().getDouble("Chat.Branding.AutoAnnouncer.Interval") * 60 * 20)); } @@ -107,14 +108,11 @@ public class ProjectKorra extends JavaPlugin { GeneralMethods.createBendingPlayer(player.getUniqueId(), player.getName()); GeneralMethods.removeUnusableAbilities(player.getName()); - statistics.load(player.getUniqueId()); - Bukkit.getScheduler().runTaskLater(ProjectKorra.plugin, new Runnable() { - @Override - public void run() { - PassiveManager.registerPassives(player); - GeneralMethods.removeUnusableAbilities(player.getName()); - } - }, 5); + Manager.getManager(StatisticsManager.class).load(player.getUniqueId()); + Bukkit.getScheduler().runTaskLater(ProjectKorra.plugin, (Runnable) () -> { + PassiveManager.registerPassives(player); + GeneralMethods.removeUnusableAbilities(player.getName()); + }, 30); } final Metrics metrics = new Metrics(this); @@ -149,25 +147,38 @@ public class ProjectKorra extends JavaPlugin { GeneralMethods.deserializeFile(); GeneralMethods.startCacheCleaner(cacheTime); + + if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { + new PlaceholderAPIHook(this).register(); + } } @Override public void onDisable() { + this.revertChecker.cancel(); GeneralMethods.stopBending(); for (final Player player : this.getServer().getOnlinePlayers()) { if (isStatisticsEnabled()) { - statistics.save(player.getUniqueId(), false); + Manager.getManager(StatisticsManager.class).save(player.getUniqueId(), false); } final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); - if (bPlayer != null) { + if (bPlayer != null && isDatabaseCooldownsEnabled()) { bPlayer.saveCooldowns(); } } + Manager.shutdown(); if (DBConnection.isOpen()) { DBConnection.sql.close(); } } + @Override + public void onLoad() { + if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null) { + WorldGuardFlag.registerBendingWorldGuardFlag(); + } + } + public static CollisionManager getCollisionManager() { return collisionManager; } @@ -188,4 +199,11 @@ public class ProjectKorra extends JavaPlugin { return ConfigManager.getConfig().getBoolean("Properties.Statistics"); } + public static boolean isDatabaseCooldownsEnabled() { + return ConfigManager.getConfig().getBoolean("Properties.DatabaseCooldowns"); + } + + public static MCTiming timing(final String name) { + return timingManager.of(name); + } } diff --git a/src/com/projectkorra/projectkorra/ability/AirAbility.java b/src/com/projectkorra/projectkorra/ability/AirAbility.java index 3e0ec60e..1c4b4a66 100644 --- a/src/com/projectkorra/projectkorra/ability/AirAbility.java +++ b/src/com/projectkorra/projectkorra/ability/AirAbility.java @@ -16,7 +16,6 @@ import com.projectkorra.projectkorra.ability.util.Collision; import com.projectkorra.projectkorra.airbending.AirSpout; import com.projectkorra.projectkorra.airbending.Suffocate; import com.projectkorra.projectkorra.util.ParticleEffect; -import com.projectkorra.projectkorra.util.ParticleEffect.ParticleData; public abstract class AirAbility extends ElementalAbility { @@ -43,8 +42,7 @@ public abstract class AirAbility extends ElementalAbility { public void handleCollision(final Collision collision) { super.handleCollision(collision); if (collision.isRemovingFirst()) { - final ParticleData particleData = new ParticleEffect.BlockData(Material.WOOL, (byte) 0); - ParticleEffect.BLOCK_CRACK.display(particleData, 1F, 1F, 1F, 0.1F, 10, collision.getLocationFirst(), 50); + ParticleEffect.BLOCK_CRACK.display(collision.getLocationFirst(), 10, 1, 1, 1, 0.1, Material.WHITE_WOOL.createBlockData()); } } @@ -80,7 +78,7 @@ public abstract class AirAbility extends ElementalAbility { } else if (particle.equalsIgnoreCase("spell")) { return ParticleEffect.SPELL; } else if (particle.equalsIgnoreCase("blacksmoke")) { - return ParticleEffect.SMOKE; + return ParticleEffect.SMOKE_NORMAL; } else if (particle.equalsIgnoreCase("smoke")) { return ParticleEffect.CLOUD; } else if (particle.equalsIgnoreCase("smallsmoke")) { @@ -113,7 +111,7 @@ public abstract class AirAbility extends ElementalAbility { * @param amount The amount of particles */ public static void playAirbendingParticles(final Location loc, final int amount) { - playAirbendingParticles(loc, amount, (float) Math.random(), (float) Math.random(), (float) Math.random()); + playAirbendingParticles(loc, amount, Math.random(), Math.random(), Math.random()); } /** @@ -126,8 +124,8 @@ public abstract class AirAbility extends ElementalAbility { * @param yOffset The yOffset to use * @param zOffset The zOffset to use */ - public static void playAirbendingParticles(final Location loc, final int amount, final float xOffset, final float yOffset, final float zOffset) { - getAirbendingParticles().display(loc, xOffset, yOffset, zOffset, 0, amount); + public static void playAirbendingParticles(final Location loc, final int amount, final double xOffset, final double yOffset, final double zOffset) { + getAirbendingParticles().display(loc, amount, xOffset, yOffset, zOffset); } /** @@ -144,11 +142,9 @@ public abstract class AirAbility extends ElementalAbility { try { sound = Sound.valueOf(getConfig().getString("Properties.Air.Sound.Sound")); - } - catch (final IllegalArgumentException exception) { + } catch (final IllegalArgumentException exception) { ProjectKorra.log.warning("Your current value for 'Properties.Air.Sound.Sound' is not valid."); - } - finally { + } finally { loc.getWorld().playSound(loc, sound, volume, pitch); } } diff --git a/src/com/projectkorra/projectkorra/ability/AvatarAbility.java b/src/com/projectkorra/projectkorra/ability/AvatarAbility.java index 112180c2..da7a25ca 100644 --- a/src/com/projectkorra/projectkorra/ability/AvatarAbility.java +++ b/src/com/projectkorra/projectkorra/ability/AvatarAbility.java @@ -37,11 +37,9 @@ public abstract class AvatarAbility extends ElementalAbility { try { sound = Sound.valueOf(getConfig().getString("Abilities.Avatar.AvatarState.Sound.Sound")); - } - catch (final IllegalArgumentException exception) { + } catch (final IllegalArgumentException exception) { ProjectKorra.log.warning("Your current value for 'Abilities.Avatar.AvatarState.Sound.Sound' is not valid."); - } - finally { + } finally { loc.getWorld().playSound(loc, sound, volume, pitch); } } diff --git a/src/com/projectkorra/projectkorra/ability/CoreAbility.java b/src/com/projectkorra/projectkorra/ability/CoreAbility.java index dc41014f..cdfb4c9e 100644 --- a/src/com/projectkorra/projectkorra/ability/CoreAbility.java +++ b/src/com/projectkorra/projectkorra/ability/CoreAbility.java @@ -3,10 +3,13 @@ package com.projectkorra.projectkorra.ability; import java.io.File; import java.io.IOException; import java.lang.reflect.Constructor; +import java.lang.reflect.Field; import java.lang.reflect.Modifier; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -17,17 +20,29 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentSkipListMap; import java.util.jar.JarFile; +import sun.reflect.ReflectionFactory; + +import org.apache.commons.lang3.Validate; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import org.apache.commons.lang3.tuple.Pair; + +import com.google.common.reflect.ClassPath; +import com.google.common.reflect.ClassPath.ClassInfo; + +import co.aikar.timings.lib.MCTiming; + import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; -import com.google.common.reflect.ClassPath; -import com.google.common.reflect.ClassPath.ClassInfo; import com.projectkorra.projectkorra.BendingPlayer; import com.projectkorra.projectkorra.Element; import com.projectkorra.projectkorra.Element.SubElement; +import com.projectkorra.projectkorra.Manager; import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ability.util.AbilityLoader; import com.projectkorra.projectkorra.ability.util.AddonAbilityLoader; @@ -37,12 +52,15 @@ import com.projectkorra.projectkorra.ability.util.ComboManager; import com.projectkorra.projectkorra.ability.util.MultiAbilityManager; import com.projectkorra.projectkorra.ability.util.MultiAbilityManager.MultiAbilityInfo; import com.projectkorra.projectkorra.ability.util.PassiveManager; +import com.projectkorra.projectkorra.attribute.Attribute; +import com.projectkorra.projectkorra.attribute.AttributeModifier; +import com.projectkorra.projectkorra.attribute.AttributePriority; import com.projectkorra.projectkorra.configuration.ConfigManager; import com.projectkorra.projectkorra.event.AbilityEndEvent; import com.projectkorra.projectkorra.event.AbilityProgressEvent; import com.projectkorra.projectkorra.event.AbilityStartEvent; - -import sun.reflect.ReflectionFactory; +import com.projectkorra.projectkorra.util.FlightHandler; +import com.projectkorra.projectkorra.util.TimeUtil; /** * CoreAbility provides default implementation of an Ability, including methods @@ -69,18 +87,23 @@ public abstract class CoreAbility implements Ability { private static final Map, CoreAbility> ABILITIES_BY_CLASS = new ConcurrentHashMap<>(); private static final double DEFAULT_COLLISION_RADIUS = 0.3; private static final List ADDON_PLUGINS = new ArrayList<>(); + private static final Map, Map> ATTRIBUTE_FIELDS = new HashMap<>(); private static int idCounter; protected Player player; protected BendingPlayer bPlayer; + protected FlightHandler flightHandler; + private final Map>>> attributeModifiers = new HashMap<>(); + private final Map attributeValues = new HashMap<>(); private boolean started; private boolean removed; private boolean hidden; private int id; private long startTime; private long startTick; + private boolean attributesModified; static { idCounter = Integer.MIN_VALUE; @@ -98,6 +121,15 @@ public abstract class CoreAbility implements Ability { * @see #getAbility(String) */ public CoreAbility() { + for (final Field field : this.getClass().getDeclaredFields()) { + if (field.isAnnotationPresent(Attribute.class)) { + final Attribute attribute = field.getAnnotation(Attribute.class); + if (!ATTRIBUTE_FIELDS.containsKey(this.getClass())) { + ATTRIBUTE_FIELDS.put(this.getClass(), new HashMap<>()); + } + ATTRIBUTE_FIELDS.get(this.getClass()).put(attribute.value(), field); + } + } } /** @@ -113,6 +145,7 @@ public abstract class CoreAbility implements Ability { this.player = player; this.bPlayer = BendingPlayer.getBendingPlayer(player); + this.flightHandler = Manager.getManager(FlightHandler.class); this.startTime = System.currentTimeMillis(); this.started = false; this.id = CoreAbility.idCounter; @@ -145,6 +178,7 @@ public abstract class CoreAbility implements Ability { this.remove(); return; } + this.started = true; this.startTime = System.currentTimeMillis(); final Class clazz = this.getClass(); @@ -231,16 +265,28 @@ public abstract class CoreAbility implements Ability { } try { - abil.progress(); + if (!abil.attributesModified) { + abil.modifyAttributes(); + abil.attributesModified = true; + } + + try (MCTiming timing = ProjectKorra.timing(abil.getName()).startTiming()) { + abil.progress(); + } + Bukkit.getServer().getPluginManager().callEvent(new AbilityProgressEvent(abil)); - } - catch (final Exception e) { + } catch (final Exception e) { e.printStackTrace(); + Bukkit.getLogger().severe(abil.toString()); + try { + abil.getPlayer().sendMessage(ChatColor.YELLOW + "[" + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()) + "] " + ChatColor.RED + "There was an error running " + abil.getName() + ". please notify the server owner describing exactly what you were doing at this moment"); + } catch (final Exception me) { + Bukkit.getLogger().severe("unable to notify ability user of error"); + } try { abil.remove(); - } - catch (final Exception re) { - re.printStackTrace(); + } catch (final Exception re) { + Bukkit.getLogger().severe("unable to fully remove ability of above error"); } } } @@ -309,7 +355,7 @@ public abstract class CoreAbility implements Ability { * Returns a "fake" instance for a CoreAbility with the specific class. * * @param clazz the class for the type of CoreAbility to be returned - * @return a "fake" CoreAbility instance or null + * @return a "fake" CoreAbility instance or null if the ability doesn't exist or isn't enabled */ public static CoreAbility getAbility(final Class clazz) { return clazz != null ? ABILITIES_BY_CLASS.get(clazz) : null; @@ -546,16 +592,13 @@ public abstract class CoreAbility implements Ability { final AddonAbility addon = (AddonAbility) ability; addon.load(); } - } - catch (final Exception e) { + } catch (final Exception e) { e.printStackTrace(); - } - catch (final Error e) { + } catch (final Error e) { e.printStackTrace(); } } - } - catch (final IOException e) { + } catch (final IOException e) { e.printStackTrace(); } } @@ -609,15 +652,14 @@ public abstract class CoreAbility implements Ability { } if (coreAbil instanceof PassiveAbility) { + PassiveAbility passive = (PassiveAbility) coreAbil; coreAbil.setHiddenAbility(true); PassiveManager.getPassives().put(name, coreAbil); - if (!PassiveManager.getPassiveClasses().containsKey(coreAbil)) { - PassiveManager.getPassiveClasses().put((PassiveAbility) coreAbil, coreAbil.getClass()); + if (!PassiveManager.getPassiveClasses().containsKey(passive)) { + PassiveManager.getPassiveClasses().put(passive, coreAbil.getClass()); } - PassiveManager.getPassiveClasses().put((PassiveAbility) coreAbil, coreAbil.getClass()); } - } - catch (Exception | Error e) { + } catch (Exception | Error e) { plugin.getLogger().warning("The ability " + coreAbil.getName() + " was not able to load, if this message shows again please remove it!"); e.printStackTrace(); ABILITIES_BY_NAME.remove(name.toLowerCase()); @@ -678,14 +720,14 @@ public abstract class CoreAbility implements Ability { } if (coreAbil instanceof PassiveAbility) { + PassiveAbility passive = (PassiveAbility) coreAbil; coreAbil.setHiddenAbility(true); PassiveManager.getPassives().put(name, coreAbil); - if (!PassiveManager.getPassiveClasses().containsKey(coreAbil)) { - PassiveManager.getPassiveClasses().put((PassiveAbility) coreAbil, coreAbil.getClass()); + if (!PassiveManager.getPassiveClasses().containsKey(passive)) { + PassiveManager.getPassiveClasses().put(passive, coreAbil.getClass()); } } - } - catch (Exception | Error e) { + } catch (Exception | Error e) { plugin.getLogger().warning("The ability " + coreAbil.getName() + " was not able to load, if this message shows again please remove it!"); e.printStackTrace(); addon.stop(); @@ -766,6 +808,9 @@ public abstract class CoreAbility implements Ability { if (this.getElement() instanceof SubElement) { elementName = ((SubElement) this.getElement()).getParentElement().getName(); } + if (this instanceof ComboAbility) { + elementName = elementName + ".Combo"; + } return ConfigManager.languageConfig.get().contains("Abilities." + elementName + "." + this.getName() + ".Instructions") ? ConfigManager.languageConfig.get().getString("Abilities." + elementName + "." + this.getName() + ".Instructions") : ""; } @@ -783,6 +828,22 @@ public abstract class CoreAbility implements Ability { return ConfigManager.languageConfig.get().getString("Abilities." + elementName + "." + this.getName() + ".Description"); } + public String getMovePreview(final Player player) { + final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); + String displayedMessage = ""; + if (bPlayer.isOnCooldown(this)) { + final long cooldown = bPlayer.getCooldown(this.getName()) - System.currentTimeMillis(); + displayedMessage = this.getElement().getColor() + "" + ChatColor.STRIKETHROUGH + this.getName() + "" + this.getElement().getColor() + " - " + TimeUtil.formatTime(cooldown); + } else { + if (bPlayer.getStance() != null && bPlayer.getStance().getName().equals(this.getName())) { + displayedMessage = this.getElement().getColor() + "" + ChatColor.UNDERLINE + this.getName(); + } else { + displayedMessage = this.getElement().getColor() + this.getName(); + } + } + return displayedMessage; + } + @Override public Player getPlayer() { return this.player; @@ -908,6 +969,71 @@ public abstract class CoreAbility implements Ability { return locations; } + public CoreAbility addAttributeModifier(final String attribute, final Number value, final AttributeModifier modification) { + return this.addAttributeModifier(attribute, value, modification, AttributePriority.MEDIUM); + } + + public CoreAbility addAttributeModifier(final String attribute, final Number value, final AttributeModifier modificationType, final AttributePriority priority) { + Validate.notNull(attribute, "attribute cannot be null"); + Validate.notNull(value, "value cannot be null"); + Validate.notNull(modificationType, "modifierMethod cannot be null"); + Validate.notNull(priority, "priority cannot be null"); + Validate.isTrue(ATTRIBUTE_FIELDS.containsKey(this.getClass()) && ATTRIBUTE_FIELDS.get(this.getClass()).containsKey(attribute), "Attribute " + attribute + " is not a defined Attribute for " + this.getName()); + if (!this.attributeModifiers.containsKey(attribute)) { + this.attributeModifiers.put(attribute, new HashMap<>()); + } + if (!this.attributeModifiers.get(attribute).containsKey(priority)) { + this.attributeModifiers.get(attribute).put(priority, new HashSet<>()); + } + this.attributeModifiers.get(attribute).get(priority).add(Pair.of(value, modificationType)); + return this; + } + + public CoreAbility setAttribute(final String attribute, final Object value) { + Validate.notNull(attribute, "attribute cannot be null"); + Validate.notNull(value, "value cannot be null"); + Validate.isTrue(ATTRIBUTE_FIELDS.containsKey(this.getClass()) && ATTRIBUTE_FIELDS.get(this.getClass()).containsKey(attribute), "Attribute " + attribute + " is not a defined Attribute for " + this.getName()); + this.attributeValues.put(attribute, value); + return this; + } + + private void modifyAttributes() { + for (final String attribute : this.attributeModifiers.keySet()) { + final Field field = ATTRIBUTE_FIELDS.get(this.getClass()).get(attribute); + final boolean accessibility = field.isAccessible(); + field.setAccessible(true); + try { + for (final AttributePriority priority : AttributePriority.values()) { + if (this.attributeModifiers.get(attribute).containsKey(priority)) { + for (final Pair pair : this.attributeModifiers.get(attribute).get(priority)) { + final Object get = field.get(this); + Validate.isTrue(get instanceof Number, "The field " + field.getName() + " cannot algebraically be modified."); + final Number oldValue = (Number) field.get(this); + final Number newValue = pair.getRight().performModification(oldValue, pair.getLeft()); + field.set(this, newValue); + } + } + } + } catch (IllegalArgumentException | IllegalAccessException e) { + e.printStackTrace(); + } finally { + field.setAccessible(accessibility); + } + } + this.attributeValues.forEach((attribute, value) -> { + final Field field = ATTRIBUTE_FIELDS.get(this.getClass()).get(attribute); + final boolean accessibility = field.isAccessible(); + field.setAccessible(true); + try { + field.set(this, value); + } catch (IllegalArgumentException | IllegalAccessException e) { + e.printStackTrace(); + } finally { + field.setAccessible(accessibility); + } + }); + } + /** * @return the current FileConfiguration for the plugin */ @@ -969,4 +1095,9 @@ public abstract class CoreAbility implements Ability { return DEFAULT_COLLISION_RADIUS; } + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); + } + } diff --git a/src/com/projectkorra/projectkorra/ability/EarthAbility.java b/src/com/projectkorra/projectkorra/ability/EarthAbility.java index 484b9b26..200bc1c2 100644 --- a/src/com/projectkorra/projectkorra/ability/EarthAbility.java +++ b/src/com/projectkorra/projectkorra/ability/EarthAbility.java @@ -11,6 +11,8 @@ import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Levelled; import org.bukkit.entity.Entity; import org.bukkit.entity.FallingBlock; import org.bukkit.entity.LivingEntity; @@ -26,11 +28,9 @@ import com.projectkorra.projectkorra.configuration.ConfigManager; import com.projectkorra.projectkorra.earthbending.RaiseEarth; import com.projectkorra.projectkorra.earthbending.lava.LavaFlow; import com.projectkorra.projectkorra.earthbending.passive.DensityShift; -import com.projectkorra.projectkorra.firebending.Illumination; import com.projectkorra.projectkorra.util.BlockSource; import com.projectkorra.projectkorra.util.Information; import com.projectkorra.projectkorra.util.ParticleEffect; -import com.projectkorra.projectkorra.util.ParticleEffect.ParticleData; import com.projectkorra.projectkorra.util.TempBlock; public abstract class EarthAbility extends ElementalAbility { @@ -87,8 +87,7 @@ public abstract class EarthAbility extends ElementalAbility { public void handleCollision(final Collision collision) { super.handleCollision(collision); if (collision.isRemovingFirst()) { - final ParticleData particleData = new ParticleEffect.BlockData(Material.DIRT, (byte) 0); - ParticleEffect.BLOCK_CRACK.display(particleData, 1F, 1F, 1F, 0.1F, 10, collision.getLocationFirst(), 50); + ParticleEffect.BLOCK_CRACK.display(collision.getLocationFirst(), 10, 1, 1, 1, 0.1, Material.DIRT.createBlockData()); } } @@ -124,12 +123,12 @@ public abstract class EarthAbility extends ElementalAbility { return isSandbendable(this.player, material); } - public void moveEarth(final Block block, final Vector direction, final int chainlength) { - this.moveEarth(block, direction, chainlength, true); + public boolean moveEarth(final Block block, final Vector direction, final int chainlength) { + return this.moveEarth(block, direction, chainlength, true); } public boolean moveEarth(Block block, final Vector direction, final int chainlength, final boolean throwplayer) { - if (this.isEarthbendable(block) && !GeneralMethods.isRegionProtectedFromBuild(this, block.getLocation())) { + if (!TempBlock.isTempBlock(block) && this.isEarthbendable(block) && !GeneralMethods.isRegionProtectedFromBuild(this, block.getLocation())) { boolean up = false; boolean down = false; final Vector norm = direction.clone().normalize(); @@ -155,9 +154,12 @@ public abstract class EarthAbility extends ElementalAbility { if (DensityShift.isPassiveSand(block)) { DensityShift.revertSand(block); } - if (Illumination.isIlluminationTorch(affectedblock) && TempBlock.isTempBlock(affectedblock)) { + if (TempBlock.isTempBlock(affectedblock)) { TempBlock.get(affectedblock).revertBlock(); } + if (LavaFlow.isLavaFlowBlock(block)) { + LavaFlow.removeBlock(block); + } if (affectedblock == null) { return false; @@ -182,9 +184,9 @@ public abstract class EarthAbility extends ElementalAbility { } if (up) { final Block topblock = affectedblock.getRelative(BlockFace.UP); - if (topblock.getType() != Material.AIR) { + if (!isAir(topblock.getType())) { GeneralMethods.breakBlock(affectedblock); - } else if (!affectedblock.isLiquid() && affectedblock.getType() != Material.AIR) { + } else if (!affectedblock.isLiquid() && !isAir(affectedblock.getType())) { moveEarthBlock(affectedblock, topblock); } } else { @@ -198,7 +200,7 @@ public abstract class EarthAbility extends ElementalAbility { affectedblock = location.clone().add(negnorm.getX() * i, negnorm.getY() * i, negnorm.getZ() * i).getBlock(); if (!this.isEarthbendable(affectedblock)) { if (down) { - if (this.isTransparent(affectedblock) && !affectedblock.isLiquid() && affectedblock.getType() != Material.AIR) { + if (this.isTransparent(affectedblock) && !affectedblock.isLiquid() && !isAir(affectedblock.getType())) { moveEarthBlock(affectedblock, block); } } @@ -221,7 +223,7 @@ public abstract class EarthAbility extends ElementalAbility { affectedblock = location.clone().add(negnorm.getX() * i, negnorm.getY() * i, negnorm.getZ() * i).getBlock(); if (!this.isEarthbendable(affectedblock)) { if (down) { - if (this.isTransparent(affectedblock) && !affectedblock.isLiquid()) { + if (this.isTransparent(affectedblock) && !affectedblock.isLiquid() && !isAir(affectedblock.getType())) { moveEarthBlock(affectedblock, block); } } @@ -265,28 +267,22 @@ public abstract class EarthAbility extends ElementalAbility { info.setBlock(block); info.setState(block.getState()); - info.setData(block.getData()); } - block.setType(Material.AIR); + block.setType(Material.AIR, false); info.setTime(System.currentTimeMillis()); TEMP_AIR_LOCATIONS.put(info.getID(), info); } - public static void displaySandParticle(final Location loc, final float xOffset, final float yOffset, final float zOffset, final float amount, final float speed, final boolean red) { + public static void displaySandParticle(final Location loc, final int amount, final double xOffset, final double yOffset, final double zOffset, final double speed, final boolean red) { if (amount <= 0) { return; } - for (int x = 0; x < amount; x++) { - if (!red) { - ParticleEffect.ITEM_CRACK.display(new ParticleEffect.ItemData(Material.SAND, (byte) 0), new Vector(((Math.random() - 0.5) * xOffset), ((Math.random() - 0.5) * yOffset), ((Math.random() - 0.5) * zOffset)), speed, loc, 255.0); - ParticleEffect.ITEM_CRACK.display(new ParticleEffect.ItemData(Material.SANDSTONE, (byte) 0), new Vector(((Math.random() - 0.5) * xOffset), ((Math.random() - 0.5) * yOffset), ((Math.random() - 0.5) * zOffset)), speed, loc, 255.0); - } else if (red) { - ParticleEffect.ITEM_CRACK.display(new ParticleEffect.ItemData(Material.SAND, (byte) 1), new Vector(((Math.random() - 0.5) * xOffset), ((Math.random() - 0.5) * yOffset), ((Math.random() - 0.5) * zOffset)), speed, loc, 255.0); - ParticleEffect.ITEM_CRACK.display(new ParticleEffect.ItemData(Material.RED_SANDSTONE, (byte) 0), new Vector(((Math.random() - 0.5) * xOffset), ((Math.random() - 0.5) * yOffset), ((Math.random() - 0.5) * zOffset)), speed, loc, 255.0); - } + final Material sand = red ? Material.RED_SAND : Material.SAND; + final Material stone = red ? Material.RED_SANDSTONE : Material.SANDSTONE; - } + ParticleEffect.BLOCK_CRACK.display(loc, amount, xOffset, yOffset, zOffset, speed, sand.createBlockData()); + ParticleEffect.BLOCK_CRACK.display(loc, amount, xOffset, yOffset, zOffset, speed, stone.createBlockData()); } /** @@ -346,13 +342,6 @@ public abstract class EarthAbility extends ElementalAbility { continue; } if (isLavabendable(player, block)) { - if (TempBlock.isTempBlock(block)) { - final TempBlock tb = TempBlock.get(block); - final byte full = 0x0; - if (tb.getState().getRawData() != full && !isLava(tb.getState().getType())) { - continue; - } - } return block; } } @@ -436,14 +425,7 @@ public abstract class EarthAbility extends ElementalAbility { } public static boolean isLavabendable(final Player player, final Block block) { - final byte full = 0x0; - if (TempBlock.isTempBlock(block)) { - final TempBlock tblock = TempBlock.instances.get(block); - if (tblock == null || !LavaFlow.getTempLavaBlocks().values().contains(tblock)) { - return false; - } - } - if (isLava(block) && block.getData() == full) { + if (isLava(block) && (block.getBlockData() instanceof Levelled && ((Levelled) block.getBlockData()).getLevel() == 0)) { return true; } return false; @@ -475,19 +457,18 @@ public abstract class EarthAbility extends ElementalAbility { MOVED_EARTH.put(target, info); if (info.getState().getType() == Material.SAND) { - if (info.getState().getRawData() == (byte) 0x1) { - target.setType(Material.RED_SANDSTONE); - } else { - target.setType(Material.SANDSTONE); - } + target.setType(Material.SANDSTONE, false); + } else if (info.getState().getType() == Material.RED_SAND) { + target.setType(Material.RED_SANDSTONE, false); } else if (info.getState().getType() == Material.GRAVEL) { - target.setType(Material.STONE); + target.setType(Material.STONE, false); + } else if (info.getState().getType().name().endsWith("CONCRETE_POWDER")) { + target.setType(Material.getMaterial(info.getState().getType().name().replace("_POWDER", "")), false); } else { - target.setType(info.getState().getType()); - target.setData(info.getState().getRawData()); + target.setBlockData(info.getState().getBlockData(), false); } - source.setType(Material.AIR); + source.setType(Material.AIR, false); } public static void playEarthbendingSound(final Location loc) { @@ -499,11 +480,9 @@ public abstract class EarthAbility extends ElementalAbility { try { sound = Sound.valueOf(getConfig().getString("Properties.Earth.EarthSound.Sound")); - } - catch (final IllegalArgumentException exception) { + } catch (final IllegalArgumentException exception) { ProjectKorra.log.warning("Your current value for 'Properties.Earth.EarthSound.Sound' is not valid."); - } - finally { + } finally { loc.getWorld().playSound(loc, sound, volume, pitch); } } @@ -514,15 +493,13 @@ public abstract class EarthAbility extends ElementalAbility { final float volume = (float) getConfig().getDouble("Properties.Earth.MetalSound.Volume"); final float pitch = (float) getConfig().getDouble("Properties.Earth.MetalSound.Pitch"); - Sound sound = Sound.ENTITY_IRONGOLEM_HURT; + Sound sound = Sound.ENTITY_IRON_GOLEM_HURT; try { sound = Sound.valueOf(getConfig().getString("Properties.Earth.MetalSound.Sound")); - } - catch (final IllegalArgumentException exception) { + } catch (final IllegalArgumentException exception) { ProjectKorra.log.warning("Your current value for 'Properties.Earth.MetalSound.Sound' is not valid."); - } - finally { + } finally { loc.getWorld().playSound(loc, sound, volume, pitch); } } @@ -537,11 +514,9 @@ public abstract class EarthAbility extends ElementalAbility { try { sound = Sound.valueOf(getConfig().getString("Properties.Earth.SandSound.Sound")); - } - catch (final IllegalArgumentException exception) { + } catch (final IllegalArgumentException exception) { ProjectKorra.log.warning("Your current value for 'Properties.Earth.SandSound.Sound' is not valid."); - } - finally { + } finally { loc.getWorld().playSound(loc, sound, volume, pitch); } } @@ -556,11 +531,9 @@ public abstract class EarthAbility extends ElementalAbility { try { sound = Sound.valueOf(getConfig().getString("Properties.Earth.LavaSound.Sound")); - } - catch (final IllegalArgumentException exception) { + } catch (final IllegalArgumentException exception) { ProjectKorra.log.warning("Your current value for 'Properties.Earth.LavaSound.Sound' is not valid."); - } - finally { + } finally { loc.getWorld().playSound(loc, sound, volume, pitch); } } @@ -579,7 +552,7 @@ public abstract class EarthAbility extends ElementalAbility { if (MOVED_EARTH.containsKey(block)) { final Information info = MOVED_EARTH.get(block); if (block.getType() == Material.SANDSTONE && info.getType() == Material.SAND) { - block.setType(Material.SAND); + block.setType(Material.SAND, false); } if (RaiseEarth.blockInAllAffectedBlocks(block)) { EarthAbility.revertBlock(block); @@ -601,7 +574,7 @@ public abstract class EarthAbility extends ElementalAbility { final Information info = TEMP_AIR_LOCATIONS.get(i); final Block block = info.getState().getBlock(); - if (block.getType() != Material.AIR && !block.isLiquid()) { + if (!ElementalAbility.isAir(block.getType()) && !block.isLiquid()) { if (force || !MOVED_EARTH.containsKey(block)) { TEMP_AIR_LOCATIONS.remove(i); } else { @@ -609,13 +582,12 @@ public abstract class EarthAbility extends ElementalAbility { } return; } else { - info.getState().update(true); + info.getState().update(true, false); TEMP_AIR_LOCATIONS.remove(i); } } public static boolean revertBlock(final Block block) { - final byte full = 0x0; if (!isEarthRevertOn()) { MOVED_EARTH.remove(block); return false; @@ -624,18 +596,18 @@ public abstract class EarthAbility extends ElementalAbility { final Information info = MOVED_EARTH.get(block); final Block sourceblock = info.getState().getBlock(); - if (info.getState().getType() == Material.AIR) { + if (ElementalAbility.isAir(info.getState().getType())) { MOVED_EARTH.remove(block); return true; } if (block.equals(sourceblock)) { - info.getState().update(true); + info.getState().update(true, false); if (RaiseEarth.blockInAllAffectedBlocks(sourceblock)) { - EarthAbility.revertBlock(sourceblock); + RaiseEarth.revertAffectedBlock(sourceblock); } if (RaiseEarth.blockInAllAffectedBlocks(block)) { - EarthAbility.revertBlock(block); + RaiseEarth.revertAffectedBlock(block); } MOVED_EARTH.remove(block); return true; @@ -647,24 +619,27 @@ public abstract class EarthAbility extends ElementalAbility { return true; } - if (sourceblock.getType() == Material.AIR || sourceblock.isLiquid()) { - info.getState().update(true); + if (ElementalAbility.isAir(sourceblock.getType()) || sourceblock.isLiquid()) { + info.getState().update(true, false); } else { } - if (GeneralMethods.isAdjacentToThreeOrMoreSources(block)) { - block.setType(Material.WATER); - block.setData(full); + if (GeneralMethods.isAdjacentToThreeOrMoreSources(block, false)) { + final BlockData data = Material.WATER.createBlockData(); + if (data instanceof Levelled) { + ((Levelled) data).setLevel(7); + } + block.setBlockData(data, false); } else { - block.setType(Material.AIR); + block.setType(Material.AIR, false); } if (RaiseEarth.blockInAllAffectedBlocks(sourceblock)) { - EarthAbility.revertBlock(sourceblock); + RaiseEarth.revertAffectedBlock(sourceblock); } if (RaiseEarth.blockInAllAffectedBlocks(block)) { - EarthAbility.revertBlock(block); + RaiseEarth.revertAffectedBlock(block); } MOVED_EARTH.remove(block); } diff --git a/src/com/projectkorra/projectkorra/ability/ElementalAbility.java b/src/com/projectkorra/projectkorra/ability/ElementalAbility.java index 16566233..b5146f40 100644 --- a/src/com/projectkorra/projectkorra/ability/ElementalAbility.java +++ b/src/com/projectkorra/projectkorra/ability/ElementalAbility.java @@ -3,18 +3,18 @@ package com.projectkorra.projectkorra.ability; import java.util.Arrays; import java.util.HashSet; import java.util.List; +import java.util.Set; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.World.Environment; import org.bukkit.block.Block; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Waterlogged; import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffectType; import com.projectkorra.projectkorra.GeneralMethods; -import com.projectkorra.rpg.event.EventManager; /** * ElementalAbility is used to hold methods that should be accessible by every @@ -25,6 +25,16 @@ public abstract class ElementalAbility extends CoreAbility { private static final PotionEffectType[] POSITIVE_EFFECTS = { PotionEffectType.ABSORPTION, PotionEffectType.DAMAGE_RESISTANCE, PotionEffectType.FAST_DIGGING, PotionEffectType.FIRE_RESISTANCE, PotionEffectType.HEAL, PotionEffectType.HEALTH_BOOST, PotionEffectType.INCREASE_DAMAGE, PotionEffectType.JUMP, PotionEffectType.NIGHT_VISION, PotionEffectType.REGENERATION, PotionEffectType.SATURATION, PotionEffectType.SPEED, PotionEffectType.WATER_BREATHING }; private static final PotionEffectType[] NEUTRAL_EFFECTS = { PotionEffectType.INVISIBILITY }; private static final PotionEffectType[] NEGATIVE_EFFECTS = { PotionEffectType.POISON, PotionEffectType.BLINDNESS, PotionEffectType.CONFUSION, PotionEffectType.HARM, PotionEffectType.HUNGER, PotionEffectType.SLOW, PotionEffectType.SLOW_DIGGING, PotionEffectType.WEAKNESS, PotionEffectType.WITHER }; + private static final Set TRANSPARENT = new HashSet<>(); + + static { + TRANSPARENT.clear(); + for (final Material mat : Material.values()) { + if (GeneralMethods.isTransparent(mat)) { + TRANSPARENT.add(mat); + } + } + } public ElementalAbility(final Player player) { super(player); @@ -39,16 +49,15 @@ public abstract class ElementalAbility extends CoreAbility { } public static Material[] getTransparentMaterials() { - return GeneralMethods.NON_OPAQUE; + return TRANSPARENT.toArray(new Material[TRANSPARENT.size()]); } public static HashSet getTransparentMaterialSet() { - final HashSet set = new HashSet(); - for (final Material material : getTransparentMaterials()) { - set.add(material); - } + return new HashSet<>(TRANSPARENT); + } - return set; + public static boolean isAir(final Material material) { + return material == Material.AIR || material == Material.CAVE_AIR || material == Material.VOID_AIR; } public static boolean isDay(final World world) { @@ -73,19 +82,10 @@ public abstract class ElementalAbility extends CoreAbility { } public static boolean isFullMoon(final World world) { - if (GeneralMethods.hasRPG()) { - final String event = EventManager.marker.get(world); - return event != null && event.equalsIgnoreCase("FullMoon"); - } else { - final long days = world.getFullTime() / 24000; - final long phase = days % 8; + final double days = Math.ceil(world.getFullTime() / 24000) + 1; + final double phase = days % 8; - if (phase == 0) { - return true; - } - - return false; - } + return phase == 0; } public static boolean isIce(final Block block) { @@ -101,7 +101,7 @@ public abstract class ElementalAbility extends CoreAbility { } public static boolean isLava(final Material material) { - return material == Material.LAVA || material == Material.STATIONARY_LAVA; + return material == Material.LAVA; } public static boolean isSnow(final Block block) { @@ -112,26 +112,8 @@ public abstract class ElementalAbility extends CoreAbility { return getConfig().getStringList("Properties.Water.SnowBlocks").contains(material.toString()); } - public static boolean isLunarEclipse(final World world) { - if (world == null || !GeneralMethods.hasRPG()) { - return false; - } - - final String event = EventManager.marker.get(world); - return event != null && event.equalsIgnoreCase("LunarEclipse"); - } - - public static boolean isSolarEclipse(final World world) { - if (world == null || !GeneralMethods.hasRPG() || !EventManager.marker.containsKey(world)) { - return false; - } - - final String event = EventManager.marker.get(world); - return event != null && event.equalsIgnoreCase("SolarEclipse"); - } - public static boolean isMeltable(final Block block) { - if (block.getType() == Material.ICE || block.getType() == Material.SNOW) { + if (isIce(block) || isSnow(block)) { return true; } @@ -147,7 +129,7 @@ public abstract class ElementalAbility extends CoreAbility { } public static boolean isMetalBlock(final Block block) { - if (block.getType() == Material.GOLD_BLOCK || block.getType() == Material.IRON_BLOCK || block.getType() == Material.IRON_ORE || block.getType() == Material.GOLD_ORE || block.getType() == Material.QUARTZ_BLOCK || block.getType() == Material.QUARTZ_ORE) { + if (block.getType() == Material.GOLD_BLOCK || block.getType() == Material.IRON_BLOCK || block.getType() == Material.IRON_ORE || block.getType() == Material.GOLD_ORE || block.getType() == Material.QUARTZ_BLOCK || block.getType() == Material.NETHER_QUARTZ_ORE) { return true; } @@ -214,15 +196,6 @@ public abstract class ElementalAbility extends CoreAbility { return getConfig().getStringList("Properties.Earth.SandBlocks").contains(material.toString()); } - public static boolean isSozinsComet(final World world) { - if (world == null || !GeneralMethods.hasRPG()) { - return false; - } - - final String event = EventManager.marker.get(world); - return event != null && event.equalsIgnoreCase("SozinsComet"); - } - public static boolean isTransparent(final Player player, final Block block) { return isTransparent(player, null, block); } @@ -231,22 +204,22 @@ public abstract class ElementalAbility extends CoreAbility { return Arrays.asList(getTransparentMaterials()).contains(block.getType()) && !GeneralMethods.isRegionProtectedFromBuild(player, abilityName, block.getLocation()); } - public static boolean isUndead(final Entity entity) { - if (entity == null) { + public static boolean isWater(final Block block) { + if (block == null) { return false; - } else if (entity.getType() == EntityType.ZOMBIE || entity.getType() == EntityType.BLAZE || entity.getType() == EntityType.GIANT || entity.getType() == EntityType.IRON_GOLEM || entity.getType() == EntityType.MAGMA_CUBE || entity.getType() == EntityType.PIG_ZOMBIE || entity.getType() == EntityType.SKELETON || entity.getType() == EntityType.SLIME || entity.getType() == EntityType.SNOWMAN || entity.getType() == EntityType.ZOMBIE) { + } else if (isWater(block.getType())) { return true; + } else { + return isWater(block.getBlockData()); } - - return false; } - public static boolean isWater(final Block block) { - return block != null ? isWater(block.getType()) : null; + public static boolean isWater(final BlockData data) { + return (data instanceof Waterlogged) ? ((Waterlogged) data).isWaterlogged() : isWater(data.getMaterial()); } public static boolean isWater(final Material material) { - return material == Material.WATER || material == Material.STATIONARY_WATER; + return material == Material.WATER || material == Material.SEAGRASS || material == Material.TALL_SEAGRASS || material == Material.KELP_PLANT || material == Material.KELP || material == Material.BUBBLE_COLUMN; } } diff --git a/src/com/projectkorra/projectkorra/ability/FireAbility.java b/src/com/projectkorra/projectkorra/ability/FireAbility.java index 3ce6708c..6b5f1ab4 100644 --- a/src/com/projectkorra/projectkorra/ability/FireAbility.java +++ b/src/com/projectkorra/projectkorra/ability/FireAbility.java @@ -1,7 +1,6 @@ package com.projectkorra.projectkorra.ability; import java.util.ArrayList; -import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -25,13 +24,10 @@ import com.projectkorra.projectkorra.configuration.ConfigManager; import com.projectkorra.projectkorra.firebending.BlazeArc; import com.projectkorra.projectkorra.util.Information; import com.projectkorra.projectkorra.util.ParticleEffect; -import com.projectkorra.projectkorra.util.ParticleEffect.ParticleData; -import com.projectkorra.rpg.RPGMethods; public abstract class FireAbility extends ElementalAbility { private static final Map TEMP_FIRE = new ConcurrentHashMap(); - private static final Material[] IGNITABLE_MATERIALS = { Material.BEDROCK, Material.BOOKSHELF, Material.BRICK, Material.CLAY, Material.CLAY_BRICK, Material.COAL_ORE, Material.COBBLESTONE, Material.DIAMOND_ORE, Material.DIAMOND_BLOCK, Material.DIRT, Material.ENDER_STONE, Material.GLOWING_REDSTONE_ORE, Material.GOLD_BLOCK, Material.GRAVEL, Material.GRASS, Material.HUGE_MUSHROOM_1, Material.HUGE_MUSHROOM_2, Material.LAPIS_BLOCK, Material.LAPIS_ORE, Material.LOG, Material.MOSSY_COBBLESTONE, Material.MYCEL, Material.NETHER_BRICK, Material.NETHERRACK, Material.OBSIDIAN, Material.REDSTONE_ORE, Material.SAND, Material.SANDSTONE, Material.SMOOTH_BRICK, Material.STONE, Material.SOUL_SAND, Material.WOOD, Material.WOOL, Material.LEAVES, Material.LEAVES_2, Material.MELON_BLOCK, Material.PUMPKIN, Material.JACK_O_LANTERN, Material.NOTE_BLOCK, Material.GLOWSTONE, Material.IRON_BLOCK, Material.DISPENSER, Material.SPONGE, Material.IRON_ORE, Material.GOLD_ORE, Material.COAL_BLOCK, Material.WORKBENCH, Material.HAY_BLOCK, Material.REDSTONE_LAMP_OFF, Material.REDSTONE_LAMP_ON, Material.EMERALD_ORE, Material.EMERALD_BLOCK, Material.REDSTONE_BLOCK, Material.QUARTZ_BLOCK, Material.QUARTZ_ORE, Material.STAINED_CLAY, Material.HARD_CLAY }; public FireAbility(final Player player) { super(player); @@ -56,15 +52,10 @@ public abstract class FireAbility extends ElementalAbility { public void handleCollision(final Collision collision) { super.handleCollision(collision); if (collision.isRemovingFirst()) { - final ParticleData particleData = new ParticleEffect.BlockData(Material.FIRE, (byte) 0); - ParticleEffect.BLOCK_CRACK.display(particleData, 1F, 1F, 1F, 0.1F, 10, collision.getLocationFirst(), 50); + ParticleEffect.BLOCK_CRACK.display(collision.getLocationFirst(), 10, 1, 1, 1, 0.1, Material.FIRE.createBlockData()); } } - public double getDayFactor(final double value) { - return this.player != null ? getDayFactor(value, this.player.getWorld()) : 1; - } - /** * Returns if fire is allowed to completely replace blocks or if it should * place a temp fire block. @@ -78,7 +69,7 @@ public abstract class FireAbility extends ElementalAbility { * fire dissipates or is destroyed. */ public static void createTempFire(final Location loc) { - if (loc.getBlock().getType() == Material.AIR) { + if (ElementalAbility.isAir(loc.getBlock().getType())) { loc.getBlock().setType(Material.FIRE); return; } @@ -96,6 +87,10 @@ public abstract class FireAbility extends ElementalAbility { TEMP_FIRE.put(loc, info); } + public double getDayFactor(final double value) { + return this.player != null ? value * getDayFactor() : 1; + } + public static double getDayFactor() { return getConfig().getDouble("Properties.Fire.DayFactor"); } @@ -113,17 +108,7 @@ public abstract class FireAbility extends ElementalAbility { */ public static double getDayFactor(final double value, final World world) { if (isDay(world)) { - if (GeneralMethods.hasRPG()) { - if (isSozinsComet(world)) { - return RPGMethods.getFactor("SozinsComet") * value; - } else if (isLunarEclipse(world)) { - return RPGMethods.getFactor("SolarEclipse") * value; - } else { - return value * getDayFactor(); - } - } else { - return value * getDayFactor(); - } + return value * getDayFactor(); } return value; } @@ -137,7 +122,7 @@ public abstract class FireAbility extends ElementalAbility { } public static boolean isIgnitable(final Material material) { - return Arrays.asList(IGNITABLE_MATERIALS).contains(material); + return material.isFlammable() || material.isBurnable(); } /** @@ -161,22 +146,20 @@ public abstract class FireAbility extends ElementalAbility { final float volume = (float) getConfig().getDouble("Properties.Fire.CombustionSound.Volume"); final float pitch = (float) getConfig().getDouble("Properties.Fire.CombustionSound.Pitch"); - Sound sound = Sound.ENTITY_FIREWORK_BLAST; + Sound sound = Sound.ENTITY_FIREWORK_ROCKET_BLAST; try { sound = Sound.valueOf(getConfig().getString("Properties.Fire.CombustionSound.Sound")); - } - catch (final IllegalArgumentException exception) { + } catch (final IllegalArgumentException exception) { ProjectKorra.log.warning("Your current value for 'Properties.Fire.CombustionSound.Sound' is not valid."); - } - finally { + } finally { loc.getWorld().playSound(loc, sound, volume, pitch); } } } - public static void playFirebendingParticles(final Location loc, final int amount, final float xOffset, final float yOffset, final float zOffset) { - ParticleEffect.FLAME.display(loc, xOffset, yOffset, zOffset, 0, amount); + public static void playFirebendingParticles(final Location loc, final int amount, final double xOffset, final double yOffset, final double zOffset) { + ParticleEffect.FLAME.display(loc, amount, xOffset, yOffset, zOffset); } public static void playFirebendingSound(final Location loc) { @@ -188,25 +171,20 @@ public abstract class FireAbility extends ElementalAbility { try { sound = Sound.valueOf(getConfig().getString("Properties.Fire.FireSound.Sound")); - } - catch (final IllegalArgumentException exception) { + } catch (final IllegalArgumentException exception) { ProjectKorra.log.warning("Your current value for 'Properties.Fire.FireSound.Sound' is not valid."); - } - finally { + } finally { loc.getWorld().playSound(loc, sound, volume, pitch); } } } public static void playLightningbendingParticle(final Location loc) { - playLightningbendingParticle(loc, (float) Math.random(), (float) Math.random(), (float) Math.random()); + playLightningbendingParticle(loc, Math.random(), Math.random(), Math.random()); } - public static void playLightningbendingParticle(final Location loc, final float xOffset, final float yOffset, final float zOffset) { - loc.setX(loc.getX() + Math.random() * (xOffset / 2 - -(xOffset / 2))); - loc.setY(loc.getY() + Math.random() * (yOffset / 2 - -(yOffset / 2))); - loc.setZ(loc.getZ() + Math.random() * (zOffset / 2 - -(zOffset / 2))); - GeneralMethods.displayColoredParticle(loc, "#01E1FF"); + public static void playLightningbendingParticle(final Location loc, final double xOffset, final double yOffset, final double zOffset) { + GeneralMethods.displayColoredParticle("#01E1FF", loc, 1, xOffset, yOffset, zOffset); } public static void playLightningbendingSound(final Location loc) { @@ -218,11 +196,9 @@ public abstract class FireAbility extends ElementalAbility { try { sound = Sound.valueOf(getConfig().getString("Properties.Fire.LightningSound.Sound")); - } - catch (final IllegalArgumentException exception) { + } catch (final IllegalArgumentException exception) { ProjectKorra.log.warning("Your current value for 'Properties.Fire.LightningSound.Sound' is not valid."); - } - finally { + } finally { loc.getWorld().playSound(loc, sound, volume, pitch); } } @@ -234,9 +210,9 @@ public abstract class FireAbility extends ElementalAbility { while (it.hasNext()) { final Location loc = it.next(); final Information info = TEMP_FIRE.get(loc); - if (info.getLocation().getBlock().getType() != Material.FIRE && info.getLocation().getBlock().getType() != Material.AIR) { + if (info.getLocation().getBlock().getType() != Material.FIRE && !ElementalAbility.isAir(info.getLocation().getBlock().getType())) { revertTempFire(loc); - } else if (info.getBlock().getType() == Material.AIR || System.currentTimeMillis() > info.getTime()) { + } else if (ElementalAbility.isAir(info.getBlock().getType()) || System.currentTimeMillis() > info.getTime()) { revertTempFire(loc); } } @@ -252,14 +228,14 @@ public abstract class FireAbility extends ElementalAbility { return; } final Information info = TEMP_FIRE.get(location); - if (info.getLocation().getBlock().getType() != Material.FIRE && info.getLocation().getBlock().getType() != Material.AIR) { - if (info.getState().getType() == Material.RED_ROSE || info.getState().getType() == Material.YELLOW_FLOWER) { - final ItemStack itemStack = new ItemStack(info.getState().getData().getItemType(), 1, info.getState().getRawData()); + if (info.getLocation().getBlock().getType() != Material.FIRE && !ElementalAbility.isAir(info.getLocation().getBlock().getType())) { + if (info.getState().getType().isBurnable() && !info.getState().getType().isOccluding()) { + final ItemStack itemStack = new ItemStack(info.getState().getType(), 1); info.getState().getBlock().getWorld().dropItemNaturally(info.getLocation(), itemStack); } } else { info.getBlock().setType(info.getState().getType()); - info.getBlock().setData(info.getState().getRawData()); + info.getBlock().setBlockData(info.getState().getBlockData()); } TEMP_FIRE.remove(location); } diff --git a/src/com/projectkorra/projectkorra/ability/PassiveAbility.java b/src/com/projectkorra/projectkorra/ability/PassiveAbility.java index 93ee299d..f664f5e5 100644 --- a/src/com/projectkorra/projectkorra/ability/PassiveAbility.java +++ b/src/com/projectkorra/projectkorra/ability/PassiveAbility.java @@ -6,14 +6,14 @@ public interface PassiveAbility { * This is a check to see if the passive requires some form of activation, * such as sneaking, clicking, etc.
* If false, the passive should not call start! - * + * * @return false if this passive should always be on */ public boolean isInstantiable(); /** * This is used if the passive should progress - * + * * @return false if progress() shouldn't be called; */ public boolean isProgressable(); diff --git a/src/com/projectkorra/projectkorra/ability/WaterAbility.java b/src/com/projectkorra/projectkorra/ability/WaterAbility.java index 6ab180bd..da332392 100644 --- a/src/com/projectkorra/projectkorra/ability/WaterAbility.java +++ b/src/com/projectkorra/projectkorra/ability/WaterAbility.java @@ -1,12 +1,16 @@ package com.projectkorra.projectkorra.ability; -import org.bukkit.Effect; +import java.util.HashSet; +import java.util.Set; + import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; +import org.bukkit.Tag; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.block.data.Levelled; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -18,14 +22,13 @@ import com.projectkorra.projectkorra.ability.util.Collision; import com.projectkorra.projectkorra.firebending.HeatControl; import com.projectkorra.projectkorra.util.BlockSource; import com.projectkorra.projectkorra.util.ParticleEffect; -import com.projectkorra.projectkorra.util.ParticleEffect.ParticleData; import com.projectkorra.projectkorra.util.TempBlock; import com.projectkorra.projectkorra.waterbending.SurgeWall; import com.projectkorra.projectkorra.waterbending.SurgeWave; +import com.projectkorra.projectkorra.waterbending.Torrent; import com.projectkorra.projectkorra.waterbending.WaterSpout; import com.projectkorra.projectkorra.waterbending.ice.PhaseChange; import com.projectkorra.projectkorra.waterbending.multiabilities.WaterArms; -import com.projectkorra.rpg.RPGMethods; public abstract class WaterAbility extends ElementalAbility { @@ -50,17 +53,6 @@ public abstract class WaterAbility extends ElementalAbility { return getIceSourceBlock(this.player, range); } - public double getNightFactor() { - if (this.getLocation() != null) { - return getNightFactor(this.getLocation().getWorld()); - } - return this.player != null ? getNightFactor(this.player.getLocation().getWorld()) : 1; - } - - public double getNightFactor(final double value) { - return this.player != null ? getNightFactor(value, this.player.getWorld()) : value; - } - public Block getPlantSourceBlock(final double range) { return this.getPlantSourceBlock(range, false); } @@ -83,17 +75,20 @@ public abstract class WaterAbility extends ElementalAbility { public void handleCollision(final Collision collision) { super.handleCollision(collision); if (collision.isRemovingFirst()) { - final ParticleData particleData = new ParticleEffect.BlockData(Material.WATER, (byte) 0); - ParticleEffect.BLOCK_CRACK.display(particleData, 1F, 1F, 1F, 0.1F, 10, collision.getLocationFirst(), 50); + ParticleEffect.BLOCK_CRACK.display(collision.getLocationFirst(), 10, 1, 1, 1, 0.1, collision.getLocationFirst().getBlock().getBlockData()); } } + public double getNightFactor(final double value) { + return this.player != null ? value * getNightFactor() : 1; + } + public static boolean isBendableWaterTempBlock(final Block block) { // TODO: Will need to be done for earth as well. return isBendableWaterTempBlock(TempBlock.get(block)); } public static boolean isBendableWaterTempBlock(final TempBlock tempBlock) { - return PhaseChange.getFrozenBlocksAsTempBlock().contains(tempBlock) || HeatControl.getMeltedBlocks().contains(tempBlock) || SurgeWall.SOURCE_BLOCKS.contains(tempBlock); + return PhaseChange.getFrozenBlocksMap().containsKey(tempBlock) || HeatControl.getMeltedBlocks().contains(tempBlock) || SurgeWall.SOURCE_BLOCKS.contains(tempBlock) || Torrent.getFrozenBlocks().containsKey(tempBlock); } public boolean isIcebendable(final Block block) { @@ -154,26 +149,16 @@ public abstract class WaterAbility extends ElementalAbility { return null; } + public static double getNightFactor() { + return getConfig().getDouble("Properties.Water.NightFactor"); + } + public static double getNightFactor(final double value, final World world) { if (isNight(world)) { - if (GeneralMethods.hasRPG()) { - if (isLunarEclipse(world)) { - return RPGMethods.getFactor("LunarEclipse") * value; - } else if (isFullMoon(world)) { - return RPGMethods.getFactor("FullMoon") * value; - } else { - return getConfig().getDouble("Properties.Water.NightFactor") * value; - } - } else { - if (isFullMoon(world)) { - return getConfig().getDouble("Properties.Water.FullMoonFactor") * value; - } else { - return getConfig().getDouble("Properties.Water.NightFactor") * value; - } - } - } else { - return value; + return value * getNightFactor(); } + + return value; } public static double getNightFactor(final World world) { @@ -214,7 +199,20 @@ public abstract class WaterAbility extends ElementalAbility { final Vector vector = location.getDirection().clone().normalize(); final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); - final Block testBlock = player.getTargetBlock(getTransparentMaterialSet(), range > 3 ? 3 : (int) range); + final Set trans = getTransparentMaterialSet(); + + if (plantbending) { + final Set remove = new HashSet<>(); + for (final Material m : trans) { + if (isPlant(m)) { + remove.add(m); + } + } + + trans.removeAll(remove); + } + + final Block testBlock = player.getTargetBlock(trans, range > 3 ? 3 : (int) range); if (bPlayer == null) { return null; } else if (isWaterbendable(player, null, testBlock) && (!isPlant(testBlock) || plantbending)) { @@ -265,7 +263,7 @@ public abstract class WaterAbility extends ElementalAbility { } public static boolean isLeaves(final Material material) { - return material == Material.LEAVES || material == Material.LEAVES_2; + return Tag.LEAVES.isTagged(material); } public static boolean isSnow(final Block block) { @@ -277,14 +275,13 @@ public abstract class WaterAbility extends ElementalAbility { } public static boolean isWaterbendable(final Player player, final String abilityName, final Block block) { - final byte full = 0x0; final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); if (bPlayer == null || !isWaterbendable(block.getType()) || GeneralMethods.isRegionProtectedFromBuild(player, abilityName, block.getLocation())) { return false; } if (TempBlock.isTempBlock(block) && !isBendableWaterTempBlock(block)) { return false; - } else if (isWater(block) && block.getData() == full) { + } else if (isWater(block) && block.getBlockData() instanceof Levelled && ((Levelled) block.getBlockData()).getLevel() == 0) { return true; } else if (isIce(block) && !bPlayer.canIcebend()) { return false; @@ -295,7 +292,7 @@ public abstract class WaterAbility extends ElementalAbility { } public static void playFocusWaterEffect(final Block block) { - block.getWorld().playEffect(block.getLocation(), Effect.SMOKE, 4, 20); + ParticleEffect.SMOKE_NORMAL.display(block.getLocation().add(0.5, 0.5, 0.5), 4); } public static void playIcebendingSound(final Location loc) { @@ -307,11 +304,9 @@ public abstract class WaterAbility extends ElementalAbility { try { sound = Sound.valueOf(getConfig().getString("Properties.Water.IceSound.Sound")); - } - catch (final IllegalArgumentException exception) { + } catch (final IllegalArgumentException exception) { ProjectKorra.log.warning("Your current value for 'Properties.Water.IceSound.Sound' is not valid."); - } - finally { + } finally { loc.getWorld().playSound(loc, sound, volume, pitch); } } @@ -326,11 +321,9 @@ public abstract class WaterAbility extends ElementalAbility { try { sound = Sound.valueOf(getConfig().getString("Properties.Water.PlantSound.Sound")); - } - catch (final IllegalArgumentException exception) { + } catch (final IllegalArgumentException exception) { ProjectKorra.log.warning("Your current value for 'Properties.Water.PlantSound.Sound' is not valid."); - } - finally { + } finally { loc.getWorld().playSound(loc, sound, volume, pitch); } } @@ -345,11 +338,9 @@ public abstract class WaterAbility extends ElementalAbility { try { sound = Sound.valueOf(getConfig().getString("Properties.Water.WaterSound.Sound")); - } - catch (final IllegalArgumentException exception) { + } catch (final IllegalArgumentException exception) { ProjectKorra.log.warning("Your current value for 'Properties.Water.WaterSound.Sound' is not valid."); - } - finally { + } finally { loc.getWorld().playSound(loc, sound, volume, pitch); } } diff --git a/src/com/projectkorra/projectkorra/ability/util/AbilityLoader.java b/src/com/projectkorra/projectkorra/ability/util/AbilityLoader.java index cea08e7d..c3752719 100644 --- a/src/com/projectkorra/projectkorra/ability/util/AbilityLoader.java +++ b/src/com/projectkorra/projectkorra/ability/util/AbilityLoader.java @@ -12,14 +12,14 @@ import java.util.List; import java.util.jar.JarEntry; import java.util.jar.JarFile; +import sun.reflect.ReflectionFactory; + import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.event.AbilityLoadEvent; -import sun.reflect.ReflectionFactory; - public class AbilityLoader { private final Plugin plugin; @@ -47,8 +47,7 @@ public class AbilityLoader { this.jar = new JarFile(new File(s)); - } - catch (final IOException e) { + } catch (final IOException e) { e.printStackTrace(); } } @@ -102,8 +101,7 @@ public class AbilityLoader { loadables.add(loadable); final AbilityLoadEvent event = new AbilityLoadEvent(this.plugin, loadable, this.jar); this.plugin.getServer().getPluginManager().callEvent(event); - } - catch (Exception | Error e) { + } catch (Exception | Error e) { continue; } } diff --git a/src/com/projectkorra/projectkorra/ability/util/AddonAbilityLoader.java b/src/com/projectkorra/projectkorra/ability/util/AddonAbilityLoader.java index cf787f3a..795b1b66 100644 --- a/src/com/projectkorra/projectkorra/ability/util/AddonAbilityLoader.java +++ b/src/com/projectkorra/projectkorra/ability/util/AddonAbilityLoader.java @@ -14,13 +14,13 @@ import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.logging.Level; +import sun.reflect.ReflectionFactory; + import org.bukkit.plugin.Plugin; import com.projectkorra.projectkorra.event.AbilityLoadEvent; import com.projectkorra.projectkorra.util.FileExtensionFilter; -import sun.reflect.ReflectionFactory; - public class AddonAbilityLoader { private final Plugin plugin; @@ -45,8 +45,7 @@ public class AddonAbilityLoader { for (final File file : this.files) { try { urls.add(file.toURI().toURL()); - } - catch (final MalformedURLException e) { + } catch (final MalformedURLException e) { e.printStackTrace(); } } @@ -79,8 +78,7 @@ public class AddonAbilityLoader { Class clazz = null; try { clazz = Class.forName(className, true, this.loader); - } - catch (Exception | Error e) { + } catch (Exception | Error e) { continue; } @@ -98,18 +96,15 @@ public class AddonAbilityLoader { this.plugin.getServer().getPluginManager().callEvent(event); } - } - catch (Exception | Error e) { + } catch (Exception | Error e) { e.printStackTrace(); this.plugin.getLogger().log(Level.WARNING, "Unknown cause"); this.plugin.getLogger().log(Level.WARNING, "The JAR file " + file.getName() + " failed to load"); - } - finally { + } finally { if (jarFile != null) { try { jarFile.close(); - } - catch (final IOException e) { + } catch (final IOException e) { e.printStackTrace(); } } diff --git a/src/com/projectkorra/projectkorra/ability/util/CollisionInitializer.java b/src/com/projectkorra/projectkorra/ability/util/CollisionInitializer.java index 0b6fb69b..b11ff4cc 100644 --- a/src/com/projectkorra/projectkorra/ability/util/CollisionInitializer.java +++ b/src/com/projectkorra/projectkorra/ability/util/CollisionInitializer.java @@ -215,9 +215,14 @@ public class CollisionInitializer { return; } this.largeAbilities.add(largeAbility); + for (final CoreAbility otherLargeAbility : this.largeAbilities) { + this.collisionManager.addCollision(new Collision(largeAbility, otherLargeAbility, true, true)); + } + for (final CoreAbility smallAbility : this.smallAbilities) { this.collisionManager.addCollision(new Collision(largeAbility, smallAbility, false, true)); } + } /** @@ -252,11 +257,9 @@ public class CollisionInitializer { } /** - * An ability that collides with other small abilities. (EarthBlast, - * FireBlast). Two colliding small abilities will remove each other. A small - * ability is removed when it collides with a large ability. + * Cancel interaction between two abilities * - * @param smallAbility the small CoreAbility + * @param ignoreAbility the small CoreAbility */ public void addIgnoreAbility(final CoreAbility ignoreAbility) { if (ignoreAbility == null) { diff --git a/src/com/projectkorra/projectkorra/ability/util/ComboManager.java b/src/com/projectkorra/projectkorra/ability/util/ComboManager.java index 5221078c..94ce54ff 100644 --- a/src/com/projectkorra/projectkorra/ability/util/ComboManager.java +++ b/src/com/projectkorra/projectkorra/ability/util/ComboManager.java @@ -19,8 +19,6 @@ import com.projectkorra.projectkorra.configuration.ConfigManager; import com.projectkorra.projectkorra.earthbending.combo.EarthDomeOthers; import com.projectkorra.projectkorra.util.ClickType; import com.projectkorra.projectkorra.util.ReflectionHandler; -import com.projectkorra.projectkorra.waterbending.combo.IceBullet.IceBulletLeftClick; -import com.projectkorra.projectkorra.waterbending.combo.IceBullet.IceBulletRightClick; public class ComboManager { private static final long CLEANUP_DELAY = 20 * 60; @@ -35,15 +33,6 @@ public class ComboManager { DESCRIPTIONS.clear(); INSTRUCTIONS.clear(); - if (ConfigManager.defaultConfig.get().getBoolean("Abilities.Water.IceBullet.Enabled")) { - final ArrayList iceBulletLeft = new ArrayList<>(); - iceBulletLeft.add(new AbilityInformation("IceBlast", ClickType.LEFT_CLICK)); - COMBO_ABILITIES.put("IceBulletLeftClick", new ComboAbilityInfo("IceBulletLeftClick", iceBulletLeft, IceBulletLeftClick.class)); - final ArrayList iceBulletRight = new ArrayList<>(); - iceBulletRight.add(new AbilityInformation("IceBlast", ClickType.RIGHT_CLICK_BLOCK)); - COMBO_ABILITIES.put("IceBulletRightClick", new ComboAbilityInfo("IceBulletRightClick", iceBulletRight, IceBulletRightClick.class)); - } - if (ConfigManager.defaultConfig.get().getBoolean("Abilities.Earth.EarthDome.Enabled")) { final ArrayList earthDomeOthers = new ArrayList<>(); earthDomeOthers.add(new AbilityInformation("RaiseEarth", ClickType.RIGHT_CLICK_BLOCK)); @@ -82,8 +71,7 @@ public class ComboManager { final Class clazz = (Class) comboAbil.getComboType(); try { ReflectionHandler.instantiateObject(clazz, player); - } - catch (final Exception e) { + } catch (final Exception e) { e.printStackTrace(); } } else { diff --git a/src/com/projectkorra/projectkorra/ability/util/MultiAbilityManager.java b/src/com/projectkorra/projectkorra/ability/util/MultiAbilityManager.java index f79cf85b..5dd09165 100644 --- a/src/com/projectkorra/projectkorra/ability/util/MultiAbilityManager.java +++ b/src/com/projectkorra/projectkorra/ability/util/MultiAbilityManager.java @@ -15,7 +15,7 @@ import com.projectkorra.projectkorra.BendingPlayer; import com.projectkorra.projectkorra.Element; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ProjectKorra; -import com.projectkorra.projectkorra.event.BindChangeEvent; +import com.projectkorra.projectkorra.event.PlayerBindChangeEvent; public class MultiAbilityManager { @@ -43,7 +43,7 @@ public class MultiAbilityManager { * @param multiAbility MultiAbility being bound */ public static void bindMultiAbility(final Player player, final String multiAbility) { - final BindChangeEvent event = new BindChangeEvent(player, multiAbility, true); + final PlayerBindChangeEvent event = new PlayerBindChangeEvent(player, multiAbility, true); Bukkit.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return; diff --git a/src/com/projectkorra/projectkorra/ability/util/PassiveManager.java b/src/com/projectkorra/projectkorra/ability/util/PassiveManager.java index 990aa7e6..e8fc5dad 100644 --- a/src/com/projectkorra/projectkorra/ability/util/PassiveManager.java +++ b/src/com/projectkorra/projectkorra/ability/util/PassiveManager.java @@ -48,8 +48,7 @@ public class PassiveManager { final Constructor constructor = clazz.getConstructor(Player.class); final Object object = constructor.newInstance(player); ((CoreAbility) object).start(); - } - catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { e.printStackTrace(); } } diff --git a/src/com/projectkorra/projectkorra/airbending/AirBlast.java b/src/com/projectkorra/projectkorra/airbending/AirBlast.java index 0ade5ca7..986d15b9 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirBlast.java +++ b/src/com/projectkorra/projectkorra/airbending/AirBlast.java @@ -9,15 +9,16 @@ import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.Sound; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import org.bukkit.block.BlockState; +import org.bukkit.block.data.Levelled; +import org.bukkit.block.data.type.Door; +import org.bukkit.block.data.type.Switch; +import org.bukkit.block.data.type.TrapDoor; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; -import org.bukkit.material.Button; -import org.bukkit.material.Door; -import org.bukkit.material.Lever; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; @@ -37,6 +38,9 @@ public class AirBlast extends AirAbility { private static final int MAX_TICKS = 10000; private static final Map ORIGINS = new ConcurrentHashMap<>(); + public static final Material[] DOORS = { Material.ACACIA_DOOR, Material.BIRCH_DOOR, Material.DARK_OAK_DOOR, Material.JUNGLE_DOOR, Material.OAK_DOOR, Material.SPRUCE_DOOR }; + public static final Material[] TDOORS = { Material.ACACIA_TRAPDOOR, Material.BIRCH_TRAPDOOR, Material.DARK_OAK_TRAPDOOR, Material.JUNGLE_TRAPDOOR, Material.OAK_TRAPDOOR, Material.SPRUCE_TRAPDOOR }; + public static final Material[] BUTTONS = { Material.ACACIA_BUTTON, Material.BIRCH_BUTTON, Material.DARK_OAK_BUTTON, Material.JUNGLE_BUTTON, Material.OAK_BUTTON, Material.SPRUCE_BUTTON, Material.STONE_BUTTON }; private boolean canFlickLevers; private boolean canOpenDoors; @@ -51,9 +55,9 @@ public class AirBlast extends AirAbility { private double speedFactor; @Attribute(Attribute.RANGE) private double range; - @Attribute(Attribute.POWER) + @Attribute(Attribute.KNOCKBACK) private double pushFactor; - @Attribute(Attribute.POWER) + @Attribute(Attribute.KNOCKBACK + "Others") private double pushFactorForOthers; @Attribute(Attribute.DAMAGE) private double damage; @@ -137,8 +141,8 @@ public class AirBlast extends AirAbility { this.speed = getConfig().getDouble("Abilities.Air.AirBlast.Speed"); this.range = getConfig().getDouble("Abilities.Air.AirBlast.Range"); this.radius = getConfig().getDouble("Abilities.Air.AirBlast.Radius"); - this.pushFactor = getConfig().getDouble("Abilities.Air.AirBlast.Push.Entities"); - this.pushFactorForOthers = getConfig().getDouble("Abilities.Air.AirBlast.Push.Self"); + this.pushFactor = getConfig().getDouble("Abilities.Air.AirBlast.Push.Self"); + this.pushFactorForOthers = getConfig().getDouble("Abilities.Air.AirBlast.Push.Entities"); this.canFlickLevers = getConfig().getBoolean("Abilities.Air.AirBlast.CanFlickLevers"); this.canOpenDoors = getConfig().getBoolean("Abilities.Air.AirBlast.CanOpenDoors"); this.canPressButtons = getConfig().getBoolean("Abilities.Air.AirBlast.CanPressButtons"); @@ -208,75 +212,72 @@ public class AirBlast extends AirAbility { } private void affect(final Entity entity) { - final boolean isUser = entity.getUniqueId() == this.player.getUniqueId(); - - if (!isUser || this.isFromOtherOrigin) { - this.pushFactor = this.pushFactorForOthers; - final Vector velocity = entity.getVelocity(); - final double max = this.speed / this.speedFactor; - double factor = this.pushFactor; - - final Vector push = this.direction.clone(); - if (Math.abs(push.getY()) > max && !isUser) { - if (push.getY() < 0) { - push.setY(-max); - } else { - push.setY(max); - } - } - if (this.location.getWorld().equals(this.origin.getWorld())) { - factor *= 1 - this.location.distance(this.origin) / (2 * this.range); - } - - if (isUser && GeneralMethods.isSolid(this.player.getLocation().add(0, -.5, 0).getBlock())) { - factor *= .5; - } - - final double comp = velocity.dot(push.clone().normalize()); - if (comp > factor) { - velocity.multiply(.5); - velocity.add(push.clone().normalize().multiply(velocity.clone().dot(push.clone().normalize()))); - } else if (comp + factor * .5 > factor) { - velocity.add(push.clone().multiply(factor - comp)); - } else { - velocity.add(push.clone().multiply(factor * .5)); - } - - if (entity instanceof Player) { - if (Commands.invincible.contains(((Player) entity).getName())) { - return; - } - } - - if (Double.isNaN(velocity.length())) { + if (entity instanceof Player) { + if (Commands.invincible.contains(((Player) entity).getName())) { return; } + } + + final boolean isUser = entity.getUniqueId() == this.player.getUniqueId(); + double knockback = this.pushFactorForOthers; - GeneralMethods.setVelocity(entity, velocity); - if (this.source != null) { - new HorizontalVelocityTracker(entity, this.player, 200l, this.source); + if (isUser) { + if (isFromOtherOrigin) { + knockback = this.pushFactor; } else { - new HorizontalVelocityTracker(entity, this.player, 200l, this); - } - - if (!isUser && entity instanceof Player) { - ProjectKorra.flightHandler.createInstance((Player) entity, this.player, 1000L, this.getName()); - } - if (entity.getFireTicks() > 0) { - entity.getWorld().playEffect(entity.getLocation(), Effect.EXTINGUISH, 0); - } - - entity.setFireTicks(0); - breakBreathbendingHold(entity); - - if (this.source != null && (this.damage > 0 && entity instanceof LivingEntity && !entity.equals(this.player) && !this.affectedEntities.contains(entity))) { - DamageHandler.damageEntity(entity, this.damage, this.source); - this.affectedEntities.add(entity); - } else if (this.source == null && (this.damage > 0 && entity instanceof LivingEntity && !entity.equals(this.player) && !this.affectedEntities.contains(entity))) { - DamageHandler.damageEntity(entity, this.damage, this); - this.affectedEntities.add(entity); + return; } } + + final double max = this.speed / this.speedFactor; + + final Vector push = this.direction.clone(); + if (Math.abs(push.getY()) > max && !isUser) { + if (push.getY() < 0) { + push.setY(-max); + } else { + push.setY(max); + } + } + + if (this.location.getWorld().equals(this.origin.getWorld())) { + knockback *= 1 - this.location.distance(this.origin) / (2 * this.range); + } + + if (GeneralMethods.isSolid(entity.getLocation().add(0, -0.5, 0).getBlock()) && source == null) { + knockback *= 0.85; + } + + push.normalize().multiply(knockback); + + if (Math.abs(entity.getVelocity().dot(push)) > knockback && entity.getVelocity().angle(push) > Math.PI / 3) { + push.normalize().add(entity.getVelocity()).multiply(knockback); + } + + GeneralMethods.setVelocity(entity, push); + + if (this.source != null) { + new HorizontalVelocityTracker(entity, this.player, 200l, this.source); + } else { + new HorizontalVelocityTracker(entity, this.player, 200l, this); + } + + if (this.damage > 0 && entity instanceof LivingEntity && !entity.equals(this.player) && !this.affectedEntities.contains(entity)) { + if (this.source != null) { + DamageHandler.damageEntity(entity, this.damage, this.source); + } else { + DamageHandler.damageEntity(entity, this.damage, this); + } + + this.affectedEntities.add(entity); + } + + if (entity.getFireTicks() > 0) { + entity.getWorld().playEffect(entity.getLocation(), Effect.EXTINGUISH, 0); + } + + entity.setFireTicks(0); + breakBreathbendingHold(entity); } @Override @@ -297,119 +298,109 @@ public class AirBlast extends AirAbility { return; } - Block block = this.location.getBlock(); + final Block block = this.location.getBlock(); + for (final Block testblock : GeneralMethods.getBlocksAroundPoint(this.location, this.radius)) { if (testblock.getType() == Material.FIRE) { testblock.setType(Material.AIR); testblock.getWorld().playEffect(testblock.getLocation(), Effect.EXTINGUISH, 0); - } - if (GeneralMethods.isRegionProtectedFromBuild(this, block.getLocation())) { + continue; + } else if (GeneralMethods.isRegionProtectedFromBuild(this, block.getLocation())) { + continue; + } else if (this.affectedLevers.contains(testblock)) { continue; } - final Material doorTypes[] = { Material.WOODEN_DOOR, Material.SPRUCE_DOOR, Material.BIRCH_DOOR, Material.JUNGLE_DOOR, Material.ACACIA_DOOR, Material.DARK_OAK_DOOR, Material.TRAP_DOOR }; - if (Arrays.asList(doorTypes).contains(block.getType()) && !this.affectedLevers.contains(block) && this.canOpenDoors) { - if (block.getData() >= 8 && block.getType() != Material.TRAP_DOOR) { - block = block.getRelative(BlockFace.DOWN); - } + if (Arrays.asList(DOORS).contains(testblock.getType())) { + if (testblock.getBlockData() instanceof Door) { + final Door door = (Door) testblock.getBlockData(); + final BlockFace face = door.getFacing(); + final Vector toPlayer = GeneralMethods.getDirection(block.getLocation(), this.player.getLocation().getBlock().getLocation()); + final double[] dims = { toPlayer.getX(), toPlayer.getY(), toPlayer.getZ() }; - this.handleDoorMechanics(block); - } - if ((block.getType() == Material.LEVER) && !this.affectedLevers.contains(block) && this.canFlickLevers) { - final Lever lever = new Lever(Material.LEVER, block.getData()); - lever.setPowered(!lever.isPowered()); - block.setData(lever.getData()); + for (int i = 0; i < 3; i++) { + if (i == 1) { + continue; + } - final Block supportBlock = block.getRelative(lever.getAttachedFace()); - if (supportBlock != null && supportBlock.getType() != Material.AIR) { - final BlockState initialSupportState = supportBlock.getState(); - final BlockState supportState = supportBlock.getState(); - supportState.setType(Material.AIR); - supportState.update(true, false); - initialSupportState.update(true); - } - this.affectedLevers.add(block); - } else if ((block.getType() == Material.STONE_BUTTON) && !this.affectedLevers.contains(block) && this.canPressButtons) { - final Button button = new Button(Material.STONE_BUTTON, block.getData()); - if (!button.isPowered()) { - button.setPowered(!button.isPowered()); - block.setData(button.getData()); + final BlockFace bf = GeneralMethods.getBlockFaceFromValue(i, dims[i]); - final Block supportBlock = block.getRelative(button.getAttachedFace()); - if (supportBlock != null && supportBlock.getType() != Material.AIR) { - final BlockState initialSupportState = supportBlock.getState(); - final BlockState supportState = supportBlock.getState(); - supportState.setType(Material.AIR); - supportState.update(true, false); - initialSupportState.update(true); - } - - final Block btBlock = block; - new BukkitRunnable() { - @Override - public void run() { - button.setPowered(!button.isPowered()); - btBlock.setData(button.getData()); - - final Block supportBlock = btBlock.getRelative(button.getAttachedFace()); - if (supportBlock != null && supportBlock.getType() != Material.AIR) { - final BlockState initialSupportState = supportBlock.getState(); - final BlockState supportState = supportBlock.getState(); - supportState.setType(Material.AIR); - supportState.update(true, false); - initialSupportState.update(true); + if (bf == face) { + if (!door.isOpen()) { + return; + } + } else if (bf.getOppositeFace() == face) { + if (door.isOpen()) { + return; } } - }.runTaskLater(ProjectKorra.plugin, 10); - - this.affectedLevers.add(block); - } - } else if ((block.getType() == Material.WOOD_BUTTON) && !this.affectedLevers.contains(block) && this.canPressButtons) { - final Button button = new Button(Material.WOOD_BUTTON, block.getData()); - if (!button.isPowered()) { - button.setPowered(!button.isPowered()); - block.setData(button.getData()); - - final Block supportBlock = block.getRelative(button.getAttachedFace()); - if (supportBlock != null && supportBlock.getType() != Material.AIR) { - final BlockState initialSupportState = supportBlock.getState(); - final BlockState supportState = supportBlock.getState(); - supportState.setType(Material.AIR); - supportState.update(true, false); - initialSupportState.update(true); } - final Block btBlock = block; + door.setOpen(!door.isOpen()); + testblock.setBlockData(door); + testblock.getWorld().playSound(testblock.getLocation(), Sound.valueOf("BLOCK_WOODEN_DOOR_" + (door.isOpen() ? "OPEN" : "CLOSE")), 0.5f, 0); + this.affectedLevers.add(testblock); + } + } else if (Arrays.asList(TDOORS).contains(testblock.getType())) { + if (testblock.getBlockData() instanceof TrapDoor) { + final TrapDoor tDoor = (TrapDoor) testblock.getBlockData(); - new BukkitRunnable() { - @Override - public void run() { - button.setPowered(!button.isPowered()); - btBlock.setData(button.getData()); - - final Block supportBlock = btBlock.getRelative(button.getAttachedFace()); - if (supportBlock != null && supportBlock.getType() != Material.AIR) { - final BlockState initialSupportState = supportBlock.getState(); - final BlockState supportState = supportBlock.getState(); - supportState.setType(Material.AIR); - supportState.update(true, false); - initialSupportState.update(true); - } + if (this.origin.getY() < block.getY()) { + if (!tDoor.isOpen()) { + return; } - }.runTaskLater(ProjectKorra.plugin, 15); + } else { + if (tDoor.isOpen()) { + return; + } + } - this.affectedLevers.add(block); + tDoor.setOpen(!tDoor.isOpen()); + testblock.setBlockData(tDoor); + testblock.getWorld().playSound(testblock.getLocation(), Sound.valueOf("BLOCK_WOODEN_TRAPDOOR_" + (tDoor.isOpen() ? "OPEN" : "CLOSE")), 0.5f, 0); + } + } else if (Arrays.asList(BUTTONS).contains(testblock.getType())) { + if (testblock.getBlockData() instanceof Switch) { + final Switch button = (Switch) testblock.getBlockData(); + if (!button.isPowered()) { + button.setPowered(true); + testblock.setBlockData(button); + this.affectedLevers.add(testblock); + + new BukkitRunnable() { + + @Override + public void run() { + button.setPowered(false); + testblock.setBlockData(button); + AirBlast.this.affectedLevers.remove(testblock); + testblock.getWorld().playSound(testblock.getLocation(), Sound.BLOCK_WOODEN_BUTTON_CLICK_OFF, 0.5f, 0); + } + + }.runTaskLater(ProjectKorra.plugin, 15); + } + + testblock.getWorld().playSound(testblock.getLocation(), Sound.BLOCK_WOODEN_BUTTON_CLICK_ON, 0.5f, 0); + } + } else if (testblock.getType() == Material.LEVER) { + if (testblock.getBlockData() instanceof Switch) { + final Switch lever = (Switch) testblock.getBlockData(); + lever.setPowered(!lever.isPowered()); + testblock.setBlockData(lever); + this.affectedLevers.add(testblock); + testblock.getWorld().playSound(testblock.getLocation(), Sound.BLOCK_LEVER_CLICK, 0.5f, 0); } } } + if ((GeneralMethods.isSolid(block) || block.isLiquid()) && !this.affectedLevers.contains(block) && this.canCoolLava) { - if (block.getType() == Material.LAVA || block.getType() == Material.STATIONARY_LAVA) { + if (block.getType() == Material.LAVA) { if (LavaFlow.isLavaFlowBlock(block)) { LavaFlow.removeBlock(block); // TODO: Make more generic for future lava generating moves. - } else if (block.getData() == 0x0) { - new TempBlock(block, Material.OBSIDIAN, (byte) 0); + } else if (block.getBlockData() instanceof Levelled && ((Levelled) block.getBlockData()).getLevel() == 0) { + new TempBlock(block, Material.OBSIDIAN); } else { - new TempBlock(block, Material.COBBLESTONE, (byte) 0); + new TempBlock(block, Material.COBBLESTONE); } } this.remove(); @@ -432,6 +423,9 @@ public class AirBlast extends AirAbility { } for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(this.location, this.radius)) { + if (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation()) || ((entity instanceof Player) && Commands.invincible.contains(((Player) entity).getName()))) { + continue; + } this.affect(entity); } @@ -458,52 +452,6 @@ public class AirBlast extends AirAbility { return removed; } - private void handleDoorMechanics(final Block block) { - boolean tDoor = false; - final boolean open = (block.getData() & 0x4) == 0x4; - - if (block.getType() != Material.TRAP_DOOR) { - final Door door = (Door) block.getState().getData(); - final BlockFace face = door.getFacing(); - final Vector toPlayer = GeneralMethods.getDirection(block.getLocation(), this.player.getLocation().getBlock().getLocation()); - final double[] dims = { toPlayer.getX(), toPlayer.getY(), toPlayer.getZ() }; - - for (int i = 0; i < 3; i++) { - if (i == 1) { - continue; - } - final BlockFace bf = GeneralMethods.getBlockFaceFromValue(i, dims[i]); - - if (bf == face) { - if (open) { - return; - } - } else if (bf.getOppositeFace() == face) { - if (!open) { - return; - } - } - } - } else { - tDoor = true; - - if (this.origin.getY() < block.getY()) { - if (!open) { - return; - } - } else { - if (open) { - return; - } - } - } - - block.setData((byte) ((block.getData() & 0x4) == 0x4 ? (block.getData() & ~0x4) : (block.getData() | 0x4))); - final String sound = "BLOCK_WOODEN_" + (tDoor ? "TRAP" : "") + "DOOR_" + (!open ? "OPEN" : "CLOSE"); - block.getWorld().playSound(block.getLocation(), sound, 0.5f, 0); - this.affectedLevers.add(block); - } - @Override public String getName() { return "AirBlast"; diff --git a/src/com/projectkorra/projectkorra/airbending/AirBurst.java b/src/com/projectkorra/projectkorra/airbending/AirBurst.java index da40b3bd..031fed78 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirBurst.java +++ b/src/com/projectkorra/projectkorra/airbending/AirBurst.java @@ -21,9 +21,10 @@ public class AirBurst extends AirAbility { private float playerFallDistance; @Attribute(Attribute.CHARGE_DURATION) private long chargeTime; + @Attribute(Attribute.COOLDOWN) private long cooldown; private double fallThreshold; - @Attribute(Attribute.POWER) + @Attribute(Attribute.KNOCKBACK) private double pushFactor; @Attribute(Attribute.DAMAGE) private double damage; @@ -320,8 +321,4 @@ public class AirBurst extends AirAbility { public ArrayList getBlasts() { return this.blasts; } - - public ArrayList getAffectedEntities() { - return this.affectedEntities; - } } diff --git a/src/com/projectkorra/projectkorra/airbending/AirScooter.java b/src/com/projectkorra/projectkorra/airbending/AirScooter.java index 78e07ec7..d4059ab2 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirScooter.java +++ b/src/com/projectkorra/projectkorra/airbending/AirScooter.java @@ -3,15 +3,18 @@ package com.projectkorra.projectkorra.airbending; import java.util.ArrayList; import java.util.Random; +import org.bukkit.Difficulty; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; +import org.bukkit.entity.Slime; +import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; import com.projectkorra.projectkorra.GeneralMethods; -import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ability.AirAbility; import com.projectkorra.projectkorra.ability.ElementalAbility; import com.projectkorra.projectkorra.attribute.Attribute; @@ -25,11 +28,15 @@ public class AirScooter extends AirAbility { private double radius; @Attribute(Attribute.COOLDOWN) private long cooldown; + @Attribute(Attribute.DURATION) private long duration; + @Attribute(Attribute.HEIGHT) private double maxHeightFromGround; private Block floorblock; private Random random; private ArrayList angles; + private Slime slime; + private Boolean useslime; private double phi = 0; @@ -38,7 +45,7 @@ public class AirScooter extends AirAbility { if (check(player)) { return; - } else if (!player.isSprinting() || GeneralMethods.isSolid(player.getEyeLocation().getBlock()) || player.getEyeLocation().getBlock().isLiquid()) { + } else if (!player.isSprinting() || GeneralMethods.isSolid(player.getEyeLocation().getBlock()) || ElementalAbility.isWater(player.getEyeLocation().getBlock())) { return; } else if (GeneralMethods.isSolid(player.getLocation().add(0, -.5, 0).getBlock())) { return; @@ -52,10 +59,11 @@ public class AirScooter extends AirAbility { this.cooldown = getConfig().getLong("Abilities.Air.AirScooter.Cooldown"); this.duration = getConfig().getLong("Abilities.Air.AirScooter.Duration"); this.maxHeightFromGround = getConfig().getDouble("Abilities.Air.AirScooter.MaxHeightFromGround"); + this.useslime = getConfig().getBoolean("Abilities.Air.AirScooter.ShowSitting"); this.random = new Random(); this.angles = new ArrayList<>(); - ProjectKorra.flightHandler.createInstance(player, this.getName()); + this.flightHandler.createInstance(player, this.getName()); player.setAllowFlight(true); player.setFlying(true); @@ -65,6 +73,21 @@ public class AirScooter extends AirAbility { for (int i = 0; i < 5; i++) { this.angles.add((double) (60 * i)); } + if (player.getWorld().getDifficulty() == Difficulty.PEACEFUL) { + this.useslime = false; + } + if (this.useslime) { + this.slime = (Slime) player.getWorld().spawnEntity(player.getLocation(), EntityType.SLIME); + if (this.slime != null) { + this.slime.setSize(1); + this.slime.setSilent(true); + this.slime.setInvulnerable(true); + this.slime.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1, true, false)); + this.slime.addPassenger(player); + } else { + this.useslime = false; + } + } this.start(); } @@ -91,7 +114,7 @@ public class AirScooter extends AirAbility { this.floorblock = null; for (int i = 0; i <= this.maxHeightFromGround; i++) { final Block block = this.player.getEyeLocation().getBlock().getRelative(BlockFace.DOWN, i); - if (GeneralMethods.isSolid(block) || block.isLiquid()) { + if (GeneralMethods.isSolid(block) || ElementalAbility.isWater(block)) { this.floorblock = block; return; } @@ -121,15 +144,28 @@ public class AirScooter extends AirAbility { return; } + if (this.useslime && (this.slime == null || !this.slime.getPassengers().contains(this.player))) { + this.bPlayer.addCooldown(this); + this.remove(); + return; + } + Vector velocity = this.player.getEyeLocation().getDirection().clone().normalize(); velocity = velocity.clone().normalize().multiply(this.speed); /* * checks the players speed and ends the move if they are going too slow */ if (System.currentTimeMillis() > this.getStartTime() + this.interval) { - if (this.player.getVelocity().length() < this.speed * 0.3) { - this.remove(); - return; + if (this.useslime) { + if (this.slime.getVelocity().length() < this.speed * 0.3) { + this.remove(); + return; + } + } else { + if (this.player.getVelocity().length() < this.speed * 0.3) { + this.remove(); + return; + } } this.spinScooter(); } @@ -138,21 +174,21 @@ public class AirScooter extends AirAbility { * lowers the player based on their distance from the ground. */ final double distance = this.player.getLocation().getY() - this.floorblock.getY(); - final double dx = Math.abs(distance - 2.4); + Math.abs(distance - 2.4); if (distance > 2.75) { - velocity.setY(-.25 * dx * dx); + velocity.setY(-.25); } else if (distance < 2) { - velocity.setY(.25 * dx * dx); + velocity.setY(.25); } else { velocity.setY(0); } final Vector v = velocity.clone().setY(0); final Block b = this.floorblock.getLocation().clone().add(v.multiply(1.2)).getBlock(); - if (!GeneralMethods.isSolid(b) && !b.isLiquid()) { - velocity.add(new Vector(0, -0.6, 0)); - } else if (GeneralMethods.isSolid(b.getRelative(BlockFace.UP)) || b.getRelative(BlockFace.UP).isLiquid()) { - velocity.add(new Vector(0, 1.0, 0)); + if (!GeneralMethods.isSolid(b) && !ElementalAbility.isWater(b)) { + velocity.add(new Vector(0, -0.1, 0)); + } else if (GeneralMethods.isSolid(b.getRelative(BlockFace.UP)) || ElementalAbility.isWater(b.getRelative(BlockFace.UP))) { + velocity.add(new Vector(0, 0.7, 0)); } final Location loc = this.player.getLocation(); @@ -164,7 +200,11 @@ public class AirScooter extends AirAbility { this.player.setSprinting(false); this.player.removePotionEffect(PotionEffectType.SPEED); - this.player.setVelocity(velocity); + if (this.useslime) { + this.slime.setVelocity(velocity); + } else { + this.player.setVelocity(velocity); + } if (this.random.nextInt(4) == 0) { playAirbendingSound(this.player.getLocation()); @@ -177,7 +217,10 @@ public class AirScooter extends AirAbility { @Override public void remove() { super.remove(); - ProjectKorra.flightHandler.removeInstance(this.player, this.getName()); + if (this.slime != null) { + this.slime.remove(); + } + this.flightHandler.removeInstance(this.player, this.getName()); this.bPlayer.addCooldown(this); } diff --git a/src/com/projectkorra/projectkorra/airbending/AirShield.java b/src/com/projectkorra/projectkorra/airbending/AirShield.java index 8596c690..80d2d69f 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirShield.java +++ b/src/com/projectkorra/projectkorra/airbending/AirShield.java @@ -22,30 +22,39 @@ import com.projectkorra.projectkorra.command.Commands; public class AirShield extends AirAbility { private boolean isToggledByAvatarState; - @Attribute(Attribute.RADIUS) + @Attribute("Max" + Attribute.RADIUS) private double maxRadius; - @Attribute(Attribute.RADIUS) + @Attribute("Initial" + Attribute.RADIUS) + private double initialRadius; private double radius; @Attribute(Attribute.SPEED) private double speed; private int streams; private int particles; + @Attribute(Attribute.COOLDOWN) private long cooldown; + @Attribute(Attribute.DURATION) private long duration; private Random random; private HashMap angles; + private boolean dynamicCooldown; public AirShield(final Player player) { super(player); - this.maxRadius = getConfig().getDouble("Abilities.Air.AirShield.Radius"); + this.maxRadius = getConfig().getDouble("Abilities.Air.AirShield.MaxRadius"); + this.initialRadius = getConfig().getDouble("Abilities.Air.AirShield.InitialRadius"); this.isToggledByAvatarState = getConfig().getBoolean("Abilities.Avatar.AvatarState.Air.AirShield.IsAvatarStateToggle"); - this.radius = this.maxRadius; + this.radius = this.initialRadius; this.cooldown = getConfig().getLong("Abilities.Air.AirShield.Cooldown"); this.duration = getConfig().getLong("Abilities.Air.AirShield.Duration"); this.speed = getConfig().getDouble("Abilities.Air.AirShield.Speed"); this.streams = getConfig().getInt("Abilities.Air.AirShield.Streams"); this.particles = getConfig().getInt("Abilities.Air.AirShield.Particles"); + this.dynamicCooldown = getConfig().getBoolean("Abilities.Air.AirShield.DynamicCooldown"); //any unused duration from shield is removed from the cooldown + if (this.duration == 0) { + this.dynamicCooldown = false; + } this.random = new Random(); this.angles = new HashMap<>(); @@ -91,7 +100,15 @@ public class AirShield extends AirAbility { return; } else if (!this.bPlayer.isAvatarState() || !this.isToggledByAvatarState) { if (!this.player.isSneaking() || !this.bPlayer.canBend(this)) { - this.bPlayer.addCooldown(this); + if (this.dynamicCooldown) { + Long reducedCooldown = this.cooldown - (this.duration - (System.currentTimeMillis() - this.getStartTime())); + if (reducedCooldown < 0L) { + reducedCooldown = 0L; + } + this.bPlayer.addCooldown(this, reducedCooldown); + } else { + this.bPlayer.addCooldown(this); + } this.remove(); return; } else if (this.duration != 0) { @@ -128,7 +145,7 @@ public class AirShield extends AirAbility { vx = (x * Math.cos(angle) - z * Math.sin(angle)) / mag; vz = (x * Math.sin(angle) + z * Math.cos(angle)) / mag; - final Vector velocity = entity.getVelocity(); + final Vector velocity = entity.getVelocity().clone(); if (this.bPlayer.isAvatarState()) { velocity.setX(AvatarState.getValue(vx)); velocity.setZ(AvatarState.getValue(vz)); diff --git a/src/com/projectkorra/projectkorra/airbending/AirSpout.java b/src/com/projectkorra/projectkorra/airbending/AirSpout.java index 84ab40fe..3e0e4ae4 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirSpout.java +++ b/src/com/projectkorra/projectkorra/airbending/AirSpout.java @@ -10,8 +10,8 @@ import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; import com.projectkorra.projectkorra.GeneralMethods; -import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ability.AirAbility; +import com.projectkorra.projectkorra.ability.ElementalAbility; import com.projectkorra.projectkorra.ability.util.Collision; import com.projectkorra.projectkorra.attribute.Attribute; @@ -22,6 +22,7 @@ public class AirSpout extends AirAbility { private int angle; private long animTime; private long interval; + @Attribute(Attribute.DURATION) private long duration; @Attribute(Attribute.COOLDOWN) private long cooldown; @@ -53,7 +54,7 @@ public class AirSpout extends AirAbility { return; } - ProjectKorra.flightHandler.createInstance(player, this.getName()); + this.flightHandler.createInstance(player, this.getName()); if (this.bPlayer.isAvatarState()) { this.height = getConfig().getDouble("Abilities.Avatar.AvatarState.Air.AirSpout.Height"); @@ -89,8 +90,21 @@ public class AirSpout extends AirAbility { } private void allowFlight() { - this.player.setAllowFlight(true); - this.player.setFlying(true); + if (!this.player.getAllowFlight()) { + this.player.setAllowFlight(true); + } + if (!this.player.isFlying()) { + this.player.setFlying(true); + } + } + + private void removeFlight() { + if (this.player.isFlying()) { + this.player.setFlying(false); + } + if (this.player.getAllowFlight()) { + this.player.setAllowFlight(false); + } } private boolean isWithinMaxSpoutHeight(final double threshold) { @@ -109,7 +123,7 @@ public class AirSpout extends AirAbility { final Block standingblock = this.player.getLocation().getBlock(); for (int i = 0; i <= this.height + 5; i++) { final Block block = standingblock.getRelative(BlockFace.DOWN, i); - if (GeneralMethods.isSolid(block) || block.isLiquid()) { + if (GeneralMethods.isSolid(block) || ElementalAbility.isWater(block)) { return block; } } @@ -135,7 +149,7 @@ public class AirSpout extends AirAbility { } final Block eyeBlock = this.player.getEyeLocation().getBlock(); - if (eyeBlock.isLiquid() || GeneralMethods.isSolid(eyeBlock)) { + if (ElementalAbility.isWater(eyeBlock) || GeneralMethods.isSolid(eyeBlock)) { this.remove(); return; } @@ -163,12 +177,7 @@ public class AirSpout extends AirAbility { @Override public void remove() { super.remove(); - ProjectKorra.flightHandler.removeInstance(this.player, this.getName()); - } - - private void removeFlight() { - this.player.setAllowFlight(false); - this.player.setFlying(false); + this.flightHandler.removeInstance(this.player, this.getName()); } private void rotateAirColumn(final Block block) { diff --git a/src/com/projectkorra/projectkorra/airbending/AirSuction.java b/src/com/projectkorra/projectkorra/airbending/AirSuction.java index cc985257..3aff0212 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirSuction.java +++ b/src/com/projectkorra/projectkorra/airbending/AirSuction.java @@ -3,24 +3,23 @@ package com.projectkorra.projectkorra.airbending; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.Random; -import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.block.data.type.Door; +import org.bukkit.block.data.type.TrapDoor; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import org.bukkit.material.Door; import org.bukkit.util.Vector; -import com.projectkorra.projectkorra.BendingPlayer; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ability.AirAbility; +import com.projectkorra.projectkorra.ability.CoreAbility; import com.projectkorra.projectkorra.ability.util.Collision; import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.command.Commands; @@ -29,13 +28,9 @@ import com.projectkorra.projectkorra.waterbending.WaterSpout; public class AirSuction extends AirAbility { - private static final int MAX_TICKS = 10000; - private static final Map ORIGINS = new ConcurrentHashMap<>(); - private static Material doorTypes[] = { Material.WOODEN_DOOR, Material.SPRUCE_DOOR, Material.BIRCH_DOOR, Material.JUNGLE_DOOR, Material.ACACIA_DOOR, Material.DARK_OAK_DOOR, Material.TRAP_DOOR }; private final List affectedDoors = new ArrayList<>(); - private boolean hasOtherOrigin; - private int ticks; + private boolean progressing; private int particleCount; @Attribute(Attribute.COOLDOWN) private long cooldown; @@ -45,12 +40,15 @@ public class AirSuction extends AirAbility { private double range; @Attribute(Attribute.RADIUS) private double radius; - @Attribute(Attribute.POWER) + @Attribute(Attribute.KNOCKBACK) private double pushFactor; + @Attribute(Attribute.KNOCKBACK + "Others") + private double pushFactorForOthers; private Random random; private Location location; private Location origin; private Vector direction; + private boolean canAffectSelf; public AirSuction(final Player player) { super(player); @@ -63,88 +61,43 @@ public class AirSuction extends AirAbility { return; } - this.hasOtherOrigin = false; - this.ticks = 0; + if (hasAbility(player, AirSuction.class)) { + final AirSuction suc = getAbility(player, AirSuction.class); + if (!suc.isProgressing()) { + final Location loc = this.getTargetLocation(); + + if (!GeneralMethods.isRegionProtectedFromBuild(player, this.getName(), loc)) { + suc.setOrigin(loc); + } + } + return; + } + + this.progressing = false; this.particleCount = getConfig().getInt("Abilities.Air.AirSuction.Particles"); this.speed = getConfig().getDouble("Abilities.Air.AirSuction.Speed"); this.range = getConfig().getDouble("Abilities.Air.AirSuction.Range"); this.radius = getConfig().getDouble("Abilities.Air.AirSuction.Radius"); - this.pushFactor = getConfig().getDouble("Abilities.Air.AirSuction.Push"); + this.pushFactor = getConfig().getDouble("Abilities.Air.AirSuction.Push.Self"); + this.pushFactorForOthers = getConfig().getDouble("Abilities.Air.AirSuction.Push.Others"); this.cooldown = getConfig().getLong("Abilities.Air.AirSuction.Cooldown"); this.random = new Random(); + this.origin = this.getTargetLocation(); + this.canAffectSelf = true; - if (ORIGINS.containsKey(player)) { - this.origin = ORIGINS.get(player); - this.hasOtherOrigin = true; - ORIGINS.remove(player); - } else { - this.origin = player.getEyeLocation(); + if (GeneralMethods.isRegionProtectedFromBuild(player, this.getName(), this.origin)) { + return; } - this.location = GeneralMethods.getTargetedLocation(player, this.range, getTransparentMaterials()); - this.direction = GeneralMethods.getDirection(this.location, this.origin).normalize(); - final Entity entity = GeneralMethods.getTargetedEntity(player, this.range); + this.location = null; - if (entity != null) { - this.direction = GeneralMethods.getDirection(entity.getLocation(), this.origin).normalize(); - this.location = this.getLocation(this.origin, this.direction.clone().multiply(-1)); - } - - this.bPlayer.addCooldown(this); if (this.bPlayer.isAvatarState()) { this.pushFactor = getConfig().getDouble("Abilities.Avatar.AvatarState.Air.AirSuction.Push"); } + this.start(); } - private static void playOriginEffect(final Player player) { - if (!ORIGINS.containsKey(player)) { - return; - } - - final Location origin = ORIGINS.get(player); - final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); - if (bPlayer == null || player.isDead() || !player.isOnline()) { - return; - } else if (!origin.getWorld().equals(player.getWorld())) { - ORIGINS.remove(player); - return; - } else if (!bPlayer.canBendIgnoreCooldowns(getAbility("AirSuction"))) { - ORIGINS.remove(player); - return; - } else if (origin.distanceSquared(player.getEyeLocation()) > getSelectRange() * getSelectRange()) { - ORIGINS.remove(player); - return; - } - - playAirbendingParticles(origin, getSelectParticles()); - } - - public static void progressOrigins() { - for (final Player player : ORIGINS.keySet()) { - playOriginEffect(player); - } - } - - public static void setOrigin(final Player player) { - final Material[] ignore = new Material[getTransparentMaterials().length + doorTypes.length]; - for (int i = 0; i < ignore.length; i++) { - if (i < getTransparentMaterials().length) { - ignore[i] = getTransparentMaterials()[i]; - } else { - ignore[i] = doorTypes[i - getTransparentMaterials().length]; - } - } - final Location location = GeneralMethods.getTargetedLocation(player, getSelectRange(), ignore); - if (location.getBlock().isLiquid() || GeneralMethods.isSolid(location.getBlock())) { - return; - } else if (GeneralMethods.isRegionProtectedFromBuild(player, "AirSuction", location)) { - return; - } else { - ORIGINS.put(player, location); - } - } - private void advanceLocation() { playAirbendingParticles(this.location, this.particleCount, 0.275F, 0.275F, 0.275F); if (this.random.nextInt(4) == 0) { @@ -153,17 +106,17 @@ public class AirSuction extends AirAbility { final double speedFactor = this.speed * (ProjectKorra.time_step / 1000.); this.location = this.location.add(this.direction.clone().multiply(speedFactor)); - if (Arrays.asList(doorTypes).contains(this.location.getBlock().getType()) && !this.affectedDoors.contains(this.location.getBlock())) { + if ((Arrays.asList(AirBlast.DOORS).contains(this.location.getBlock().getType()) || Arrays.asList(AirBlast.TDOORS).contains(this.location.getBlock().getType())) && !this.affectedDoors.contains(this.location.getBlock())) { this.handleDoorMechanics(this.location.getBlock()); } } private void handleDoorMechanics(final Block block) { boolean tDoor = false; - final boolean open = (block.getData() & 0x4) == 0x4; + boolean open = false; - if (block.getType() != Material.TRAP_DOOR) { - final Door door = (Door) block.getState().getData(); + if (Arrays.asList(AirBlast.DOORS).contains(block.getType())) { + final Door door = (Door) block.getBlockData(); final BlockFace face = door.getFacing(); final Vector toPlayer = GeneralMethods.getDirection(block.getLocation(), this.player.getLocation().getBlock().getLocation()); final double[] dims = { toPlayer.getX(), toPlayer.getY(), toPlayer.getZ() }; @@ -175,44 +128,57 @@ public class AirSuction extends AirAbility { final BlockFace bf = GeneralMethods.getBlockFaceFromValue(i, dims[i]); if (bf == face) { - if (!open) { + if (!door.isOpen()) { return; } } else if (bf.getOppositeFace() == face) { - if (open) { + if (door.isOpen()) { return; } } } + + door.setOpen(!door.isOpen()); + block.setBlockData(door); + open = door.isOpen(); } else { tDoor = true; + final TrapDoor trap = (TrapDoor) block.getBlockData(); if (this.origin.getY() < block.getY()) { - if (open) { + if (trap.isOpen()) { return; } } else { - if (!open) { + if (!trap.isOpen()) { return; } } + + trap.setOpen(!trap.isOpen()); + block.setBlockData(trap); + open = trap.isOpen(); } - block.setData((byte) ((block.getData() & 0x4) == 0x4 ? (block.getData() & ~0x4) : (block.getData() | 0x4))); - final String sound = "BLOCK_WOODEN_" + (tDoor ? "TRAP" : "") + "DOOR_" + (!open ? "OPEN" : "CLOSE"); + final String sound = "block_wooden_" + (tDoor ? "trap" : "") + "door_" + (!open ? "open" : "close"); block.getWorld().playSound(block.getLocation(), sound, 0.5f, 0); this.affectedDoors.add(block); } - private Location getLocation(final Location origin, final Vector direction) { - Location location = origin.clone(); - for (double i = 1; i <= this.range; i++) { - location = origin.clone().add(direction.clone().multiply(i)); - if ((!this.isTransparent(location.getBlock()) && !Arrays.asList(doorTypes).contains(location.getBlock().getType())) || GeneralMethods.isRegionProtectedFromBuild(this, location)) { - return origin.clone().add(direction.clone().multiply(i - 1)); + private Location getTargetLocation() { + final Material[] ignore = new Material[getTransparentMaterials().length + AirBlast.DOORS.length + AirBlast.TDOORS.length]; + + for (int i = 0; i < ignore.length; i++) { + if (i < getTransparentMaterials().length) { + ignore[i] = getTransparentMaterials()[i]; + } else if (i < getTransparentMaterials().length + AirBlast.DOORS.length) { + ignore[i] = AirBlast.DOORS[i - getTransparentMaterials().length]; + } else { + ignore[i] = AirBlast.TDOORS[i - getTransparentMaterials().length - AirBlast.DOORS.length]; } } - return location; + + return GeneralMethods.getTargetedLocation(this.player, getSelectRange(), ignore); } @Override @@ -220,60 +186,55 @@ public class AirSuction extends AirAbility { if (this.player.isDead() || !this.player.isOnline()) { this.remove(); return; - } else if (GeneralMethods.isRegionProtectedFromBuild(this.player, "AirSuction", this.location)) { - this.remove(); - return; } - this.ticks++; - if (this.ticks > MAX_TICKS) { - this.remove(); - return; - } else if ((this.location.distanceSquared(this.origin) > this.range * this.range) || (this.location.distanceSquared(this.origin) <= 1)) { - this.remove(); - return; - } + if (this.progressing) { + if (GeneralMethods.isRegionProtectedFromBuild(this.player, "AirSuction", this.location)) { + this.remove(); + return; + } else if (!this.location.getWorld().equals(this.origin.getWorld()) || this.location.distanceSquared(this.origin) > this.range * this.range || this.location.distanceSquared(this.origin) <= 1) { + this.remove(); + return; + } - for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(this.location, this.radius)) { - if (entity.getEntityId() != this.player.getEntityId() || this.hasOtherOrigin) { - final Vector velocity = entity.getVelocity(); + for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(this.location, this.radius)) { + if (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation()) || ((entity instanceof Player) && Commands.invincible.contains(((Player) entity).getName()))) { + continue; + } + if ((entity.getEntityId() == this.player.getEntityId()) && !this.canAffectSelf) { + continue; + } + + double knockback = this.pushFactor; + + if (entity.getEntityId() != player.getEntityId()) { + knockback = this.pushFactorForOthers; + } + final double max = this.speed; - double factor = this.pushFactor; - final Vector push = this.direction.clone(); - if (Math.abs(push.getY()) > max && entity.getEntityId() != this.player.getEntityId()) { + + if (Math.abs(push.getY()) > max) { if (push.getY() < 0) { push.setY(-max); } else { push.setY(max); } } + if (this.location.getWorld().equals(this.origin.getWorld())) { - factor *= 1 - this.location.distance(this.origin) / (2 * this.range); + knockback *= 1 - this.location.distance(this.origin) / (2 * this.range); + } + + push.normalize().multiply(knockback); + + if (Math.abs(entity.getVelocity().dot(push)) > knockback) { + push.normalize().add(entity.getVelocity()).multiply(knockback); } - final double comp = velocity.dot(push.clone().normalize()); - if (comp > factor) { - velocity.multiply(.5); - velocity.add(push.clone().normalize().multiply(velocity.clone().dot(push.clone().normalize()))); - } else if (comp + factor * .5 > factor) { - velocity.add(push.clone().multiply(factor - comp)); - } else { - velocity.add(push.clone().multiply(factor * .5)); - } - - if (entity instanceof Player) { - if (Commands.invincible.contains(((Player) entity).getName())) { - continue; - } - } - - GeneralMethods.setVelocity(entity, velocity); + GeneralMethods.setVelocity(entity, push.normalize().multiply(knockback)); new HorizontalVelocityTracker(entity, this.player, 200l, this); entity.setFallDistance(0); - if (entity.getEntityId() != this.player.getEntityId() && entity instanceof Player) { - ProjectKorra.flightHandler.createInstance((Player) entity, this.player, 5000L, this.getName()); - } if (entity.getFireTicks() > 0) { entity.getWorld().playEffect(entity.getLocation(), Effect.EXTINGUISH, 0); @@ -281,9 +242,46 @@ public class AirSuction extends AirAbility { entity.setFireTicks(0); breakBreathbendingHold(entity); } + + this.advanceLocation(); + } else { + playAirbendingParticles(this.origin, 5, 0.5, 0.5, 0.5); + } + } + + public void shoot() { + Location target; + final Entity entity = GeneralMethods.getTargetedEntity(this.player, this.range); + + if (entity != null) { + target = entity.getLocation(); + } else { + target = this.getTargetLocation(); } - this.advanceLocation(); + this.location = target.clone(); + this.direction = GeneralMethods.getDirection(this.location, this.origin).normalize(); + this.progressing = true; + this.bPlayer.addCooldown(this); + } + + public static void shoot(final Player player) { + AirSuction suc = null; + + if (CoreAbility.hasAbility(player, AirSuction.class)) { + suc = CoreAbility.getAbility(player, AirSuction.class); + if (suc.isProgressing()) { + return; + } + } else { + suc = new AirSuction(player); + suc.setOrigin(player.getEyeLocation().clone()); + suc.setCanEffectSelf(false); + } + + if (suc.getOrigin() != null) { + suc.shoot(); + } } /** @@ -335,6 +333,10 @@ public class AirSuction extends AirAbility { return this.getRadius(); } + public boolean isProgressing() { + return this.progressing; + } + public Location getOrigin() { return this.origin; } @@ -351,22 +353,6 @@ public class AirSuction extends AirAbility { this.direction = direction; } - public boolean isHasOtherOrigin() { - return this.hasOtherOrigin; - } - - public void setHasOtherOrigin(final boolean hasOtherOrigin) { - this.hasOtherOrigin = hasOtherOrigin; - } - - public int getTicks() { - return this.ticks; - } - - public void setTicks(final int ticks) { - this.ticks = ticks; - } - public int getParticleCount() { return this.particleCount; } @@ -415,8 +401,8 @@ public class AirSuction extends AirAbility { this.cooldown = cooldown; } - public static Map getOrigins() { - return ORIGINS; + public void setCanEffectSelf(final boolean affect) { + this.canAffectSelf = affect; } public static int getSelectParticles() { diff --git a/src/com/projectkorra/projectkorra/airbending/AirSwipe.java b/src/com/projectkorra/projectkorra/airbending/AirSwipe.java index aaa556b3..999bfa45 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirSwipe.java +++ b/src/com/projectkorra/projectkorra/airbending/AirSwipe.java @@ -9,6 +9,7 @@ import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.data.Levelled; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -33,16 +34,18 @@ public class AirSwipe extends AirAbility { private static final int MAX_AFFECTABLE_ENTITIES = 10; private boolean charging; + @Attribute("Arc") private int arc; private int particles; - private int stepSize; + @Attribute("ArcIncrement") + private int arcIncrement; @Attribute(Attribute.CHARGE_DURATION) private long maxChargeTime; @Attribute(Attribute.COOLDOWN) private long cooldown; @Attribute(Attribute.DAMAGE) private double damage; - @Attribute(Attribute.POWER) + @Attribute(Attribute.KNOCKBACK) private double pushFactor; @Attribute(Attribute.SPEED) private double speed; @@ -74,10 +77,10 @@ public class AirSwipe extends AirAbility { } this.charging = charging; - this.origin = player.getEyeLocation(); + this.origin = GeneralMethods.getMainHandLocation(player); this.particles = getConfig().getInt("Abilities.Air.AirSwipe.Particles"); this.arc = getConfig().getInt("Abilities.Air.AirSwipe.Arc"); - this.stepSize = getConfig().getInt("Abilities.Air.AirSwipe.StepSize"); + this.arcIncrement = getConfig().getInt("Abilities.Air.AirSwipe.StepSize"); this.maxChargeTime = getConfig().getLong("Abilities.Air.AirSwipe.MaxChargeTime"); this.cooldown = getConfig().getLong("Abilities.Air.AirSwipe.Cooldown"); this.damage = getConfig().getDouble("Abilities.Air.AirSwipe.Damage"); @@ -159,19 +162,21 @@ public class AirSwipe extends AirAbility { } } - if (block.getType() != Material.AIR) { + if (!isAir(block.getType())) { if (block.getType().equals(Material.SNOW)) { continue; + } else if (isPlant(block.getType())) { + block.breakNaturally(); } else { this.elements.remove(direction); } if (isLava(block)) { if (LavaFlow.isLavaFlowBlock(block)) { LavaFlow.removeBlock(block); // TODO: Make more generic for future lava generating moves. - } else if (block.getData() == 0x0) { - new TempBlock(block, Material.OBSIDIAN, (byte) 0); + } else if (block.getBlockData() instanceof Levelled && ((Levelled) block.getBlockData()).getLevel() == 0) { + new TempBlock(block, Material.OBSIDIAN); } else { - new TempBlock(block, Material.COBBLESTONE, (byte) 0); + new TempBlock(block, Material.COBBLESTONE); } } } else { @@ -191,7 +196,7 @@ public class AirSwipe extends AirAbility { private void affectPeople(final Location location, final Vector direction) { final List entities = GeneralMethods.getEntitiesAroundPoint(location, this.radius); - final Vector fDirection = direction; + final Vector fDirection = direction.clone(); for (int i = 0; i < entities.size(); i++) { final Entity entity = entities.get(i); @@ -213,19 +218,14 @@ public class AirSwipe extends AirAbility { GeneralMethods.setVelocity(entity, fDirection.multiply(AirSwipe.this.pushFactor)); } - if (entity instanceof LivingEntity && !AirSwipe.this.affectedEntities.contains(entity)) { + if (!AirSwipe.this.affectedEntities.contains(entity)) { if (AirSwipe.this.damage != 0) { DamageHandler.damageEntity(entity, AirSwipe.this.damage, abil); } AirSwipe.this.affectedEntities.add(entity); } - if (entity instanceof Player) { - ProjectKorra.flightHandler.createInstance((Player) entity, AirSwipe.this.player, 1000L, AirSwipe.this.getName()); - } breakBreathbendingHold(entity); - if (AirSwipe.this.elements.containsKey(fDirection)) { - AirSwipe.this.elements.remove(fDirection); - } + AirSwipe.this.elements.remove(direction); } else if (entity.getEntityId() != AirSwipe.this.player.getEntityId() && !(entity instanceof LivingEntity)) { GeneralMethods.setVelocity(entity, fDirection.multiply(AirSwipe.this.pushFactor)); @@ -239,7 +239,7 @@ public class AirSwipe extends AirAbility { private void launch() { this.bPlayer.addCooldown("AirSwipe", this.cooldown); this.origin = this.player.getEyeLocation(); - for (double i = -this.arc; i <= this.arc; i += this.stepSize) { + for (double i = -this.arc; i <= this.arc; i += this.arcIncrement) { final double angle = Math.toRadians(i); final Vector direction = this.player.getEyeLocation().getDirection().clone(); @@ -443,12 +443,12 @@ public class AirSwipe extends AirAbility { this.cooldown = cooldown; } - public int getStepSize() { - return this.stepSize; + public int getArcIncrement() { + return this.arcIncrement; } - public void setStepSize(final int stepSize) { - this.stepSize = stepSize; + public void setArcIncrement(final int arcIncrement) { + this.arcIncrement = arcIncrement; } } diff --git a/src/com/projectkorra/projectkorra/airbending/Suffocate.java b/src/com/projectkorra/projectkorra/airbending/Suffocate.java index 91eb2044..a42abeae 100644 --- a/src/com/projectkorra/projectkorra/airbending/Suffocate.java +++ b/src/com/projectkorra/projectkorra/airbending/Suffocate.java @@ -97,7 +97,6 @@ public class Suffocate extends AirAbility { this.chargeTime = getConfig().getLong("Abilities.Avatar.AvatarState.Air.Suffocate.ChargeTime"); this.damage = getConfig().getDouble("Abilities.Avatar.AvatarState.Air.Suffocate.Damage"); this.range = getConfig().getDouble("Abilities.Avatar.AvatarState.Air.Suffocate.Range"); - } if (this.particleCount < 1) { @@ -143,7 +142,6 @@ public class Suffocate extends AirAbility { } } - this.bPlayer.addCooldown(this); this.start(); } @@ -172,7 +170,7 @@ public class Suffocate extends AirAbility { if (this.player.getWorld().equals(this.targets.get(0).getWorld())) { dist = this.player.getEyeLocation().distance(this.targets.get(0).getEyeLocation()); } - final Location targetLoc = this.player.getEyeLocation().clone().add(this.player.getEyeLocation().getDirection().normalize().multiply(dist)); + final Location targetLoc = GeneralMethods.getTargetedLocation(player, dist, false, getTransparentMaterials()); final List ents = GeneralMethods.getEntitiesAroundPoint(targetLoc, this.constantAimRadius); for (int i = 0; i < this.targets.size(); i++) { @@ -337,6 +335,7 @@ public class Suffocate extends AirAbility { @Override public void remove() { super.remove(); + this.bPlayer.addCooldown(this); for (int i = 0; i < this.tasks.size(); i++) { this.tasks.get(i).cancel(); this.tasks.remove(i); diff --git a/src/com/projectkorra/projectkorra/airbending/Tornado.java b/src/com/projectkorra/projectkorra/airbending/Tornado.java index 10901e9c..fc41a7a5 100644 --- a/src/com/projectkorra/projectkorra/airbending/Tornado.java +++ b/src/com/projectkorra/projectkorra/airbending/Tornado.java @@ -12,14 +12,16 @@ import org.bukkit.entity.Player; import org.bukkit.util.Vector; import com.projectkorra.projectkorra.GeneralMethods; -import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ability.AirAbility; +import com.projectkorra.projectkorra.ability.ElementalAbility; import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.command.Commands; public class Tornado extends AirAbility { + @Attribute(Attribute.COOLDOWN) private final long cooldown; + @Attribute(Attribute.DURATION) private final long duration; private int numberOfStreams; private int particleCount; @@ -27,7 +29,7 @@ public class Tornado extends AirAbility { private double speed; @Attribute(Attribute.HEIGHT) private double maxHeight; - @Attribute(Attribute.POWER) + @Attribute(Attribute.KNOCKBACK) private double playerPushFactor; @Attribute(Attribute.RADIUS) private double radius; @@ -68,7 +70,7 @@ public class Tornado extends AirAbility { } } - ProjectKorra.flightHandler.createInstance(player, this.getName()); + this.flightHandler.createInstance(player, this.getName()); player.setAllowFlight(true); this.start(); } @@ -95,7 +97,7 @@ public class Tornado extends AirAbility { @Override public void remove() { super.remove(); - ProjectKorra.flightHandler.removeInstance(this.player, this.getName()); + this.flightHandler.removeInstance(this.player, this.getName()); } private void rotateTornado() { @@ -103,7 +105,7 @@ public class Tornado extends AirAbility { final double timefactor = this.currentHeight / this.maxHeight; this.currentRadius = timefactor * this.radius; - if (this.origin.getBlock().getType() != Material.AIR && this.origin.getBlock().getType() != Material.BARRIER) { + if (!ElementalAbility.isAir(this.origin.getBlock().getType()) && this.origin.getBlock().getType() != Material.BARRIER) { this.origin.setY(this.origin.getY() - 1. / 10. * this.currentHeight); for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(this.origin, this.currentHeight)) { @@ -126,8 +128,13 @@ public class Tornado extends AirAbility { mag = Math.sqrt(x * x + z * z); - vx = (x * Math.cos(angle) - z * Math.sin(angle)) / mag; - vz = (x * Math.sin(angle) + z * Math.cos(angle)) / mag; + if (mag == 0.0) { + vx = 0.0; + vz = 0.0; + } else { + vx = (x * Math.cos(angle) - z * Math.sin(angle)) / mag; + vz = (x * Math.sin(angle) + z * Math.cos(angle)) / mag; + } if (entity instanceof Player) { vy = 0.05 * this.playerPushFactor; @@ -157,7 +164,7 @@ public class Tornado extends AirAbility { } } - final Vector velocity = entity.getVelocity(); + final Vector velocity = entity.getVelocity().clone(); velocity.setX(vx); velocity.setZ(vz); velocity.setY(vy); @@ -166,10 +173,6 @@ public class Tornado extends AirAbility { entity.setFallDistance(0); breakBreathbendingHold(entity); - - if (entity instanceof Player) { - ProjectKorra.flightHandler.createInstance((Player) entity, 50L, this.getName()); - } } } } diff --git a/src/com/projectkorra/projectkorra/airbending/combo/AirStream.java b/src/com/projectkorra/projectkorra/airbending/combo/AirStream.java index 9b827a5f..02678172 100644 --- a/src/com/projectkorra/projectkorra/airbending/combo/AirStream.java +++ b/src/com/projectkorra/projectkorra/airbending/combo/AirStream.java @@ -1,8 +1,6 @@ package com.projectkorra.projectkorra.airbending.combo; import java.util.ArrayList; -import java.util.HashSet; -import java.util.Set; import org.bukkit.Location; import org.bukkit.entity.Entity; @@ -20,13 +18,17 @@ import com.projectkorra.projectkorra.command.Commands; import com.projectkorra.projectkorra.util.ClickType; public class AirStream extends AirAbility implements ComboAbility { + + @Attribute(Attribute.COOLDOWN) private long cooldown; private long time; @Attribute(Attribute.SPEED) private double speed; @Attribute(Attribute.RANGE) private double range; + @Attribute("EntityCarry" + Attribute.HEIGHT) private double airStreamMaxEntityHeight; + @Attribute("EntityCarry" + Attribute.DURATION) private double airStreamEntityCarryDuration; private Location origin; private Location currentLoc; @@ -34,14 +36,12 @@ public class AirStream extends AirAbility implements ComboAbility { private Vector direction; private ArrayList affectedEntities; private ArrayList tasks; - private Set flights; public AirStream(final Player player) { super(player); this.affectedEntities = new ArrayList<>(); this.tasks = new ArrayList<>(); - this.flights = new HashSet<>(); if (!this.bPlayer.canBendIgnoreBindsCooldowns(this)) { return; @@ -54,14 +54,14 @@ public class AirStream extends AirAbility implements ComboAbility { this.range = getConfig().getDouble("Abilities.Air.AirStream.Range"); this.speed = getConfig().getDouble("Abilities.Air.AirStream.Speed"); this.cooldown = getConfig().getLong("Abilities.Air.AirStream.Cooldown"); - this.airStreamMaxEntityHeight = getConfig().getDouble("Abilities.Air.AirStream.EntityHeight"); - this.airStreamEntityCarryDuration = getConfig().getLong("Abilities.Air.AirStream.EntityDuration"); + this.airStreamMaxEntityHeight = getConfig().getDouble("Abilities.Air.AirStream.EntityCarry.Height"); + this.airStreamEntityCarryDuration = getConfig().getLong("Abilities.Air.AirStream.EntityCarry.Duration"); if (this.bPlayer.isAvatarState()) { this.cooldown = 0; this.range = getConfig().getDouble("Abilities.Avatar.AvatarState.Air.AirStream.Range"); - this.airStreamMaxEntityHeight = getConfig().getDouble("Abilities.Avatar.AvatarState.Air.AirStream.EntityHeight"); - this.airStreamEntityCarryDuration = getConfig().getDouble("Abilities.Avatar.AvatarState.Air.AirStream.EntityDuration"); + this.airStreamMaxEntityHeight = getConfig().getDouble("Abilities.Avatar.AvatarState.Air.AirStream.EntityCarry.Height"); + this.airStreamEntityCarryDuration = getConfig().getDouble("Abilities.Avatar.AvatarState.Air.AirStream.EntityCarry.Duration"); } this.bPlayer.addCooldown(this); @@ -93,11 +93,6 @@ public class AirStream extends AirAbility implements ComboAbility { this.currentLoc = this.origin.clone(); } final Entity target = GeneralMethods.getTargetedEntity(this.player, this.range); - if (target instanceof Player) { - if (Commands.invincible.contains(((Player) target).getName())) { - return; - } - } if (target != null && target.getLocation().distanceSquared(this.currentLoc) > 49) { this.destination = target.getLocation(); @@ -105,6 +100,11 @@ public class AirStream extends AirAbility implements ComboAbility { this.destination = GeneralMethods.getTargetedLocation(this.player, this.range, getTransparentMaterials()); } + if (GeneralMethods.locationEqualsIgnoreDirection(this.currentLoc, this.destination)) { + this.remove(); + return; + } + this.direction = GeneralMethods.getDirection(this.currentLoc, this.destination).normalize(); this.currentLoc.add(this.direction.clone().multiply(this.speed)); @@ -157,15 +157,13 @@ public class AirStream extends AirAbility implements ComboAbility { } if (!entity.equals(this.player) && !this.affectedEntities.contains(entity)) { this.affectedEntities.add(entity); - if (entity instanceof Player) { - final Player ep = (Player) entity; - ProjectKorra.flightHandler.createInstance(ep, this.player, this.getName()); - this.flights.add(ep); - } } } for (final Entity entity : this.affectedEntities) { + if (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation()) || ((entity instanceof Player) && Commands.invincible.contains(((Player) entity).getName()))) { + continue; + } final Vector force = GeneralMethods.getDirection(entity.getLocation(), this.currentLoc); entity.setVelocity(force.clone().normalize().multiply(this.speed)); entity.setFallDistance(0F); @@ -178,10 +176,6 @@ public class AirStream extends AirAbility implements ComboAbility { for (final BukkitRunnable task : this.tasks) { task.cancel(); } - for (final Player flyer : this.flights) { - ProjectKorra.flightHandler.removeInstance(flyer, this.getName()); - } - this.flights.clear(); } @Override @@ -191,7 +185,7 @@ public class AirStream extends AirAbility implements ComboAbility { @Override public boolean isHarmlessAbility() { - return true; + return false; } @Override @@ -302,16 +296,7 @@ public class AirStream extends AirAbility implements ComboAbility { this.tasks = tasks; } - public Set getFlights() { - return this.flights; - } - public void setCooldown(final long cooldown) { this.cooldown = cooldown; } - - @Override - public String getInstructions() { - return "AirShield (Hold Shift) > AirSuction (Left Click) > AirBlast (Left Click)"; - } } diff --git a/src/com/projectkorra/projectkorra/airbending/combo/AirSweep.java b/src/com/projectkorra/projectkorra/airbending/combo/AirSweep.java index 6410d9b7..5bbfd83d 100644 --- a/src/com/projectkorra/projectkorra/airbending/combo/AirSweep.java +++ b/src/com/projectkorra/projectkorra/airbending/combo/AirSweep.java @@ -3,6 +3,7 @@ package com.projectkorra.projectkorra.airbending.combo; import java.util.ArrayList; import java.util.List; +import com.projectkorra.projectkorra.object.HorizontalVelocityTracker; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; @@ -17,6 +18,7 @@ import com.projectkorra.projectkorra.ability.ComboAbility; import com.projectkorra.projectkorra.ability.util.Collision; import com.projectkorra.projectkorra.ability.util.ComboManager.AbilityInformation; import com.projectkorra.projectkorra.attribute.Attribute; +import com.projectkorra.projectkorra.command.Commands; import com.projectkorra.projectkorra.firebending.combo.FireComboStream; import com.projectkorra.projectkorra.util.ClickType; import com.projectkorra.projectkorra.util.DamageHandler; @@ -24,6 +26,7 @@ import com.projectkorra.projectkorra.util.DamageHandler; public class AirSweep extends AirAbility implements ComboAbility { private int progressCounter; + @Attribute(Attribute.COOLDOWN) private long cooldown; @Attribute(Attribute.DAMAGE) private double damage; @@ -31,7 +34,7 @@ public class AirSweep extends AirAbility implements ComboAbility { private double speed; @Attribute(Attribute.RANGE) private double range; - @Attribute(Attribute.POWER) + @Attribute(Attribute.KNOCKBACK) private double knockback; private Location origin; private Location currentLoc; @@ -129,18 +132,23 @@ public class AirSweep extends AirAbility implements ComboAbility { if (this.origin == null) { this.direction = this.player.getEyeLocation().getDirection().normalize(); - this.origin = this.player.getLocation().add(this.direction.clone().multiply(10)); + this.origin = GeneralMethods.getMainHandLocation(player).add(this.direction.clone().multiply(10)); } if (this.progressCounter < 8) { return; } if (this.destination == null) { - this.destination = this.player.getLocation().add(this.player.getEyeLocation().getDirection().normalize().multiply(10)); + this.destination = GeneralMethods.getMainHandLocation(player).add(GeneralMethods.getMainHandLocation(player).getDirection().normalize().multiply(10)); final Vector origToDest = GeneralMethods.getDirection(this.origin, this.destination); + final Location hand = GeneralMethods.getMainHandLocation(player); for (double i = 0; i < 30; i++) { - final Vector vec = GeneralMethods.getDirection(this.player.getLocation(), this.origin.clone().add(origToDest.clone().multiply(i / 30))); + final Location endLoc = this.origin.clone().add(origToDest.clone().multiply(i / 30)); + if (GeneralMethods.locationEqualsIgnoreDirection(hand, endLoc)) { + continue; + } + final Vector vec = GeneralMethods.getDirection(hand, endLoc); - final FireComboStream fs = new FireComboStream(this.player, this, vec, this.player.getLocation(), this.range, this.speed); + final FireComboStream fs = new FireComboStream(this.player, this, vec, hand, this.range, this.speed); fs.setDensity(1); fs.setSpread(0F); fs.setUseNewParticles(true); @@ -185,17 +193,17 @@ public class AirSweep extends AirAbility implements ComboAbility { this.remove(); return; } - if (!entity.equals(this.player) && !this.affectedEntities.contains(entity)) { - this.affectedEntities.add(entity); + if (!entity.equals(this.player) && !(entity instanceof Player && Commands.invincible.contains(((Player) entity).getName()))) { if (this.knockback != 0) { - final Vector force = fstream.getDirection(); - entity.setVelocity(force.multiply(this.knockback)); + final Vector force = fstream.getLocation().getDirection(); + GeneralMethods.setVelocity(entity, force.clone().multiply(this.knockback)); + new HorizontalVelocityTracker(entity, this.player, 200l, this); + entity.setFallDistance(0); } - if (this.damage != 0) { - if (entity instanceof LivingEntity) { - if (fstream.getAbility().getName().equalsIgnoreCase("AirSweep")) { - DamageHandler.damageEntity(entity, this.damage, this); - } else { + if(!this.affectedEntities.contains(entity)) { + this.affectedEntities.add(entity); + if (this.damage != 0) { + if (entity instanceof LivingEntity) { DamageHandler.damageEntity(entity, this.damage, this); } } @@ -332,9 +340,4 @@ public class AirSweep extends AirAbility implements ComboAbility { public void setTasks(final ArrayList tasks) { this.tasks = tasks; } - - @Override - public String getInstructions() { - return "AirSwipe (Left Click) > AirSwipe (Left Click) > AirBurst (Hold Shift) > AirBurst (Left Click)"; - } } diff --git a/src/com/projectkorra/projectkorra/airbending/combo/Twister.java b/src/com/projectkorra/projectkorra/airbending/combo/Twister.java index 869b0389..9c18fe6f 100644 --- a/src/com/projectkorra/projectkorra/airbending/combo/Twister.java +++ b/src/com/projectkorra/projectkorra/airbending/combo/Twister.java @@ -22,6 +22,7 @@ public class Twister extends AirAbility implements ComboAbility { TWISTER_MOVING, TWISTER_STATIONARY } + @Attribute(Attribute.COOLDOWN) private long cooldown; private long time; @Attribute(Attribute.DAMAGE) @@ -141,12 +142,10 @@ public class Twister extends AirAbility implements ComboAbility { } for (final Entity entity : this.affectedEntities) { - final Vector forceDir = GeneralMethods.getDirection(entity.getLocation(), this.currentLoc.clone().add(0, height, 0)); - if (entity instanceof Player) { - if (Commands.invincible.contains(((Player) entity).getName())) { - break; - } + if (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation()) || ((entity instanceof Player) && Commands.invincible.contains(((Player) entity).getName()))) { + continue; } + final Vector forceDir = GeneralMethods.getDirection(entity.getLocation(), this.currentLoc.clone().add(0, height, 0)); entity.setVelocity(forceDir.clone().normalize().multiply(0.3)); } } @@ -193,9 +192,4 @@ public class Twister extends AirAbility implements ComboAbility { twister.add(new AbilityInformation("AirBlast", ClickType.LEFT_CLICK)); return twister; } - - @Override - public String getInstructions() { - return "AirShield (Tap Shift) > Tornado (Hold Shift) > AirBlast (Left Click)"; - } } diff --git a/src/com/projectkorra/projectkorra/airbending/flight/FlightMultiAbility.java b/src/com/projectkorra/projectkorra/airbending/flight/FlightMultiAbility.java index f6a67a72..ac696629 100644 --- a/src/com/projectkorra/projectkorra/airbending/flight/FlightMultiAbility.java +++ b/src/com/projectkorra/projectkorra/airbending/flight/FlightMultiAbility.java @@ -26,6 +26,7 @@ import com.projectkorra.projectkorra.ability.util.MultiAbilityManager; import com.projectkorra.projectkorra.ability.util.MultiAbilityManager.MultiAbilityInfoSub; import com.projectkorra.projectkorra.airbending.AirScooter; import com.projectkorra.projectkorra.airbending.AirSpout; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.firebending.FireJet; import com.projectkorra.projectkorra.util.ActionBar; import com.projectkorra.projectkorra.util.DamageHandler; @@ -46,10 +47,18 @@ public class FlightMultiAbility extends FlightAbility implements MultiAbility { SOAR, GLIDE, LEVITATE, ENDING; } - public double speed = 1, baseSpeed, slowSpeed, fastSpeed, multiplier; - public FlightMode mode = FlightMode.SOAR; - public long prevCheck = 0, duration; - public Vector prevDir; + private double speed; + private double slowSpeed; + private double fastSpeed; + private double multiplier; + @Attribute(Attribute.SPEED) + private double baseSpeed; + private FlightMode mode = FlightMode.SOAR; + @Attribute(Attribute.DURATION) + private long duration; + @Attribute(Attribute.COOLDOWN) + private long cooldown; + private Vector prevDir; public FlightMultiAbility(final Player player) { super(player); @@ -104,12 +113,15 @@ public class FlightMultiAbility extends FlightAbility implements MultiAbility { } MultiAbilityManager.bindMultiAbility(player, "Flight"); - ProjectKorra.flightHandler.createInstance(player, ID); + this.flightHandler.createInstance(player, ID); this.hadGlide = player.isGliding(); flying.add(player.getUniqueId()); this.prevDir = player.getEyeLocation().getDirection().clone(); this.duration = getConfig().getLong("Abilities.Air.Flight.Duration"); + this.cooldown = getConfig().getLong("Abilities.Air.Flight.Cooldown"); this.baseSpeed = getConfig().getDouble("Abilities.Air.Flight.BaseSpeed"); + + this.speed = 1; this.slowSpeed = this.baseSpeed / 2; this.fastSpeed = this.baseSpeed * 2; this.multiplier = this.baseSpeed; @@ -118,7 +130,7 @@ public class FlightMultiAbility extends FlightAbility implements MultiAbility { @Override public long getCooldown() { - return getConfig().getLong("Abilities.Air.Flight.Cooldown"); + return this.cooldown; } @Override @@ -209,11 +221,7 @@ public class FlightMultiAbility extends FlightAbility implements MultiAbility { } this.prevDir = this.player.getEyeLocation().getDirection().clone(); - } - this.particles(); - - if (this.speed > this.baseSpeed) { for (final Entity e : GeneralMethods.getEntitiesAroundPoint(this.player.getLocation(), this.speed)) { if (e instanceof LivingEntity && e.getEntityId() != this.player.getEntityId() && !this.player.getPassengers().contains(e)) { if (!GeneralMethods.isRegionProtectedFromBuild(this.player, e.getLocation())) { @@ -225,6 +233,7 @@ public class FlightMultiAbility extends FlightAbility implements MultiAbility { } } + this.particles(); this.player.setVelocity(this.player.getEyeLocation().getDirection().clone().multiply(this.multiplier)); } else if (this.mode == FlightMode.GLIDE) { this.player.setAllowFlight(false); @@ -252,8 +261,8 @@ public class FlightMultiAbility extends FlightAbility implements MultiAbility { } private void particles() { - ParticleEffect.CLOUD.display(GeneralMethods.getRightSide(this.player.getLocation(), 0.55).add(this.player.getVelocity().clone()), 0f, 0f, 0f, 0f, 1); - ParticleEffect.CLOUD.display(GeneralMethods.getLeftSide(this.player.getLocation(), 0.55).add(this.player.getVelocity().clone()), 0f, 0f, 0f, 0f, 1); + ParticleEffect.CLOUD.display(GeneralMethods.getRightSide(this.player.getLocation(), 0.55).add(this.player.getVelocity().clone()), 1, 0, 0, 0); + ParticleEffect.CLOUD.display(GeneralMethods.getLeftSide(this.player.getLocation(), 0.55).add(this.player.getVelocity().clone()), 1, 0, 0, 0); } private String speed() { @@ -311,7 +320,7 @@ public class FlightMultiAbility extends FlightAbility implements MultiAbility { if (this.player.isOnline() && !this.player.isDead()) { this.player.eject(); } - ProjectKorra.flightHandler.removeInstance(this.player, ID); + this.flightHandler.removeInstance(this.player, ID); this.player.setGliding(this.hadGlide); } diff --git a/src/com/projectkorra/projectkorra/airbending/passive/AirAgility.java b/src/com/projectkorra/projectkorra/airbending/passive/AirAgility.java index 82e30348..99f796dc 100644 --- a/src/com/projectkorra/projectkorra/airbending/passive/AirAgility.java +++ b/src/com/projectkorra/projectkorra/airbending/passive/AirAgility.java @@ -6,30 +6,26 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import com.projectkorra.projectkorra.ability.AirAbility; -import com.projectkorra.projectkorra.ability.ChiAbility; -import com.projectkorra.projectkorra.ability.CoreAbility; import com.projectkorra.projectkorra.ability.PassiveAbility; -import com.projectkorra.projectkorra.chiblocking.passive.ChiAgility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.configuration.ConfigManager; public class AirAgility extends AirAbility implements PassiveAbility { // Configurable variables. + @Attribute("Jump") private int jumpPower; + @Attribute(Attribute.SPEED) private int speedPower; - // Instance related variables. - private boolean jumpActivate; - private boolean speedActivate; - public AirAgility(final Player player) { super(player); this.setFields(); } public void setFields() { - this.jumpPower = ConfigManager.getConfig().getInt("Abilities.Air.Passive.AirAgility.JumpPower"); - this.speedPower = ConfigManager.getConfig().getInt("Abilities.Air.Passive.AirAgility.SpeedPower"); + this.jumpPower = ConfigManager.getConfig().getInt("Abilities.Air.Passive.AirAgility.JumpPower") - 1; + this.speedPower = ConfigManager.getConfig().getInt("Abilities.Air.Passive.AirAgility.SpeedPower") - 1; } @Override @@ -38,42 +34,13 @@ public class AirAgility extends AirAbility implements PassiveAbility { return; } - if (CoreAbility.hasAbility(this.player, ChiAgility.class) && this.bPlayer.canBendPassive(CoreAbility.getAbility(ChiAbility.class))) { - final ChiAgility chiAgility = CoreAbility.getAbility(this.player, ChiAgility.class); - if (chiAgility.getJumpPower() > this.jumpPower) { - this.jumpPower = chiAgility.getJumpPower(); - } - if (chiAgility.getSpeedPower() > this.speedPower) { - this.speedPower = chiAgility.getSpeedPower(); - } - } - // Jump Buff. - this.jumpActivate = true; - if (this.player.hasPotionEffect(PotionEffectType.JUMP)) { - final PotionEffect potion = this.player.getPotionEffect(PotionEffectType.JUMP); - if (potion.getAmplifier() > this.jumpPower - 1) { - this.jumpActivate = false; - } else { - this.player.removePotionEffect(PotionEffectType.JUMP); - } + if (!this.player.hasPotionEffect(PotionEffectType.JUMP) || this.player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() < this.jumpPower || (this.player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() == this.jumpPower && this.player.getPotionEffect(PotionEffectType.JUMP).getDuration() == 1)) { + this.player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 10, this.jumpPower, true, false), true); } - if (this.jumpActivate) { - this.player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 20, this.jumpPower - 1, true, false), false); - } - // Speed Buff. - this.speedActivate = true; - if (this.player.hasPotionEffect(PotionEffectType.SPEED)) { - final PotionEffect potion = this.player.getPotionEffect(PotionEffectType.SPEED); - if (potion.getAmplifier() > this.speedPower - 1) { - this.speedActivate = false; - } else { - this.player.removePotionEffect(PotionEffectType.SPEED); - } - } - if (this.speedActivate) { - this.player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 20, this.speedPower - 1, true, false), false); + if (!this.player.hasPotionEffect(PotionEffectType.SPEED) || this.player.getPotionEffect(PotionEffectType.SPEED).getAmplifier() < this.speedPower || (this.player.getPotionEffect(PotionEffectType.SPEED).getAmplifier() == this.speedPower && this.player.getPotionEffect(PotionEffectType.SPEED).getDuration() == 1)) { + this.player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 10, this.speedPower, true, false), true); } } diff --git a/src/com/projectkorra/projectkorra/airbending/passive/AirSaturation.java b/src/com/projectkorra/projectkorra/airbending/passive/AirSaturation.java index 434ce514..b64f93fa 100644 --- a/src/com/projectkorra/projectkorra/airbending/passive/AirSaturation.java +++ b/src/com/projectkorra/projectkorra/airbending/passive/AirSaturation.java @@ -17,8 +17,7 @@ public class AirSaturation extends AirAbility implements PassiveAbility { } @Override - public void progress() { - } + public void progress() {} @Override public boolean isSneakAbility() { diff --git a/src/com/projectkorra/projectkorra/airbending/util/AirbendingManager.java b/src/com/projectkorra/projectkorra/airbending/util/AirbendingManager.java index 28b23bf9..d7649e55 100644 --- a/src/com/projectkorra/projectkorra/airbending/util/AirbendingManager.java +++ b/src/com/projectkorra/projectkorra/airbending/util/AirbendingManager.java @@ -2,7 +2,6 @@ package com.projectkorra.projectkorra.airbending.util; import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.airbending.AirBlast; -import com.projectkorra.projectkorra.airbending.AirSuction; public class AirbendingManager implements Runnable { @@ -15,7 +14,6 @@ public class AirbendingManager implements Runnable { @Override public void run() { AirBlast.progressOrigins(); - AirSuction.progressOrigins(); } } diff --git a/src/com/projectkorra/projectkorra/attribute/Attribute.java b/src/com/projectkorra/projectkorra/attribute/Attribute.java index 80c69ed0..9ebe4c3c 100644 --- a/src/com/projectkorra/projectkorra/attribute/Attribute.java +++ b/src/com/projectkorra/projectkorra/attribute/Attribute.java @@ -6,22 +6,10 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) -@Target(value = { ElementType.FIELD }) +@Target(ElementType.FIELD) public @interface Attribute { - /** - * This is the attribute name that is added to the CoreAbility name. E.g. - * Returning "Damage" on a FireBlast ability would make the attribute - * "FireBlastDamage" - */ - String value() default ""; - - /** - * This is for overriding the attribute name if the name you want should not - * come from the CoreAbility name. E.g. Returning "FastSwimSpeed" would make - * the Attribute name "FastSwimSpeed", instead of ability + "FastSwimSpeed" - */ - String attribute() default ""; + public String value(); public static final String SPEED = "Speed"; public static final String RANGE = "Range"; @@ -31,7 +19,9 @@ public @interface Attribute { public static final String DURATION = "Duration"; public static final String RADIUS = "Radius"; public static final String CHARGE_DURATION = "ChargeTime"; - public static final String POWER = "Power"; public static final String WIDTH = "Width"; public static final String HEIGHT = "Height"; + public static final String KNOCKBACK = "Knockback"; + public static final String KNOCKUP = "Knockup"; + public static final String FIRE_TICK = "FireTicks"; } diff --git a/src/com/projectkorra/projectkorra/attribute/AttributeModifier.java b/src/com/projectkorra/projectkorra/attribute/AttributeModifier.java index f9fcb484..d865988b 100644 --- a/src/com/projectkorra/projectkorra/attribute/AttributeModifier.java +++ b/src/com/projectkorra/projectkorra/attribute/AttributeModifier.java @@ -1,64 +1,79 @@ package com.projectkorra.projectkorra.attribute; -import org.bukkit.plugin.Plugin; +public enum AttributeModifier { -import com.projectkorra.projectkorra.ProjectKorra; -import com.projectkorra.projectkorra.ability.CoreAbility; -import com.projectkorra.projectkorra.ability.FireAbility; -import com.projectkorra.projectkorra.ability.WaterAbility; + ADDITION((oldValue, modifier) -> { + if (oldValue instanceof Double || modifier instanceof Double) { + return oldValue.doubleValue() + modifier.doubleValue(); + } else if (oldValue instanceof Float || modifier instanceof Float) { + return oldValue.floatValue() + modifier.floatValue(); + } else if (oldValue instanceof Long || modifier instanceof Long) { + return oldValue.longValue() + modifier.longValue(); + } else if (oldValue instanceof Integer || modifier instanceof Integer) { + return oldValue.intValue() + modifier.intValue(); + } + return 0; + }), SUBTRACTION((oldValue, modifier) -> { + if (oldValue instanceof Double || modifier instanceof Double) { + return oldValue.doubleValue() - modifier.doubleValue(); + } else if (oldValue instanceof Float || modifier instanceof Float) { + return oldValue.floatValue() - modifier.floatValue(); + } else if (oldValue instanceof Long || modifier instanceof Long) { + return oldValue.longValue() - modifier.longValue(); + } else if (oldValue instanceof Integer || modifier instanceof Integer) { + return oldValue.intValue() - modifier.intValue(); + } + return 0; + }), MULTIPLICATION((oldValue, modifier) -> { + if (oldValue instanceof Double || modifier instanceof Double) { + return oldValue.doubleValue() * modifier.doubleValue(); + } else if (oldValue instanceof Float || modifier instanceof Float) { + return oldValue.floatValue() * modifier.floatValue(); + } else if (oldValue instanceof Long || modifier instanceof Long) { + return oldValue.longValue() * modifier.longValue(); + } else if (oldValue instanceof Integer || modifier instanceof Integer) { + return oldValue.intValue() * modifier.intValue(); + } + return 0; + }), DIVISION((oldValue, modifier) -> { + if (oldValue instanceof Double || modifier instanceof Double) { + return oldValue.doubleValue() / modifier.doubleValue(); + } else if (oldValue instanceof Float || modifier instanceof Float) { + return oldValue.floatValue() / modifier.floatValue(); + } else if (oldValue instanceof Long || modifier instanceof Long) { + return oldValue.longValue() / modifier.longValue(); + } else if (oldValue instanceof Integer || modifier instanceof Integer) { + return oldValue.intValue() / modifier.intValue(); + } + return 0; + }); -public class AttributeModifier { + private AttributeModifierMethod modifier; - private double modifier = 1.0D; - private final AttributeModifierType type; - - public enum AttributeModifierType { - MULTIPLY, ADDITION - }; - - public AttributeModifier(final String name, final double modifier, final AttributeModifierType type, final Plugin plugin) { + private AttributeModifier(final AttributeModifierMethod modifier) { this.modifier = modifier; - this.type = type; } - public AttributeModifier(final String name, final AttributeModifierType type, final Plugin plugin) { - this(name, 1.0D, type, plugin); - } - - protected AttributeModifier(final String name, final AttributeModifierType type, final double modifier) { - this(name, modifier, type, ProjectKorra.plugin); - } - - /** - * Should return the modifier that should be applied to the Attribute. Is - * called every time it is applied, so the value doesn't have to be final. - * - * @return The modifier - */ - public double getModifier(final CoreAbility ability) { + public AttributeModifierMethod getModifier() { return this.modifier; } - /** - * Returns what type of math should be done with the modifier. - * - * @return The modifier type - */ - public AttributeModifierType getType() { - return this.type; + public Number performModification(final Number oldValue, final Number modifier) { + if (this == DIVISION && modifier.doubleValue() == 0) { + throw new IllegalArgumentException("Attribute modifier for DIVISION cannot be zero!"); + } + return this.modifier.performModification(oldValue, modifier); } - public static AttributeModifier WATERBENDING_NIGHT = new AttributeModifier("WaterbendingNightModifier", AttributeModifierType.MULTIPLY, 1.0) { - @Override - public double getModifier(final CoreAbility ability) { - return WaterAbility.getNightFactor(ability.getPlayer().getWorld()); - } - }; + /** + * Functional interface for modifying fields with the {@link Attribute} + * annotation + */ + @FunctionalInterface + public interface AttributeModifierMethod { + + public Number performModification(Number oldValue, Number modifier); + + } - public static AttributeModifier FIREBENDING_DAY = new AttributeModifier("FirebendingDayModifier", AttributeModifierType.MULTIPLY, 1.0) { - @Override - public double getModifier(final CoreAbility ability) { - return FireAbility.getDayFactor(1.0, ability.getPlayer().getWorld()); - } - }; } diff --git a/src/com/projectkorra/projectkorra/attribute/AttributePriority.java b/src/com/projectkorra/projectkorra/attribute/AttributePriority.java new file mode 100644 index 00000000..bca4d039 --- /dev/null +++ b/src/com/projectkorra/projectkorra/attribute/AttributePriority.java @@ -0,0 +1,7 @@ +package com.projectkorra.projectkorra.attribute; + +public enum AttributePriority { + + LOW, MEDIUM, HIGH; + +} diff --git a/src/com/projectkorra/projectkorra/attribute/Attributes.java b/src/com/projectkorra/projectkorra/attribute/Attributes.java deleted file mode 100644 index aac52eb4..00000000 --- a/src/com/projectkorra/projectkorra/attribute/Attributes.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.projectkorra.projectkorra.attribute; - -import java.lang.reflect.Field; - -import org.bukkit.Bukkit; - -import com.projectkorra.projectkorra.Element; -import com.projectkorra.projectkorra.ability.CoreAbility; -import com.projectkorra.projectkorra.attribute.AttributeModifier.AttributeModifierType; -import com.projectkorra.projectkorra.event.AttributeModifyEvent; - -public class Attributes { - /** - * Modifies all abilities of the provided element for the given attribute - * and modifier - * - * @param element The type of abilities being changed. Can be a subelement. - * @param attribute What attribute to modify - * @param modifier The modifier - */ - public static void modify(final Element element, final String attribute, final AttributeModifier modifier) { - for (final CoreAbility ability : CoreAbility.getAbilitiesByElement(element)) { - modify(ability, attribute, modifier); - } - }; - - /** - * Modifies all the attribute of the provided ability from the given - * attribute and modifier - * - * @param ability The ability to change - * @param attribute What attribute to modify - * @param modifier The modifier - */ - public static void modify(final CoreAbility ability, final String attribute, final AttributeModifier modifier) { - if (ability.getPlayer() == null) { - for (final CoreAbility ability2 : CoreAbility.getAbilities(ability.getClass())) { - modify(ability2, attribute, modifier); - } - return; - } - - for (final Field field : ability.getClass().getDeclaredFields()) { - if (field.isAnnotationPresent(Attribute.class)) { - final Attribute annotation = field.getAnnotation(Attribute.class); - String attrToTest = ability.getName() + annotation.value(); - if (!annotation.attribute().equals("")) { - attrToTest = annotation.attribute(); - } - - if (attrToTest.equalsIgnoreCase(attribute)) { - final boolean flag = field.isAccessible(); - - if (!flag) { - field.setAccessible(true); - } - - try { - if (field.getDeclaringClass().equals(Double.TYPE.getClass())) { - final double oldValue = field.getDouble(ability); - double newValue = modifier.getType() == AttributeModifierType.MULTIPLY ? oldValue * modifier.getModifier(ability) : oldValue + modifier.getModifier(ability); - - final AttributeModifyEvent event = new AttributeModifyEvent(ability, attribute, oldValue, newValue, modifier); - Bukkit.getPluginManager().callEvent(event); - newValue = event.getNewValue(); - - field.setDouble(ability, newValue); - } else if (field.getDeclaringClass().equals(Long.TYPE.getClass())) { - final long oldValue = field.getLong(ability); - long newValue = (long) (modifier.getType() == AttributeModifierType.MULTIPLY ? oldValue * modifier.getModifier(ability) : oldValue + modifier.getModifier(ability)); - - final AttributeModifyEvent event = new AttributeModifyEvent(ability, attribute, oldValue, newValue, modifier); - Bukkit.getPluginManager().callEvent(event); - newValue = (long) event.getNewValue(); - - field.setLong(ability, newValue); - } else if (field.getDeclaringClass().equals(Integer.TYPE.getClass())) { - final int oldValue = field.getInt(ability); - int newValue = (int) (modifier.getType() == AttributeModifierType.MULTIPLY ? oldValue * modifier.getModifier(ability) : oldValue + modifier.getModifier(ability)); - - final AttributeModifyEvent event = new AttributeModifyEvent(ability, attribute, oldValue, newValue, modifier); - Bukkit.getPluginManager().callEvent(event); - newValue = (int) event.getNewValue(); - - field.setInt(ability, newValue); - } - - } - catch (final IllegalArgumentException e) { - e.printStackTrace(); - } - catch (final IllegalAccessException e) { - e.printStackTrace(); - } - - if (!flag) { - field.setAccessible(false); - } - } - } - } - } - -} diff --git a/src/com/projectkorra/projectkorra/avatar/AvatarState.java b/src/com/projectkorra/projectkorra/avatar/AvatarState.java index 9dde2e74..308c0fb3 100644 --- a/src/com/projectkorra/projectkorra/avatar/AvatarState.java +++ b/src/com/projectkorra/projectkorra/avatar/AvatarState.java @@ -64,11 +64,6 @@ public class AvatarState extends AvatarAbility { @Override public void progress() { if (!this.bPlayer.canBendIgnoreBindsCooldowns(this)) { - if (this.player != null) { - if (this.bPlayer.isOnCooldown(this)) { - this.bPlayer.removeCooldown(this); - } - } this.remove(); return; } @@ -85,18 +80,23 @@ public class AvatarState extends AvatarAbility { } private void addPotionEffects() { - final int duration = 70; if (this.regenEnabled) { - this.player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, duration, this.regenPower)); + this.addProgressPotionEffect(PotionEffectType.REGENERATION, this.regenPower); } if (this.speedEnabled) { - this.player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, duration, this.speedPower)); + this.addProgressPotionEffect(PotionEffectType.SPEED, this.speedPower); } if (this.resistanceEnabled) { - this.player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, duration, this.resistancePower)); + this.addProgressPotionEffect(PotionEffectType.DAMAGE_RESISTANCE, this.resistancePower); } if (this.fireResistanceEnabled) { - this.player.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, duration, this.fireResistancePower)); + this.addProgressPotionEffect(PotionEffectType.FIRE_RESISTANCE, this.fireResistancePower); + } + } + + private void addProgressPotionEffect(final PotionEffectType effect, final int power) { + if (!this.player.hasPotionEffect(effect) || this.player.getPotionEffect(effect).getAmplifier() < power || (this.player.getPotionEffect(effect).getAmplifier() == power && this.player.getPotionEffect(effect).getDuration() == 1)) { + this.player.addPotionEffect(new PotionEffect(effect, 10, power, true, false), true); } } diff --git a/src/com/projectkorra/projectkorra/chiblocking/AcrobatStance.java b/src/com/projectkorra/projectkorra/chiblocking/AcrobatStance.java index 63b7f3b3..1c7b6063 100644 --- a/src/com/projectkorra/projectkorra/chiblocking/AcrobatStance.java +++ b/src/com/projectkorra/projectkorra/chiblocking/AcrobatStance.java @@ -9,13 +9,21 @@ import org.bukkit.potion.PotionEffectType; import com.projectkorra.projectkorra.Element; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.ChiAbility; +import com.projectkorra.projectkorra.attribute.Attribute; public class AcrobatStance extends ChiAbility { + @Attribute(Attribute.COOLDOWN) private long cooldown; + @Attribute(Attribute.DURATION) + private long duration; + @Attribute(Attribute.SPEED) private int speed; + @Attribute("Jump") private int jump; + @Attribute("ChiBlockBoost") private double chiBlockBoost; + @Attribute("ParalyzeDodgeBoost") private double paralyzeDodgeBoost; public AcrobatStance(final Player player) { @@ -24,8 +32,9 @@ public class AcrobatStance extends ChiAbility { return; } this.cooldown = getConfig().getLong("Abilities.Chi.AcrobatStance.Cooldown"); - this.speed = getConfig().getInt("Abilities.Chi.AcrobatStance.Speed") + 1; - this.jump = getConfig().getInt("Abilities.Chi.AcrobatStance.Jump") + 1; + this.duration = getConfig().getLong("Abilities.Chi.AcrobatStance.Duration"); + this.speed = getConfig().getInt("Abilities.Chi.AcrobatStance.Speed") - 1; + this.jump = getConfig().getInt("Abilities.Chi.AcrobatStance.Jump") - 1; this.chiBlockBoost = getConfig().getDouble("Abilities.Chi.AcrobatStance.ChiBlockBoost"); this.paralyzeDodgeBoost = getConfig().getDouble("Abilities.Chi.AcrobatStance.ParalyzeChanceDecrease"); @@ -40,7 +49,7 @@ public class AcrobatStance extends ChiAbility { this.start(); this.bPlayer.setStance(this); GeneralMethods.displayMovePreview(player); - player.playSound(player.getLocation(), Sound.ENTITY_ENDERDRAGON_HURT, 0.5F, 2F); + player.playSound(player.getLocation(), Sound.ENTITY_ENDER_DRAGON_HURT, 0.5F, 2F); } @Override @@ -48,13 +57,16 @@ public class AcrobatStance extends ChiAbility { if (!this.bPlayer.canBendIgnoreBinds(this) || !this.bPlayer.hasElement(Element.CHI)) { this.remove(); return; + } else if (this.duration != 0 && System.currentTimeMillis() > this.getStartTime() + this.duration) { + this.remove(); + return; } - if (!this.player.hasPotionEffect(PotionEffectType.SPEED)) { - this.player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 60, this.speed, true)); + if (!this.player.hasPotionEffect(PotionEffectType.SPEED) || this.player.getPotionEffect(PotionEffectType.SPEED).getAmplifier() < this.speed || (this.player.getPotionEffect(PotionEffectType.SPEED).getAmplifier() == this.speed && this.player.getPotionEffect(PotionEffectType.SPEED).getDuration() == 1)) { + this.player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 10, this.speed, true, false), true); } - if (!this.player.hasPotionEffect(PotionEffectType.JUMP)) { - this.player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 60, this.jump, true)); + if (!this.player.hasPotionEffect(PotionEffectType.JUMP) || this.player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() < this.jump || (this.player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() == this.jump && this.player.getPotionEffect(PotionEffectType.JUMP).getDuration() == 1)) { + this.player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 10, this.jump, true, false), true); } } @@ -64,7 +76,7 @@ public class AcrobatStance extends ChiAbility { this.bPlayer.addCooldown(this); this.bPlayer.setStance(null); GeneralMethods.displayMovePreview(this.player); - this.player.playSound(this.player.getLocation(), Sound.ENTITY_ENDERDRAGON_SHOOT, 0.5F, 2F); + this.player.playSound(this.player.getLocation(), Sound.ENTITY_ENDER_DRAGON_SHOOT, 0.5F, 2F); this.player.removePotionEffect(PotionEffectType.SPEED); this.player.removePotionEffect(PotionEffectType.JUMP); } @@ -110,6 +122,14 @@ public class AcrobatStance extends ChiAbility { this.jump = jump; } + public long getDuration() { + return this.duration; + } + + public void setDuration(final long duration) { + this.duration = duration; + } + public double getChiBlockBoost() { return this.chiBlockBoost; } diff --git a/src/com/projectkorra/projectkorra/chiblocking/Paralyze.java b/src/com/projectkorra/projectkorra/chiblocking/Paralyze.java index 007b14bd..a7682dde 100644 --- a/src/com/projectkorra/projectkorra/chiblocking/Paralyze.java +++ b/src/com/projectkorra/projectkorra/chiblocking/Paralyze.java @@ -19,6 +19,8 @@ public class Paralyze extends ChiAbility { @Attribute(Attribute.COOLDOWN) private long cooldown; + @Attribute(Attribute.DURATION) + private long duration; private Entity target; public Paralyze(final Player sourceplayer, final Entity targetentity) { @@ -27,7 +29,11 @@ public class Paralyze extends ChiAbility { return; } this.target = targetentity; + if (!(this.target instanceof LivingEntity)) { + return; + } this.cooldown = getConfig().getLong("Abilities.Chi.Paralyze.Cooldown"); + this.duration = getConfig().getLong("Abilities.Chi.Paralyze.Duration"); this.start(); } @@ -40,13 +46,13 @@ public class Paralyze extends ChiAbility { return; } } - paralyze(this.target); + this.paralyze(this.target); this.bPlayer.addCooldown(this); } this.remove(); } - private static void paralyze(final Entity entity) { + private void paralyze(final Entity entity) { if (entity instanceof Creature) { ((Creature) entity).setTarget(null); } @@ -57,8 +63,8 @@ public class Paralyze extends ChiAbility { } } final MovementHandler mh = new MovementHandler((LivingEntity) entity, CoreAbility.getAbility(Paralyze.class)); - mh.stopWithDuration(getDuration() / 1000 * 20, Element.CHI.getColor() + "* Paralyzed *"); - entity.getWorld().playSound(entity.getLocation(), Sound.ENTITY_ENDERDRAGON_HURT, 2, 0); + mh.stopWithDuration(this.duration / 1000 * 20, Element.CHI.getColor() + "* Paralyzed *"); + entity.getWorld().playSound(entity.getLocation(), Sound.ENTITY_ENDER_DRAGON_HURT, 2, 0); } @Override @@ -86,10 +92,6 @@ public class Paralyze extends ChiAbility { return false; } - public static long getDuration() { - return getConfig().getLong("Abilities.Chi.Paralyze.Duration"); - } - public Entity getTarget() { return this.target; } @@ -98,4 +100,7 @@ public class Paralyze extends ChiAbility { this.target = target; } + public long getDuration() { + return this.duration; + } } diff --git a/src/com/projectkorra/projectkorra/chiblocking/QuickStrike.java b/src/com/projectkorra/projectkorra/chiblocking/QuickStrike.java index 5e416c51..45d0269a 100644 --- a/src/com/projectkorra/projectkorra/chiblocking/QuickStrike.java +++ b/src/com/projectkorra/projectkorra/chiblocking/QuickStrike.java @@ -13,6 +13,7 @@ public class QuickStrike extends ChiAbility { @Attribute(Attribute.DAMAGE) private double damage; + @Attribute("ChiBlockChance") private int blockChance; private Entity target; @Attribute(Attribute.COOLDOWN) diff --git a/src/com/projectkorra/projectkorra/chiblocking/Smokescreen.java b/src/com/projectkorra/projectkorra/chiblocking/Smokescreen.java index e94c33ec..bfa1af99 100644 --- a/src/com/projectkorra/projectkorra/chiblocking/Smokescreen.java +++ b/src/com/projectkorra/projectkorra/chiblocking/Smokescreen.java @@ -3,7 +3,6 @@ package com.projectkorra.projectkorra.chiblocking; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -15,6 +14,7 @@ import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.ChiAbility; import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.command.Commands; +import com.projectkorra.projectkorra.util.ParticleEffect; public class Smokescreen extends ChiAbility { @@ -55,7 +55,7 @@ public class Smokescreen extends ChiAbility { for (int i = 0; i < 125; i++) { final Location newLoc = new Location(loc.getWorld(), loc.getX() + x, loc.getY() + y, loc.getZ() + z); for (int direction = 0; direction < 8; direction++) { - loc.getWorld().playEffect(newLoc, Effect.SMOKE, direction); + ParticleEffect.SMOKE_NORMAL.display(newLoc, 4, 0.5, 0.5, 0.5); } if (z == 2) { z = -2; diff --git a/src/com/projectkorra/projectkorra/chiblocking/SwiftKick.java b/src/com/projectkorra/projectkorra/chiblocking/SwiftKick.java index 7e924db9..eb2e6d09 100644 --- a/src/com/projectkorra/projectkorra/chiblocking/SwiftKick.java +++ b/src/com/projectkorra/projectkorra/chiblocking/SwiftKick.java @@ -1,11 +1,11 @@ package com.projectkorra.projectkorra.chiblocking; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import com.projectkorra.projectkorra.ability.ChiAbility; +import com.projectkorra.projectkorra.ability.ElementalAbility; import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.chiblocking.passive.ChiPassive; import com.projectkorra.projectkorra.util.DamageHandler; @@ -14,6 +14,7 @@ public class SwiftKick extends ChiAbility { @Attribute(Attribute.DAMAGE) private double damage; + @Attribute("ChiBlockChance") private int blockChance; @Attribute(Attribute.COOLDOWN) private long cooldown; @@ -37,7 +38,7 @@ public class SwiftKick extends ChiAbility { this.remove(); return; } - if (this.player.getLocation().subtract(0, 0.5, 0).getBlock().getType() != Material.AIR) { + if (!ElementalAbility.isAir(this.player.getLocation().subtract(0, 0.5, 0).getBlock().getType())) { this.remove(); return; } diff --git a/src/com/projectkorra/projectkorra/chiblocking/WarriorStance.java b/src/com/projectkorra/projectkorra/chiblocking/WarriorStance.java index 6f16daba..6d6d0e8a 100644 --- a/src/com/projectkorra/projectkorra/chiblocking/WarriorStance.java +++ b/src/com/projectkorra/projectkorra/chiblocking/WarriorStance.java @@ -9,11 +9,17 @@ import org.bukkit.potion.PotionEffectType; import com.projectkorra.projectkorra.Element; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.ChiAbility; +import com.projectkorra.projectkorra.attribute.Attribute; public class WarriorStance extends ChiAbility { + @Attribute(Attribute.COOLDOWN) private long cooldown; + @Attribute(Attribute.DURATION) + private long duration; + @Attribute("Strength") private int strength; + @Attribute("Resistance") private int resistance; public WarriorStance(final Player player) { @@ -22,8 +28,9 @@ public class WarriorStance extends ChiAbility { return; } this.cooldown = getConfig().getLong("Abilities.Chi.WarriorStance.Cooldown"); + this.duration = getConfig().getLong("Abilities.Chi.WarriorStance.Duration"); this.strength = getConfig().getInt("Abilities.Chi.WarriorStance.Strength") - 1; - this.resistance = getConfig().getInt("Abilities.Chi.WarriorStance.Resistance"); + this.resistance = getConfig().getInt("Abilities.Chi.WarriorStance.Resistance"); //intended to be negative final ChiAbility stance = this.bPlayer.getStance(); if (stance != null) { @@ -36,7 +43,7 @@ public class WarriorStance extends ChiAbility { this.start(); this.bPlayer.setStance(this); GeneralMethods.displayMovePreview(player); - player.playSound(player.getLocation(), Sound.ENTITY_ENDERDRAGON_HURT, 0.5F, 2F); + player.playSound(player.getLocation(), Sound.ENTITY_ENDER_DRAGON_HURT, 0.5F, 2F); } @Override @@ -44,13 +51,16 @@ public class WarriorStance extends ChiAbility { if (!this.bPlayer.canBendIgnoreBinds(this) || !this.bPlayer.hasElement(Element.CHI)) { this.remove(); return; + } else if (this.duration != 0 && System.currentTimeMillis() > this.getStartTime() + this.duration) { + this.remove(); + return; } - if (!this.player.hasPotionEffect(PotionEffectType.DAMAGE_RESISTANCE)) { - this.player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 60, this.resistance, true)); + if (!this.player.hasPotionEffect(PotionEffectType.DAMAGE_RESISTANCE) || this.player.getPotionEffect(PotionEffectType.DAMAGE_RESISTANCE).getAmplifier() > this.resistance || (this.player.getPotionEffect(PotionEffectType.DAMAGE_RESISTANCE).getAmplifier() == this.resistance && this.player.getPotionEffect(PotionEffectType.DAMAGE_RESISTANCE).getDuration() == 1)) { //special case for negative resistance + this.player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 10, this.resistance, true, false), true); } - if (!this.player.hasPotionEffect(PotionEffectType.INCREASE_DAMAGE)) { - this.player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 60, this.strength, true)); + if (!this.player.hasPotionEffect(PotionEffectType.INCREASE_DAMAGE) || this.player.getPotionEffect(PotionEffectType.INCREASE_DAMAGE).getAmplifier() < this.strength || (this.player.getPotionEffect(PotionEffectType.INCREASE_DAMAGE).getAmplifier() == this.strength && this.player.getPotionEffect(PotionEffectType.INCREASE_DAMAGE).getDuration() == 1)) { + this.player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 10, this.strength, true, false), true); } } @@ -61,7 +71,7 @@ public class WarriorStance extends ChiAbility { this.bPlayer.setStance(null); if (this.player != null) { GeneralMethods.displayMovePreview(this.player); - this.player.playSound(this.player.getLocation(), Sound.ENTITY_ENDERDRAGON_SHOOT, 0.5F, 2F); + this.player.playSound(this.player.getLocation(), Sound.ENTITY_ENDER_DRAGON_SHOOT, 0.5F, 2F); this.player.removePotionEffect(PotionEffectType.DAMAGE_RESISTANCE); this.player.removePotionEffect(PotionEffectType.INCREASE_DAMAGE); } @@ -108,4 +118,12 @@ public class WarriorStance extends ChiAbility { this.resistance = resistance; } + public long getDuration() { + return this.duration; + } + + public void setDuration(final long duration) { + this.duration = duration; + } + } diff --git a/src/com/projectkorra/projectkorra/chiblocking/combo/Immobilize.java b/src/com/projectkorra/projectkorra/chiblocking/combo/Immobilize.java index ad0197ae..0ebef009 100644 --- a/src/com/projectkorra/projectkorra/chiblocking/combo/Immobilize.java +++ b/src/com/projectkorra/projectkorra/chiblocking/combo/Immobilize.java @@ -13,12 +13,16 @@ import com.projectkorra.projectkorra.ability.ChiAbility; import com.projectkorra.projectkorra.ability.ComboAbility; import com.projectkorra.projectkorra.ability.CoreAbility; import com.projectkorra.projectkorra.ability.util.ComboManager.AbilityInformation; +import com.projectkorra.projectkorra.attribute.Attribute; +import com.projectkorra.projectkorra.command.Commands; import com.projectkorra.projectkorra.util.ClickType; import com.projectkorra.projectkorra.util.MovementHandler; public class Immobilize extends ChiAbility implements ComboAbility { + @Attribute(Attribute.DURATION) private long duration; + @Attribute(Attribute.COOLDOWN) private long cooldown; private Entity target; @@ -35,6 +39,9 @@ public class Immobilize extends ChiAbility implements ComboAbility { this.remove(); return; } else { + if (GeneralMethods.isRegionProtectedFromBuild(this, this.target.getLocation()) || ((this.target instanceof Player) && Commands.invincible.contains(((Player) this.target).getName()))) { + return; + } paralyze(this.target, this.duration); this.bPlayer.addCooldown(this); } @@ -58,8 +65,7 @@ public class Immobilize extends ChiAbility implements ComboAbility { } @Override - public void progress() { - } + public void progress() {} @Override public boolean isSneakAbility() { @@ -115,9 +121,4 @@ public class Immobilize extends ChiAbility implements ComboAbility { public void setCooldown(final long cooldown) { this.cooldown = cooldown; } - - @Override - public String getInstructions() { - return "QuickStrike > SwiftKick > QuickStrike > QuickStrike"; - } } diff --git a/src/com/projectkorra/projectkorra/chiblocking/passive/Acrobatics.java b/src/com/projectkorra/projectkorra/chiblocking/passive/Acrobatics.java index 02bfdaa2..7c5daace 100644 --- a/src/com/projectkorra/projectkorra/chiblocking/passive/Acrobatics.java +++ b/src/com/projectkorra/projectkorra/chiblocking/passive/Acrobatics.java @@ -17,8 +17,7 @@ public class Acrobatics extends ChiAbility implements PassiveAbility { } @Override - public void progress() { - } + public void progress() {} @Override public boolean isSneakAbility() { diff --git a/src/com/projectkorra/projectkorra/chiblocking/passive/ChiAgility.java b/src/com/projectkorra/projectkorra/chiblocking/passive/ChiAgility.java index c3265521..4c4af02e 100644 --- a/src/com/projectkorra/projectkorra/chiblocking/passive/ChiAgility.java +++ b/src/com/projectkorra/projectkorra/chiblocking/passive/ChiAgility.java @@ -5,32 +5,27 @@ import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import com.projectkorra.projectkorra.ability.AirAbility; import com.projectkorra.projectkorra.ability.ChiAbility; -import com.projectkorra.projectkorra.ability.CoreAbility; import com.projectkorra.projectkorra.ability.PassiveAbility; -import com.projectkorra.projectkorra.airbending.passive.AirAgility; -import com.projectkorra.projectkorra.chiblocking.AcrobatStance; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.configuration.ConfigManager; public class ChiAgility extends ChiAbility implements PassiveAbility { // Configurable variables. + @Attribute("Jump") private int jumpPower; + @Attribute(Attribute.SPEED) private int speedPower; - // Instance related variables. - private boolean jumpActivate; - private boolean speedActivate; - public ChiAgility(final Player player) { super(player); this.setFields(); } public void setFields() { - this.jumpPower = ConfigManager.getConfig().getInt("Abilities.Chi.Passive.ChiAgility.JumpPower"); - this.speedPower = ConfigManager.getConfig().getInt("Abilities.Chi.Passive.ChiAgility.SpeedPower"); + this.jumpPower = ConfigManager.getConfig().getInt("Abilities.Chi.Passive.ChiAgility.JumpPower") - 1; + this.speedPower = ConfigManager.getConfig().getInt("Abilities.Chi.Passive.ChiAgility.SpeedPower") - 1; } @Override @@ -39,47 +34,13 @@ public class ChiAgility extends ChiAbility implements PassiveAbility { return; } - if (CoreAbility.hasAbility(this.player, AirAgility.class) && this.bPlayer.canBendPassive(CoreAbility.getAbility(AirAbility.class))) { - final AirAgility airAgility = CoreAbility.getAbility(this.player, AirAgility.class); - if (airAgility.getJumpPower() > this.jumpPower) { - this.jumpPower = airAgility.getJumpPower(); - } - if (airAgility.getSpeedPower() > this.speedPower) { - this.speedPower = airAgility.getSpeedPower(); - } - } - - if (hasAbility(this.player, AcrobatStance.class)) { - final AcrobatStance stance = getAbility(this.player, AcrobatStance.class); - this.jumpPower = Math.max(this.jumpPower, stance.getJump()); - this.speedPower = Math.max(this.speedPower, stance.getSpeed()); - } // Jump Buff. - this.jumpActivate = true; - if (this.player.hasPotionEffect(PotionEffectType.JUMP)) { - final PotionEffect potion = this.player.getPotionEffect(PotionEffectType.JUMP); - if (potion.getAmplifier() > this.jumpPower - 1) { - this.jumpActivate = false; - } else { - this.player.removePotionEffect(PotionEffectType.JUMP); - } + if (!this.player.hasPotionEffect(PotionEffectType.JUMP) || this.player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() < this.jumpPower || (this.player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() == this.jumpPower && this.player.getPotionEffect(PotionEffectType.JUMP).getDuration() == 1)) { + this.player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 10, this.jumpPower, true, false), true); } - if (this.jumpActivate) { - this.player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 20, this.jumpPower - 1, true, false), false); - } - // Speed Buff. - this.speedActivate = true; - if (this.player.hasPotionEffect(PotionEffectType.SPEED)) { - final PotionEffect potion = this.player.getPotionEffect(PotionEffectType.SPEED); - if (potion.getAmplifier() > this.speedPower - 1) { - this.speedActivate = false; - } else { - this.player.removePotionEffect(PotionEffectType.SPEED); - } - } - if (this.speedActivate) { - this.player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 20, this.speedPower - 1, true, false), false); + if (!this.player.hasPotionEffect(PotionEffectType.SPEED) || this.player.getPotionEffect(PotionEffectType.SPEED).getAmplifier() < this.speedPower || (this.player.getPotionEffect(PotionEffectType.SPEED).getAmplifier() == this.speedPower && this.player.getPotionEffect(PotionEffectType.SPEED).getDuration() == 1)) { + this.player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 10, this.speedPower, true, false), true); } } diff --git a/src/com/projectkorra/projectkorra/chiblocking/passive/ChiPassive.java b/src/com/projectkorra/projectkorra/chiblocking/passive/ChiPassive.java index fd34dafc..de5113bc 100644 --- a/src/com/projectkorra/projectkorra/chiblocking/passive/ChiPassive.java +++ b/src/com/projectkorra/projectkorra/chiblocking/passive/ChiPassive.java @@ -58,7 +58,7 @@ public class ChiPassive { } bPlayer.blockChi(); - player.getWorld().playSound(player.getLocation(), Sound.ENTITY_ENDERDRAGON_HURT, 2, 0); + player.getWorld().playSound(player.getLocation(), Sound.ENTITY_ENDER_DRAGON_HURT, 2, 0); final long start = System.currentTimeMillis(); new BukkitRunnable() { diff --git a/src/com/projectkorra/projectkorra/chiblocking/passive/ChiSaturation.java b/src/com/projectkorra/projectkorra/chiblocking/passive/ChiSaturation.java index 24b2f46b..af5ec688 100644 --- a/src/com/projectkorra/projectkorra/chiblocking/passive/ChiSaturation.java +++ b/src/com/projectkorra/projectkorra/chiblocking/passive/ChiSaturation.java @@ -17,8 +17,7 @@ public class ChiSaturation extends ChiAbility implements PassiveAbility { } @Override - public void progress() { - } + public void progress() {} @Override public boolean isSneakAbility() { diff --git a/src/com/projectkorra/projectkorra/command/BindCommand.java b/src/com/projectkorra/projectkorra/command/BindCommand.java index c71ebed6..980d2284 100644 --- a/src/com/projectkorra/projectkorra/command/BindCommand.java +++ b/src/com/projectkorra/projectkorra/command/BindCommand.java @@ -69,8 +69,7 @@ public class BindCommand extends PKCommand { if (args.size() == 2) { try { this.bind(sender, args.get(0), Integer.parseInt(args.get(1))); - } - catch (final NumberFormatException ex) { + } catch (final NumberFormatException ex) { GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.wrongNumber); } } diff --git a/src/com/projectkorra/projectkorra/command/ClearCommand.java b/src/com/projectkorra/projectkorra/command/ClearCommand.java index 98d4ad1e..3963554e 100644 --- a/src/com/projectkorra/projectkorra/command/ClearCommand.java +++ b/src/com/projectkorra/projectkorra/command/ClearCommand.java @@ -67,8 +67,7 @@ public class ClearCommand extends PKCommand { } else { GeneralMethods.sendBrandingMessage(sender, ChatColor.YELLOW + this.alreadyEmpty); } - } - catch (final NumberFormatException e) { + } catch (final NumberFormatException e) { GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.wrongNumber); } } diff --git a/src/com/projectkorra/projectkorra/command/Commands.java b/src/com/projectkorra/projectkorra/command/Commands.java index ae2fd2fd..8d23bcdc 100644 --- a/src/com/projectkorra/projectkorra/command/Commands.java +++ b/src/com/projectkorra/projectkorra/command/Commands.java @@ -6,9 +6,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; import org.bukkit.command.PluginCommand; import com.projectkorra.projectkorra.ProjectKorra; @@ -98,26 +96,23 @@ public class Commands { new VersionCommand(); new WhoCommand(); - final CommandExecutor exe = new CommandExecutor() { - @Override - public boolean onCommand(final CommandSender s, final Command c, final String label, final String[] args) { - if (Arrays.asList(commandaliases).contains(label.toLowerCase())) { - if (args.length > 0) { - final List sendingArgs = Arrays.asList(args).subList(1, args.length); - for (final PKCommand command : PKCommand.instances.values()) { - if (Arrays.asList(command.getAliases()).contains(args[0].toLowerCase())) { - command.execute(s, sendingArgs); - return true; - } + final CommandExecutor exe = (s, c, label, args) -> { + if (Arrays.asList(commandaliases).contains(label.toLowerCase())) { + if (args.length > 0) { + final List sendingArgs = Arrays.asList(args).subList(1, args.length); + for (final PKCommand command : PKCommand.instances.values()) { + if (Arrays.asList(command.getAliases()).contains(args[0].toLowerCase())) { + command.execute(s, sendingArgs); + return true; } } - - PKCommand.instances.get("help").execute(s, new ArrayList()); - return true; } - return false; + PKCommand.instances.get("help").execute(s, new ArrayList()); + return true; } + + return false; }; projectkorra.setExecutor(exe); projectkorra.setTabCompleter(new BendingTabComplete()); diff --git a/src/com/projectkorra/projectkorra/command/HelpCommand.java b/src/com/projectkorra/projectkorra/command/HelpCommand.java index d09c9c4b..5d3194d5 100644 --- a/src/com/projectkorra/projectkorra/command/HelpCommand.java +++ b/src/com/projectkorra/projectkorra/command/HelpCommand.java @@ -9,7 +9,6 @@ import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import com.projectkorra.items.command.PKICommand; import com.projectkorra.projectkorra.Element; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.AddonAbility; @@ -18,7 +17,6 @@ import com.projectkorra.projectkorra.ability.CoreAbility; import com.projectkorra.projectkorra.ability.PassiveAbility; import com.projectkorra.projectkorra.ability.util.ComboManager; import com.projectkorra.projectkorra.configuration.ConfigManager; -import com.projectkorra.rpg.commands.RPGCommand; /** * Executor for /bending help. Extends {@link PKCommand}. @@ -68,23 +66,7 @@ public class HelpCommand extends PKCommand { strings.add(command.getProperUse()); } } - if (GeneralMethods.hasItems()) { - for (final PKICommand command : PKICommand.instances.values()) { - if (sender.hasPermission("bendingitems.command." + command.getName())) { - strings.add(command.getProperUse()); - } - } - } - if (GeneralMethods.hasRPG()) { - for (final RPGCommand command : RPGCommand.instances.values()) { - if (sender.hasPermission("bending.command.rpg." + command.getName())) { - strings.add(command.getProperUse()); - } - } - } - if (GeneralMethods.hasSpirits()) { - // spirits commands being added (if needed). - } + Collections.sort(strings); Collections.reverse(strings); strings.add(instances.get("help").getProperUse()); @@ -108,23 +90,7 @@ public class HelpCommand extends PKCommand { for (final PKCommand command : instances.values()) { strings.add(command.getProperUse()); } - if (GeneralMethods.hasItems()) { - for (final PKICommand command : PKICommand.instances.values()) { - if (sender.hasPermission("bendingitems.command." + command.getName())) { - strings.add(command.getProperUse()); - } - } - } - if (GeneralMethods.hasRPG()) { - for (final RPGCommand command : RPGCommand.instances.values()) { - if (sender.hasPermission("bending.command.rpg." + command.getName())) { - strings.add(command.getProperUse()); - } - } - } - if (GeneralMethods.hasSpirits()) { - // spirits commands being added (if needed). - } + for (final String s : this.getPage(strings, ChatColor.GOLD + "Commands: <" + this.required + "> [" + this.optional + "]", Integer.valueOf(arg), true)) { if (firstMessage) { GeneralMethods.sendBrandingMessage(sender, s); diff --git a/src/com/projectkorra/projectkorra/command/PresetCommand.java b/src/com/projectkorra/projectkorra/command/PresetCommand.java index efa04582..97708f6e 100644 --- a/src/com/projectkorra/projectkorra/command/PresetCommand.java +++ b/src/com/projectkorra/projectkorra/command/PresetCommand.java @@ -77,41 +77,45 @@ public class PresetCommand extends PKCommand { bPlayer = BendingPlayer.getBendingPlayer(player); } - // bending preset list. - if (args.size() == 1) { - if (Arrays.asList(listaliases).contains(args.get(0)) && this.hasPermission(sender, "list")) { - boolean firstMessage = true; - - final List presets = Preset.presets.get(player.getUniqueId()); - final List presetNames = new ArrayList(); - - if (presets == null || presets.isEmpty()) { - GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.noPresets); - return; - } - - for (final Preset preset : presets) { - presetNames.add(preset.getName()); - } - - for (final String s : this.getPage(presetNames, ChatColor.GOLD + "Presets: ", 1, false)) { - if (firstMessage) { - GeneralMethods.sendBrandingMessage(sender, s); - firstMessage = false; - } else { - sender.sendMessage(ChatColor.YELLOW + s); - } - } - - return; + int page = 1; + String name = null; + if (args.size() == 1 && !Arrays.asList(listaliases).contains(args.get(0))){ + this.help(sender, false); + } else if (args.size() >= 2) { + if (Arrays.asList(listaliases).contains(args.get(0))) { + page = Integer.parseInt(args.get(1)); } else { - this.help(sender, false); - return; + name = args.get(1); } } - final String name = args.get(1); - if (Arrays.asList(deletealiases).contains(args.get(0)) && this.hasPermission(sender, "delete")) { // bending preset delete name. + // bending preset list. + if (Arrays.asList(listaliases).contains(args.get(0)) && this.hasPermission(sender, "list")) { + boolean firstMessage = true; + + final List presets = Preset.presets.get(player.getUniqueId()); + final List presetNames = new ArrayList(); + + if (presets == null || presets.isEmpty()) { + GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.noPresets); + return; + } + + for (final Preset preset : presets) { + presetNames.add(preset.getName()); + } + + for (final String s : this.getPage(presetNames, ChatColor.GOLD + "Presets: ", page, false)) { + if (firstMessage) { + GeneralMethods.sendBrandingMessage(sender, s); + firstMessage = false; + } else { + sender.sendMessage(ChatColor.YELLOW + s); + } + } + + return; + } else if (Arrays.asList(deletealiases).contains(args.get(0)) && this.hasPermission(sender, "delete")) { // bending preset delete name. if (!Preset.presetExists(player, name)) { GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.noPresetName); return; diff --git a/src/com/projectkorra/projectkorra/command/RemoveCommand.java b/src/com/projectkorra/projectkorra/command/RemoveCommand.java index cd793d28..cd867a16 100644 --- a/src/com/projectkorra/projectkorra/command/RemoveCommand.java +++ b/src/com/projectkorra/projectkorra/command/RemoveCommand.java @@ -16,7 +16,6 @@ import com.projectkorra.projectkorra.configuration.ConfigManager; import com.projectkorra.projectkorra.event.PlayerChangeElementEvent; import com.projectkorra.projectkorra.event.PlayerChangeElementEvent.Result; import com.projectkorra.projectkorra.event.PlayerChangeSubElementEvent; -import com.projectkorra.rpg.RPGMethods; /** * Executor for /bending remove. Extends {@link PKCommand}. @@ -135,9 +134,6 @@ public class RemoveCommand extends PKCommand { GeneralMethods.saveElements(bPlayer); GeneralMethods.saveSubElements(bPlayer); GeneralMethods.removeUnusableAbilities(player.getName()); - if (GeneralMethods.hasRPG()) { - RPGMethods.revokeAvatar(bPlayer.getUUID()); - } if (!player.getName().equalsIgnoreCase(sender.getName())) { GeneralMethods.sendBrandingMessage(sender, ChatColor.YELLOW + this.succesfullyRemovedAllElementsTargetConfirm.replace("{target}", ChatColor.DARK_AQUA + player.getName() + ChatColor.YELLOW)); } diff --git a/src/com/projectkorra/projectkorra/command/StatsCommand.java b/src/com/projectkorra/projectkorra/command/StatsCommand.java index 9f84ae9f..cef2aa8f 100644 --- a/src/com/projectkorra/projectkorra/command/StatsCommand.java +++ b/src/com/projectkorra/projectkorra/command/StatsCommand.java @@ -5,7 +5,6 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -93,9 +92,7 @@ public class StatsCommand extends PKCommand { int page = 1; try { page = Integer.parseInt(args.get(3)); - } - catch (IndexOutOfBoundsException | NumberFormatException e) { - } + } catch (IndexOutOfBoundsException | NumberFormatException e) {} final Object o = object; final int p = page; new BukkitRunnable() { @@ -160,8 +157,7 @@ public class StatsCommand extends PKCommand { final int minIndex = maxIndex - 9; try { uuids.get(minIndex); - } - catch (final IndexOutOfBoundsException e) { + } catch (final IndexOutOfBoundsException e) { messages.add("&7No statistics found."); return messages; } @@ -201,8 +197,7 @@ public class StatsCommand extends PKCommand { } } } - } - catch (final SQLException e) { + } catch (final SQLException e) { e.printStackTrace(); } for (final Player player : ProjectKorra.plugin.getServer().getOnlinePlayers()) { @@ -218,20 +213,17 @@ public class StatsCommand extends PKCommand { } } final List list = new ArrayList<>(uuids); - Collections.sort(list, new Comparator() { - @Override - public int compare(final UUID u1, final UUID u2) { - long value1 = 0; - long value2 = 0; - if (object == null) { - value1 = StatisticsMethods.getStatisticTotal(u1, statistic); - value2 = StatisticsMethods.getStatisticTotal(u2, statistic); - } else { - value1 = StatisticsMethods.getStatistic(u1, object, statistic); - value2 = StatisticsMethods.getStatistic(u2, object, statistic); - } - return (int) (value2 - value1); + Collections.sort(list, (u1, u2) -> { + long value1 = 0; + long value2 = 0; + if (object == null) { + value1 = StatisticsMethods.getStatisticTotal(u1, statistic); + value2 = StatisticsMethods.getStatisticTotal(u2, statistic); + } else { + value1 = StatisticsMethods.getStatistic(u1, object, statistic); + value2 = StatisticsMethods.getStatistic(u2, object, statistic); } + return (int) (value2 - value1); }); return list; } diff --git a/src/com/projectkorra/projectkorra/command/WhoCommand.java b/src/com/projectkorra/projectkorra/command/WhoCommand.java index a337f865..bf49ff86 100644 --- a/src/com/projectkorra/projectkorra/command/WhoCommand.java +++ b/src/com/projectkorra/projectkorra/command/WhoCommand.java @@ -29,9 +29,6 @@ import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ability.CoreAbility; import com.projectkorra.projectkorra.configuration.ConfigManager; -import com.projectkorra.rpg.RPGMethods; -import com.projectkorra.spirits.SpiritElement; -import com.projectkorra.spirits.SpiritPlayer; /** * Executor for /bending who. Extends {@link PKCommand}. @@ -73,14 +70,11 @@ public class WhoCommand extends PKCommand { in.close(); WhoCommand.this.staff.clear(); WhoCommand.this.staff.putAll(updatedstaff); - } - catch (final SocketException e) { + } catch (final SocketException e) { ProjectKorra.log.info("Could not update staff list."); - } - catch (final MalformedURLException e) { + } catch (final MalformedURLException e) { e.printStackTrace(); - } - catch (final IOException e) { + } catch (final IOException e) { e.printStackTrace(); } } @@ -178,8 +172,7 @@ public class WhoCommand extends PKCommand { count++; try { Thread.sleep(delay); - } - catch (final InterruptedException e) { + } catch (final InterruptedException e) { e.printStackTrace(); GeneralMethods.sendBrandingMessage(sender, ChatColor.DARK_RED + WhoCommand.this.databaseOverload); break; @@ -309,18 +302,6 @@ public class WhoCommand extends PKCommand { sender.sendMessage(element.getColor() + "" + (bPlayer.isElementToggled(element) ? "" : ChatColor.STRIKETHROUGH) + "- " + element.getName() + (element.getType() != null ? element.getType().getBender() : "")); if (player_ != null) { for (final SubElement subelement : Element.getSubElements(element)) { - if (GeneralMethods.hasSpirits()) { - final SpiritPlayer sPlayer = SpiritPlayer.getSpiritPlayer(player_); - if (subelement.equals(SpiritElement.DARK) && sPlayer.isLightSpirit()) { - sender.sendMessage(subelement.getColor() + " Is " + sPlayer.getSpirit().getName() + element.getName()); - } - if (subelement.equals(SpiritElement.LIGHT) && sPlayer.isDarkSpirit()) { - sender.sendMessage(subelement.getColor() + " Is " + sPlayer.getSpirit().getName() + element.getName()); - } - if (sPlayer.isSpirit()) { - continue; - } - } if (bPlayer.canUseSubElement(subelement)) { sender.sendMessage(subelement.getColor() + " Can " + (!subelement.getType().equals(ElementType.NO_SUFFIX) ? "" : "use ") + subelement.getName() + subelement.getType().getBend()); } @@ -343,21 +324,12 @@ public class WhoCommand extends PKCommand { } } - if (GeneralMethods.hasRPG()) { - if (RPGMethods.isCurrentAvatar(player.getUniqueId())) { - sender.sendMessage(Element.AVATAR.getColor() + "Current Avatar"); - } else if (RPGMethods.hasBeenAvatar(player.getUniqueId())) { - sender.sendMessage(Element.AVATAR.getColor() + "Former Avatar"); - } - } - if (this.staff.containsKey(uuid.toString())) { sender.sendMessage(this.staff.get(uuid.toString())); } if (player.getPlayer() != null && player.getPlayer().hasPermission("bending.donor")) { - // Requires Servers to define `server-name` in their server.properties file. Example: server-name=My Server. - sender.sendMessage(Element.AVATAR.getColor() + ProjectKorra.plugin.getServer().getServerName() + " Donor"); + sender.sendMessage(Element.AVATAR.getColor() + "Server Donor"); } } diff --git a/src/com/projectkorra/projectkorra/configuration/Config.java b/src/com/projectkorra/projectkorra/configuration/Config.java index bb63cd01..84f2e499 100644 --- a/src/com/projectkorra/projectkorra/configuration/Config.java +++ b/src/com/projectkorra/projectkorra/configuration/Config.java @@ -40,8 +40,7 @@ public class Config { try { this.file.getParentFile().mkdir(); this.plugin.getLogger().info("Generating new directory for " + this.file.getName() + "!"); - } - catch (final Exception e) { + } catch (final Exception e) { this.plugin.getLogger().info("Failed to generate directory!"); e.printStackTrace(); } @@ -51,8 +50,7 @@ public class Config { try { this.file.createNewFile(); this.plugin.getLogger().info("Generating new " + this.file.getName() + "!"); - } - catch (final Exception e) { + } catch (final Exception e) { this.plugin.getLogger().info("Failed to generate " + this.file.getName() + "!"); e.printStackTrace(); } @@ -76,8 +74,7 @@ public class Config { this.create(); try { this.config.load(this.file); - } - catch (final Exception e) { + } catch (final Exception e) { e.printStackTrace(); } } @@ -91,8 +88,7 @@ public class Config { try { this.config.options().copyDefaults(true); this.config.save(this.file); - } - catch (final Exception e) { + } catch (final Exception e) { e.printStackTrace(); } } diff --git a/src/com/projectkorra/projectkorra/configuration/ConfigManager.java b/src/com/projectkorra/projectkorra/configuration/ConfigManager.java index 429e365f..f3408e79 100644 --- a/src/com/projectkorra/projectkorra/configuration/ConfigManager.java +++ b/src/com/projectkorra/projectkorra/configuration/ConfigManager.java @@ -3,6 +3,7 @@ package com.projectkorra.projectkorra.configuration; import java.io.File; import java.util.ArrayList; +import org.bukkit.Material; import org.bukkit.configuration.file.FileConfiguration; public class ConfigManager { @@ -266,9 +267,12 @@ public class ConfigManager { config.addDefault("Abilities.Air.Suffocate.Instructions", "Hold sneak while looking at a target to begin suffocating them. If the target goes out of range, you get damaged, or you release sneak, the ability will cancel."); config.addDefault("Abilities.Air.Suffocate.DeathMessage", "{victim} was asphyxiated by {attacker}'s {ability}"); config.addDefault("Abilities.Air.Combo.Twister.Description", "Create a cyclone of air that travels along the ground grabbing nearby entities."); + config.addDefault("Abilities.Air.Combo.Twister.Instructions", "AirShield (Tap Shift) > Tornado (Hold Shift) > AirBlast (Left Click)"); config.addDefault("Abilities.Air.Combo.AirStream.Description", "Control a large stream of air that grabs onto enemies allowing you to direct them temporarily."); + config.addDefault("Abilities.Air.Combo.AirStream.Instructions", "AirShield (Hold Shift) > AirSuction (Left Click) > AirBlast (Left Click)"); config.addDefault("Abilities.Air.Combo.AirSweep.Description", "Sweep the air in front of you hitting multiple enemies, causing moderate damage and a large knockback. The radius and direction of AirSweep is controlled by moving your mouse in a sweeping motion. For example, if you want to AirSweep upward, then move your mouse upward right after you left click AirBurst"); config.addDefault("Abilities.Air.Combo.AirSweep.DeathMessage", "{victim} was swept away by {attacker}'s {ability}"); + config.addDefault("Abilities.Air.Combo.AirSweep.Instructions", "AirSwipe (Left Click) > AirSwipe (Left Click) > AirBurst (Hold Shift) > AirBurst (Left Click)"); config.addDefault("Abilities.Air.Passive.AirAgility.Description", "AirAgility is a passive ability which enables airbenders to run faster and jump higher."); config.addDefault("Abilities.Air.Passive.AirSaturation.Description", "AirSaturation is a passive ability which causes airbenders' hunger to deplete at a slower rate."); config.addDefault("Abilities.Air.Passive.GracefulDescent.Description", "GracefulDescent is a passive ability which allows airbenders to make a gentle landing, negating all fall damage on any surface."); @@ -311,8 +315,10 @@ public class ConfigManager { config.addDefault("Abilities.Water.WaterSpout.Instructions", "\n" + "(Spout) Left click to activate a spout beneath you and hold spacebar to go higher. If you wish to go lower, simply hold sneak. To disable this ability, left click once again." + "\n" + "(Wave) Left click a water source and hold sneak until water has formed around you. Then, release sneak to ride a water wave that transports you in the direction you're looking. To cancel this water wave, left click with WaterSpout."); config.addDefault("Abilities.Water.Combo.IceBullet.Description", "Using a large cavern of ice, you can punch ice shards at your opponent causing moderate damage. To rapid fire, you must alternate between Left clicking and right clicking with IceBlast."); config.addDefault("Abilities.Water.Combo.IceBullet.DeathMessage", "{victim}'s heart was frozen by {attacker}'s {ability}"); + config.addDefault("Abilities.Water.Combo.IceBullet.Instructions", "WaterBubble (Tap Shift) > IceBlast (Hold Shift) > Wait for ice to Form > Then alternate between Left and Right click with IceBlast"); config.addDefault("Abilities.Water.Combo.IceWave.Description", "PhaseChange your WaterWave into an IceWave that freezes and damages enemies."); config.addDefault("Abilities.Water.Combo.IceWave.DeathMessage", "{victim} was frozen solid by {attacker}'s {ability}"); + config.addDefault("Abilities.Water.Combo.IceWave.Instructions", "Create a WaterSpout Wave > PhaseChange (Left Click)"); config.addDefault("Abilities.Water.Passive.FastSwim.Description", "FastSwim is a passive ability for waterbenders allowing them to travel quickly through the water. Simple hold shift while underwater to propel yourself forward."); config.addDefault("Abilities.Water.Passive.HydroSink.Description", "Hydrosink is a passive ability for waterbenders enabling them to softly land on any waterbendable surface, cancelling all damage."); @@ -350,7 +356,9 @@ public class ConfigManager { config.addDefault("Abilities.Earth.Tremorsense.Description", "This is a pure utility ability for earthbenders. If you are in an area of low-light and are standing on top of an earthbendable block, this ability will automatically turn that block into glowstone, visible *only by you*. If you lose contact with a bendable block, the light will go out as you have lost contact with the earth and cannot 'see' until you can touch earth again. Additionally, if you click with this ability selected, smoke will appear above nearby earth with pockets of air beneath them."); config.addDefault("Abilities.Earth.Tremorsense.Instructions", "Simply left click while on an earthbendable block."); config.addDefault("Abilities.Earth.Combo.EarthDome.Description", "EarthDome allows earthbenders to surround themselves or another entity in earth, temporarily preventing anything from entering or escaping the dome."); + config.addDefault("Abilities.Earth.Combo.EarthDome.Instructions", "(Self) RaiseEarth (Right click) > Shockwave (Right click)\\n(Projection) RaiseEarth(Right click) > Shockwave (Left click)"); config.addDefault("Abilities.Earth.Combo.EarthPillars.Description", "Send players and entities flying into the air and possibly stunning them by raising pillars of earth under their feet, dealing damage initally as well. This combo can also be used by falling from high off the ground and landing while on the Catapult ability"); + config.addDefault("Abilities.Earth.Combo.EarthPillars.Instructions", "Shockwave (Tap sneak) > Shockwave (Hold sneak) > Catapult (Release sneak)"); config.addDefault("Abilities.Earth.Passive.DensityShift.Description", "DensityShift is a passive ability which allows earthbenders to make a firm landing negating all fall damage on any earthbendable surface."); config.addDefault("Abilities.Earth.Passive.FerroControl.Description", "FerroControl is a passive ability which allows metalbenders to simply open and close iron doors by sneaking."); @@ -387,13 +395,18 @@ public class ConfigManager { config.addDefault("Abilities.Fire.WallOfFire.DeathMessage", "{victim} ran into {attacker}'s {ability}"); config.addDefault("Abilities.Fire.Combo.FireKick.Description", "A short ranged arc of fire launches from the player's feet dealing moderate damage to enemies."); config.addDefault("Abilities.Fire.Combo.FireKick.DeathMessage", "{victim} was kicked to the floor, in flames, from {attacker}'s {ability}"); + config.addDefault("Abilities.Fire.Combo.FireKick.Instructions", "FireBlast > FireBlast > (Hold sneak) > FireBlast"); config.addDefault("Abilities.Fire.Combo.FireSpin.Description", "A circular array of fire that causes damage and massive knockback to nearby enemies."); config.addDefault("Abilities.Fire.Combo.FireSpin.DeathMessage", "{victim} was caught in {attacker}'s {ability} inferno"); + config.addDefault("Abilities.Fire.Combo.FireSpin.Instructions", "FireBlast > FireBlast > FireShield (Left Click) > FireShield (Tap Shift)"); config.addDefault("Abilities.Fire.Combo.JetBlaze.Description", "Damages and burns all enemies in the proximity of your FireJet."); config.addDefault("Abilities.Fire.Combo.JetBlaze.DeathMessage", "{victim} was lit ablaze by {attacker}'s {ability}"); + config.addDefault("Abilities.Fire.Combo.JetBlaze.Instructions", "FireJet (Tap Shift) > FireJet (Tap Shift) > Blaze (Tap Shift) > FireJet"); config.addDefault("Abilities.Fire.Combo.JetBlast.Description", "Create an explosive blast that propels your FireJet at higher speeds."); + config.addDefault("Abilities.Fire.Combo.JetBlast.Instructions", "FireJet (Tap Shift) > FireJet (Tap Shift) > FireShield (Tap Shift) > FireJet"); config.addDefault("Abilities.Fire.Combo.FireWheel.Description", "A high-speed wheel of fire that travels along the ground for long distances dealing high damage."); config.addDefault("Abilities.Fire.Combo.FireWheel.DeathMessage", "{victim} was incinerated by {attacker}'s {ability}"); + config.addDefault("Abilities.Fire.Combo.FireWheel.Instructions", "FireShield (Hold Shift) > Right Click a block in front of you twice > Switch to Blaze > Release Shift"); config.addDefault("Commands.Help.Elements.Chi", "Chiblockers focus on bare handed combat, utilizing their agility and speed to stop any bender right in their path. Although they lack the ability to bend any of the other elements, they are great in combat, and a serious threat to any bender. Chiblocking was first shown to be used by Ty Lee in Avatar: The Last Airbender, then later by members of the Equalists in The Legend of Korra.\nEnter /b display Chi for a list of the available chi abilities."); config.addDefault("Abilities.Chi.AcrobatStance.Description", "AcrobatStance gives a Chiblocker a higher probability of blocking a Bender's Chi while granting them a Speed and Jump Boost. It also increases the rate at which the hunger bar depletes."); @@ -416,6 +429,7 @@ public class ConfigManager { config.addDefault("Abilities.Chi.SwiftKick.Instructions", "Jump and left click on a player to swift kick them."); config.addDefault("Abilities.Chi.SwiftKick.DeathMessage", "{victim} was kicked to the floor by {attacker}'s {ability}"); config.addDefault("Abilities.Chi.Combo.Immobilize.Description", "Immobilizes the opponent for several seconds."); + config.addDefault("Abilities.Chi.Combo.Immobilize.Instructions", "QuickStrike > SwiftKick > QuickStrike > QuickStrike"); config.addDefault("Abilities.Chi.Passive.ChiAgility.Description", "ChiAgility is a passive ability which enables chiblockers to run faster and jump higher."); config.addDefault("Abilities.Chi.Passive.ChiSaturation.Description", "ChiSaturation is a passive ability which causes chiblockers' hunger to deplete at a slower rate."); config.addDefault("Abilities.Chi.Passive.Acrobatics.Description", "Acrobatics is a passive ability which negates all fall damage based on a percent chance."); @@ -427,67 +441,104 @@ public class ConfigManager { config = defaultConfig.get(); final ArrayList earthBlocks = new ArrayList(); - earthBlocks.add("DIRT"); - earthBlocks.add("MYCEL"); - earthBlocks.add("GRASS"); - earthBlocks.add("STONE"); - earthBlocks.add("GRAVEL"); - earthBlocks.add("CLAY"); - earthBlocks.add("COAL_ORE"); - earthBlocks.add("REDSTONE_ORE"); - earthBlocks.add("LAPIS_ORE"); - earthBlocks.add("DIAMOND_ORE"); - earthBlocks.add("NETHERRACK"); - earthBlocks.add("COBBLESTONE"); - earthBlocks.add("STEP"); - earthBlocks.add("GRASS_PATH"); + earthBlocks.add(Material.DIRT.toString()); + earthBlocks.add(Material.MYCELIUM.toString()); + earthBlocks.add(Material.STONE.toString()); + earthBlocks.add(Material.GRAVEL.toString()); + earthBlocks.add(Material.CLAY.toString()); + earthBlocks.add(Material.COAL_ORE.toString()); + earthBlocks.add(Material.REDSTONE_ORE.toString()); + earthBlocks.add(Material.LAPIS_ORE.toString()); + earthBlocks.add(Material.DIAMOND_ORE.toString()); + earthBlocks.add(Material.EMERALD_ORE.toString()); + earthBlocks.add(Material.NETHERRACK.toString()); + earthBlocks.add(Material.COBBLESTONE.toString()); + earthBlocks.add(Material.STONE_SLAB.toString()); + earthBlocks.add(Material.COBBLESTONE_SLAB.toString()); + earthBlocks.add(Material.GRASS_BLOCK.toString()); + earthBlocks.add(Material.GRASS_PATH.toString()); + earthBlocks.add(Material.ANDESITE.toString()); + earthBlocks.add(Material.GRANITE.toString()); + earthBlocks.add(Material.DIORITE.toString()); final ArrayList metalBlocks = new ArrayList(); - metalBlocks.add("IRON_ORE"); - metalBlocks.add("GOLD_ORE"); - metalBlocks.add("QUARTZ_ORE"); - metalBlocks.add("IRON_BLOCK"); - metalBlocks.add("GOLD_BLOCK"); - metalBlocks.add("QUARTZ_BLOCK"); + metalBlocks.add(Material.IRON_ORE.toString()); + metalBlocks.add(Material.GOLD_ORE.toString()); + metalBlocks.add(Material.NETHER_QUARTZ_ORE.toString()); + metalBlocks.add(Material.IRON_BLOCK.toString()); + metalBlocks.add(Material.GOLD_BLOCK.toString()); + metalBlocks.add(Material.QUARTZ_BLOCK.toString()); final ArrayList sandBlocks = new ArrayList(); - sandBlocks.add("SAND"); - sandBlocks.add("SANDSTONE"); - sandBlocks.add("RED_SAND"); - sandBlocks.add("RED_SANDSTONE"); + sandBlocks.add(Material.SAND.toString()); + sandBlocks.add(Material.SANDSTONE.toString()); + sandBlocks.add(Material.SANDSTONE_SLAB.toString()); + sandBlocks.add(Material.RED_SAND.toString()); + sandBlocks.add(Material.RED_SANDSTONE.toString()); + sandBlocks.add(Material.RED_SANDSTONE_SLAB.toString()); final ArrayList iceBlocks = new ArrayList(); - iceBlocks.add("ICE"); - iceBlocks.add("PACKED_ICE"); + iceBlocks.add(Material.ICE.toString()); + iceBlocks.add(Material.PACKED_ICE.toString()); + iceBlocks.add(Material.BLUE_ICE.toString()); + iceBlocks.add(Material.FROSTED_ICE.toString()); final ArrayList plantBlocks = new ArrayList(); - plantBlocks.add("SAPLING"); - plantBlocks.add("LEAVES"); - plantBlocks.add("LEAVES_2"); - plantBlocks.add("DEAD_BUSH"); - plantBlocks.add("YELLOW_FLOWER"); - plantBlocks.add("RED_ROSE"); - plantBlocks.add("RED_MUSHROOM"); - plantBlocks.add("BROWN_MUSHROOM"); - plantBlocks.add("CACTUS"); - plantBlocks.add("PUMPKIN"); - plantBlocks.add("HUGE_MUSHROOM_1"); - plantBlocks.add("HUGE_MUSHROOM_2"); - plantBlocks.add("MELON_BLOCK"); - plantBlocks.add("VINE"); - plantBlocks.add("WATER_LILY"); - plantBlocks.add("DOUBLE_PLANT"); - plantBlocks.add("CROPS"); - plantBlocks.add("LONG_GRASS"); - plantBlocks.add("SUGAR_CANE_BLOCK"); - plantBlocks.add("PUMPKIN_STEM"); - plantBlocks.add("MELON_STEM"); + plantBlocks.add(Material.ACACIA_SAPLING.toString()); + plantBlocks.add(Material.BIRCH_SAPLING.toString()); + plantBlocks.add(Material.DARK_OAK_SAPLING.toString()); + plantBlocks.add(Material.JUNGLE_SAPLING.toString()); + plantBlocks.add(Material.OAK_SAPLING.toString()); + plantBlocks.add(Material.SPRUCE_SAPLING.toString()); + plantBlocks.add(Material.ACACIA_LEAVES.toString()); + plantBlocks.add(Material.BIRCH_LEAVES.toString()); + plantBlocks.add(Material.DARK_OAK_LEAVES.toString()); + plantBlocks.add(Material.JUNGLE_LEAVES.toString()); + plantBlocks.add(Material.OAK_LEAVES.toString()); + plantBlocks.add(Material.SPRUCE_LEAVES.toString()); + plantBlocks.add(Material.DEAD_BUSH.toString()); + plantBlocks.add(Material.ORANGE_TULIP.toString()); + plantBlocks.add(Material.PINK_TULIP.toString()); + plantBlocks.add(Material.RED_TULIP.toString()); + plantBlocks.add(Material.WHITE_TULIP.toString()); + plantBlocks.add(Material.ROSE_BUSH.toString()); + plantBlocks.add(Material.BLUE_ORCHID.toString()); + plantBlocks.add(Material.ALLIUM.toString()); + plantBlocks.add(Material.DANDELION.toString()); + plantBlocks.add(Material.LILAC.toString()); + plantBlocks.add(Material.OXEYE_DAISY.toString()); + plantBlocks.add(Material.AZURE_BLUET.toString()); + plantBlocks.add(Material.PEONY.toString()); + plantBlocks.add(Material.SUNFLOWER.toString()); + plantBlocks.add(Material.POPPY.toString()); + plantBlocks.add(Material.FERN.toString()); + plantBlocks.add(Material.LARGE_FERN.toString()); + plantBlocks.add(Material.RED_MUSHROOM.toString()); + plantBlocks.add(Material.RED_MUSHROOM_BLOCK.toString()); + plantBlocks.add(Material.BROWN_MUSHROOM.toString()); + plantBlocks.add(Material.BROWN_MUSHROOM_BLOCK.toString()); + plantBlocks.add(Material.MUSHROOM_STEM.toString()); + plantBlocks.add(Material.CACTUS.toString()); + plantBlocks.add(Material.PUMPKIN.toString()); + plantBlocks.add(Material.PUMPKIN_STEM.toString()); + plantBlocks.add(Material.MELON.toString()); + plantBlocks.add(Material.MELON_STEM.toString()); + plantBlocks.add(Material.VINE.toString()); + plantBlocks.add(Material.LILY_PAD.toString()); + plantBlocks.add(Material.WHEAT.toString()); + plantBlocks.add(Material.BEETROOTS.toString()); + plantBlocks.add(Material.CARROTS.toString()); + plantBlocks.add(Material.POTATOES.toString()); + plantBlocks.add(Material.SUGAR_CANE.toString()); + plantBlocks.add(Material.GRASS.toString()); + plantBlocks.add(Material.TALL_GRASS.toString()); final ArrayList snowBlocks = new ArrayList<>(); - snowBlocks.add("SNOW"); + snowBlocks.add(Material.SNOW.toString()); config.addDefault("Properties.UpdateChecker", true); config.addDefault("Properties.Statistics", true); + config.addDefault("Properties.DatabaseCooldowns", true); config.addDefault("Properties.BendingPreview", true); config.addDefault("Properties.BendingAffectFallingSand.Normal", true); config.addDefault("Properties.BendingAffectFallingSand.NormalStrengthMultiplier", 1.0); @@ -497,6 +548,7 @@ public class ConfigManager { config.addDefault("Properties.TogglePassivesWithAllBending", true); config.addDefault("Properties.SeaLevel", 62); config.addDefault("Properties.ChooseCooldown", 0L); + config.addDefault("Properties.MaxPresets", 10); config.addDefault("Properties.HorizontalCollisionPhysics.Enabled", true); config.addDefault("Properties.HorizontalCollisionPhysics.DamageOnBarrierBlock", false); @@ -512,7 +564,9 @@ public class ConfigManager { config.addDefault("Properties.RegionProtection.RespectLWC", true); config.addDefault("Properties.RegionProtection.Residence.Flag", "bending"); config.addDefault("Properties.RegionProtection.Residence.Respect", true); - config.addDefault("Properties.RegionProtection.Kingdoms", true); + config.addDefault("Properties.RegionProtection.RespectKingdoms", true); + config.addDefault("Properties.RegionProtection.RespectPlotSquared", true); + config.addDefault("Properties.RegionProtection.RespectRedProtect", true); config.addDefault("Properties.RegionProtection.CacheBlockTime", 5000); config.addDefault("Properties.Air.CanBendWithWeapons", false); @@ -523,6 +577,8 @@ public class ConfigManager { config.addDefault("Properties.Air.Sound.Pitch", 2); config.addDefault("Properties.Water.DynamicSourcing", true); + config.addDefault("Properties.Water.FreezePlayerHead", true); + config.addDefault("Properties.Water.FreezePlayerFeet", true); config.addDefault("Properties.Water.CanBendWithWeapons", true); config.addDefault("Properties.Water.IceBlocks", iceBlocks); config.addDefault("Properties.Water.PlantBlocks", plantBlocks); @@ -553,7 +609,7 @@ public class ConfigManager { config.addDefault("Properties.Earth.EarthSound.Sound", "ENTITY_GHAST_SHOOT"); config.addDefault("Properties.Earth.EarthSound.Volume", 1); config.addDefault("Properties.Earth.EarthSound.Pitch", 1); - config.addDefault("Properties.Earth.MetalSound.Sound", "ENTITY_IRONGOLEM_HURT"); + config.addDefault("Properties.Earth.MetalSound.Sound", "ENTITY_IRON_GOLEM_HURT"); config.addDefault("Properties.Earth.MetalSound.Volume", 1); config.addDefault("Properties.Earth.MetalSound.Pitch", 1.25); config.addDefault("Properties.Earth.SandSound.Sound", "BLOCK_SAND_BREAK"); @@ -571,7 +627,7 @@ public class ConfigManager { config.addDefault("Properties.Fire.FireSound.Sound", "BLOCK_FIRE_AMBIENT"); config.addDefault("Properties.Fire.FireSound.Volume", 1); config.addDefault("Properties.Fire.FireSound.Pitch", 1); - config.addDefault("Properties.Fire.CombustionSound.Sound", "ENTITY_FIREWORK_BLAST"); + config.addDefault("Properties.Fire.CombustionSound.Sound", "ENTITY_FIREWORK_ROCKET_BLAST"); config.addDefault("Properties.Fire.CombustionSound.Volume", 1); config.addDefault("Properties.Fire.CombustionSound.Pitch", 0); config.addDefault("Properties.Fire.LightningSound.Sound", "ENTITY_CREEPER_HURT"); @@ -619,8 +675,8 @@ public class ConfigManager { config.addDefault("Abilities.Avatar.AvatarState.Air.Suffocate.Damage", 3); config.addDefault("Abilities.Avatar.AvatarState.Air.Suffocate.Range", 16); config.addDefault("Abilities.Avatar.AvatarState.Air.AirStream.Range", 60); - config.addDefault("Abilities.Avatar.AvatarState.Air.AirStream.EntityHeight", 21); - config.addDefault("Abilities.Avatar.AvatarState.Air.AirStream.EntityDuration", 20000); + config.addDefault("Abilities.Avatar.AvatarState.Air.AirStream.EntityCarry.Height", 21); + config.addDefault("Abilities.Avatar.AvatarState.Air.AirStream.EntityCarry.Duration", 20000); config.addDefault("Abilities.Avatar.AvatarState.Air.AirSweep.Damage", 6); config.addDefault("Abilities.Avatar.AvatarState.Air.AirSweep.Range", 21); config.addDefault("Abilities.Avatar.AvatarState.Air.AirSweep.Knockback", 4); @@ -705,18 +761,20 @@ public class ConfigManager { config.addDefault("Abilities.Avatar.AvatarState.Water.WaterManipulation.Damage", 5); config.addDefault("Abilities.Avatar.AvatarState.Water.IceBlast.Damage", 4); config.addDefault("Abilities.Avatar.AvatarState.Water.IceBlast.Range", 30); + config.addDefault("Abilities.Avatar.AvatarState.Water.IceBlast.Cooldown", 0); + config.addDefault("Abilities.Avatar.AvatarState.Water.IceBullet.Cooldown", 0); config.addDefault("Abilities.Avatar.AvatarState.Water.IceSpike.Damage", 4); config.addDefault("Abilities.Avatar.AvatarState.Water.IceSpike.Range", 30); config.addDefault("Abilities.Avatar.AvatarState.Water.IceSpike.Push", 0.9); config.addDefault("Abilities.Avatar.AvatarState.Water.IceSpike.Height", 7); - config.addDefault("Abilities.Avatar.AvatarState.Water.IceSpike.SlowPower", 3); + config.addDefault("Abilities.Avatar.AvatarState.Water.IceSpike.SlowPotency", 3); config.addDefault("Abilities.Avatar.AvatarState.Water.IceSpike.SlowDuration", 90); config.addDefault("Abilities.Avatar.AvatarState.Water.IceSpike.Field.Damage", 3); config.addDefault("Abilities.Avatar.AvatarState.Water.IceSpike.Field.Radius", 8); config.addDefault("Abilities.Avatar.AvatarState.Water.IceSpike.Field.Push", 1.2); config.addDefault("Abilities.Avatar.AvatarState.Water.IceSpike.Blast.Range", 30); config.addDefault("Abilities.Avatar.AvatarState.Water.IceSpike.Blast.Damage", 3); - config.addDefault("Abilities.Avatar.AvatarState.Water.IceSpike.Blast.SlowPower", 3); + config.addDefault("Abilities.Avatar.AvatarState.Water.IceSpike.Blast.SlowPotency", 3); config.addDefault("Abilities.Avatar.AvatarState.Water.IceSpike.Blast.SlowDuration", 90); config.addDefault("Abilities.Avatar.AvatarState.Water.IceBullet.Damage", 4); config.addDefault("Abilities.Avatar.AvatarState.Water.IceBullet.Range", 16); @@ -724,7 +782,7 @@ public class ConfigManager { config.addDefault("Abilities.Avatar.AvatarState.Water.IceBullet.ShootTime", 12000); config.addDefault("Abilities.Avatar.AvatarState.Water.IceWave.Damage", 4); config.addDefault("Abilities.Avatar.AvatarState.Water.WaterSpout.Height", 20); - config.addDefault("Abilities.Avatar.AvatarState.Water.WaterSpout.Wave.FlightTime", 5000); + config.addDefault("Abilities.Avatar.AvatarState.Water.WaterSpout.Wave.FlightDuration", 5000); config.addDefault("Abilities.Air.Passive.Factor", 0.3); config.addDefault("Abilities.Air.Passive.AirAgility.Enabled", true); @@ -741,8 +799,8 @@ public class ConfigManager { config.addDefault("Abilities.Air.AirBlast.SelectParticles", 4); config.addDefault("Abilities.Air.AirBlast.Particles", 6); config.addDefault("Abilities.Air.AirBlast.Cooldown", 500); - config.addDefault("Abilities.Air.AirBlast.Push.Self", 2.5); - config.addDefault("Abilities.Air.AirBlast.Push.Entities", 3.5); + config.addDefault("Abilities.Air.AirBlast.Push.Self", 2.0); + config.addDefault("Abilities.Air.AirBlast.Push.Entities", 1.6); config.addDefault("Abilities.Air.AirBlast.CanFlickLevers", true); config.addDefault("Abilities.Air.AirBlast.CanOpenDoors", true); config.addDefault("Abilities.Air.AirBlast.CanPressButtons", true); @@ -750,7 +808,7 @@ public class ConfigManager { config.addDefault("Abilities.Air.AirBurst.Enabled", true); config.addDefault("Abilities.Air.AirBurst.FallThreshold", 10); - config.addDefault("Abilities.Air.AirBurst.PushFactor", 1.5); + config.addDefault("Abilities.Air.AirBurst.PushFactor", 2.8); config.addDefault("Abilities.Air.AirBurst.ChargeTime", 1750); config.addDefault("Abilities.Air.AirBurst.Damage", 0); config.addDefault("Abilities.Air.AirBurst.Cooldown", 0); @@ -760,6 +818,7 @@ public class ConfigManager { config.addDefault("Abilities.Air.AirBurst.AngleTheta", 10); config.addDefault("Abilities.Air.AirScooter.Enabled", true); + config.addDefault("Abilities.Air.AirScooter.ShowSitting", false); config.addDefault("Abilities.Air.AirScooter.Speed", 0.675); config.addDefault("Abilities.Air.AirScooter.Interval", 100); config.addDefault("Abilities.Air.AirScooter.Radius", 1); @@ -770,10 +829,12 @@ public class ConfigManager { config.addDefault("Abilities.Air.AirShield.Enabled", true); config.addDefault("Abilities.Air.AirShield.Cooldown", 0); config.addDefault("Abilities.Air.AirShield.Duration", 0); - config.addDefault("Abilities.Air.AirShield.Radius", 7); + config.addDefault("Abilities.Air.AirShield.MaxRadius", 7); + config.addDefault("Abilities.Air.AirShield.InitialRadius", 1); config.addDefault("Abilities.Air.AirShield.Streams", 5); config.addDefault("Abilities.Air.AirShield.Speed", 10); config.addDefault("Abilities.Air.AirShield.Particles", 5); + config.addDefault("Abilities.Air.AirShield.DynamicCooldown", false); config.addDefault("Abilities.Air.AirSpout.Enabled", true); config.addDefault("Abilities.Air.AirSpout.Cooldown", 0); @@ -786,7 +847,8 @@ public class ConfigManager { config.addDefault("Abilities.Air.AirSuction.Range", 20); config.addDefault("Abilities.Air.AirSuction.SelectRange", 10); config.addDefault("Abilities.Air.AirSuction.Radius", 2); - config.addDefault("Abilities.Air.AirSuction.Push", 2.5); + config.addDefault("Abilities.Air.AirSuction.Push.Self", 2.0); + config.addDefault("Abilities.Air.AirSuction.Push.Others", 1.3); config.addDefault("Abilities.Air.AirSuction.Cooldown", 500); config.addDefault("Abilities.Air.AirSuction.Particles", 6); config.addDefault("Abilities.Air.AirSuction.SelectParticles", 6); @@ -811,7 +873,7 @@ public class ConfigManager { config.addDefault("Abilities.Air.Suffocate.Enabled", true); config.addDefault("Abilities.Air.Suffocate.ChargeTime", 500); - config.addDefault("Abilities.Air.Suffocate.Cooldown", 0); + config.addDefault("Abilities.Air.Suffocate.Cooldown", 6500); config.addDefault("Abilities.Air.Suffocate.Range", 20); config.addDefault("Abilities.Air.Suffocate.Damage", 2); config.addDefault("Abilities.Air.Suffocate.DamageInitialDelay", 2); @@ -852,8 +914,8 @@ public class ConfigManager { config.addDefault("Abilities.Air.AirStream.Enabled", true); config.addDefault("Abilities.Air.AirStream.Speed", 0.5); config.addDefault("Abilities.Air.AirStream.Range", 40); - config.addDefault("Abilities.Air.AirStream.EntityDuration", 4000); - config.addDefault("Abilities.Air.AirStream.EntityHeight", 14); + config.addDefault("Abilities.Air.AirStream.EntityCarry.Duration", 4000); + config.addDefault("Abilities.Air.AirStream.EntityCarry.Height", 14); config.addDefault("Abilities.Air.AirStream.Cooldown", 7000); config.addDefault("Abilities.Air.AirSweep.Enabled", true); @@ -872,9 +934,9 @@ public class ConfigManager { config.addDefault("Abilities.Water.Bloodbending.Enabled", true); config.addDefault("Abilities.Water.Bloodbending.CanOnlyBeUsedAtNight", true); config.addDefault("Abilities.Water.Bloodbending.CanBeUsedOnUndeadMobs", true); - config.addDefault("Abilities.Water.Bloodbending.ThrowFactor", 2); + config.addDefault("Abilities.Water.Bloodbending.Knockback", 2); config.addDefault("Abilities.Water.Bloodbending.Range", 10); - config.addDefault("Abilities.Water.Bloodbending.HoldTime", 0); + config.addDefault("Abilities.Water.Bloodbending.Duration", 0); config.addDefault("Abilities.Water.Bloodbending.Cooldown", 3000); config.addDefault("Abilities.Water.Bloodbending.CanOnlyBeUsedDuringFullMoon", true); config.addDefault("Abilities.Water.Bloodbending.CanBloodbendOtherBloodbenders", false); @@ -884,8 +946,7 @@ public class ConfigManager { config.addDefault("Abilities.Water.HealingWaters.Range", 5); config.addDefault("Abilities.Water.HealingWaters.Interval", 750); config.addDefault("Abilities.Water.HealingWaters.ChargeTime", 1000); - config.addDefault("Abilities.Water.HealingWaters.Power", 1); - config.addDefault("Abilities.Water.HealingWaters.HealingDuration", 70); + config.addDefault("Abilities.Water.HealingWaters.PotionPotency", 1); config.addDefault("Abilities.Water.HealingWaters.Duration", 0); config.addDefault("Abilities.Water.HealingWaters.EnableParticles", true); @@ -896,6 +957,7 @@ public class ConfigManager { config.addDefault("Abilities.Water.IceBlast.CollisionRadius", 1.5); config.addDefault("Abilities.Water.IceBlast.Interval", 20); config.addDefault("Abilities.Water.IceBlast.Cooldown", 1500); + config.addDefault("Abilities.Water.IceBlast.AllowSnow", false); config.addDefault("Abilities.Water.IceSpike.Enabled", true); config.addDefault("Abilities.Water.IceSpike.Cooldown", 2000); @@ -905,11 +967,11 @@ public class ConfigManager { config.addDefault("Abilities.Water.IceSpike.Height", 6); config.addDefault("Abilities.Water.IceSpike.Speed", 25); config.addDefault("Abilities.Water.IceSpike.SlowCooldown", 5000); - config.addDefault("Abilities.Water.IceSpike.SlowPower", 2); + config.addDefault("Abilities.Water.IceSpike.SlowPotency", 2); config.addDefault("Abilities.Water.IceSpike.SlowDuration", 70); config.addDefault("Abilities.Water.IceSpike.Field.Damage", 2); config.addDefault("Abilities.Water.IceSpike.Field.Radius", 6); - config.addDefault("Abilities.Water.IceSpike.Field.Push", 1); + config.addDefault("Abilities.Water.IceSpike.Field.Knockup", 1); config.addDefault("Abilities.Water.IceSpike.Field.Cooldown", 2000); config.addDefault("Abilities.Water.IceSpike.Blast.Range", 20); config.addDefault("Abilities.Water.IceSpike.Blast.Damage", 1); @@ -917,7 +979,7 @@ public class ConfigManager { config.addDefault("Abilities.Water.IceSpike.Blast.DeflectRange", 3); config.addDefault("Abilities.Water.IceSpike.Blast.Cooldown", 500); config.addDefault("Abilities.Water.IceSpike.Blast.SlowCooldown", 5000); - config.addDefault("Abilities.Water.IceSpike.Blast.SlowPower", 2); + config.addDefault("Abilities.Water.IceSpike.Blast.SlowPotency", 2); config.addDefault("Abilities.Water.IceSpike.Blast.SlowDuration", 70); config.addDefault("Abilities.Water.IceSpike.Blast.Interval", 20); @@ -948,8 +1010,8 @@ public class ConfigManager { config.addDefault("Abilities.Water.Surge.Wave.Radius", 3); config.addDefault("Abilities.Water.Surge.Wave.Range", 20); config.addDefault("Abilities.Water.Surge.Wave.SelectRange", 12); - config.addDefault("Abilities.Water.Surge.Wave.HorizontalPush", 1); - config.addDefault("Abilities.Water.Surge.Wave.VerticalPush", 0.2); + config.addDefault("Abilities.Water.Surge.Wave.Knockback", 1); + config.addDefault("Abilities.Water.Surge.Wave.Knockup", 0.2); config.addDefault("Abilities.Water.Surge.Wave.MaxFreezeRadius", 7); config.addDefault("Abilities.Water.Surge.Wave.Cooldown", 500); config.addDefault("Abilities.Water.Surge.Wave.Interval", 30); @@ -968,10 +1030,10 @@ public class ConfigManager { config.addDefault("Abilities.Water.Torrent.SuccessiveDamage", 1); config.addDefault("Abilities.Water.Torrent.MaxLayer", 3); config.addDefault("Abilities.Water.Torrent.MaxHits", 2); - config.addDefault("Abilities.Water.Torrent.Push", 1); + config.addDefault("Abilities.Water.Torrent.Knockback", 1); config.addDefault("Abilities.Water.Torrent.Angle", 20); config.addDefault("Abilities.Water.Torrent.Radius", 3); - config.addDefault("Abilities.Water.Torrent.MaxUpwardForce", 0.2); + config.addDefault("Abilities.Water.Torrent.Knockup", 0.2); config.addDefault("Abilities.Water.Torrent.Interval", 30); config.addDefault("Abilities.Water.Torrent.Cooldown", 0); config.addDefault("Abilities.Water.Torrent.Revert", true); @@ -1015,14 +1077,14 @@ public class ConfigManager { config.addDefault("Abilities.Water.WaterArms.Whip.Pull.Multiplier", 0.15); - config.addDefault("Abilities.Water.WaterArms.Whip.Punch.PunchDamage", 0.5); + config.addDefault("Abilities.Water.WaterArms.Whip.Punch.Damage", 0.5); config.addDefault("Abilities.Water.WaterArms.Whip.Punch.MaxLength", 8); config.addDefault("Abilities.Water.WaterArms.Whip.Punch.NightAugments.MaxLength.Normal", 11); config.addDefault("Abilities.Water.WaterArms.Whip.Punch.NightAugments.MaxLength.FullMoon", 13); config.addDefault("Abilities.Water.WaterArms.Whip.Grapple.RespectRegions", false); - config.addDefault("Abilities.Water.WaterArms.Whip.Grab.HoldTime", 3500); + config.addDefault("Abilities.Water.WaterArms.Whip.Grab.Duration", 3500); config.addDefault("Abilities.Water.WaterArms.Freeze.Range", 20); config.addDefault("Abilities.Water.WaterArms.Freeze.Damage", 2); @@ -1030,7 +1092,7 @@ public class ConfigManager { config.addDefault("Abilities.Water.WaterArms.Spear.Range", 30); config.addDefault("Abilities.Water.WaterArms.Spear.Damage", 3); config.addDefault("Abilities.Water.WaterArms.Spear.DamageEnabled", true); - config.addDefault("Abilities.Water.WaterArms.Spear.Sphere", 2); + config.addDefault("Abilities.Water.WaterArms.Spear.SphereRadius", 2); config.addDefault("Abilities.Water.WaterArms.Spear.Duration", 4500); config.addDefault("Abilities.Water.WaterArms.Spear.Length", 18); @@ -1056,7 +1118,7 @@ public class ConfigManager { config.addDefault("Abilities.Water.WaterManipulation.CollisionRadius", 1.5); config.addDefault("Abilities.Water.WaterManipulation.DeflectRange", 3); config.addDefault("Abilities.Water.WaterManipulation.Speed", 35); - config.addDefault("Abilities.Water.WaterManipulation.Push", 0.3); + config.addDefault("Abilities.Water.WaterManipulation.Knockback", 0.3); config.addDefault("Abilities.Water.WaterManipulation.Cooldown", 1000); config.addDefault("Abilities.Water.WaterSpout.Enabled", true); @@ -1074,7 +1136,7 @@ public class ConfigManager { config.addDefault("Abilities.Water.WaterSpout.Wave.SelectRange", 6); config.addDefault("Abilities.Water.WaterSpout.Wave.AnimationSpeed", 1.2); config.addDefault("Abilities.Water.WaterSpout.Wave.ChargeTime", 500); - config.addDefault("Abilities.Water.WaterSpout.Wave.FlightTime", 2500); + config.addDefault("Abilities.Water.WaterSpout.Wave.FlightDuration", 2500); config.addDefault("Abilities.Water.WaterSpout.Wave.Speed", 1.3); config.addDefault("Abilities.Water.WaterSpout.Wave.Cooldown", 6000); @@ -1093,6 +1155,7 @@ public class ConfigManager { config.addDefault("Abilities.Water.IceBullet.AnimationSpeed", 1); config.addDefault("Abilities.Water.IceBullet.ShootTime", 10000); config.addDefault("Abilities.Water.IceBullet.Cooldown", 10000); + config.addDefault("Abilities.Water.IceBullet.ShotCooldown", 500); config.addDefault("Abilities.Earth.Passive.Duration", 2500); config.addDefault("Abilities.Earth.Passive.DensityShift.Enabled", true); @@ -1153,7 +1216,9 @@ public class ConfigManager { config.addDefault("Abilities.Earth.EarthTunnel.Radius", 0.25); config.addDefault("Abilities.Earth.EarthTunnel.Revert", true); config.addDefault("Abilities.Earth.EarthTunnel.DropLootIfNotRevert", false); + config.addDefault("Abilities.Earth.EarthTunnel.IgnoreOres", false); config.addDefault("Abilities.Earth.EarthTunnel.Interval", 30); + config.addDefault("Abilities.Earth.EarthTunnel.BlocksPerInterval", 1); config.addDefault("Abilities.Earth.Extraction.Enabled", true); config.addDefault("Abilities.Earth.Extraction.SelectRange", 5); @@ -1185,37 +1250,37 @@ public class ConfigManager { config.addDefault("Abilities.Earth.LavaFlow.RevertMaterial", "STONE"); config.addDefault("Abilities.Earth.EarthSmash.Enabled", true); - config.addDefault("Abilities.Earth.EarthSmash.AllowGrab", true); - config.addDefault("Abilities.Earth.EarthSmash.AllowFlight", true); - config.addDefault("Abilities.Earth.EarthSmash.GrabRange", 16); + config.addDefault("Abilities.Earth.EarthSmash.Duration", 30000); config.addDefault("Abilities.Earth.EarthSmash.SelectRange", 12); config.addDefault("Abilities.Earth.EarthSmash.ChargeTime", 1500); config.addDefault("Abilities.Earth.EarthSmash.Cooldown", 3000); - config.addDefault("Abilities.Earth.EarthSmash.ShootRange", 25); config.addDefault("Abilities.Earth.EarthSmash.Damage", 5); config.addDefault("Abilities.Earth.EarthSmash.Knockback", 3.5); config.addDefault("Abilities.Earth.EarthSmash.Knockup", 0.15); - config.addDefault("Abilities.Earth.EarthSmash.FlightSpeed", 0.72); - config.addDefault("Abilities.Earth.EarthSmash.FlightTimer", 3000); - config.addDefault("Abilities.Earth.EarthSmash.RemoveTimer", 30000); + config.addDefault("Abilities.Earth.EarthSmash.Flight.Enabled", true); + config.addDefault("Abilities.Earth.EarthSmash.Flight.Speed", 0.72); + config.addDefault("Abilities.Earth.EarthSmash.Flight.Duration", 3000); + config.addDefault("Abilities.Earth.EarthSmash.Flight.AnimationInterval", 0); + config.addDefault("Abilities.Earth.EarthSmash.Flight.DetectionRadius", 3.5); + config.addDefault("Abilities.Earth.EarthSmash.Grab.Enabled", true); + config.addDefault("Abilities.Earth.EarthSmash.Grab.Range", 16); + config.addDefault("Abilities.Earth.EarthSmash.Grab.DetectionRadius", 2.5); + config.addDefault("Abilities.Earth.EarthSmash.Shoot.Range", 25); + config.addDefault("Abilities.Earth.EarthSmash.Shoot.AnimationInterval", 25); config.addDefault("Abilities.Earth.EarthSmash.RequiredBendableBlocks", 11); config.addDefault("Abilities.Earth.EarthSmash.MaxBlocksToPassThrough", 3); - config.addDefault("Abilities.Earth.EarthSmash.ShootAnimationInterval", 25); - config.addDefault("Abilities.Earth.EarthSmash.FlightAnimationInterval", 0); config.addDefault("Abilities.Earth.EarthSmash.LiftAnimationInterval", 30); - config.addDefault("Abilities.Earth.EarthSmash.GrabDetectionRadius", 2.5); - config.addDefault("Abilities.Earth.EarthSmash.FlightDetectionRadius", 3.5); config.addDefault("Abilities.Earth.MetalClips.Enabled", true); config.addDefault("Abilities.Earth.MetalClips.Damage", 2); - config.addDefault("Abilities.Earth.MetalClips.CrushDamage", 1); config.addDefault("Abilities.Earth.MetalClips.Range", 10); - config.addDefault("Abilities.Earth.MetalClips.MagnetRange", 20); - config.addDefault("Abilities.Earth.MetalClips.MagnetPower", 0.6); config.addDefault("Abilities.Earth.MetalClips.Cooldown", 6000); - config.addDefault("Abilities.Earth.MetalClips.CrushCooldown", 2000); - config.addDefault("Abilities.Earth.MetalClips.MagnetCooldown", 1000); config.addDefault("Abilities.Earth.MetalClips.Duration", 10000); + config.addDefault("Abilities.Earth.MetalClips.Magnet.Range", 20); + config.addDefault("Abilities.Earth.MetalClips.Magnet.Speed", 0.6); + config.addDefault("Abilities.Earth.MetalClips.Magnet.Cooldown", 1000); + config.addDefault("Abilities.Earth.MetalClips.Crush.Damage", 1); + config.addDefault("Abilities.Earth.MetalClips.Crush.Cooldown", 2000); config.addDefault("Abilities.Earth.MetalClips.ThrowEnabled", true); config.addDefault("Abilities.Earth.RaiseEarth.Enabled", true); @@ -1247,7 +1312,7 @@ public class ConfigManager { config.addDefault("Abilities.Earth.EarthPillars.Enabled", true); config.addDefault("Abilities.Earth.EarthPillars.Cooldown", 8000); config.addDefault("Abilities.Earth.EarthPillars.Radius", 9); - config.addDefault("Abilities.Earth.EarthPillars.Power", 1.2); + config.addDefault("Abilities.Earth.EarthPillars.Knockup", 1.2); config.addDefault("Abilities.Earth.EarthPillars.Damage.Enabled", true); config.addDefault("Abilities.Earth.EarthPillars.Damage.Value", 2); config.addDefault("Abilities.Earth.EarthPillars.FallThreshold", 12); @@ -1264,7 +1329,7 @@ public class ConfigManager { config.addDefault("Abilities.Fire.Combustion.Enabled", true); config.addDefault("Abilities.Fire.Combustion.Cooldown", 10000); config.addDefault("Abilities.Fire.Combustion.BreakBlocks", false); - config.addDefault("Abilities.Fire.Combustion.Power", 1.0); + config.addDefault("Abilities.Fire.Combustion.ExplosivePower", 1.0); config.addDefault("Abilities.Fire.Combustion.Damage", 4); config.addDefault("Abilities.Fire.Combustion.Radius", 4); config.addDefault("Abilities.Fire.Combustion.Range", 35); @@ -1274,7 +1339,7 @@ public class ConfigManager { config.addDefault("Abilities.Fire.FireBlast.Speed", 20); config.addDefault("Abilities.Fire.FireBlast.Range", 20); config.addDefault("Abilities.Fire.FireBlast.CollisionRadius", 1.5); - config.addDefault("Abilities.Fire.FireBlast.Push", 0.3); + config.addDefault("Abilities.Fire.FireBlast.Knockback", 0.3); config.addDefault("Abilities.Fire.FireBlast.Damage", 3); config.addDefault("Abilities.Fire.FireBlast.Cooldown", 1500); config.addDefault("Abilities.Fire.FireBlast.Dissipate", false); @@ -1282,6 +1347,7 @@ public class ConfigManager { config.addDefault("Abilities.Fire.FireBlast.SmokeParticleRadius", 0.3); config.addDefault("Abilities.Fire.FireBlast.FlameParticleRadius", 0.275); config.addDefault("Abilities.Fire.FireBlast.Charged.ChargeTime", 3000); + config.addDefault("Abilities.Fire.FireBlast.Charged.Cooldown", 2000); config.addDefault("Abilities.Fire.FireBlast.Charged.CollisionRadius", 2); config.addDefault("Abilities.Fire.FireBlast.Charged.Damage", 4); config.addDefault("Abilities.Fire.FireBlast.Charged.DamageRadius", 4); @@ -1304,6 +1370,7 @@ public class ConfigManager { config.addDefault("Abilities.Fire.FireJet.Speed", 0.8); config.addDefault("Abilities.Fire.FireJet.Duration", 2000); config.addDefault("Abilities.Fire.FireJet.Cooldown", 7000); + config.addDefault("Abilities.Fire.FireJet.ShowGliding", false); config.addDefault("Abilities.Fire.FireManipulation.Enabled", false); @@ -1326,8 +1393,8 @@ public class ConfigManager { config.addDefault("Abilities.Fire.FireShield.Disc.Radius", 1.5); config.addDefault("Abilities.Fire.FireShield.Disc.Duration", 1000); config.addDefault("Abilities.Fire.FireShield.Disc.Cooldown", 500); - config.addDefault("Abilities.Fire.FireShield.Interval", 100); - config.addDefault("Abilities.Fire.FireShield.FireTicks", 2); + config.addDefault("Abilities.Fire.FireShield.Shield.FireTicks", 2); + config.addDefault("Abilities.Fire.FireShield.Disc.FireTicks", 2); config.addDefault("Abilities.Fire.HeatControl.Enabled", true); config.addDefault("Abilities.Fire.HeatControl.Cook.Interval", 1000); @@ -1426,9 +1493,10 @@ public class ConfigManager { config.addDefault("Abilities.Chi.AcrobatStance.Enabled", true); config.addDefault("Abilities.Chi.AcrobatStance.Cooldown", 0); + config.addDefault("Abilities.Chi.AcrobatStance.Duration", 0); config.addDefault("Abilities.Chi.AcrobatStance.ChiBlockBoost", 3); - config.addDefault("Abilities.Chi.AcrobatStance.Speed", 1); - config.addDefault("Abilities.Chi.AcrobatStance.Jump", 1); + config.addDefault("Abilities.Chi.AcrobatStance.Speed", 3); + config.addDefault("Abilities.Chi.AcrobatStance.Jump", 3); config.addDefault("Abilities.Chi.HighJump.Enabled", true); config.addDefault("Abilities.Chi.HighJump.Height", 1.3); @@ -1451,6 +1519,7 @@ public class ConfigManager { config.addDefault("Abilities.Chi.WarriorStance.Enabled", true); config.addDefault("Abilities.Chi.WarriorStance.Cooldown", 0); + config.addDefault("Abilities.Chi.WarriorStance.Duration", 0); config.addDefault("Abilities.Chi.WarriorStance.Strength", 1); config.addDefault("Abilities.Chi.WarriorStance.Resistance", -3); diff --git a/src/com/projectkorra/projectkorra/earthbending/Catapult.java b/src/com/projectkorra/projectkorra/earthbending/Catapult.java index 78e8fb64..78bfe6bd 100644 --- a/src/com/projectkorra/projectkorra/earthbending/Catapult.java +++ b/src/com/projectkorra/projectkorra/earthbending/Catapult.java @@ -4,21 +4,23 @@ import java.util.Random; import org.bukkit.Effect; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.block.data.BlockData; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.util.Vector; +import com.projectkorra.projectkorra.command.Commands; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.EarthAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.util.ParticleEffect; -import com.projectkorra.projectkorra.util.ParticleEffect.BlockData; public class Catapult extends EarthAbility { private double stageTimeMult; + @Attribute(Attribute.COOLDOWN) private long cooldown; private Location origin; private Location target; @@ -30,6 +32,7 @@ public class Catapult extends EarthAbility { private Vector up; private double angle; private boolean cancelWithAngle; + private BlockData bentBlockData; public Catapult(final Player player, final boolean sneak) { super(player); @@ -38,12 +41,17 @@ public class Catapult extends EarthAbility { if (!(isEarth(b) || isSand(b) || isMetal(b))) { return; } + + this.bentBlockData = b.getBlockData(); + if (!this.bPlayer.canBend(this)) { return; } + if (this.bPlayer.isAvatarState()) { this.cooldown = getConfig().getLong("Abilities.Avatar.AvatarState.Earth.Catapult.Cooldown"); } + this.charging = sneak; this.start(); } @@ -62,6 +70,9 @@ public class Catapult extends EarthAbility { private void moveEarth(final Vector apply, final Vector direction) { for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(this.origin, 2)) { if (entity.getEntityId() != this.player.getEntityId()) { + if (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation()) || ((entity instanceof Player) && Commands.invincible.contains(((Player) entity).getName()))) { + continue; + } entity.setVelocity(apply); } } @@ -75,6 +86,14 @@ public class Catapult extends EarthAbility { return; } + final Block b = this.player.getLocation().getBlock().getRelative(BlockFace.DOWN, 1); + if (!(isEarth(b) || isSand(b) || isMetal(b))) { + this.remove(); + return; + } + + this.bentBlockData = b.getBlockData(); + if (this.charging) { if (this.stage == 4 || !this.player.isSneaking()) { this.charging = false; @@ -83,20 +102,14 @@ public class Catapult extends EarthAbility { this.stage++; this.stageStart = System.currentTimeMillis(); final Random random = new Random(); - ParticleEffect.BLOCK_DUST.display(new BlockData(Material.DIRT, (byte) 0), random.nextFloat(), random.nextFloat(), random.nextFloat(), 0, 20, this.player.getLocation(), 257); - ParticleEffect.BLOCK_DUST.display(new BlockData(Material.DIRT, (byte) 0), random.nextFloat(), random.nextFloat(), random.nextFloat(), 0, 20, this.player.getLocation().add(0, 0.5, 0), 257); + ParticleEffect.BLOCK_DUST.display(this.player.getLocation(), 15, random.nextFloat(), random.nextFloat(), random.nextFloat(), this.bentBlockData); + ParticleEffect.BLOCK_DUST.display(this.player.getLocation().add(0, 0.5, 0), 10, random.nextFloat(), random.nextFloat(), random.nextFloat(), this.bentBlockData); this.player.getWorld().playEffect(this.player.getLocation(), Effect.GHAST_SHOOT, 0, 10); } } return; } - final Block b = this.player.getLocation().getBlock().getRelative(BlockFace.DOWN, 1); - if (!(isEarth(b) || isSand(b) || isMetal(b))) { - this.remove(); - return; - } - Vector direction = null; if (!this.activationHandled) { this.origin = this.player.getLocation().clone(); diff --git a/src/com/projectkorra/projectkorra/earthbending/Collapse.java b/src/com/projectkorra/projectkorra/earthbending/Collapse.java index 9ddeb79d..1bcf02ac 100644 --- a/src/com/projectkorra/projectkorra/earthbending/Collapse.java +++ b/src/com/projectkorra/projectkorra/earthbending/Collapse.java @@ -11,16 +11,21 @@ import org.bukkit.entity.Player; import org.bukkit.util.Vector; import com.projectkorra.projectkorra.ability.EarthAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.util.BlockSource; import com.projectkorra.projectkorra.util.ClickType; public class Collapse extends EarthAbility { private int distance; + @Attribute(Attribute.HEIGHT) private int height; private long time; + @Attribute(Attribute.COOLDOWN) private long cooldown; + @Attribute(Attribute.SELECT_RANGE) private double selectRange; + @Attribute(Attribute.SPEED) private double speed; private Location origin; private Location location; @@ -93,7 +98,7 @@ public class Collapse extends EarthAbility { thisBlock = this.block.getWorld().getBlockAt(this.location.clone().add(this.direction.clone().multiply(-i))); this.affectedBlocks.put(thisBlock, thisBlock); if (RaiseEarth.blockInAllAffectedBlocks(thisBlock)) { - EarthAbility.revertBlock(thisBlock); + RaiseEarth.revertAffectedBlock(thisBlock); } } } diff --git a/src/com/projectkorra/projectkorra/earthbending/CollapseWall.java b/src/com/projectkorra/projectkorra/earthbending/CollapseWall.java index 61422a2a..ff316ff2 100644 --- a/src/com/projectkorra/projectkorra/earthbending/CollapseWall.java +++ b/src/com/projectkorra/projectkorra/earthbending/CollapseWall.java @@ -11,14 +11,19 @@ import org.bukkit.entity.Player; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.EarthAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.util.BlockSource; import com.projectkorra.projectkorra.util.ClickType; public class CollapseWall extends EarthAbility { + @Attribute(Attribute.SELECT_RANGE) private int selectRange; + @Attribute(Attribute.HEIGHT) private int height; + @Attribute(Attribute.COOLDOWN) private long cooldown; + @Attribute(Attribute.RADIUS) private double radius; private Location location; private Map blocks; @@ -92,8 +97,7 @@ public class CollapseWall extends EarthAbility { } @Override - public void progress() { - } + public void progress() {} @Override public Location getLocation() { diff --git a/src/com/projectkorra/projectkorra/earthbending/EarthArmor.java b/src/com/projectkorra/projectkorra/earthbending/EarthArmor.java index 000e9b5c..07bb6393 100644 --- a/src/com/projectkorra/projectkorra/earthbending/EarthArmor.java +++ b/src/com/projectkorra/projectkorra/earthbending/EarthArmor.java @@ -12,7 +12,6 @@ import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.LeatherArmorMeta; -import org.bukkit.material.MaterialData; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.scheduler.BukkitRunnable; @@ -21,6 +20,8 @@ import org.bukkit.util.Vector; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ability.EarthAbility; +import com.projectkorra.projectkorra.ability.ElementalAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.command.Commands; import com.projectkorra.projectkorra.util.ParticleEffect; import com.projectkorra.projectkorra.util.TempArmor; @@ -29,11 +30,14 @@ import com.projectkorra.projectkorra.util.TempBlock; public class EarthArmor extends EarthAbility { private boolean formed; - private MaterialData headData; - private MaterialData legsData; + private Material headMaterial; + private Material legsMaterial; + @Attribute(Attribute.COOLDOWN) private long cooldown; private long interval; + @Attribute(Attribute.DURATION) private long maxDuration; + @Attribute(Attribute.SELECT_RANGE) private double selectRange; private Block headBlock; private Block legsBlock; @@ -42,6 +46,7 @@ public class EarthArmor extends EarthAbility { private boolean active; private PotionEffect oldAbsorbtion = null; private float goldHearts; + @Attribute("GoldHearts") private int maxGoldHearts; private TempArmor armor; @@ -68,8 +73,8 @@ public class EarthArmor extends EarthAbility { this.headBlock = this.getTargetEarthBlock((int) this.selectRange); if (!GeneralMethods.isRegionProtectedFromBuild(this, this.headBlock.getLocation()) && this.getEarthbendableBlocksLength(this.headBlock, new Vector(0, -1, 0), 2) >= 2) { this.legsBlock = this.headBlock.getRelative(BlockFace.DOWN); - this.headData = this.headBlock.getState().getData(); - this.legsData = this.legsBlock.getState().getData(); + this.headMaterial = this.headBlock.getType(); + this.legsMaterial = this.legsBlock.getType(); this.headBlockLocation = this.headBlock.getLocation(); this.legsBlockLocation = this.legsBlock.getLocation(); @@ -110,10 +115,10 @@ public class EarthArmor extends EarthAbility { final LeatherArmorMeta metaLegs = (LeatherArmorMeta) leggings.getItemMeta(); final LeatherArmorMeta metaBottom = (LeatherArmorMeta) boots.getItemMeta(); - metaHead.setColor(Color.fromRGB(getColor(this.headData.getItemType(), this.headData.getData()))); - metaChest.setColor(Color.fromRGB(getColor(this.headData.getItemType(), this.headData.getData()))); - metaLegs.setColor(Color.fromRGB(getColor(this.legsData.getItemType(), this.legsData.getData()))); - metaBottom.setColor(Color.fromRGB(getColor(this.legsData.getItemType(), this.legsData.getData()))); + metaHead.setColor(Color.fromRGB(getColor(this.headMaterial))); + metaChest.setColor(Color.fromRGB(getColor(this.headMaterial))); + metaLegs.setColor(Color.fromRGB(getColor(this.legsMaterial))); + metaBottom.setColor(Color.fromRGB(getColor(this.legsMaterial))); head.setItemMeta(metaHead); chestplate.setItemMeta(metaChest); @@ -179,17 +184,17 @@ public class EarthArmor extends EarthAbility { if (this.isTransparent(newHeadBlock) && !newHeadBlock.isLiquid()) { GeneralMethods.breakBlock(newHeadBlock); - } else if (!this.isEarthbendable(newHeadBlock) && !newHeadBlock.isLiquid() && newHeadBlock.getType() != Material.AIR) { - ParticleEffect.BLOCK_CRACK.display(new ParticleEffect.BlockData(this.headData.getItemType(), this.headData.getData()), 0.5F, 0.5F, 0.5F, 1, 32, newLegsBlock.getLocation(), 128); + } else if (!this.isEarthbendable(newHeadBlock) && !newHeadBlock.isLiquid() && !ElementalAbility.isAir(newHeadBlock.getType())) { + ParticleEffect.BLOCK_CRACK.display(newHeadBlock.getLocation(), 8, 0.5, 0.5, 0.5, newHeadBlock.getBlockData()); this.remove(); return false; } if (this.isTransparent(newLegsBlock) && !newLegsBlock.isLiquid()) { GeneralMethods.breakBlock(newLegsBlock); - } else if (!this.isEarthbendable(newLegsBlock) && !newLegsBlock.isLiquid() && newLegsBlock.getType() != Material.AIR) { + } else if (!this.isEarthbendable(newLegsBlock) && !newLegsBlock.isLiquid() && !ElementalAbility.isAir(newLegsBlock.getType())) { newLegsBlock.getLocation().getWorld().playSound(newLegsBlock.getLocation(), Sound.BLOCK_GRASS_BREAK, 1, 1); - ParticleEffect.BLOCK_CRACK.display(new ParticleEffect.BlockData(this.legsData.getItemType(), this.legsData.getData()), 0.5F, 0.5F, 0.5F, 1, 32, newLegsBlock.getLocation(), 128); + ParticleEffect.BLOCK_CRACK.display(newHeadBlock.getLocation(), 8, 0.5, 0.5, 0.5, newLegsBlock.getBlockData()); this.remove(); return false; } @@ -200,14 +205,14 @@ public class EarthArmor extends EarthAbility { } if (!newHeadBlock.equals(this.headBlock)) { - new TempBlock(newHeadBlock, this.headData.getItemType(), this.headData.getData()); + new TempBlock(newHeadBlock, this.headMaterial); if (TempBlock.isTempBlock(this.headBlock)) { TempBlock.revertBlock(this.headBlock, Material.AIR); } } if (!newLegsBlock.equals(this.legsBlock)) { - new TempBlock(newLegsBlock, this.legsData.getItemType(), this.legsData.getData()); + new TempBlock(newLegsBlock, this.legsMaterial); if (TempBlock.isTempBlock(this.legsBlock)) { TempBlock.revertBlock(this.legsBlock, Material.AIR); } @@ -229,8 +234,8 @@ public class EarthArmor extends EarthAbility { this.player.getLocation().getWorld().playSound(this.player.getLocation(), Sound.BLOCK_STONE_BREAK, 2, 1); this.player.getLocation().getWorld().playSound(this.player.getLocation(), Sound.BLOCK_STONE_BREAK, 2, 1); - ParticleEffect.BLOCK_CRACK.display(new ParticleEffect.BlockData(this.headData.getItemType(), this.headData.getData()), 0.1F, 0.1F, 0.1F, 1, 32, this.player.getEyeLocation(), 128); - ParticleEffect.BLOCK_CRACK.display(new ParticleEffect.BlockData(this.legsData.getItemType(), this.legsData.getData()), 0.1F, 0.1F, 0.1F, 1, 32, this.player.getLocation(), 128); + ParticleEffect.BLOCK_CRACK.display(this.player.getEyeLocation(), 8, 0.1, 0.1, 0.1, this.headMaterial.createBlockData()); + ParticleEffect.BLOCK_CRACK.display(this.player.getLocation(), 8, 0.1F, 0.1F, 0.1F, this.legsMaterial.createBlockData()); this.bPlayer.addCooldown(this); this.remove(); @@ -292,18 +297,18 @@ public class EarthArmor extends EarthAbility { new BukkitRunnable() { @Override public void run() { - EarthArmor.this.goldHearts = GeneralMethods.getAbsorbationHealth(EarthArmor.this.player); - if (EarthArmor.this.formed && EarthArmor.this.goldHearts < 0.9F) { - EarthArmor.this.bPlayer.addCooldown(abil); + abil.goldHearts = GeneralMethods.getAbsorbationHealth(EarthArmor.this.player); + if (abil.formed && abil.goldHearts < 0.9F) { + abil.bPlayer.addCooldown(abil); - EarthArmor.this.player.getLocation().getWorld().playSound(EarthArmor.this.player.getLocation(), Sound.BLOCK_STONE_BREAK, 2, 1); - EarthArmor.this.player.getLocation().getWorld().playSound(EarthArmor.this.player.getLocation(), Sound.BLOCK_STONE_BREAK, 2, 1); - EarthArmor.this.player.getLocation().getWorld().playSound(EarthArmor.this.player.getLocation(), Sound.BLOCK_STONE_BREAK, 2, 1); + abil.player.getLocation().getWorld().playSound(abil.player.getLocation(), Sound.BLOCK_STONE_BREAK, 2, 1); + abil.player.getLocation().getWorld().playSound(abil.player.getLocation(), Sound.BLOCK_STONE_BREAK, 2, 1); + abil.player.getLocation().getWorld().playSound(abil.player.getLocation(), Sound.BLOCK_STONE_BREAK, 2, 1); - ParticleEffect.BLOCK_CRACK.display(new ParticleEffect.BlockData(EarthArmor.this.headData.getItemType(), EarthArmor.this.headData.getData()), 0.1F, 0.1F, 0.1F, 1, 32, EarthArmor.this.player.getEyeLocation(), 128); - ParticleEffect.BLOCK_CRACK.display(new ParticleEffect.BlockData(EarthArmor.this.legsData.getItemType(), EarthArmor.this.legsData.getData()), 0.1F, 0.1F, 0.1F, 1, 32, EarthArmor.this.player.getLocation(), 128); + ParticleEffect.BLOCK_CRACK.display(abil.player.getEyeLocation(), 8, 0.1, 0.1, 0.1, abil.headMaterial.createBlockData()); + ParticleEffect.BLOCK_CRACK.display(abil.player.getLocation(), 8, 0.1F, 0.1F, 0.1F, abil.legsMaterial.createBlockData()); - EarthArmor.this.remove(); + abil.remove(); } } }.runTaskLater(ProjectKorra.plugin, 1L); @@ -322,31 +327,34 @@ public class EarthArmor extends EarthAbility { if (material == Material.GRASS) { return 0xa86e45; // Default dirt brown. } - if (material == Material.MYCEL) { + if (material == Material.MYCELIUM) { return 0xa86e45; // Default dirt brown. } + if (material == Material.GRASS_BLOCK) { + return 0xa86e45; + } if (material == Material.CLAY) { return 0xBAC2D1; // Dull gray-brown. } - if (material == Material.STONE && damage == 0x0) { + if (material == Material.STONE || material == Material.STONE_BRICKS) { return 0x9e9e9e; // Gray. } - if (material == Material.STONE && (damage == 0x1 || damage == 0x2)) { + if (material == Material.GRANITE || material == Material.POLISHED_GRANITE) { return 0xc69489; // Pink. } - if (material == Material.STONE && (damage == 0x3 || damage == 0x4)) { + if (material == Material.DIORITE || material == Material.POLISHED_DIORITE) { return 0xe3e3e5; // White. } - if (material == Material.STONE && (damage == 0x5 || damage == 0x6)) { + if (material == Material.ANDESITE || material == Material.POLISHED_ANDESITE) { return 0xa3a3a3; // Gray. } if (material == Material.COBBLESTONE) { return 0x6B6B6B; // Dark Gray. } - if (material == Material.SAND && damage == 0x0) { + if (material == Material.SAND) { return 0xffffaf; // Sand yellow. } - if (material == Material.SAND && damage == 0x1) { + if (material == Material.RED_SAND) { return 0xb85f25; // Sand orange. } if (material == Material.SANDSTONE) { @@ -362,7 +370,7 @@ public class EarthArmor extends EarthAbility { return 0xa2a38f; // Gray-yellow. } if (material == Material.GOLD_BLOCK) { - return 0xF2F204; // Gold - Could be a tiny bit darker. + return 0xF1F103; // Gold - Could be a tiny bit darker. } if (material == Material.IRON_ORE) { return 0xa39d91; // Gray-brown. @@ -385,58 +393,58 @@ public class EarthArmor extends EarthAbility { if (material == Material.NETHERRACK) { return 0x9b3131; // Pinkish-red. } - if (material == Material.QUARTZ_ORE) { + if (material == Material.NETHER_QUARTZ_ORE) { return 0xb75656; // Pinkish-red. } if (material == Material.QUARTZ_BLOCK) { return 0xfff4f4; // White. } - if (material == Material.STAINED_CLAY && damage == 0x0) { + if (material == Material.WHITE_TERRACOTTA) { return 0xCFAFA0; // White Stained Clay. } - if (material == Material.STAINED_CLAY && damage == 0x1) { + if (material == Material.ORANGE_TERRACOTTA) { return 0xA75329; // Orange. } - if (material == Material.STAINED_CLAY && damage == 0x2) { + if (material == Material.MAGENTA_TERRACOTTA) { return 0x95596E; // Magenta. } - if (material == Material.STAINED_CLAY && damage == 0x3) { + if (material == Material.LIGHT_BLUE_TERRACOTTA) { return 0x736E8A; // Light blue. } - if (material == Material.STAINED_CLAY && damage == 0x4) { + if (material == Material.YELLOW_TERRACOTTA) { return 0xBA8825; // Yellow. } - if (material == Material.STAINED_CLAY && damage == 0x5) { + if (material == Material.LIME_TERRACOTTA) { return 0x6B7736; // Lime. } - if (material == Material.STAINED_CLAY && damage == 0x6) { + if (material == Material.PINK_TERRACOTTA) { return 0xA24D4F; // Pink. } - if (material == Material.STAINED_CLAY && damage == 0x7) { + if (material == Material.GRAY_TERRACOTTA) { return 0x3A2923; // Gray. } - if (material == Material.STAINED_CLAY && damage == 0x8) { + if (material == Material.LIGHT_GRAY_TERRACOTTA) { return 0x876A61; // Light Gray. } - if (material == Material.STAINED_CLAY && damage == 0x9) { + if (material == Material.CYAN_TERRACOTTA) { return 0x575B5B; // Cyan. } - if (material == Material.STAINED_CLAY && damage == 0xA) { + if (material == Material.PURPLE_TERRACOTTA) { return 0x734453; // Purple. } - if (material == Material.STAINED_CLAY && damage == 0xB) { + if (material == Material.BLUE_TERRACOTTA) { return 0x493A5A; // Blue. } - if (material == Material.STAINED_CLAY && damage == 0xC) { + if (material == Material.BROWN_TERRACOTTA) { return 0x4C3223; // Brown. } - if (material == Material.STAINED_CLAY && damage == 0xD) { + if (material == Material.GREEN_TERRACOTTA) { return 0x4B522A; // Green. } - if (material == Material.STAINED_CLAY && damage == 0xE) { + if (material == Material.RED_TERRACOTTA) { return 0x8D3B2E; // Red. } - if (material == Material.STAINED_CLAY && damage == 0xF) { + if (material == Material.BLACK_TERRACOTTA) { return 0x251610; // Black. } @@ -452,8 +460,8 @@ public class EarthArmor extends EarthAbility { this.player.getLocation().getWorld().playSound(this.player.getLocation(), Sound.BLOCK_STONE_BREAK, 2, 1); this.player.getLocation().getWorld().playSound(this.player.getLocation(), Sound.BLOCK_STONE_BREAK, 2, 1); - ParticleEffect.BLOCK_CRACK.display(new ParticleEffect.BlockData(this.headData.getItemType(), this.headData.getData()), 0.1F, 0.1F, 0.1F, 1, 32, this.player.getEyeLocation(), 128); - ParticleEffect.BLOCK_CRACK.display(new ParticleEffect.BlockData(this.legsData.getItemType(), this.legsData.getData()), 0.1F, 0.1F, 0.1F, 1, 32, this.player.getLocation(), 128); + ParticleEffect.BLOCK_CRACK.display(this.player.getEyeLocation(), 8, 0.1, 0.1, 0.1, this.headMaterial.createBlockData()); + ParticleEffect.BLOCK_CRACK.display(this.player.getLocation(), 8, 0.1F, 0.1F, 0.1F, this.legsMaterial.createBlockData()); this.bPlayer.addCooldown(this); this.remove(); @@ -521,20 +529,20 @@ public class EarthArmor extends EarthAbility { this.formed = formed; } - public MaterialData getHeadData() { - return this.headData; + public Material getHeadMaterial() { + return this.headMaterial; } - public void setHeadData(final MaterialData materialdata) { - this.headData = materialdata; + public void setHeadMaterial(final Material material) { + this.headMaterial = material; } - public MaterialData getLegsData() { - return this.legsData; + public Material getLegsMaterial() { + return this.legsMaterial; } - public void setLegsData(final MaterialData materialdata) { - this.legsData = materialdata; + public void setLegsMaterial(final Material material) { + this.legsMaterial = material; } public double getSelectRange() { diff --git a/src/com/projectkorra/projectkorra/earthbending/EarthBlast.java b/src/com/projectkorra/projectkorra/earthbending/EarthBlast.java index f681b87f..6157139e 100644 --- a/src/com/projectkorra/projectkorra/earthbending/EarthBlast.java +++ b/src/com/projectkorra/projectkorra/earthbending/EarthBlast.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -15,10 +16,12 @@ import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.AirAbility; import com.projectkorra.projectkorra.ability.EarthAbility; import com.projectkorra.projectkorra.ability.util.Collision; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.earthbending.passive.DensityShift; import com.projectkorra.projectkorra.util.BlockSource; import com.projectkorra.projectkorra.util.ClickType; import com.projectkorra.projectkorra.util.DamageHandler; +import com.projectkorra.projectkorra.util.TempBlock; public class EarthBlast extends EarthAbility { private boolean isProgressing; @@ -27,15 +30,21 @@ public class EarthBlast extends EarthAbility { private boolean canHitSelf; private long time; private long interval; + @Attribute(Attribute.COOLDOWN) private long cooldown; + @Attribute(Attribute.RANGE) private double range; + @Attribute(Attribute.DAMAGE) private double damage; + @Attribute(Attribute.SPEED) private double speed; + @Attribute(Attribute.KNOCKBACK) private double pushFactor; + @Attribute(Attribute.SELECT_RANGE) private double selectRange; + @Attribute("DeflectRange") private double deflectRange; private double collisionRadius; - private byte sourceData; private Material sourceType; private Location location; private Location destination; @@ -63,7 +72,6 @@ public class EarthBlast extends EarthAbility { if (this.bPlayer.isAvatarState()) { this.cooldown = getConfig().getLong("Abilities.Avatar.AvatarState.Earth.EarthBlast.Cooldown"); this.damage = getConfig().getDouble("Abilities.Avatar.AvatarState.Earth.EarthBlast.Damage"); - } if (this.prepare()) { @@ -100,17 +108,12 @@ public class EarthBlast extends EarthAbility { DensityShift.revertSand(this.sourceBlock); } - this.sourceData = this.sourceBlock.getData(); if (this.sourceBlock.getType() == Material.SAND) { this.sourceType = Material.SAND; - if (this.sourceBlock.getData() == (byte) 0x1) { - this.sourceBlock.setType(Material.RED_SANDSTONE); - } else { - this.sourceBlock.setType(Material.SANDSTONE); - } - } else if (this.sourceBlock.getType() == Material.STEP) { - this.sourceBlock.setType(Material.STEP); - this.sourceType = Material.STEP; + this.sourceBlock.setType(Material.SANDSTONE); + } else if (this.sourceBlock.getType() == Material.RED_SAND) { + this.sourceType = Material.RED_SAND; + this.sourceBlock.setType(Material.RED_SANDSTONE); } else if (this.sourceBlock.getType() == Material.STONE) { this.sourceBlock.setType(Material.COBBLESTONE); this.sourceType = Material.STONE; @@ -134,15 +137,14 @@ public class EarthBlast extends EarthAbility { for (int j = 0; j < this.getEarthbendableBlocks().size(); j++) { try { trans[i] = Material.valueOf(this.getEarthbendableBlocks().get(j)); - } - catch (final IllegalArgumentException e) { + } catch (final IllegalArgumentException e) { continue; } i++; } if (target == null) { - location = GeneralMethods.getTargetedLocation(this.player, this.range, trans); + location = GeneralMethods.getTargetedLocation(this.player, this.range, true, trans); } else { location = ((LivingEntity) target).getEyeLocation(); } @@ -154,6 +156,8 @@ public class EarthBlast extends EarthAbility { final Block block = BlockSource.getEarthSourceBlock(this.player, this.range, ClickType.SHIFT_DOWN); if (block == null || !this.isEarthbendable(block)) { return false; + } else if (TempBlock.isTempBlock(block)) { + return false; } boolean selectedABlockInUse = false; @@ -291,10 +295,6 @@ public class EarthBlast extends EarthAbility { if (isEarthRevertOn()) { this.sourceBlock.setType(this.sourceType); - this.sourceBlock.setData(this.sourceData); - if (this.sourceBlock.getType() == Material.RED_SANDSTONE && this.sourceType == Material.SAND) { - this.sourceBlock.setData((byte) 0x1); - } moveEarthBlock(this.sourceBlock, block); @@ -318,7 +318,6 @@ public class EarthBlast extends EarthAbility { if (this.sourceBlock.getType() == Material.RED_SANDSTONE) { this.sourceType = Material.SAND; this.sourceBlock.setType(this.sourceType); - this.sourceBlock.setData((byte) 0x1); } else { this.sourceBlock.setType(this.sourceType); } @@ -348,17 +347,7 @@ public class EarthBlast extends EarthAbility { if (this.destination != null && this.sourceBlock != null) { this.sourceBlock.setType(Material.AIR); } else if (this.sourceBlock != null) { - if (this.sourceBlock.getType() == Material.SAND) { - if (this.sourceBlock.getData() == (byte) 0x1) { - this.sourceBlock.setType(this.sourceType); - this.sourceBlock.setData((byte) 0x1); - } else { - this.sourceBlock.setType(this.sourceType); - } - } else { - this.sourceBlock.setType(this.sourceType); - this.sourceBlock.setData(this.sourceData); - } + this.sourceBlock.setType(this.sourceType); } } @@ -374,15 +363,29 @@ public class EarthBlast extends EarthAbility { } final Entity target = GeneralMethods.getTargetedEntity(this.player, this.range, new ArrayList()); - if (target == null) { - this.destination = this.getTargetEarthBlock((int) this.range).getLocation(); - this.firstDestination = this.sourceBlock.getLocation().clone(); - this.firstDestination.setY(this.destination.getY()); + if (target != null) { + this.destination = target.getLocation(); } else { - this.destination = ((LivingEntity) target).getEyeLocation(); - this.firstDestination = this.sourceBlock.getLocation().clone(); - this.firstDestination.setY(this.destination.getY()); - this.destination = GeneralMethods.getPointOnLine(this.firstDestination, this.destination, this.range); + this.destination = this.getTargetLocation(); + } + + if (this.sourceBlock == null) { + return; + } + this.location = this.sourceBlock.getLocation(); + if (this.destination.distanceSquared(this.location) < 1) { + return; + } + + this.firstDestination = this.location.clone(); + if (this.destination.getY() - this.location.getY() > 2) { + this.firstDestination.setY(this.destination.getY() - 1); + } else if (this.location.getY() > player.getEyeLocation().getY() && this.location.getBlock().getRelative(BlockFace.UP).isPassable()) { + this.firstDestination.subtract(0, 2, 0); + } else if (this.location.getBlock().getRelative(BlockFace.UP).isPassable() && this.location.getBlock().getRelative(BlockFace.UP, 2).isPassable()) { + this.firstDestination.add(0, 2, 0); + } else { + this.firstDestination.add(GeneralMethods.getDirection(this.location, this.destination).normalize().setY(0)); } if (this.destination.distanceSquared(this.location) <= 1) { @@ -394,7 +397,6 @@ public class EarthBlast extends EarthAbility { final Material currentType = this.sourceBlock.getType(); this.sourceBlock.setType(this.sourceType); - this.sourceBlock.setData(this.sourceData); if (isEarthRevertOn()) { addTempAirBlock(this.sourceBlock); } else { @@ -466,7 +468,6 @@ public class EarthBlast extends EarthAbility { if (mloc.distanceSquared(location) <= blast.range * blast.range && GeneralMethods.getDistanceFromLine(vector, location, blast.location) < blast.deflectRange && mloc.distanceSquared(location.clone().add(vector)) < mloc.distanceSquared(location.clone().add(vector.clone().multiply(-1)))) { blast.redirect(player, blast.getTargetLocation()); } - } } diff --git a/src/com/projectkorra/projectkorra/earthbending/EarthDome.java b/src/com/projectkorra/projectkorra/earthbending/EarthDome.java index 6526fc00..4ad7b0a9 100644 --- a/src/com/projectkorra/projectkorra/earthbending/EarthDome.java +++ b/src/com/projectkorra/projectkorra/earthbending/EarthDome.java @@ -12,14 +12,18 @@ import org.bukkit.entity.Player; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.EarthAbility; +import com.projectkorra.projectkorra.attribute.Attribute; public class EarthDome extends EarthAbility { - public Location center; - public double radius; - public int height; - public Set checked = new HashSet<>(); - public Set corners = new HashSet<>(); + private Location center; + @Attribute(Attribute.RADIUS) + private double radius; + @Attribute(Attribute.HEIGHT) + private int height; + @Attribute(Attribute.COOLDOWN) + private long cooldown; + private Set checked; public EarthDome(final Player player, final Location center) { super(player); @@ -31,26 +35,10 @@ public class EarthDome extends EarthAbility { this.center = center; this.radius = getConfig().getDouble("Abilities.Earth.EarthDome.Radius"); this.height = getConfig().getInt("Abilities.Earth.EarthDome.Height"); + this.cooldown = getConfig().getLong("Abilities.Earth.EarthDome.Cooldown"); + this.checked = new HashSet<>(); - for (int i = 0; i < 2; i++) { - for (final Location check : this.getCircle(center, this.radius + i, 10)) { - Block b = check.getBlock(); - if (this.checked.contains(b)) { - continue; - } - - b = this.getAppropriateBlock(b); - if (b == null) { - continue; - } - - new RaiseEarth(player, b.getLocation(), Math.round(this.height - i)); - this.checked.add(b); - } - - } - - this.bPlayer.addCooldown("EarthDome", this.getCooldown()); + this.start(); } public EarthDome(final Player player) { @@ -81,6 +69,26 @@ public class EarthDome extends EarthAbility { @Override public void progress() { + for (int i = 0; i < 2; i++) { + for (final Location check : this.getCircle(this.center, this.radius + i, 10)) { + Block currBlock = check.getBlock(); + if (this.checked.contains(currBlock)) { + continue; + } + + currBlock = this.getAppropriateBlock(currBlock); + if (currBlock == null) { + continue; + } + + new RaiseEarth(this.player, currBlock.getLocation(), Math.round(this.height - i)); + this.checked.add(currBlock); + } + + } + + this.bPlayer.addCooldown("EarthDome", this.getCooldown()); + this.remove(); } @Override @@ -95,7 +103,7 @@ public class EarthDome extends EarthAbility { @Override public long getCooldown() { - return getConfig().getLong("Abilities.Earth.EarthDome.Cooldown"); + return this.cooldown; } @Override diff --git a/src/com/projectkorra/projectkorra/earthbending/EarthGrab.java b/src/com/projectkorra/projectkorra/earthbending/EarthGrab.java index bcf32e23..4084b813 100644 --- a/src/com/projectkorra/projectkorra/earthbending/EarthGrab.java +++ b/src/com/projectkorra/projectkorra/earthbending/EarthGrab.java @@ -8,6 +8,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.block.data.Ageable; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Arrow; import org.bukkit.entity.Entity; @@ -15,6 +16,7 @@ import org.bukkit.entity.Item; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Skeleton; +import org.bukkit.entity.Trident; import org.bukkit.entity.Zombie; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.LeatherArmorMeta; @@ -27,10 +29,11 @@ import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ability.CoreAbility; import com.projectkorra.projectkorra.ability.EarthAbility; +import com.projectkorra.projectkorra.ability.ElementalAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.avatar.AvatarState; import com.projectkorra.projectkorra.util.MovementHandler; import com.projectkorra.projectkorra.util.ParticleEffect; -import com.projectkorra.projectkorra.util.ParticleEffect.BlockData; import com.projectkorra.projectkorra.util.TempArmor; import com.projectkorra.projectkorra.util.TempArmorStand; import com.projectkorra.projectkorra.util.TempBlock; @@ -38,8 +41,18 @@ import com.projectkorra.projectkorra.util.TempBlock; public class EarthGrab extends EarthAbility { private LivingEntity target; - private long cooldown, lastHit = 0, interval; - private double range, dragSpeed, trapHP, trappedHP, damageThreshold; + @Attribute(Attribute.COOLDOWN) + private long cooldown; + private long lastHit; + private long interval; + @Attribute(Attribute.RANGE) + private double range; + @Attribute(Attribute.SPEED) + private double dragSpeed; + @Attribute("TrapHealth") + private double trapHP; + private double trappedHP; + private double damageThreshold; private GrabMode mode; private boolean initiated = false; private MovementHandler mHandler; @@ -47,7 +60,7 @@ public class EarthGrab extends EarthAbility { private Location origin; private Vector direction; private TempArmor armor; - private final Material[] crops = new Material[] { Material.BEETROOT_BLOCK, Material.CARROT, Material.POTATO, Material.SUGAR_CANE_BLOCK, Material.CROPS, Material.MELON_BLOCK, Material.PUMPKIN }; + private final Material[] crops = new Material[] { Material.WHEAT, Material.BEETROOTS, Material.CARROTS, Material.POTATOES, Material.SUGAR_CANE, Material.MELON, Material.PUMPKIN }; public static enum GrabMode { TRAP, DRAG, PROJECTING; @@ -83,6 +96,7 @@ public class EarthGrab extends EarthAbility { this.damageThreshold = getConfig().getDouble("Abilities.Earth.EarthGrab.DamageThreshold"); this.origin = this.player.getLocation().clone(); this.direction = this.player.getLocation().getDirection().setY(0).normalize(); + this.lastHit = 0; } @Override @@ -137,9 +151,11 @@ public class EarthGrab extends EarthAbility { top.setType(Material.AIR); } - while (!this.isEarthbendable(top)) { - if (this.isTransparent(top)) { - top = top.getRelative(BlockFace.DOWN); + if (!this.isEarthbendable(top)) { + Block under = top.getRelative(BlockFace.DOWN); + + if (this.isTransparent(top) && this.isEarthbendable(under)) { + top = under; } else { this.remove(); return; @@ -153,7 +169,7 @@ public class EarthGrab extends EarthAbility { this.origin.setY(top.getY() + 1); - ParticleEffect.BLOCK_DUST.display(new BlockData(this.origin.getBlock().getRelative(BlockFace.DOWN).getType(), (byte) 0), 0.2f, 0.5f, 0.2f, 0, 27, this.origin, 256); + ParticleEffect.BLOCK_DUST.display(this.origin, 27, 0.2, 0.5, 0.2, this.origin.getBlock().getRelative(BlockFace.DOWN).getBlockData()); playEarthbendingSound(this.origin); for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(this.origin, 1)) { if (entity instanceof LivingEntity && entity.getEntityId() != this.player.getEntityId() && this.isEarthbendable(entity.getLocation().getBlock().getRelative(BlockFace.DOWN))) { @@ -182,7 +198,7 @@ public class EarthGrab extends EarthAbility { this.trap.setHealth(this.trapHP); this.trap.setMetadata("earthgrab:trap", new FixedMetadataValue(ProjectKorra.plugin, this)); - new TempBlock(this.target.getLocation().clone().subtract(0, 1, 0).getBlock(), this.target.getLocation().clone().subtract(0, 1, 0).getBlock().getType(), (byte) 0); + new TempBlock(this.target.getLocation().clone().subtract(0, 1, 0).getBlock(), this.target.getLocation().clone().subtract(0, 1, 0).getBlock().getType()); this.mHandler = new MovementHandler(this.target, this); this.mHandler.stop(Element.EARTH.getColor() + "* Trapped *"); @@ -206,9 +222,9 @@ public class EarthGrab extends EarthAbility { this.initiated = true; } - ParticleEffect.BLOCK_DUST.display(new BlockData(this.target.getLocation().getBlock().getRelative(BlockFace.DOWN).getType(), (byte) 0), 0.3f, 0.6f, 0.3f, 0, 36, this.target.getLocation(), 256); + ParticleEffect.BLOCK_DUST.display(this.target.getLocation(), 36, 0.3, 0.6, 0.3, this.target.getLocation().getBlock().getRelative(BlockFace.DOWN).getBlockData()); - if (this.trap.getLocation().clone().subtract(0, 0.1, 0).getBlock().getType() != Material.AIR) { + if (!ElementalAbility.isAir(this.trap.getLocation().clone().subtract(0, 0.1, 0).getBlock().getType())) { this.trap.setGravity(false); } else { this.trap.setGravity(true); @@ -276,7 +292,7 @@ public class EarthGrab extends EarthAbility { } final Block b = l.getBlock(); - if (b.getData() == (byte) 7 || b.getType() == Material.MELON_BLOCK || b.getType() == Material.PUMPKIN) { + if ((b.getBlockData() instanceof Ageable && ((Ageable) b.getBlockData()).getAge() == ((Ageable) b.getBlockData()).getMaximumAge()) || b.getType() == Material.MELON || b.getType() == Material.PUMPKIN) { b.breakNaturally(); } } @@ -288,20 +304,24 @@ public class EarthGrab extends EarthAbility { } for (Entity entity : ents) { - if (!isEarth(entity.getLocation().clone().subtract(0, 1, 0).getBlock()) && (this.bPlayer.canSandbend() && !isSand(entity.getLocation().clone().subtract(0, 1, 0).getBlock())) && entity.getLocation().clone().subtract(0, 1, 0).getBlock().getType() != Material.SOIL) { + if (!isEarth(entity.getLocation().clone().subtract(0, 1, 0).getBlock()) && (this.bPlayer.canSandbend() && !isSand(entity.getLocation().clone().subtract(0, 1, 0).getBlock())) && entity.getLocation().clone().subtract(0, 1, 0).getBlock().getType() != Material.FARMLAND) { continue; } - - if (entity instanceof Arrow) { - final Location l = entity.getLocation(); - entity.remove(); - entity = l.getWorld().dropItem(l, new ItemStack(Material.ARROW, 1)); + if (entity instanceof Trident) { + continue; + } else if (entity instanceof Arrow) { + final Arrow arrow = (Arrow) entity; + if (arrow.getPickupStatus() == Arrow.PickupStatus.ALLOWED) { + final Location l = entity.getLocation(); + entity.remove(); + entity = l.getWorld().dropItem(l, new ItemStack(Material.ARROW, 1)); + } } else if (!(entity instanceof Item)) { continue; } final Block b = entity.getLocation().getBlock().getRelative(BlockFace.DOWN); entity.setVelocity(GeneralMethods.getDirection(entity.getLocation(), this.player.getLocation()).normalize().multiply(this.dragSpeed)); - ParticleEffect.BLOCK_CRACK.display(new BlockData(b.getType(), b.getData()), 0, 0, 0, 0, 1, entity.getLocation(), 256); + ParticleEffect.BLOCK_CRACK.display(entity.getLocation(), 2, 0, 0, 0, b.getBlockData()); playEarthbendingSound(entity.getLocation()); } } @@ -310,7 +330,7 @@ public class EarthGrab extends EarthAbility { if (System.currentTimeMillis() >= this.lastHit + this.interval) { this.trapHP -= 1; this.lastHit = System.currentTimeMillis(); - ParticleEffect.BLOCK_CRACK.display(new BlockData(this.target.getLocation().getBlock().getRelative(BlockFace.DOWN).getType(), (byte) 0), 0.1f, 0.5f, 0.1f, 0, 17, this.target.getLocation().clone().add(0, 1, 0), 256); + ParticleEffect.BLOCK_CRACK.display(this.target.getLocation().clone().add(0, 1, 0), 17, 0.1, 0.5, 0.1, this.target.getLocation().getBlock().getRelative(BlockFace.DOWN).getBlockData()); playEarthbendingSound(this.target.getLocation()); } } @@ -318,8 +338,7 @@ public class EarthGrab extends EarthAbility { @Override public void remove() { super.remove(); - if (this.mode == GrabMode.TRAP) { - this.bPlayer.addCooldown(this); + if (this.mode == GrabMode.TRAP && this.initiated) { this.mHandler.reset(); this.trap.remove(); if (TempArmor.getTempArmorList(this.target).contains(this.armor)) { diff --git a/src/com/projectkorra/projectkorra/earthbending/EarthSmash.java b/src/com/projectkorra/projectkorra/earthbending/EarthSmash.java index 1e0e3a8b..e71a0d9e 100644 --- a/src/com/projectkorra/projectkorra/earthbending/EarthSmash.java +++ b/src/com/projectkorra/projectkorra/earthbending/EarthSmash.java @@ -8,6 +8,7 @@ import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -16,6 +17,9 @@ import org.bukkit.util.Vector; import com.projectkorra.projectkorra.BendingPlayer; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.EarthAbility; +import com.projectkorra.projectkorra.ability.ElementalAbility; +import com.projectkorra.projectkorra.attribute.Attribute; +import com.projectkorra.projectkorra.command.Commands; import com.projectkorra.projectkorra.util.ClickType; import com.projectkorra.projectkorra.util.DamageHandler; import com.projectkorra.projectkorra.util.ParticleEffect; @@ -27,27 +31,40 @@ public class EarthSmash extends EarthAbility { START, LIFTING, LIFTED, GRABBED, SHOT, FLYING, REMOVED } + @Attribute("AllowGrab") private boolean allowGrab; + @Attribute("AllowFlight") private boolean allowFlight; private int animationCounter; private int progressCounter; private int requiredBendableBlocks; private int maxBlocksToPassThrough; private long delay; + @Attribute(Attribute.COOLDOWN) private long cooldown; + @Attribute(Attribute.CHARGE_DURATION) private long chargeTime; - private long removeTimer; - private long flightRemoveTimer; + @Attribute(Attribute.DURATION) + private long duration; + @Attribute("Flight" + Attribute.DURATION) + private long flightDuration; private long flightStartTime; private long shootAnimationInterval; private long flightAnimationInterval; private long liftAnimationInterval; + @Attribute(Attribute.SELECT_RANGE) private double selectRange; + @Attribute("GrabRange") private double grabRange; + @Attribute("ShootRange") private double shootRange; + @Attribute(Attribute.DAMAGE) private double damage; + @Attribute(Attribute.KNOCKBACK) private double knockback; + @Attribute(Attribute.KNOCKUP) private double knockup; + @Attribute(Attribute.SPEED) private double flightSpeed; private double grabbedDistance; private double grabDetectionRadius; @@ -125,24 +142,24 @@ public class EarthSmash extends EarthAbility { public void setFields() { final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(this.player); - this.shootAnimationInterval = getConfig().getLong("Abilities.Earth.EarthSmash.ShootAnimationInterval"); - this.flightAnimationInterval = getConfig().getLong("Abilities.Earth.EarthSmash.FlightAnimationInterval"); + this.shootAnimationInterval = getConfig().getLong("Abilities.Earth.EarthSmash.Shoot.AnimationInterval"); + this.flightAnimationInterval = getConfig().getLong("Abilities.Earth.EarthSmash.Flight.AnimationInterval"); this.liftAnimationInterval = getConfig().getLong("Abilities.Earth.EarthSmash.LiftAnimationInterval"); - this.grabDetectionRadius = getConfig().getDouble("Abilities.Earth.EarthSmash.GrabDetectionRadius"); - this.flightDetectionRadius = getConfig().getDouble("Abilities.Earth.EarthSmash.FlightDetectionRadius"); - this.allowGrab = getConfig().getBoolean("Abilities.Earth.EarthSmash.AllowGrab"); - this.allowFlight = getConfig().getBoolean("Abilities.Earth.EarthSmash.AllowFlight"); + this.grabDetectionRadius = getConfig().getDouble("Abilities.Earth.EarthSmash.Grab.DetectionRadius"); + this.flightDetectionRadius = getConfig().getDouble("Abilities.Earth.EarthSmash.Flight.DetectionRadius"); + this.allowGrab = getConfig().getBoolean("Abilities.Earth.EarthSmash.Grab.Enabled"); + this.allowFlight = getConfig().getBoolean("Abilities.Earth.EarthSmash.Flight.Enabled"); this.selectRange = getConfig().getDouble("Abilities.Earth.EarthSmash.SelectRange"); - this.grabRange = getConfig().getDouble("Abilities.Earth.EarthSmash.GrabRange"); - this.shootRange = getConfig().getDouble("Abilities.Earth.EarthSmash.ShootRange"); + this.grabRange = getConfig().getDouble("Abilities.Earth.EarthSmash.Grab.Range"); + this.shootRange = getConfig().getDouble("Abilities.Earth.EarthSmash.Shoot.Range"); this.damage = getConfig().getDouble("Abilities.Earth.EarthSmash.Damage"); this.knockback = getConfig().getDouble("Abilities.Earth.EarthSmash.Knockback"); this.knockup = getConfig().getDouble("Abilities.Earth.EarthSmash.Knockup"); - this.flightSpeed = getConfig().getDouble("Abilities.Earth.EarthSmash.FlightSpeed"); + this.flightSpeed = getConfig().getDouble("Abilities.Earth.EarthSmash.Flight.Speed"); this.chargeTime = getConfig().getLong("Abilities.Earth.EarthSmash.ChargeTime"); this.cooldown = getConfig().getLong("Abilities.Earth.EarthSmash.Cooldown"); - this.flightRemoveTimer = getConfig().getLong("Abilities.Earth.EarthSmash.FlightTimer"); - this.removeTimer = getConfig().getLong("Abilities.Earth.EarthSmash.RemoveTimer"); + this.flightDuration = getConfig().getLong("Abilities.Earth.EarthSmash.Flight.Duration"); + this.duration = getConfig().getLong("Abilities.Earth.EarthSmash.Duration"); if (bPlayer.isAvatarState()) { this.selectRange = getConfig().getDouble("Abilities.Avatar.AvatarState.Earth.EarthSmash.SelectRange"); @@ -152,7 +169,7 @@ public class EarthSmash extends EarthAbility { this.damage = getConfig().getDouble("Abilities.Avatar.AvatarState.Earth.EarthSmash.Damage"); this.knockback = getConfig().getDouble("Abilities.Avatar.AvatarState.Earth.EarthSmash.Knockback"); this.flightSpeed = getConfig().getDouble("Abilities.Avatar.AvatarState.Earth.EarthSmash.FlightSpeed"); - this.flightRemoveTimer = getConfig().getLong("Abilities.Avatar.AvatarState.Earth.EarthSmash.FlightTimer"); + this.flightDuration = getConfig().getLong("Abilities.Avatar.AvatarState.Earth.EarthSmash.FlightTimer"); this.shootRange = getConfig().getDouble("Abilities.Avatar.AvatarState.Earth.EarthSmash.ShootRange"); } } @@ -160,7 +177,7 @@ public class EarthSmash extends EarthAbility { @Override public void progress() { this.progressCounter++; - if (this.state == State.LIFTED && this.removeTimer > 0 && System.currentTimeMillis() - this.getStartTime() > this.removeTimer) { + if (this.state == State.LIFTED && this.duration > 0 && System.currentTimeMillis() - this.getStartTime() > this.duration) { this.remove(); return; } @@ -195,7 +212,7 @@ public class EarthSmash extends EarthAbility { } else if (System.currentTimeMillis() - this.getStartTime() > this.chargeTime) { final Location tempLoc = this.player.getEyeLocation().add(this.player.getEyeLocation().getDirection().normalize().multiply(1.2)); tempLoc.add(0, 0.3, 0); - ParticleEffect.SMOKE.display(tempLoc, 0.3F, 0.1F, 0.3F, 0, 4); + ParticleEffect.SMOKE_NORMAL.display(tempLoc, 4, 0.3, 0.1, 0.3, 0); } } else if (this.state == State.LIFTING) { if (System.currentTimeMillis() - this.delay >= this.liftAnimationInterval) { @@ -210,12 +227,11 @@ public class EarthSmash extends EarthAbility { // Check to make sure the new location is available to move to. for (final Block block : this.getBlocks()) { - if (block.getType() != Material.AIR && !this.isTransparent(block)) { + if (!ElementalAbility.isAir(block.getType()) && !this.isTransparent(block)) { this.location = oldLoc; break; } } - this.draw(); return; } else { @@ -240,7 +256,7 @@ public class EarthSmash extends EarthAbility { // If an earthsmash runs into too many blocks we should remove it. int badBlocksFound = 0; for (final Block block : this.getBlocks()) { - if (block.getType() != Material.AIR && (!this.isTransparent(block) || block.getType() == Material.WATER || block.getType() == Material.STATIONARY_WATER)) { + if (!ElementalAbility.isAir(block.getType()) && (!this.isTransparent(block) || block.getType() == Material.WATER)) { badBlocksFound++; } } @@ -274,6 +290,9 @@ public class EarthSmash extends EarthAbility { return; } for (final Entity entity : entities) { + if (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation()) || ((entity instanceof Player) && Commands.invincible.contains(((Player) entity).getName()))) { + continue; + } entity.setVelocity(direction.clone().multiply(this.flightSpeed)); } @@ -287,7 +306,7 @@ public class EarthSmash extends EarthAbility { } this.draw(); } - if (System.currentTimeMillis() - this.flightStartTime > this.flightRemoveTimer) { + if (System.currentTimeMillis() - this.flightStartTime > this.flightDuration) { this.remove(); return; } @@ -330,7 +349,7 @@ public class EarthSmash extends EarthAbility { // Make sure there is a clear path upward otherwise remove. for (int y = 0; y <= 3; y++) { final Block tempBlock = this.location.clone().add(0, y, 0).getBlock(); - if (!this.isTransparent(tempBlock) && tempBlock.getType() != Material.AIR) { + if (!this.isTransparent(tempBlock) && !ElementalAbility.isAir(tempBlock.getType())) { this.remove(); return; } @@ -342,7 +361,7 @@ public class EarthSmash extends EarthAbility { for (int z = -1; z <= 1; z++) { if ((Math.abs(x) + Math.abs(y) + Math.abs(z)) % 2 == 0) { final Block block = tempLoc.clone().add(x, y, z).getBlock(); - this.currentBlocks.add(new BlockRepresenter(x, y, z, this.selectMaterialForRepresenter(block.getType()), block.getData())); + this.currentBlocks.add(new BlockRepresenter(x, y, z, this.selectMaterialForRepresenter(block.getType()), block.getBlockData())); } } } @@ -403,7 +422,7 @@ public class EarthSmash extends EarthAbility { } if (this.player != null && this.isTransparent(block)) { - this.affectedBlocks.add(new TempBlock(block, blockRep.getType(), blockRep.getData())); + this.affectedBlocks.add(new TempBlock(block, blockRep.getType())); getPreventEarthbendingBlocks().add(block); } } @@ -547,6 +566,9 @@ public class EarthSmash extends EarthAbility { final List entities = GeneralMethods.getEntitiesAroundPoint(this.location, this.flightDetectionRadius); for (final Entity entity : entities) { if (entity instanceof LivingEntity && entity != this.player && !this.affectedEntities.contains(entity)) { + if (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation()) || ((entity instanceof Player) && Commands.invincible.contains(((Player) entity).getName()))) { + continue; + } this.affectedEntities.add(entity); final double damage = this.currentBlocks.size() / 13.0 * this.damage; DamageHandler.damageEntity(entity, damage, this); @@ -602,9 +624,9 @@ public class EarthSmash extends EarthAbility { public class BlockRepresenter { private int x, y, z; private Material type; - private byte data; + private BlockData data; - public BlockRepresenter(final int x, final int y, final int z, final Material type, final byte data) { + public BlockRepresenter(final int x, final int y, final int z, final Material type, final BlockData data) { this.x = x; this.y = y; this.z = z; @@ -628,7 +650,7 @@ public class EarthSmash extends EarthAbility { return this.type; } - public byte getData() { + public BlockData getData() { return this.data; } @@ -648,7 +670,7 @@ public class EarthSmash extends EarthAbility { this.type = type; } - public void setData(final byte data) { + public void setData(final BlockData data) { this.data = data; } @@ -782,20 +804,20 @@ public class EarthSmash extends EarthAbility { this.chargeTime = chargeTime; } - public long getRemoveTimer() { - return this.removeTimer; + public long getDuration() { + return this.duration; } - public void setRemoveTimer(final long removeTimer) { - this.removeTimer = removeTimer; + public void setDuration(final long duration) { + this.duration = duration; } - public long getFlightRemoveTimer() { - return this.flightRemoveTimer; + public long getFlightDuration() { + return this.flightDuration; } - public void setFlightRemoveTimer(final long flightRemoveTimer) { - this.flightRemoveTimer = flightRemoveTimer; + public void setFlightDuration(final long flightDuration) { + this.flightDuration = flightDuration; } public long getFlightStartTime() { diff --git a/src/com/projectkorra/projectkorra/earthbending/EarthTunnel.java b/src/com/projectkorra/projectkorra/earthbending/EarthTunnel.java index 0921bac1..29319ec5 100644 --- a/src/com/projectkorra/projectkorra/earthbending/EarthTunnel.java +++ b/src/com/projectkorra/projectkorra/earthbending/EarthTunnel.java @@ -1,10 +1,6 @@ package com.projectkorra.projectkorra.earthbending; -import java.util.ArrayList; import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Location; import org.bukkit.Material; @@ -16,29 +12,34 @@ import org.bukkit.util.Vector; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.EarthAbility; import com.projectkorra.projectkorra.ability.ElementalAbility; -import com.projectkorra.projectkorra.configuration.ConfigManager; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.util.TempBlock; public class EarthTunnel extends EarthAbility { private long interval; + private int blocksPerInterval; private long time; + @Attribute("Depth") private double depth; + @Attribute(Attribute.COOLDOWN) private long cooldown; + private long revertTime; private double radius; private double angle; + @Attribute(Attribute.RADIUS) private double maxRadius; + @Attribute(Attribute.RANGE) private double range; private double radiusIncrement; private boolean revert; private boolean dropLootIfNotRevert; + private boolean ignoreOres; private Block block; private Location origin; private Location location; private Vector direction; - public static Map airBlocks = new ConcurrentHashMap(); - public EarthTunnel(final Player player) { super(player); @@ -47,8 +48,11 @@ public class EarthTunnel extends EarthAbility { this.range = getConfig().getDouble("Abilities.Earth.EarthTunnel.Range"); this.radius = getConfig().getDouble("Abilities.Earth.EarthTunnel.Radius"); this.interval = getConfig().getLong("Abilities.Earth.EarthTunnel.Interval"); + this.blocksPerInterval = getConfig().getInt("Abilities.Earth.EarthTunnel.BlocksPerInterval"); this.revert = getConfig().getBoolean("Abilities.Earth.EarthTunnel.Revert"); this.dropLootIfNotRevert = getConfig().getBoolean("Abilities.Earth.EarthTunnel.DropLootIfNotRevert"); + this.ignoreOres = getConfig().getBoolean("Abilities.Earth.EarthTunnel.IgnoreOres"); + this.revertTime = getConfig().getLong("Properties.Earth.RevertCheckTime"); this.time = System.currentTimeMillis(); @@ -87,72 +91,90 @@ public class EarthTunnel extends EarthAbility { if (System.currentTimeMillis() - this.time >= this.interval) { this.time = System.currentTimeMillis(); - if (Math.abs(Math.toDegrees(this.player.getEyeLocation().getDirection().angle(this.direction))) > 20 || !this.player.isSneaking()) { - this.bPlayer.addCooldown(this); - this.remove(); - return; - } else { - while ((!isEarth(this.block) && !isSand(this.block))) { - if (!this.isTransparent(this.block)) { + for (int i = 1; i <= this.blocksPerInterval; i++) { + if (Math.abs(Math.toDegrees(this.player.getEyeLocation().getDirection().angle(this.direction))) > 20 || !this.player.isSneaking()) { + this.bPlayer.addCooldown(this); + this.remove(); + return; + } else { + while ((!isEarth(this.block) && !isSand(this.block)) || (this.ignoreOres && this.isOre(this.block))) { + if (!this.isTransparent(this.block) && (this.ignoreOres && !this.isOre(this.block))) { + this.remove(); + return; + } + + if (this.angle >= 360) { + this.angle = 0; + if (this.radius >= this.maxRadius) { + this.radius = this.radiusIncrement; + if (this.depth >= this.range) { + this.bPlayer.addCooldown(this); + this.remove(); + return; + } else { + this.depth += 0.5; + } + } else { + this.radius += this.radiusIncrement; + } + } else { + this.angle += 20; + } + + final Vector vec = GeneralMethods.getOrthogonalVector(this.direction, this.angle, this.radius); + this.block = this.location.clone().add(this.direction.clone().normalize().multiply(this.depth)).add(vec).getBlock(); + } + + if (GeneralMethods.isRegionProtectedFromBuild(this, this.block.getLocation())) { + this.bPlayer.addCooldown(this); this.remove(); return; } - if (this.angle >= 360) { - this.angle = 0; - if (this.radius >= this.maxRadius) { - this.radius = this.radiusIncrement; - if (this.depth >= this.range) { - this.bPlayer.addCooldown(this); - this.remove(); - return; - } else { - this.depth += 0.5; - } + if (this.revert) { + if (getMovedEarth().containsKey(this.block)) { + this.block.setType(Material.AIR); } else { - this.radius += this.radiusIncrement; - } - } else { - this.angle += 20; - } - - final Vector vec = GeneralMethods.getOrthogonalVector(this.direction, this.angle, this.radius); - this.block = this.location.clone().add(this.direction.clone().normalize().multiply(this.depth)).add(vec).getBlock(); - } - - if (GeneralMethods.isRegionProtectedFromBuild(this, this.block.getLocation())) { - this.bPlayer.addCooldown(this); - this.remove(); - return; - } - - if (this.revert) { - if (getMovedEarth().containsKey(this.block)) { - this.block.setType(Material.AIR); - } else { - airBlocks.put(new TempBlock(this.block, Material.AIR, (byte) 0), System.currentTimeMillis()); - if (isPlant(this.block.getRelative(BlockFace.UP)) || isSnow(this.block.getRelative(BlockFace.UP))) { - final Block above = this.block.getRelative(BlockFace.UP); - final Block above2 = above.getRelative(BlockFace.UP); - if (isPlant(above) || isSnow(above)) { - airBlocks.put(new TempBlock(above, Material.AIR, (byte) 0), System.currentTimeMillis()); - if (isPlant(above2) && above2.getType().equals(Material.DOUBLE_PLANT)) { - airBlocks.put(new TempBlock(above2, Material.AIR, (byte) 0), System.currentTimeMillis()); + new TempBlock(this.block, Material.AIR).setRevertTime(revertTime); + if (isPlant(this.block.getRelative(BlockFace.UP)) || isSnow(this.block.getRelative(BlockFace.UP))) { + final Block above = this.block.getRelative(BlockFace.UP); + final Block above2 = above.getRelative(BlockFace.UP); + if (isPlant(above) || isSnow(above)) { + new TempBlock(above, Material.AIR).setRevertTime(revertTime); + if (isPlant(above2) && above2.getType().equals(Material.TALL_GRASS)) { + new TempBlock(above2, Material.AIR).setRevertTime(revertTime); + } } } } - } - } else { - if (this.dropLootIfNotRevert) { - this.block.breakNaturally(); } else { - this.block.setType(Material.AIR); + if (this.dropLootIfNotRevert) { + this.block.breakNaturally(); + } else { + this.block.setType(Material.AIR); + } } } } } } + private boolean isOre(final Block block) { + switch (block.getType()) { + case COAL_ORE: + case IRON_ORE: + case GOLD_ORE: + case LAPIS_ORE: + case REDSTONE_ORE: + case DIAMOND_ORE: + case EMERALD_ORE: + case NETHER_QUARTZ_ORE: + return true; + default: + return false; + } + } + @Override public String getName() { return "EarthTunnel"; @@ -178,15 +200,6 @@ public class EarthTunnel extends EarthAbility { return false; } - @Override - public List getLocations() { - final ArrayList locations = new ArrayList<>(); - for (final TempBlock tblock : airBlocks.keySet()) { - locations.add(tblock.getLocation()); - } - return locations; - } - public long getInterval() { return this.interval; } @@ -279,15 +292,4 @@ public class EarthTunnel extends EarthAbility { this.location = location; } - public static void revertAirBlocks() { - if (ConfigManager.defaultConfig.get().getBoolean("Abilities.Earth.EarthTunnel.Revert")) { - for (final TempBlock tempBlock : EarthTunnel.airBlocks.keySet()) { - if (EarthTunnel.airBlocks.get(tempBlock) + ConfigManager.defaultConfig.get().getLong("Properties.Earth.RevertCheckTime") <= System.currentTimeMillis()) { - tempBlock.revertBlock(); - EarthTunnel.airBlocks.remove(tempBlock); - } - } - } - } - } diff --git a/src/com/projectkorra/projectkorra/earthbending/RaiseEarth.java b/src/com/projectkorra/projectkorra/earthbending/RaiseEarth.java index 779600c4..12330e89 100644 --- a/src/com/projectkorra/projectkorra/earthbending/RaiseEarth.java +++ b/src/com/projectkorra/projectkorra/earthbending/RaiseEarth.java @@ -2,31 +2,32 @@ package com.projectkorra.projectkorra.earthbending; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; import org.bukkit.util.Vector; import com.projectkorra.projectkorra.ability.EarthAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.configuration.ConfigManager; import com.projectkorra.projectkorra.util.BlockSource; import com.projectkorra.projectkorra.util.ClickType; +import com.projectkorra.projectkorra.util.TempBlock; public class RaiseEarth extends EarthAbility { - private static final Map ALL_AFFECTED_BLOCKS = new ConcurrentHashMap<>(); - private int distance; + @Attribute(Attribute.HEIGHT) private int height; private long time; private long interval; + @Attribute(Attribute.COOLDOWN) private long cooldown; + @Attribute(Attribute.SELECT_RANGE) private double selectRange; + @Attribute(Attribute.SPEED) private double speed; private Block block; private Vector direction; @@ -54,8 +55,7 @@ public class RaiseEarth extends EarthAbility { this.origin = this.block.getLocation(); this.location = this.origin.clone(); this.distance = this.getEarthbendableBlocksLength(this.block, this.direction.clone().multiply(-1), this.height); - } - catch (final IllegalStateException e) { + } catch (final IllegalStateException e) { return; } @@ -101,12 +101,8 @@ public class RaiseEarth extends EarthAbility { } private boolean canInstantiate() { - if (this.location.getBlock().getRelative(BlockFace.UP).getType() == Material.STATIONARY_LAVA) { - return false; - } - for (final Block block : this.affectedBlocks.keySet()) { - if (!this.isEarthbendable(block) || ALL_AFFECTED_BLOCKS.containsKey(block)) { + if (!this.isEarthbendable(block) || TempBlock.isTempBlock(block)) { return false; } } @@ -145,11 +141,15 @@ public class RaiseEarth extends EarthAbility { } public static boolean blockInAllAffectedBlocks(final Block block) { - return ALL_AFFECTED_BLOCKS.containsKey(block); + for (RaiseEarth raiseEarth : getAbilities(RaiseEarth.class)) { + if (raiseEarth.affectedBlocks.contains(block)) { + return true; + } + } + return false; } public static void revertAffectedBlock(final Block block) { - ALL_AFFECTED_BLOCKS.remove(block); for (final RaiseEarth raiseEarth : getAbilities(RaiseEarth.class)) { raiseEarth.affectedBlocks.remove(block); } diff --git a/src/com/projectkorra/projectkorra/earthbending/RaiseEarthWall.java b/src/com/projectkorra/projectkorra/earthbending/RaiseEarthWall.java index 081e872d..72070e5e 100644 --- a/src/com/projectkorra/projectkorra/earthbending/RaiseEarthWall.java +++ b/src/com/projectkorra/projectkorra/earthbending/RaiseEarthWall.java @@ -8,14 +8,19 @@ import org.bukkit.entity.Player; import org.bukkit.util.Vector; import com.projectkorra.projectkorra.ability.EarthAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.util.BlockSource; import com.projectkorra.projectkorra.util.ClickType; public class RaiseEarthWall extends EarthAbility { + @Attribute(Attribute.SELECT_RANGE) private int selectRange; + @Attribute(Attribute.HEIGHT) private int height; + @Attribute(Attribute.WIDTH) private int width; + @Attribute(Attribute.COOLDOWN) private long cooldown; private Location location; @@ -35,61 +40,7 @@ public class RaiseEarthWall extends EarthAbility { this.width = getConfig().getInt("Abilities.Avatar.AvatarState.Earth.RaiseEarth.Wall.Width"); } - final Vector direction = player.getEyeLocation().getDirection().normalize(); - double ox, oy, oz; - direction.setY(0); - ox = -direction.getZ(); - oy = 0; - oz = direction.getX(); - - Vector orth = new Vector(ox, oy, oz); - orth = orth.normalize(); - orth = getDegreeRoundedVector(orth, 0.25); - - final Block sblock = BlockSource.getEarthSourceBlock(player, this.selectRange, ClickType.SHIFT_DOWN); - - if (sblock == null) { - this.location = this.getTargetEarthBlock(this.selectRange).getLocation(); - } else { - this.location = sblock.getLocation(); - } - - final World world = this.location.getWorld(); - boolean shouldAddCooldown = false; - - for (int i = 0; i < this.width; i++) { - final double adjustedI = i - this.width / 2.0; - Block block = world.getBlockAt(this.location.clone().add(orth.clone().multiply(adjustedI))); - - if (this.isTransparent(block)) { - for (int j = 1; j < this.height; j++) { - block = block.getRelative(BlockFace.DOWN); - if (this.isEarthbendable(block)) { - shouldAddCooldown = true; - new RaiseEarth(player, block.getLocation(), this.height); - } else if (!this.isTransparent(block)) { - break; - } - } - } else if (this.isEarthbendable(block.getRelative(BlockFace.UP))) { - for (int j = 1; j < this.height; j++) { - block = block.getRelative(BlockFace.UP); - if (this.isTransparent(block)) { - shouldAddCooldown = true; - new RaiseEarth(player, block.getRelative(BlockFace.DOWN).getLocation(), this.height); - } else if (!this.isEarthbendable(block)) { - break; - } - } - } else if (this.isEarthbendable(block)) { - shouldAddCooldown = true; - new RaiseEarth(player, block.getLocation(), this.height); - } - } - - if (shouldAddCooldown) { - this.bPlayer.addCooldown("RaiseEarthWall", this.cooldown); - } + this.start(); } private static Vector getDegreeRoundedVector(Vector vec, final double degreeIncrement) { @@ -123,6 +74,62 @@ public class RaiseEarthWall extends EarthAbility { @Override public void progress() { + final Vector direction = this.player.getEyeLocation().getDirection().normalize(); + double ox, oy, oz; + direction.setY(0); + ox = -direction.getZ(); + oy = 0; + oz = direction.getX(); + + Vector orth = new Vector(ox, oy, oz); + orth = orth.normalize(); + orth = getDegreeRoundedVector(orth, 0.25); + + final Block sblock = BlockSource.getEarthSourceBlock(this.player, this.selectRange, ClickType.SHIFT_DOWN); + + if (sblock == null) { + this.location = this.getTargetEarthBlock(this.selectRange).getLocation(); + } else { + this.location = sblock.getLocation(); + } + + final World world = this.location.getWorld(); + boolean shouldAddCooldown = false; + + for (int i = 0; i < this.width; i++) { + final double adjustedI = i - this.width / 2.0; + Block block = world.getBlockAt(this.location.clone().add(orth.clone().multiply(adjustedI))); + + if (this.isTransparent(block)) { + for (int j = 1; j < this.height; j++) { + block = block.getRelative(BlockFace.DOWN); + if (this.isEarthbendable(block)) { + shouldAddCooldown = true; + new RaiseEarth(this.player, block.getLocation(), this.height); + } else if (!this.isTransparent(block)) { + break; + } + } + } else if (this.isEarthbendable(block.getRelative(BlockFace.UP))) { + for (int j = 1; j < this.height; j++) { + block = block.getRelative(BlockFace.UP); + if (this.isTransparent(block)) { + shouldAddCooldown = true; + new RaiseEarth(this.player, block.getRelative(BlockFace.DOWN).getLocation(), this.height); + } else if (!this.isEarthbendable(block)) { + break; + } + } + } else if (this.isEarthbendable(block)) { + shouldAddCooldown = true; + new RaiseEarth(this.player, block.getLocation(), this.height); + } + } + + if (shouldAddCooldown) { + this.bPlayer.addCooldown("RaiseEarthWall", this.cooldown); + } + this.remove(); } @Override diff --git a/src/com/projectkorra/projectkorra/earthbending/Ripple.java b/src/com/projectkorra/projectkorra/earthbending/Ripple.java index d46932f1..25fc4bb2 100644 --- a/src/com/projectkorra/projectkorra/earthbending/Ripple.java +++ b/src/com/projectkorra/projectkorra/earthbending/Ripple.java @@ -5,7 +5,6 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.Entity; @@ -17,7 +16,9 @@ import org.bukkit.util.Vector; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.AirAbility; import com.projectkorra.projectkorra.ability.EarthAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.avatar.AvatarState; +import com.projectkorra.projectkorra.command.Commands; import com.projectkorra.projectkorra.util.DamageHandler; public class Ripple extends EarthAbility { @@ -26,8 +27,11 @@ public class Ripple extends EarthAbility { private int step; private int maxStep; + @Attribute(Attribute.RANGE) private double range; + @Attribute(Attribute.DAMAGE) private double damage; + @Attribute(Attribute.KNOCKBACK) private double knockback; private Vector direction; private Location origin; @@ -214,7 +218,7 @@ public class Ripple extends EarthAbility { final Block topblock = loc.getBlock(); final Block botblock = loc.clone().add(0, -1, 0).getBlock(); - if (this.isTransparent(topblock) && !topblock.isLiquid() && this.isEarthbendable(botblock) && botblock.getType() != Material.STATIONARY_LAVA) { + if (this.isTransparent(topblock) && !topblock.isLiquid() && this.isEarthbendable(botblock)) { location = loc.clone().add(0, -1, 0); this.locations.add(location); break; @@ -271,6 +275,9 @@ public class Ripple extends EarthAbility { } private void affect(final Entity entity) { + if (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation()) || ((entity instanceof Player) && Commands.invincible.contains(((Player) entity).getName()))) { + return; + } if (entity instanceof LivingEntity) { DamageHandler.damageEntity(entity, this.damage, this); } diff --git a/src/com/projectkorra/projectkorra/earthbending/Shockwave.java b/src/com/projectkorra/projectkorra/earthbending/Shockwave.java index c7417018..56f1402d 100644 --- a/src/com/projectkorra/projectkorra/earthbending/Shockwave.java +++ b/src/com/projectkorra/projectkorra/earthbending/Shockwave.java @@ -1,20 +1,23 @@ package com.projectkorra.projectkorra.earthbending; -import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.EarthAbility; +import com.projectkorra.projectkorra.attribute.Attribute; +import com.projectkorra.projectkorra.util.ParticleEffect; public class Shockwave extends EarthAbility { private boolean charged; + @Attribute(Attribute.CHARGE_DURATION) private long chargeTime; + @Attribute(Attribute.COOLDOWN) private long cooldown; private double angle; private double threshold; + @Attribute(Attribute.RANGE) private double range; public Shockwave(final Player player, final boolean fall) { @@ -79,8 +82,8 @@ public class Shockwave extends EarthAbility { return; } } else if (this.charged) { - final Location location = this.player.getEyeLocation(); - location.getWorld().playEffect(location, Effect.SMOKE, GeneralMethods.getIntCardinalDirection(this.player.getEyeLocation().getDirection()), 3); + final Location location = this.player.getEyeLocation().add(this.player.getEyeLocation().getDirection()); + ParticleEffect.SMOKE_NORMAL.display(location, 1); } } diff --git a/src/com/projectkorra/projectkorra/earthbending/Tremorsense.java b/src/com/projectkorra/projectkorra/earthbending/Tremorsense.java index c5811fd9..5865ea91 100644 --- a/src/com/projectkorra/projectkorra/earthbending/Tremorsense.java +++ b/src/com/projectkorra/projectkorra/earthbending/Tremorsense.java @@ -14,6 +14,8 @@ import org.bukkit.entity.Player; import com.projectkorra.projectkorra.BendingPlayer; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.EarthAbility; +import com.projectkorra.projectkorra.ability.ElementalAbility; +import com.projectkorra.projectkorra.attribute.Attribute; public class Tremorsense extends EarthAbility { @@ -21,10 +23,14 @@ public class Tremorsense extends EarthAbility { private static final Map BLOCKS = new ConcurrentHashMap(); private byte lightThreshold; + @Attribute("Depth") private int maxDepth; + @Attribute(Attribute.RADIUS) private int radius; + @Attribute(Attribute.COOLDOWN) private long cooldown; private Block block; + @Attribute(Attribute.RANGE) private int stickyRange; public Tremorsense(final Player player, final boolean clicked) { @@ -73,7 +79,7 @@ public class Tremorsense extends EarthAbility { } else if (!this.isEarthbendable(blocki) && earth) { foundAir = true; break; - } else if (!this.isEarthbendable(blocki) && !earth && blocki.getType() != Material.AIR) { + } else if (!this.isEarthbendable(blocki) && !earth && !ElementalAbility.isAir(blocki.getType())) { break; } } @@ -97,11 +103,11 @@ public class Tremorsense extends EarthAbility { if (isBendable && this.block == null) { this.block = standBlock; - this.player.sendBlockChange(this.block.getLocation(), 89, (byte) 1); + this.player.sendBlockChange(this.block.getLocation(), Material.GLOWSTONE, (byte) 1); } else if (isBendable && !this.block.equals(standBlock)) { this.revertGlowBlock(); this.block = standBlock; - this.player.sendBlockChange(this.block.getLocation(), 89, (byte) 1); + this.player.sendBlockChange(this.block.getLocation(), Material.GLOWSTONE, (byte) 1); } else if (this.block == null) { return; } else if (!this.player.getWorld().equals(this.block.getWorld())) { @@ -122,7 +128,7 @@ public class Tremorsense extends EarthAbility { public void revertGlowBlock() { if (this.block != null) { - this.player.sendBlockChange(this.block.getLocation(), this.block.getTypeId(), this.block.getData()); + this.player.sendBlockChange(this.block.getLocation(), this.block.getType(), this.block.getData()); } } diff --git a/src/com/projectkorra/projectkorra/earthbending/combo/EarthDomeOthers.java b/src/com/projectkorra/projectkorra/earthbending/combo/EarthDomeOthers.java index ac62f043..295fde3c 100644 --- a/src/com/projectkorra/projectkorra/earthbending/combo/EarthDomeOthers.java +++ b/src/com/projectkorra/projectkorra/earthbending/combo/EarthDomeOthers.java @@ -10,15 +10,17 @@ import org.bukkit.util.Vector; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.EarthAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.earthbending.EarthDome; import com.projectkorra.projectkorra.util.ParticleEffect; -import com.projectkorra.projectkorra.util.ParticleEffect.BlockData; public class EarthDomeOthers extends EarthAbility { - public Vector direction; - public double range = 0, maxRange; - public Location loc; + private Vector direction; + private double range; + @Attribute(Attribute.RANGE) + private double maxRange; + private Location loc; public EarthDomeOthers(final Player player) { super(player); @@ -34,6 +36,7 @@ public class EarthDomeOthers extends EarthAbility { if (!isEarthbendable(this.loc.getBlock().getRelative(BlockFace.DOWN).getType(), true, true, true)) { return; } + this.range = 0; this.direction = this.loc.getDirection().setY(0); this.maxRange = getConfig().getDouble("Abilities.Earth.EarthDome.Range"); this.start(); @@ -74,8 +77,8 @@ public class EarthDomeOthers extends EarthAbility { this.loc.setY(top.getY() + 1); - ParticleEffect.CRIT.display(this.loc, 0.4f, 0, 0.4f, 0.001f, 9); - ParticleEffect.BLOCK_DUST.display(new BlockData(this.loc.getBlock().getRelative(BlockFace.DOWN).getType(), (byte) 0), 0.2f, 0.1f, 0.2f, 0.001f, 7, this.loc, 255); + ParticleEffect.CRIT.display(this.loc, 9, 0.4, 0, 0.4, 0.001); + ParticleEffect.BLOCK_DUST.display(this.loc, 7, 0.2, 0.1, 0.2, 0.001, this.loc.getBlock().getRelative(BlockFace.DOWN).getBlockData()); for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(this.loc, 2)) { if (!(entity instanceof LivingEntity) || entity.getEntityId() == this.player.getEntityId()) { diff --git a/src/com/projectkorra/projectkorra/earthbending/combo/EarthDomeSelf.java b/src/com/projectkorra/projectkorra/earthbending/combo/EarthDomeSelf.java index 34919871..04fd92d2 100644 --- a/src/com/projectkorra/projectkorra/earthbending/combo/EarthDomeSelf.java +++ b/src/com/projectkorra/projectkorra/earthbending/combo/EarthDomeSelf.java @@ -20,8 +20,7 @@ public class EarthDomeSelf extends EarthAbility implements ComboAbility { } @Override - public void progress() { - } + public void progress() {} @Override public boolean isSneakAbility() { @@ -60,9 +59,4 @@ public class EarthDomeSelf extends EarthAbility implements ComboAbility { combo.add(new AbilityInformation("Shockwave", ClickType.RIGHT_CLICK_BLOCK)); return combo; } - - @Override - public String getInstructions() { - return "\n(Self) RaiseEarth (Right click) > Shockwave (Right click)\n(Projection) RaiseEarth(Right click) > Shockwave (Left click)"; - } } diff --git a/src/com/projectkorra/projectkorra/earthbending/combo/EarthPillars.java b/src/com/projectkorra/projectkorra/earthbending/combo/EarthPillars.java index 122a12e4..611c63f4 100644 --- a/src/com/projectkorra/projectkorra/earthbending/combo/EarthPillars.java +++ b/src/com/projectkorra/projectkorra/earthbending/combo/EarthPillars.java @@ -16,16 +16,24 @@ import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.ComboAbility; import com.projectkorra.projectkorra.ability.EarthAbility; import com.projectkorra.projectkorra.ability.util.ComboManager.AbilityInformation; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.earthbending.RaiseEarth; import com.projectkorra.projectkorra.util.ClickType; import com.projectkorra.projectkorra.util.DamageHandler; import com.projectkorra.projectkorra.util.ParticleEffect; -import com.projectkorra.projectkorra.util.ParticleEffect.BlockData; public class EarthPillars extends EarthAbility implements ComboAbility { - public double radius, damage, power, fallThreshold; - public boolean damaging; - public Map entities; + + @Attribute(Attribute.RADIUS) + private double radius; + @Attribute(Attribute.DAMAGE) + private double damage; + @Attribute(Attribute.KNOCKUP) + private double knockup; + private double fallThreshold; + private boolean damaging; + private boolean firstTime; + private Map entities; public EarthPillars(final Player player, final boolean fall) { super(player); @@ -41,16 +49,7 @@ public class EarthPillars extends EarthAbility implements ComboAbility { } } - for (final Entity e : GeneralMethods.getEntitiesAroundPoint(player.getLocation(), this.radius)) { - if (e instanceof LivingEntity && e.getEntityId() != player.getEntityId() && isEarthbendable(e.getLocation().getBlock().getRelative(BlockFace.DOWN).getType(), true, true, false)) { - ParticleEffect.BLOCK_DUST.display(new BlockData(e.getLocation().clone().subtract(0, 1, 0).getBlock().getType(), (byte) 0), 1f, 0.1f, 1f, 0, 6, e.getLocation(), 255); - this.affect((LivingEntity) e); - } - } - - if (this.entities.isEmpty()) { - return; - } + this.firstTime = true; this.start(); } @@ -58,16 +57,16 @@ public class EarthPillars extends EarthAbility implements ComboAbility { private void setFields(final boolean fall) { this.radius = getConfig().getDouble("Abilities.Earth.EarthPillars.Radius"); this.damage = getConfig().getDouble("Abilities.Earth.EarthPillars.Damage.Value"); - this.power = getConfig().getDouble("Abilities.Earth.EarthPillars.Power"); + this.knockup = getConfig().getDouble("Abilities.Earth.EarthPillars.Knockup"); this.damaging = getConfig().getBoolean("Abilities.Earth.EarthPillars.Damage.Enabled"); this.entities = new HashMap<>(); if (fall) { this.fallThreshold = getConfig().getDouble("Abilities.Earth.EarthPillars.FallThreshold"); this.damaging = true; - this.damage *= this.power; + this.damage *= this.knockup; this.radius = this.fallThreshold; - this.power += (this.player.getFallDistance() > this.fallThreshold ? this.player.getFallDistance() : this.fallThreshold) / 100; + this.knockup += (this.player.getFallDistance() > this.fallThreshold ? this.player.getFallDistance() : this.fallThreshold) / 100; } } @@ -78,6 +77,21 @@ public class EarthPillars extends EarthAbility implements ComboAbility { @Override public void progress() { + if (this.firstTime) { + for (final Entity e : GeneralMethods.getEntitiesAroundPoint(this.player.getLocation(), this.radius)) { + if (e instanceof LivingEntity && e.getEntityId() != this.player.getEntityId() && isEarthbendable(e.getLocation().getBlock().getRelative(BlockFace.DOWN).getType(), true, true, false)) { + ParticleEffect.BLOCK_DUST.display(e.getLocation(), 10, 1, 0.1, 1, e.getLocation().getBlock().getRelative(BlockFace.DOWN).getBlockData()); + this.affect((LivingEntity) e); + } + } + + if (this.entities.isEmpty()) { + this.remove(); + return; + } + this.firstTime = false; + } + final List removal = new ArrayList<>(); for (final RaiseEarth abil : this.entities.keySet()) { if (abil.isRemoved() && abil.isStarted()) { @@ -87,7 +101,7 @@ public class EarthPillars extends EarthAbility implements ComboAbility { continue; } - lent.setVelocity(new Vector(0, this.power, 0)); + lent.setVelocity(new Vector(0, this.knockup, 0)); } if (this.damaging) { DamageHandler.damageEntity(lent, this.damage, this); @@ -147,9 +161,4 @@ public class EarthPillars extends EarthAbility implements ComboAbility { earthPillars.add(new AbilityInformation("Catapult", ClickType.SHIFT_UP)); return earthPillars; } - - @Override - public String getInstructions() { - return "Shockwave (Tap sneak) > Shockwave (Hold sneak) > Catapult (Release sneak)"; - } } diff --git a/src/com/projectkorra/projectkorra/earthbending/lava/LavaFlow.java b/src/com/projectkorra/projectkorra/earthbending/lava/LavaFlow.java index d8754031..b41bf2ad 100644 --- a/src/com/projectkorra/projectkorra/earthbending/lava/LavaFlow.java +++ b/src/com/projectkorra/projectkorra/earthbending/lava/LavaFlow.java @@ -17,9 +17,12 @@ import org.bukkit.scheduler.BukkitRunnable; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ability.CoreAbility; +import com.projectkorra.projectkorra.ability.EarthAbility; import com.projectkorra.projectkorra.ability.LavaAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.util.BlockSource; import com.projectkorra.projectkorra.util.ClickType; +import com.projectkorra.projectkorra.util.Information; import com.projectkorra.projectkorra.util.ParticleEffect; import com.projectkorra.projectkorra.util.TempBlock; @@ -44,8 +47,10 @@ public class LavaFlow extends LavaAbility { private long time; private long clickLavaDelay; private long clickLandDelay; + @Attribute("Click" + Attribute.COOLDOWN) private long clickLavaCooldown; private long clickLandCooldown; + @Attribute("Shift" + Attribute.COOLDOWN) private long shiftCooldown; private long clickLavaCleanupDelay; private long clickLandCleanupDelay; @@ -53,14 +58,20 @@ public class LavaFlow extends LavaAbility { private double particleOffset; private double currentRadius; private double shiftPlatformRadius; + @Attribute("Shift" + Attribute.RADIUS) private double shiftMaxRadius; + @Attribute("Shift" + Attribute.SPEED) private double shiftFlowSpeed; private double shiftRemoveSpeed; private double shiftRemoveDelay; + @Attribute(Attribute.RANGE) private double clickRange; + @Attribute("Click" + Attribute.RADIUS) private double clickLavaRadius; private double clickLandRadius; + @Attribute("ClickLava" + Attribute.SPEED) private double lavaCreateSpeed; + @Attribute("ClickLand" + Attribute.SPEED) private double landCreateSpeed; private AbilityType type; private Location origin; @@ -245,14 +256,14 @@ public class LavaFlow extends LavaAbility { } } else if (Math.random() < this.particleDensity && dSquared < Math.pow(this.currentRadius + this.particleDensity, 2) && this.currentRadius + this.particleDensity < this.shiftMaxRadius && random.nextInt(3) == 0) { - ParticleEffect.LAVA.display(loc, (float) Math.random(), (float) Math.random(), (float) Math.random(), 0, 1); + ParticleEffect.LAVA.display(loc, 1, Math.random(), Math.random(), Math.random()); } } } if (!this.shiftIsFinished) { if (random.nextInt(10) == 0) { - ParticleEffect.LAVA.display(this.player.getLocation(), (float) Math.random(), (float) Math.random(), (float) Math.random(), 0, 1); + ParticleEffect.LAVA.display(this.player.getLocation(), 1, Math.random(), Math.random(), Math.random()); } } @@ -292,7 +303,7 @@ public class LavaFlow extends LavaAbility { if (!isWater(tempBlock)) { if (tempBlock != null && !isLava(tempBlock) && Math.random() < this.particleDensity && tempBlock.getLocation().distanceSquared(this.origin) <= Math.pow(this.clickLavaRadius, 2)) { if (random.nextInt(5) == 0) { - ParticleEffect.LAVA.display(loc, (float) Math.random(), (float) Math.random(), (float) Math.random(), 0, 1); + ParticleEffect.LAVA.display(loc, 1, Math.random(), Math.random(), Math.random()); } } } @@ -348,7 +359,7 @@ public class LavaFlow extends LavaAbility { final Block above = block.getRelative(BlockFace.UP); if ((isEarth(block) || isSand(block) || isMetal(block)) && !isWater(above)) { - ParticleEffect.LAVA.display(loc, (float) Math.random(), (float) Math.random(), (float) Math.random(), 0, 1); + ParticleEffect.LAVA.display(loc, 1, Math.random(), Math.random(), Math.random(), 0); } } } @@ -377,15 +388,21 @@ public class LavaFlow extends LavaAbility { */ public void createLava(final Block block) { if (isEarth(block) || isSand(block) || isMetal(block)) { + if (EarthAbility.getMovedEarth().containsKey(block)) { + final Information info = EarthAbility.getMovedEarth().get(block); + if (!info.getBlock().equals(block)) { + return; + } + } if (isPlant(block.getRelative(BlockFace.UP)) || isSnow(block.getRelative(BlockFace.UP))) { final Block above = block.getRelative(BlockFace.UP); final Block above2 = above.getRelative(BlockFace.UP); if (isPlant(above) || isSnow(above)) { - final TempBlock tb = new TempBlock(above, Material.AIR, (byte) 0); + final TempBlock tb = new TempBlock(above, Material.AIR); TEMP_AIR_BLOCKS.put(above, tb); this.affectedBlocks.add(tb); - if (isPlant(above2) && above2.getType().equals(Material.DOUBLE_PLANT)) { - final TempBlock tb2 = new TempBlock(above2, Material.AIR, (byte) 0); + if (isPlant(above2) && above2.getType().equals(Material.TALL_GRASS)) { + final TempBlock tb2 = new TempBlock(above2, Material.AIR); TEMP_AIR_BLOCKS.put(above2, tb2); this.affectedBlocks.add(tb); } @@ -393,20 +410,17 @@ public class LavaFlow extends LavaAbility { return; } } - TempBlock tblock; + TempBlock tblock = null; if (this.allowNaturalFlow) { - tblock = new TempBlock(block, Material.LAVA, (byte) 0); + block.setType(Material.LAVA); + block.setBlockData(GeneralMethods.getLavaData(0)); } else { - tblock = new TempBlock(block, Material.STATIONARY_LAVA, (byte) 0); + tblock = new TempBlock(block, Material.LAVA, GeneralMethods.getLavaData(0)); } if (tblock != null) { TEMP_LAVA_BLOCKS.put(block, tblock); this.affectedBlocks.add(tblock); - - if (this.allowNaturalFlow) { - TempBlock.removeBlock(block); - } } } } @@ -425,7 +439,7 @@ public class LavaFlow extends LavaAbility { return; } - final TempBlock tblock = new TempBlock(testBlock, this.revertMaterial, testBlock.getData()); + final TempBlock tblock = new TempBlock(testBlock, this.revertMaterial); this.affectedBlocks.add(tblock); TEMP_LAND_BLOCKS.put(testBlock, tblock); } @@ -507,9 +521,8 @@ public class LavaFlow extends LavaAbility { TEMP_AIR_BLOCKS.remove(tblock.getBlock()); } - if (isTempAir && tblock.getState().getType() == Material.DOUBLE_PLANT) { - tblock.getBlock().getRelative(BlockFace.UP).setType(Material.DOUBLE_PLANT); - tblock.getBlock().getRelative(BlockFace.UP).setData((byte) (tblock.getState().getRawData() + 8)); + if (isTempAir && tblock.getState().getType() == Material.TALL_GRASS) { + tblock.getBlock().getRelative(BlockFace.UP).setType(Material.TALL_GRASS); } } }.runTaskLater(ProjectKorra.plugin, (long) (i / this.shiftRemoveSpeed)); diff --git a/src/com/projectkorra/projectkorra/earthbending/lava/LavaSurge.java b/src/com/projectkorra/projectkorra/earthbending/lava/LavaSurge.java index 8d2954cd..fead9aa4 100644 --- a/src/com/projectkorra/projectkorra/earthbending/lava/LavaSurge.java +++ b/src/com/projectkorra/projectkorra/earthbending/lava/LavaSurge.java @@ -19,6 +19,7 @@ import org.bukkit.entity.Player; import org.bukkit.util.Vector; import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.ability.ElementalAbility; import com.projectkorra.projectkorra.ability.LavaAbility; import com.projectkorra.projectkorra.util.BlockSource; import com.projectkorra.projectkorra.util.ClickType; @@ -95,7 +96,7 @@ public class LavaSurge extends LavaAbility { public boolean prepare() { final Block targetBlock = BlockSource.getEarthSourceBlock(this.player, this.prepareRange, ClickType.SHIFT_DOWN); - if (targetBlock == null || !(targetBlock.getRelative(BlockFace.UP).getType() == Material.AIR) && !isLava(targetBlock.getRelative(BlockFace.UP))) { + if (targetBlock == null || !(ElementalAbility.isAir(targetBlock.getRelative(BlockFace.UP).getType())) && !isLava(targetBlock.getRelative(BlockFace.UP))) { return false; } @@ -118,9 +119,7 @@ public class LavaSurge extends LavaAbility { try { targetLocation = GeneralMethods.getTargetedEntity(this.player, this.travelRange * 2, null).getLocation(); - } - catch (final NullPointerException e) { - } + } catch (final NullPointerException e) {} if (targetLocation == null) { this.remove(); @@ -216,7 +215,7 @@ public class LavaSurge extends LavaAbility { playEarthbendingSound(b.getLocation()); for (int i = 0; i < 2; i++) { - final TempBlock tb = new TempBlock(b, Material.STATIONARY_LAVA, (byte) 0); + final TempBlock tb = new TempBlock(b, Material.LAVA, GeneralMethods.getLavaData(0)); this.fractureTempBlocks.add(tb); } } @@ -228,7 +227,7 @@ public class LavaSurge extends LavaAbility { } if (curTime > this.time + (this.fallingBlockInterval * this.fallingBlocksCount)) { - final FallingBlock fbs = GeneralMethods.spawnFallingBlock(this.sourceBlock.getLocation().add(0, 1, 0), 11, (byte) 0); + final FallingBlock fbs = GeneralMethods.spawnFallingBlock(this.sourceBlock.getLocation().add(0, 1, 0), Material.MAGMA_BLOCK, Material.MAGMA_BLOCK.createBlockData()); this.fallingBlocks.add(fbs); ALL_FALLING_BLOCKS.add(fbs); double x = this.random.nextDouble() / 5; @@ -242,7 +241,7 @@ public class LavaSurge extends LavaAbility { for (final Block b : this.fracture) { if (this.random.nextBoolean() && b != this.sourceBlock) { - final FallingBlock fb = GeneralMethods.spawnFallingBlock(b.getLocation().add(new Vector(0, 1, 0)), 11, (byte) 0); + final FallingBlock fb = GeneralMethods.spawnFallingBlock(b.getLocation().add(new Vector(0, 1, 0)), Material.MAGMA_BLOCK, Material.MAGMA_BLOCK.createBlockData()); ALL_FALLING_BLOCKS.add(fb); this.fallingBlocks.add(fb); fb.setVelocity(this.direction.clone().add(new Vector(this.random.nextDouble() / 10, 0.1, this.random.nextDouble() / 10)).multiply(1.2)); diff --git a/src/com/projectkorra/projectkorra/earthbending/lava/LavaSurgeWall.java b/src/com/projectkorra/projectkorra/earthbending/lava/LavaSurgeWall.java index 2ad5e163..360690f5 100644 --- a/src/com/projectkorra/projectkorra/earthbending/lava/LavaSurgeWall.java +++ b/src/com/projectkorra/projectkorra/earthbending/lava/LavaSurgeWall.java @@ -13,6 +13,7 @@ import org.bukkit.entity.Player; import org.bukkit.util.Vector; import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.ability.ElementalAbility; import com.projectkorra.projectkorra.ability.LavaAbility; import com.projectkorra.projectkorra.avatar.AvatarState; import com.projectkorra.projectkorra.firebending.FireBlast; @@ -160,7 +161,7 @@ public class LavaSurgeWall extends LavaAbility { if (this.forming) { final ArrayList blocks = new ArrayList(); - final Location loc = GeneralMethods.getTargetedLocation(this.player, (int) this.range, Material.WATER, Material.STATIONARY_WATER, Material.ICE); + final Location loc = GeneralMethods.getTargetedLocation(this.player, (int) this.range, Material.WATER, Material.ICE); this.location = loc.clone(); final Vector dir = this.player.getEyeLocation().getDirection(); Vector vec; @@ -176,7 +177,7 @@ public class LavaSurgeWall extends LavaAbility { } if (WALL_BLOCKS.containsKey(block)) { blocks.add(block); - } else if (!blocks.contains(block) && (block.getType() == Material.AIR || block.getType() == Material.FIRE || this.isLavabendable(block))) { + } else if (!blocks.contains(block) && (ElementalAbility.isAir(block.getType()) || block.getType() == Material.FIRE || this.isLavabendable(block))) { WALL_BLOCKS.put(block, this.player); this.addWallBlock(block); blocks.add(block); @@ -212,7 +213,7 @@ public class LavaSurgeWall extends LavaAbility { block = this.location.getBlock(); } - if (block.getType() != Material.AIR) { + if (!ElementalAbility.isAir(block.getType())) { this.breakBlock(); return; } else if (!this.progressing) { @@ -232,7 +233,7 @@ public class LavaSurgeWall extends LavaAbility { } private void addWallBlock(final Block block) { - new TempBlock(block, Material.STATIONARY_LAVA, (byte) 8); + new TempBlock(block, Material.LAVA, GeneralMethods.getLavaData(0)); } private void breakBlock() { @@ -272,7 +273,7 @@ public class LavaSurgeWall extends LavaAbility { return; } if (!TempBlock.isTempBlock(block)) { - new TempBlock(block, Material.STATIONARY_LAVA, (byte) 8); + new TempBlock(block, Material.LAVA, GeneralMethods.getLavaData(0)); AFFECTED_BLOCKS.put(block, block); } } diff --git a/src/com/projectkorra/projectkorra/earthbending/lava/LavaSurgeWave.java b/src/com/projectkorra/projectkorra/earthbending/lava/LavaSurgeWave.java index 1d2f342d..cb3d3145 100644 --- a/src/com/projectkorra/projectkorra/earthbending/lava/LavaSurgeWave.java +++ b/src/com/projectkorra/projectkorra/earthbending/lava/LavaSurgeWave.java @@ -165,13 +165,13 @@ public class LavaSurgeWave extends LavaAbility { final Block blockl = this.location.getBlock(); final ArrayList blocks = new ArrayList(); - if (!GeneralMethods.isRegionProtectedFromBuild(this, this.location) && blockl.getType() != Material.LEAVES && (blockl.getType() == Material.AIR || blockl.getType() == Material.FIRE || ElementalAbility.isPlant(blockl) || isLava(blockl))) { + if (!GeneralMethods.isRegionProtectedFromBuild(this, this.location) && (ElementalAbility.isAir(blockl.getType()) || blockl.getType() == Material.FIRE || ElementalAbility.isPlant(blockl) || isLava(blockl))) { for (double i = 0; i <= this.radius; i += 0.5) { for (double angle = 0; angle < 360; angle += 10) { final Vector vec = GeneralMethods.getOrthogonalVector(this.targetDirection, angle, i); final Block block = this.location.clone().add(vec).getBlock(); - if (!blocks.contains(block) && (block.getType() == Material.AIR || block.getType() == Material.FIRE) || this.isLavabendable(block)) { + if (!blocks.contains(block) && (ElementalAbility.isAir(block.getType()) || block.getType() == Material.FIRE) || this.isLavabendable(block)) { blocks.add(block); FireBlast.removeFireBlastsAroundPoint(block.getLocation(), 2); } @@ -253,7 +253,7 @@ public class LavaSurgeWave extends LavaAbility { if (GeneralMethods.isRegionProtectedFromBuild(this, block.getLocation())) { return; } else if (!TempBlock.isTempBlock(block)) { - new TempBlock(block, Material.STATIONARY_LAVA, (byte) 8); + new TempBlock(block, Material.LAVA, GeneralMethods.getLavaData(0)); this.waveBlocks.put(block, block); } } diff --git a/src/com/projectkorra/projectkorra/earthbending/metal/Extraction.java b/src/com/projectkorra/projectkorra/earthbending/metal/Extraction.java index 0805d894..d5ce3436 100644 --- a/src/com/projectkorra/projectkorra/earthbending/metal/Extraction.java +++ b/src/com/projectkorra/projectkorra/earthbending/metal/Extraction.java @@ -11,12 +11,18 @@ import org.bukkit.inventory.ItemStack; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.MetalAbility; +import com.projectkorra.projectkorra.attribute.Attribute; +import com.projectkorra.projectkorra.util.TempBlock; public class Extraction extends MetalAbility { + @Attribute("DoubleChance") private int doubleChance; + @Attribute("TripleChance") private int tripleChance; + @Attribute(Attribute.SELECT_RANGE) private int selectRange; + @Attribute(Attribute.COOLDOWN) private long cooldown; private Block originBlock; @@ -37,7 +43,7 @@ public class Extraction extends MetalAbility { return; } - if (!GeneralMethods.isRegionProtectedFromBuild(this, this.originBlock.getLocation())) { + if (!GeneralMethods.isRegionProtectedFromBuild(this, this.originBlock.getLocation()) && !TempBlock.isTempBlock(this.originBlock)) { final Material material = this.originBlock.getType(); Material type = null; @@ -52,7 +58,7 @@ public class Extraction extends MetalAbility { player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.GOLD_INGOT, this.getAmount())); type = Material.STONE; break; - case QUARTZ_ORE: + case NETHER_QUARTZ_ORE: this.originBlock.setType(Material.NETHERRACK); player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.QUARTZ, this.getAmount())); type = Material.NETHERRACK; @@ -91,8 +97,7 @@ public class Extraction extends MetalAbility { } @Override - public void progress() { - } + public void progress() {} @Override public Location getLocation() { diff --git a/src/com/projectkorra/projectkorra/earthbending/metal/MetalClips.java b/src/com/projectkorra/projectkorra/earthbending/metal/MetalClips.java index b4857b18..d535e137 100644 --- a/src/com/projectkorra/projectkorra/earthbending/metal/MetalClips.java +++ b/src/com/projectkorra/projectkorra/earthbending/metal/MetalClips.java @@ -2,6 +2,7 @@ package com.projectkorra.projectkorra.earthbending.metal; import java.util.ArrayList; import java.util.Arrays; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -17,9 +18,11 @@ import org.bukkit.entity.Zombie; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; +import com.projectkorra.projectkorra.command.Commands; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.CoreAbility; import com.projectkorra.projectkorra.ability.MetalAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.util.DamageHandler; import com.projectkorra.projectkorra.util.TempArmor; @@ -27,27 +30,39 @@ public class MetalClips extends MetalAbility { private static final Map ENTITY_CLIPS_COUNT = new ConcurrentHashMap<>(); private static final Map TARGET_TO_ABILITY = new ConcurrentHashMap<>(); - private static final Material[] METAL_ITEMS = { Material.IRON_INGOT, Material.IRON_HELMET, Material.IRON_CHESTPLATE, Material.IRON_LEGGINGS, Material.IRON_BOOTS, Material.IRON_BLOCK, Material.IRON_AXE, Material.IRON_PICKAXE, Material.IRON_SWORD, Material.IRON_HOE, Material.IRON_SPADE, Material.IRON_DOOR }; + private static final Material[] METAL_ITEMS = { Material.IRON_INGOT, Material.IRON_HELMET, Material.IRON_CHESTPLATE, Material.IRON_LEGGINGS, Material.IRON_BOOTS, Material.IRON_BLOCK, Material.IRON_AXE, Material.IRON_PICKAXE, Material.IRON_SWORD, Material.IRON_HOE, Material.IRON_SHOVEL, Material.IRON_DOOR }; private boolean isBeingWorn; private boolean isControlling; + @Attribute("CanThrow") private boolean canThrow; private boolean isMagnetized; + @Attribute("CanUse4Clips") private boolean canUse4Clips; + @Attribute("CanLoot") private boolean canLoot; private boolean hasSnuck; private int metalClipsCount; private int abilityType; private int armorTime; + @Attribute("Magnet" + Attribute.RANGE) private int magnetRange; private long armorStartTime; + @Attribute(Attribute.COOLDOWN) private long cooldown; + @Attribute("Shoot" + Attribute.COOLDOWN) private long shootCooldown; + @Attribute("Crush" + Attribute.COOLDOWN) private long crushCooldown; + @Attribute("Magnet" + Attribute.COOLDOWN) private long magnetCooldown; - private double magnetPower; + @Attribute("Magnet" + Attribute.SPEED) + private double magnetSpeed; + @Attribute(Attribute.RANGE) private double range; + @Attribute("Crush" + Attribute.DAMAGE) private double crushDamage; + @Attribute(Attribute.DAMAGE) private double damage; private LivingEntity targetEntity; private List trackedIngots; @@ -65,11 +80,11 @@ public class MetalClips extends MetalAbility { this.range = getConfig().getDouble("Abilities.Earth.MetalClips.Range"); this.cooldown = getConfig().getLong("Abilities.Earth.MetalClips.Cooldown"); this.shootCooldown = 600; - this.crushCooldown = getConfig().getLong("Abilities.Earth.MetalClips.CrushCooldown"); - this.magnetCooldown = getConfig().getLong("Abilities.Earth.MetalClips.MagnetCooldown"); - this.magnetRange = getConfig().getInt("Abilities.Earth.MetalClips.MagnetRange"); - this.magnetPower = getConfig().getDouble("Abilities.Earth.MetalClips.MagnetPower"); - this.crushDamage = getConfig().getDouble("Abilities.Earth.MetalClips.CrushDamage"); + this.crushCooldown = getConfig().getLong("Abilities.Earth.MetalClips.Crush.Cooldown"); + this.magnetCooldown = getConfig().getLong("Abilities.Earth.MetalClips.Magnet.Cooldown"); + this.magnetRange = getConfig().getInt("Abilities.Earth.MetalClips.Magnet.Range"); + this.magnetSpeed = getConfig().getDouble("Abilities.Earth.MetalClips.Magnet.Speed"); + this.crushDamage = getConfig().getDouble("Abilities.Earth.MetalClips.Crush.Damage"); this.damage = getConfig().getDouble("Abilities.Earth.MetalClips.Damage"); this.canThrow = (getConfig().getBoolean("Abilities.Earth.MetalClips.ThrowEnabled") && player.hasPermission("bending.ability.metalclips.throw")); this.trackedIngots = new ArrayList<>(); @@ -151,7 +166,7 @@ public class MetalClips extends MetalAbility { return; } else if (this.metalClipsCount == 3 && !this.canUse4Clips) { return; - } else if (this.targetEntity != null && GeneralMethods.isRegionProtectedFromBuild(this, this.targetEntity.getLocation())) { + } else if (this.targetEntity != null && (GeneralMethods.isRegionProtectedFromBuild(this, this.targetEntity.getLocation()) || ((targetEntity instanceof Player) && Commands.invincible.contains(((Player) targetEntity).getName())))) { return; } @@ -189,15 +204,11 @@ public class MetalClips extends MetalAbility { } public void resetArmor() { - if (!this.isMagnetized) { - this.bPlayer.addCooldown(this); - } if (this.targetEntity == null || !TempArmor.hasTempArmor(this.targetEntity) || this.targetEntity.isDead()) { return; } TempArmor.getVisibleTempArmor(this.targetEntity).revert(); - this.dropIngots(this.targetEntity.getLocation()); this.isBeingWorn = false; } @@ -219,7 +230,7 @@ public class MetalClips extends MetalAbility { dz = target.getZ() - location.getZ(); final Vector vector = new Vector(dx, dy, dz); vector.normalize(); - this.targetEntity.setVelocity(vector.multiply(this.metalClipsCount / 2).normalize()); + this.targetEntity.setVelocity(vector.multiply(this.metalClipsCount / 2D)); this.remove(); } @@ -257,7 +268,7 @@ public class MetalClips extends MetalAbility { } this.isControlling = false; this.isMagnetized = false; - if (this.metalClipsCount < 4 && this.hasSnuck && this.abilityType == 0) { + if (this.metalClipsCount > 0 && this.hasSnuck && this.abilityType == 0) { this.launch(); } } @@ -333,7 +344,7 @@ public class MetalClips extends MetalAbility { final Item iron = (Item) entity; if (Arrays.asList(METAL_ITEMS).contains(iron.getItemStack().getType())) { - iron.setVelocity(vector.normalize().multiply(this.magnetPower).add(new Vector(0, 0.2, 0))); + iron.setVelocity(vector.normalize().multiply(this.magnetSpeed).add(new Vector(0, 0.2, 0))); } } } @@ -401,46 +412,47 @@ public class MetalClips extends MetalAbility { } } - for (int i = this.trackedIngots.size() - 1; i >= 0; i--) { - final Item ii = this.trackedIngots.get(i); + final Iterator it = this.trackedIngots.iterator(); + while (it.hasNext()) { + final Item ii = it.next(); if (ii.isOnGround()) { - this.trackedIngots.remove(i); + it.remove(); continue; } - if (ii.getItemStack().getType() == Material.IRON_INGOT) { - if (GeneralMethods.getEntitiesAroundPoint(ii.getLocation(), 2).size() == 0) { - this.remove(); - return; - } + for (final Entity e : GeneralMethods.getEntitiesAroundPoint(ii.getLocation(), 1.8)) { + if (e instanceof LivingEntity && e.getEntityId() != this.player.getEntityId()) { + if ((e instanceof Player || e instanceof Zombie || e instanceof Skeleton)) { + if (this.targetEntity == null) { + this.targetEntity = (LivingEntity) e; + TARGET_TO_ABILITY.put(this.targetEntity, this); + this.formArmor(); + } else if (this.targetEntity == e) { + this.formArmor(); + } else { + if (TARGET_TO_ABILITY.get(this.targetEntity) == this) { + this.resetArmor(); + this.metalClipsCount = 0; + ENTITY_CLIPS_COUNT.remove(this.targetEntity); + TARGET_TO_ABILITY.remove(this.targetEntity); - for (final Entity e : GeneralMethods.getEntitiesAroundPoint(ii.getLocation(), 2)) { - if (e instanceof LivingEntity && e.getEntityId() != this.player.getEntityId()) { - if ((e instanceof Player || e instanceof Zombie || e instanceof Skeleton)) { - if (this.targetEntity == null) { this.targetEntity = (LivingEntity) e; TARGET_TO_ABILITY.put(this.targetEntity, this); this.formArmor(); - } else if (this.targetEntity == e) { - this.formArmor(); } else { - this.dropIngots(e.getLocation()); TARGET_TO_ABILITY.get(this.targetEntity).remove(); } - } else { - DamageHandler.damageEntity(e, this.player, this.damage, this); - this.dropIngots(e.getLocation(), ii.getItemStack().getAmount()); - this.remove(); } - - ii.remove(); - break; + } else { + DamageHandler.damageEntity(e, this.player, this.damage, this); + this.dropIngots(e.getLocation(), ii.getItemStack().getAmount()); } + it.remove(); + ii.remove(); + break; } } } - - this.removeDeadIngots(); } public void dropIngots(final Location loc) { @@ -452,20 +464,14 @@ public class MetalClips extends MetalAbility { i.setPickupDelay(61); } - public void removeDeadIngots() { - for (int i = 0; i < this.trackedIngots.size(); i++) { - final Item ii = this.trackedIngots.get(i); - if (ii.isDead()) { - this.trackedIngots.remove(ii); - } - } - } - @Override public void remove() { super.remove(); this.resetArmor(); + if (!this.isMagnetized) { + this.bPlayer.addCooldown(this); + } this.trackedIngots.clear(); this.metalClipsCount = 0; @@ -639,12 +645,12 @@ public class MetalClips extends MetalAbility { this.armorStartTime = armorStartTime; } - public double getMagnetPower() { - return this.magnetPower; + public double getMagnetSpeed() { + return this.magnetSpeed; } - public void setMagnetPower(final double magnetPower) { - this.magnetPower = magnetPower; + public void setMagnetSpeed(final double magnetSpeed) { + this.magnetSpeed = magnetSpeed; } public double getRange() { diff --git a/src/com/projectkorra/projectkorra/earthbending/passive/DensityShift.java b/src/com/projectkorra/projectkorra/earthbending/passive/DensityShift.java index ba00ce20..fded2585 100644 --- a/src/com/projectkorra/projectkorra/earthbending/passive/DensityShift.java +++ b/src/com/projectkorra/projectkorra/earthbending/passive/DensityShift.java @@ -1,14 +1,13 @@ package com.projectkorra.projectkorra.earthbending.passive; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; +import java.util.HashSet; +import java.util.Set; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; -import org.bukkit.material.MaterialData; import com.projectkorra.projectkorra.BendingPlayer; import com.projectkorra.projectkorra.GeneralMethods; @@ -20,8 +19,7 @@ import com.projectkorra.projectkorra.configuration.ConfigManager; import com.projectkorra.projectkorra.util.TempBlock; public class DensityShift extends EarthAbility implements PassiveAbility { - private static final Map SAND_BLOCKS = new ConcurrentHashMap<>(); - private static final Map SAND_ID_ENTITIES = new ConcurrentHashMap<>(); + private static final Set SAND_BLOCKS = new HashSet<>(); public DensityShift(final Player player) { super(player); @@ -40,40 +38,21 @@ public class DensityShift extends EarthAbility implements PassiveAbility { return true; } - if (ElementalAbility.isEarth(block) || ElementalAbility.isTransparent(player, block)) { - if (!ElementalAbility.isTransparent(player, block)) { - final MaterialData type = block.getState().getData(); - if (GeneralMethods.isSolid(block.getRelative(BlockFace.DOWN))) { - if (type.getItemType() == Material.RED_SANDSTONE) { - final byte data = (byte) 0x1; - block.setType(Material.SAND); - block.setData(data); - } else { - block.setType(Material.SAND); - } - - if (!SAND_BLOCKS.containsKey(block)) { - SAND_ID_ENTITIES.put(block, type); - SAND_BLOCKS.put(block, System.currentTimeMillis()); - } - } - } - + if (ElementalAbility.isEarth(block)) { for (final Block affectedBlock : GeneralMethods.getBlocksAroundPoint(block.getLocation(), 2)) { if (ElementalAbility.isEarth(affectedBlock)) { if (GeneralMethods.isSolid(affectedBlock.getRelative(BlockFace.DOWN))) { - final MaterialData type = affectedBlock.getState().getData(); - if (type.getItemType() == Material.RED_SANDSTONE) { - final byte data = (byte) 0x1; - affectedBlock.setType(Material.SAND); - affectedBlock.setData(data); - } else { - affectedBlock.setType(Material.SAND); + Material sand = Material.SAND; + if (affectedBlock.getType() == Material.RED_SANDSTONE) { + sand = Material.RED_SAND; } - if (!SAND_BLOCKS.containsKey(affectedBlock)) { - SAND_ID_ENTITIES.put(affectedBlock, type); - SAND_BLOCKS.put(affectedBlock, System.currentTimeMillis()); + final TempBlock tb = new TempBlock(affectedBlock, sand); + + if (!SAND_BLOCKS.contains(tb)) { + SAND_BLOCKS.add(tb); + tb.setRevertTime(getDuration()); + tb.setRevertTask(() -> SAND_BLOCKS.remove(tb)); } } } @@ -86,53 +65,41 @@ public class DensityShift extends EarthAbility implements PassiveAbility { } public static boolean isPassiveSand(final Block block) { - return SAND_BLOCKS.containsKey(block); - } - - public static void revertSand(final Block block) { - final MaterialData materialdata = SAND_ID_ENTITIES.get(block); - SAND_ID_ENTITIES.remove(block); - SAND_BLOCKS.remove(block); - - if (block.getType() == Material.SAND) { - block.setType(materialdata.getItemType()); - block.setData(materialdata.getData()); + if (TempBlock.isTempBlock(block)) { + return SAND_BLOCKS.contains(TempBlock.get(block)); + } else { + return false; } } - public static void revertSands() { - for (final Block block : SAND_BLOCKS.keySet()) { - if (System.currentTimeMillis() >= SAND_BLOCKS.get(block) + getDuration()) { - revertSand(block); - } + public static void revertSand(final Block block) { + if (TempBlock.isTempBlock(block)) { + TempBlock.get(block).revertBlock(); } } public static void revertAllSand() { - for (final Block block : SAND_BLOCKS.keySet()) { - revertSand(block); + for (final TempBlock block : SAND_BLOCKS) { + block.setRevertTask(null); + block.revertBlock(); } + SAND_BLOCKS.clear(); } public static void removeAll() { revertAllSand(); } - public static Map getSandBlocks() { + public static Set getSandBlocks() { return SAND_BLOCKS; } - public static Map getSandIdEntities() { - return SAND_ID_ENTITIES; - } - public static long getDuration() { return ConfigManager.getConfig().getLong("Abilities.Earth.Passive.Duration"); } @Override - public void progress() { - } + public void progress() {} @Override public boolean isSneakAbility() { diff --git a/src/com/projectkorra/projectkorra/earthbending/passive/FerroControl.java b/src/com/projectkorra/projectkorra/earthbending/passive/FerroControl.java index 509cfa23..994235ab 100644 --- a/src/com/projectkorra/projectkorra/earthbending/passive/FerroControl.java +++ b/src/com/projectkorra/projectkorra/earthbending/passive/FerroControl.java @@ -6,7 +6,8 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; +import org.bukkit.block.data.type.Door; +import org.bukkit.block.data.type.TrapDoor; import org.bukkit.entity.Player; import com.projectkorra.projectkorra.GeneralMethods; @@ -20,11 +21,13 @@ public class FerroControl extends MetalAbility implements PassiveAbility { public FerroControl(final Player player) { super(player); + this.start(); } @Override public void progress() { if (!this.player.isSneaking() || !this.bPlayer.canUsePassive(this) || !this.bPlayer.canBendPassive(this)) { + this.remove(); return; } @@ -32,17 +35,21 @@ public class FerroControl extends MetalAbility implements PassiveAbility { this.block = this.player.getTargetBlock((HashSet) null, 5); if (this.block != null) { - if (this.block.getType() == Material.IRON_DOOR_BLOCK && !GeneralMethods.isRegionProtectedFromBuild(this.player, this.block.getLocation())) { - if (this.block.getData() >= 8) { - this.block = this.block.getRelative(BlockFace.DOWN); - } + if (this.block.getType() == Material.IRON_DOOR && !GeneralMethods.isRegionProtectedFromBuild(this.player, this.block.getLocation())) { + final Door door = (Door) this.block.getBlockData(); - this.block.setData((byte) ((this.block.getData() & 0x4) == 0x4 ? (this.block.getData() & ~0x4) : (this.block.getData() | 0x4))); - open = (this.block.getData() & 0x4) == 0x4; + door.setOpen(!door.isOpen()); + this.block.setBlockData(door); + + open = door.isOpen(); used = true; } else if (this.block.getType() == Material.IRON_TRAPDOOR && !GeneralMethods.isRegionProtectedFromBuild(this.player, this.block.getLocation())) { - this.block.setData((byte) ((this.block.getData() & 0x4) == 0x4 ? (this.block.getData() & ~0x4) : (this.block.getData() | 0x4))); - open = (this.block.getData() & 0x4) == 0x4; + final TrapDoor trap = (TrapDoor) this.block.getBlockData(); + + trap.setOpen(!trap.isOpen()); + this.block.setBlockData(trap); + + open = trap.isOpen(); used = true; tDoor = true; } @@ -54,6 +61,7 @@ public class FerroControl extends MetalAbility implements PassiveAbility { this.block.getWorld().playSound(this.block.getLocation(), Sound.valueOf(sound), 0.5f, 0); this.bPlayer.addCooldown(this, 200); } + this.remove(); } @Override @@ -83,7 +91,7 @@ public class FerroControl extends MetalAbility implements PassiveAbility { @Override public boolean isInstantiable() { - return true; + return false; } @Override diff --git a/src/com/projectkorra/projectkorra/earthbending/util/EarthbendingManager.java b/src/com/projectkorra/projectkorra/earthbending/util/EarthbendingManager.java index 6e120490..40ff1d12 100644 --- a/src/com/projectkorra/projectkorra/earthbending/util/EarthbendingManager.java +++ b/src/com/projectkorra/projectkorra/earthbending/util/EarthbendingManager.java @@ -3,10 +3,8 @@ package com.projectkorra.projectkorra.earthbending.util; import org.bukkit.Bukkit; import com.projectkorra.projectkorra.ProjectKorra; -import com.projectkorra.projectkorra.earthbending.EarthTunnel; import com.projectkorra.projectkorra.earthbending.Shockwave; import com.projectkorra.projectkorra.earthbending.Tremorsense; -import com.projectkorra.projectkorra.earthbending.passive.DensityShift; import com.projectkorra.projectkorra.util.RevertChecker; public class EarthbendingManager implements Runnable { @@ -18,10 +16,8 @@ public class EarthbendingManager implements Runnable { @Override public void run() { - DensityShift.revertSands(); RevertChecker.revertEarthBlocks(); Shockwave.progressAll(); Tremorsense.manage(Bukkit.getServer()); - EarthTunnel.revertAirBlocks(); } } diff --git a/src/com/projectkorra/projectkorra/event/AttributeModifyEvent.java b/src/com/projectkorra/projectkorra/event/AttributeModifyEvent.java deleted file mode 100644 index 774079e5..00000000 --- a/src/com/projectkorra/projectkorra/event/AttributeModifyEvent.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.projectkorra.projectkorra.event; - -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; - -import com.projectkorra.projectkorra.ability.CoreAbility; -import com.projectkorra.projectkorra.attribute.AttributeModifier; - -public class AttributeModifyEvent extends Event { - - private final CoreAbility ability; - private final String attribute; - private final double oldValue; - private double newValue; - private final AttributeModifier modifier; - - public AttributeModifyEvent(final CoreAbility ability, final String attribute, final double oldValue, final double newValue, final AttributeModifier modifier) { - this.ability = ability; - this.attribute = attribute; - this.oldValue = oldValue; - this.newValue = newValue; - this.modifier = modifier; - } - - public CoreAbility getAbility() { - return this.ability; - } - - public AttributeModifier getModifier() { - return this.modifier; - } - - public boolean hasModifier() { - return this.modifier != null; - } - - public String getAttribute() { - return this.attribute; - } - - public double getOldValue() { - return this.oldValue; - } - - public double getNewValue() { - return this.newValue; - } - - public void setNewValue(final double newValue) { - this.newValue = newValue; - } - - @Override - public HandlerList getHandlers() { - return null; - } - -} diff --git a/src/com/projectkorra/projectkorra/event/BindChangeEvent.java b/src/com/projectkorra/projectkorra/event/PlayerBindChangeEvent.java similarity index 85% rename from src/com/projectkorra/projectkorra/event/BindChangeEvent.java rename to src/com/projectkorra/projectkorra/event/PlayerBindChangeEvent.java index 79bc2b67..eb2e36d4 100644 --- a/src/com/projectkorra/projectkorra/event/BindChangeEvent.java +++ b/src/com/projectkorra/projectkorra/event/PlayerBindChangeEvent.java @@ -9,7 +9,7 @@ import org.bukkit.event.HandlerList; * * @author savior67 */ -public class BindChangeEvent extends Event { +public class PlayerBindChangeEvent extends Event { private static final HandlerList handlers = new HandlerList(); private final Player player; @@ -20,7 +20,7 @@ public class BindChangeEvent extends Event { private boolean cancelled; // bind event for abilities. - public BindChangeEvent(final Player player, final String ability, final int slot, final boolean isBinding) { + public PlayerBindChangeEvent(final Player player, final String ability, final int slot, final boolean isBinding) { this.player = player; this.ability = ability; this.slot = slot; @@ -30,7 +30,7 @@ public class BindChangeEvent extends Event { } // used for multi abilities. - public BindChangeEvent(final Player player, final String ability, final boolean isBinding) { + public PlayerBindChangeEvent(final Player player, final String ability, final boolean isBinding) { this.player = player; this.ability = ability; this.slot = -1; diff --git a/src/com/projectkorra/projectkorra/event/PlayerChangeElementEvent.java b/src/com/projectkorra/projectkorra/event/PlayerChangeElementEvent.java index b898fb8e..0db15b8a 100644 --- a/src/com/projectkorra/projectkorra/event/PlayerChangeElementEvent.java +++ b/src/com/projectkorra/projectkorra/event/PlayerChangeElementEvent.java @@ -76,8 +76,7 @@ public class PlayerChangeElementEvent extends Event { public static enum Result { CHOOSE, REMOVE, ADD, PERMAREMOVE; - private Result() { - } + private Result() {} } } diff --git a/src/com/projectkorra/projectkorra/event/PlayerChangeSubElementEvent.java b/src/com/projectkorra/projectkorra/event/PlayerChangeSubElementEvent.java index 9dc656a8..4f648512 100644 --- a/src/com/projectkorra/projectkorra/event/PlayerChangeSubElementEvent.java +++ b/src/com/projectkorra/projectkorra/event/PlayerChangeSubElementEvent.java @@ -74,7 +74,6 @@ public class PlayerChangeSubElementEvent extends Event { public static enum Result { CHOOSE, REMOVE, ADD, PERMAREMOVE; - private Result() { - } + private Result() {} } } diff --git a/src/com/projectkorra/projectkorra/firebending/Blaze.java b/src/com/projectkorra/projectkorra/firebending/Blaze.java index 3bd1933a..280f85bb 100644 --- a/src/com/projectkorra/projectkorra/firebending/Blaze.java +++ b/src/com/projectkorra/projectkorra/firebending/Blaze.java @@ -5,13 +5,18 @@ import org.bukkit.entity.Player; import org.bukkit.util.Vector; import com.projectkorra.projectkorra.ability.FireAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.avatar.AvatarState; public class Blaze extends FireAbility { + @Attribute("Arc") private int arc; + @Attribute(Attribute.COOLDOWN) private long cooldown; + @Attribute(Attribute.RANGE) private double range; + @Attribute(Attribute.SPEED) private double speed; public Blaze(final Player player) { @@ -59,8 +64,7 @@ public class Blaze extends FireAbility { } @Override - public void progress() { - } + public void progress() {} @Override public Location getLocation() { diff --git a/src/com/projectkorra/projectkorra/firebending/BlazeArc.java b/src/com/projectkorra/projectkorra/firebending/BlazeArc.java index 996b5977..94184f74 100644 --- a/src/com/projectkorra/projectkorra/firebending/BlazeArc.java +++ b/src/com/projectkorra/projectkorra/firebending/BlazeArc.java @@ -1,6 +1,5 @@ package com.projectkorra.projectkorra.firebending; -import java.util.Arrays; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -8,25 +7,29 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.block.BlockState; import org.bukkit.entity.Player; -import org.bukkit.material.MaterialData; import org.bukkit.util.Vector; +import com.projectkorra.projectkorra.BendingPlayer; +import com.projectkorra.projectkorra.Element; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.FireAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.waterbending.plant.PlantRegrowth; public class BlazeArc extends FireAbility { private static final long DISSIPATE_REMOVE_TIME = 400; - private static final Material[] OVERWRITABLE_MATERIALS = { Material.SAPLING, Material.LONG_GRASS, Material.DEAD_BUSH, Material.YELLOW_FLOWER, Material.RED_ROSE, Material.BROWN_MUSHROOM, Material.RED_MUSHROOM, Material.FIRE, Material.SNOW, Material.TORCH }; - private static final Map IGNITED_BLOCKS = new ConcurrentHashMap(); - private static final Map IGNITED_TIMES = new ConcurrentHashMap(); - private static final Map REPLACED_BLOCKS = new ConcurrentHashMap(); + private static final Map IGNITED_BLOCKS = new ConcurrentHashMap<>(); + private static final Map IGNITED_TIMES = new ConcurrentHashMap<>(); + private static final Map REPLACED_BLOCKS = new ConcurrentHashMap<>(); private long time; private long interval; + @Attribute(Attribute.RANGE) private double range; + @Attribute(Attribute.SPEED) private double speed; private Location origin; private Location location; @@ -50,13 +53,13 @@ public class BlazeArc extends FireAbility { } private void ignite(final Block block) { - if (block.getType() != Material.FIRE && block.getType() != Material.AIR) { + if (block.getType() != Material.FIRE && !isAir(block.getType())) { if (canFireGrief()) { if (isPlant(block) || isSnow(block)) { new PlantRegrowth(this.player, block); } } else if (block.getType() != Material.FIRE) { - REPLACED_BLOCKS.put(block.getLocation(), block.getState().getData()); + REPLACED_BLOCKS.put(block.getLocation(), block.getState()); } } @@ -86,17 +89,9 @@ public class BlazeArc extends FireAbility { return; } - if (isIgnitable(this.player, block)) { - this.ignite(block); - } else if (isIgnitable(this.player, block.getRelative(BlockFace.DOWN))) { - this.ignite(block.getRelative(BlockFace.DOWN)); - this.location = block.getRelative(BlockFace.DOWN).getLocation(); - } else if (isIgnitable(this.player, block.getRelative(BlockFace.UP))) { - this.ignite(block.getRelative(BlockFace.UP)); - this.location = block.getRelative(BlockFace.UP).getLocation(); - } else { - this.remove(); - return; + final Block ignitable = getIgnitable(block); + if (ignitable != null) { + this.ignite(ignitable); } } } @@ -125,17 +120,42 @@ public class BlazeArc extends FireAbility { } } - public static boolean isIgnitable(final Player player, final Block block) { - if (block.getType() == Material.FIRE) { - return true; - } else if (Arrays.asList(OVERWRITABLE_MATERIALS).contains(block.getType())) { - return true; - } else if (block.getType() != Material.AIR) { - return false; + public static Block getIgnitable(final Block block) { + Block top = block; + + for (int i = 0; i < 2; i++) { + if (GeneralMethods.isSolid(top.getRelative(BlockFace.DOWN))) { + break; + } + + top = top.getRelative(BlockFace.DOWN); } - final Block belowBlock = block.getRelative(BlockFace.DOWN); - return isIgnitable(belowBlock); + if (top.getType() == Material.FIRE) { + return top; + } else if (top.getType().isBurnable()) { + return top; + } else if (isAir(top.getType())) { + return top; + } else { + return null; + } + } + + public static boolean isIgnitable(final Player player, final Block block) { + if (!BendingPlayer.getBendingPlayer(player).hasElement(Element.FIRE)) { + return false; + } else if (!GeneralMethods.isSolid(block.getRelative(BlockFace.DOWN))) { + return false; + } else if (block.getType() == Material.FIRE) { + return true; + } else if (block.getType().isBurnable()) { + return true; + } else if (isAir(block.getType())) { + return true; + } else { + return false; + } } public static void removeAllCleanup() { @@ -162,8 +182,8 @@ public class BlazeArc extends FireAbility { IGNITED_TIMES.remove(block); } if (REPLACED_BLOCKS.containsKey(block.getLocation())) { - block.setType(REPLACED_BLOCKS.get(block.getLocation()).getItemType()); - block.setData(REPLACED_BLOCKS.get(block.getLocation()).getData()); + block.setType(REPLACED_BLOCKS.get(block.getLocation()).getType()); + block.setBlockData(REPLACED_BLOCKS.get(block.getLocation()).getBlockData()); REPLACED_BLOCKS.remove(block.getLocation()); } } @@ -248,10 +268,6 @@ public class BlazeArc extends FireAbility { return DISSIPATE_REMOVE_TIME; } - public static Material[] getOverwritableMaterials() { - return OVERWRITABLE_MATERIALS; - } - public static Map getIgnitedBlocks() { return IGNITED_BLOCKS; } @@ -260,7 +276,7 @@ public class BlazeArc extends FireAbility { return IGNITED_TIMES; } - public static Map getReplacedBlocks() { + public static Map getReplacedBlocks() { return REPLACED_BLOCKS; } diff --git a/src/com/projectkorra/projectkorra/firebending/BlazeRing.java b/src/com/projectkorra/projectkorra/firebending/BlazeRing.java index b4f5c859..648a4248 100644 --- a/src/com/projectkorra/projectkorra/firebending/BlazeRing.java +++ b/src/com/projectkorra/projectkorra/firebending/BlazeRing.java @@ -5,10 +5,13 @@ import org.bukkit.entity.Player; import org.bukkit.util.Vector; import com.projectkorra.projectkorra.ability.FireAbility; +import com.projectkorra.projectkorra.attribute.Attribute; public class BlazeRing extends FireAbility { + @Attribute(Attribute.RANGE) private int range; + @Attribute(Attribute.COOLDOWN) private long cooldown; private double angleIncrement; private Location location; @@ -56,8 +59,7 @@ public class BlazeRing extends FireAbility { } @Override - public void progress() { - } + public void progress() {} @Override public Location getLocation() { diff --git a/src/com/projectkorra/projectkorra/firebending/FireBlast.java b/src/com/projectkorra/projectkorra/firebending/FireBlast.java index e73c1f71..b8d674b6 100644 --- a/src/com/projectkorra/projectkorra/firebending/FireBlast.java +++ b/src/com/projectkorra/projectkorra/firebending/FireBlast.java @@ -19,7 +19,9 @@ import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ability.AirAbility; import com.projectkorra.projectkorra.ability.FireAbility; import com.projectkorra.projectkorra.ability.util.Collision; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.avatar.AvatarState; +import com.projectkorra.projectkorra.command.Commands; import com.projectkorra.projectkorra.firebending.util.FireDamageTimer; import com.projectkorra.projectkorra.util.DamageHandler; import com.projectkorra.projectkorra.util.ParticleEffect; @@ -29,20 +31,29 @@ public class FireBlast extends FireAbility { private static final int MAX_TICKS = 10000; + @Attribute("PowerFurnace") private boolean powerFurnace; private boolean showParticles; private boolean dissipate; private boolean isFireBurst = false; private boolean fireBurstIgnite; private int ticks; + @Attribute(Attribute.COOLDOWN) private long cooldown; private double speedFactor; + @Attribute(Attribute.RANGE) private double range; + @Attribute(Attribute.DAMAGE) private double damage; + @Attribute(Attribute.SPEED) private double speed; private double collisionRadius; + @Attribute(Attribute.FIRE_TICK) private double fireTicks; - private double pushFactor; + @Attribute(Attribute.KNOCKBACK) + private double knockback; + private double flameRadius; + private double smokeRadius; private Random random; private Location location; private Location origin; @@ -103,31 +114,41 @@ public class FireBlast extends FireAbility { this.speed = getConfig().getDouble("Abilities.Fire.FireBlast.Speed"); this.collisionRadius = getConfig().getDouble("Abilities.Fire.FireBlast.CollisionRadius"); this.fireTicks = getConfig().getDouble("Abilities.Fire.FireBlast.FireTicks"); - this.pushFactor = getConfig().getDouble("Abilities.Fire.FireBlast.Push"); + this.knockback = getConfig().getDouble("Abilities.Fire.FireBlast.Knockback"); + this.flameRadius = getConfig().getDouble("Abilities.Fire.FireBlast.FlameParticleRadius"); + this.smokeRadius = getConfig().getDouble("Abilities.Fire.FireBlast.SmokeParticleRadius"); this.random = new Random(); } private void advanceLocation() { - if (this.showParticles) { - ParticleEffect.FLAME.display(this.location, 0.275F, 0.275F, 0.275F, 0, 6); - ParticleEffect.SMOKE.display(this.location, 0.3F, 0.3F, 0.3F, 0, 3); + if (this.isFireBurst) { + this.flameRadius += 0.06; + this.smokeRadius += 0.06; } + + if (this.showParticles) { + ParticleEffect.FLAME.display(this.location, 6, this.flameRadius, this.flameRadius, this.flameRadius); + ParticleEffect.SMOKE_NORMAL.display(this.location, 3, this.smokeRadius, this.smokeRadius, this.smokeRadius); + } + if (GeneralMethods.checkDiagonalWall(this.location, this.direction)) { this.remove(); return; } + this.location = this.location.add(this.direction.clone().multiply(this.speedFactor)); + if (this.random.nextInt(4) == 0) { playFirebendingSound(this.location); } } private void affect(final Entity entity) { - if (entity.getUniqueId() != this.player.getUniqueId()) { + if (entity.getUniqueId() != this.player.getUniqueId() && !GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation()) && !((entity instanceof Player) && Commands.invincible.contains(((Player) entity).getName()))) { if (this.bPlayer.isAvatarState()) { - GeneralMethods.setVelocity(entity, this.direction.clone().multiply(AvatarState.getValue(this.pushFactor))); + GeneralMethods.setVelocity(entity, this.direction.clone().multiply(AvatarState.getValue(this.knockback))); } else { - GeneralMethods.setVelocity(entity, this.direction.clone().multiply(this.pushFactor)); + GeneralMethods.setVelocity(entity, this.direction.clone().multiply(this.knockback)); } if (entity instanceof LivingEntity) { entity.setFireTicks((int) (this.fireTicks * 20)); @@ -195,11 +216,9 @@ public class FireBlast extends FireAbility { return; } - for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(this.location, this.collisionRadius)) { + Entity entity = GeneralMethods.getClosestEntity(this.location, this.collisionRadius); + if (entity != null) { this.affect(entity); - if (entity instanceof LivingEntity) { - break; - } } this.advanceLocation(); @@ -359,11 +378,11 @@ public class FireBlast extends FireAbility { } public double getPushFactor() { - return this.pushFactor; + return this.knockback; } public void setPushFactor(final double pushFactor) { - this.pushFactor = pushFactor; + this.knockback = pushFactor; } public Random getRandom() { @@ -414,4 +433,5 @@ public class FireBlast extends FireAbility { this.isFireBurst = isFireBurst; } + } diff --git a/src/com/projectkorra/projectkorra/firebending/FireBlastCharged.java b/src/com/projectkorra/projectkorra/firebending/FireBlastCharged.java index eafa6d54..60df8218 100644 --- a/src/com/projectkorra/projectkorra/firebending/FireBlastCharged.java +++ b/src/com/projectkorra/projectkorra/firebending/FireBlastCharged.java @@ -20,6 +20,7 @@ import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.AirAbility; import com.projectkorra.projectkorra.ability.CoreAbility; import com.projectkorra.projectkorra.ability.FireAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.avatar.AvatarState; import com.projectkorra.projectkorra.util.DamageHandler; import com.projectkorra.projectkorra.util.ParticleEffect; @@ -33,14 +34,22 @@ public class FireBlastCharged extends FireAbility { private boolean canDamageBlocks; private boolean dissipate; private long time; + @Attribute(Attribute.CHARGE_DURATION) private long chargeTime; + @Attribute(Attribute.COOLDOWN) + private long cooldown; private long interval; + @Attribute(Attribute.DAMAGE) private double maxDamage; + @Attribute(Attribute.RANGE) private double range; private double collisionRadius; + @Attribute(Attribute.DAMAGE + Attribute.RANGE) private double damageRadius; + @Attribute("Explosion" + Attribute.RANGE) private double explosionRadius; private double innerRadius; + @Attribute(Attribute.FIRE_TICK) private double fireTicks; private TNTPrimed explosion; private Location origin; @@ -59,6 +68,7 @@ public class FireBlastCharged extends FireAbility { this.canDamageBlocks = getConfig().getBoolean("Abilities.Fire.FireBlast.Charged.DamageBlocks"); this.dissipate = getConfig().getBoolean("Abilities.Fire.FireBlast.Dissipate"); this.chargeTime = getConfig().getLong("Abilities.Fire.FireBlast.Charged.ChargeTime"); + this.cooldown = getConfig().getLong("Abilities.Fire.FireBlast.Charged.Cooldown"); this.time = System.currentTimeMillis(); this.interval = 25; this.collisionRadius = getConfig().getDouble("Abilities.Fire.FireBlast.Charged.CollisionRadius"); @@ -187,7 +197,7 @@ public class FireBlastCharged extends FireAbility { } } this.location.getWorld().playSound(this.location, Sound.ENTITY_GENERIC_EXPLODE, 5, 1); - ParticleEffect.EXPLOSION_HUGE.display(new Vector(0, 0, 0), 0, this.location, 255.0D); + ParticleEffect.EXPLOSION_HUGE.display(this.location, 1, 0, 0, 0); } } @@ -197,8 +207,8 @@ public class FireBlastCharged extends FireAbility { private void executeFireball() { for (final Block block : GeneralMethods.getBlocksAroundPoint(this.location, this.collisionRadius)) { - ParticleEffect.FLAME.display(block.getLocation(), 0.5F, 0.5F, 0.5F, 0, 5); - ParticleEffect.SMOKE.display(block.getLocation(), 0.5F, 0.5F, 0.5F, 0, 2); + ParticleEffect.FLAME.display(block.getLocation(), 5, 0.5, 0.5, 0.5, 0); + ParticleEffect.SMOKE_NORMAL.display(block.getLocation(), 2, 0.5, 0.5, 0.5, 0); if ((new Random()).nextInt(4) == 0) { playFirebendingSound(this.location); } @@ -206,7 +216,7 @@ public class FireBlastCharged extends FireAbility { } boolean exploded = false; - for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(this.location, 2 * this.collisionRadius)) { + for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(this.location, this.collisionRadius)) { if (entity.getEntityId() == this.player.getEntityId() || GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation())) { continue; } @@ -225,7 +235,7 @@ public class FireBlastCharged extends FireAbility { for (final Block block : GeneralMethods.getBlocksAroundPoint(location, this.collisionRadius)) { if (BlazeArc.isIgnitable(this.player, block)) { if (block.getType() != Material.FIRE) { - BlazeArc.getReplacedBlocks().put(block.getLocation(), block.getState().getData()); + BlazeArc.getReplacedBlocks().put(block.getLocation(), block.getState()); } block.setType(Material.FIRE); if (this.dissipate) { @@ -238,10 +248,10 @@ public class FireBlastCharged extends FireAbility { @Override public void progress() { - if (!this.bPlayer.canBendIgnoreBindsCooldowns(this) && !this.launched) { + if (!this.bPlayer.canBendIgnoreBinds(this) && !this.launched) { this.remove(); return; - } else if (!this.bPlayer.canBend(CoreAbility.getAbility("FireBlast")) && !this.launched) { + } else if (!this.bPlayer.canBendIgnoreCooldowns(CoreAbility.getAbility("FireBlast")) && !this.launched) { this.remove(); return; } else if (!this.player.isSneaking() && !this.charged) { @@ -297,6 +307,14 @@ public class FireBlastCharged extends FireAbility { } } + @Override + public void remove() { + super.remove(); + if (this.charged) { + this.bPlayer.addCooldown(this); + } + } + @Override public String getName() { return "FireBlast"; @@ -309,7 +327,7 @@ public class FireBlastCharged extends FireAbility { @Override public long getCooldown() { - return 0; + return this.cooldown; } @Override diff --git a/src/com/projectkorra/projectkorra/firebending/FireBurst.java b/src/com/projectkorra/projectkorra/firebending/FireBurst.java index fbe4a357..268aeaa5 100644 --- a/src/com/projectkorra/projectkorra/firebending/FireBurst.java +++ b/src/com/projectkorra/projectkorra/firebending/FireBurst.java @@ -13,13 +13,19 @@ import org.bukkit.util.Vector; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ability.FireAbility; +import com.projectkorra.projectkorra.attribute.Attribute; public class FireBurst extends FireAbility { + @Attribute("Charged") private boolean charged; + @Attribute(Attribute.DAMAGE) private int damage; + @Attribute(Attribute.CHARGE_DURATION) private long chargeTime; + @Attribute(Attribute.RANGE) private long range; + @Attribute(Attribute.COOLDOWN) private long cooldown; private double angleTheta; private double anglePhi; @@ -46,7 +52,7 @@ public class FireBurst extends FireAbility { if (isDay(player.getWorld())) { this.chargeTime /= getDayFactor(); } - if (this.bPlayer.isAvatarState() || isSozinsComet(player.getWorld())) { + if (this.bPlayer.isAvatarState()) { this.chargeTime = getConfig().getLong("Abilities.Avatar.AvatarState.Fire.FireBurst.Damage"); this.damage = getConfig().getInt("Abilities.Avatar.AvatarState.Fire.FireBurst.Damage"); this.cooldown = getConfig().getLong("Abilities.Avatar.AvatarState.Fire.FireBurst.Cooldown"); @@ -86,6 +92,7 @@ public class FireBurst extends FireAbility { if (direction.angle(vector) <= angle) { final FireBlast fblast = new FireBlast(location, direction.normalize(), this.player, this.damage, safeBlocks); fblast.setRange(this.range); + fblast.setFireBurst(true); } } } @@ -157,6 +164,7 @@ public class FireBurst extends FireAbility { fblast.setRange(this.range); fblast.setShowParticles(false); + fblast.setFireBurst(true); this.blasts.add(fblast); } } diff --git a/src/com/projectkorra/projectkorra/firebending/FireJet.java b/src/com/projectkorra/projectkorra/firebending/FireJet.java index 5c759111..68da1d7a 100644 --- a/src/com/projectkorra/projectkorra/firebending/FireJet.java +++ b/src/com/projectkorra/projectkorra/firebending/FireJet.java @@ -1,5 +1,7 @@ package com.projectkorra.projectkorra.firebending; +import static com.projectkorra.projectkorra.firebending.Illumination.isIlluminationTorch; + import java.util.Random; import org.bukkit.Location; @@ -8,19 +10,26 @@ import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import com.projectkorra.projectkorra.ProjectKorra; +import com.projectkorra.projectkorra.ability.ElementalAbility; import com.projectkorra.projectkorra.ability.FireAbility; import com.projectkorra.projectkorra.airbending.AirSpout; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.util.ParticleEffect; public class FireJet extends FireAbility { + @Attribute("AvatarStateToggle") private boolean avatarStateToggled; private long time; + @Attribute(Attribute.DURATION) private long duration; + @Attribute(Attribute.COOLDOWN) private long cooldown; + @Attribute(Attribute.SPEED) private double speed; private Random random; + private Boolean previousGlidingState; + private Boolean showGliding; public FireJet(final Player player) { super(player); @@ -42,28 +51,32 @@ public class FireJet extends FireAbility { this.duration = getConfig().getLong("Abilities.Fire.FireJet.Duration"); this.speed = getConfig().getDouble("Abilities.Fire.FireJet.Speed"); this.cooldown = getConfig().getLong("Abilities.Fire.FireJet.Cooldown"); + this.showGliding = getConfig().getBoolean("Abilities.Fire.FireJet.ShowGliding"); this.random = new Random(); this.speed = this.getDayFactor(this.speed); final Block block = player.getLocation().getBlock(); - if (BlazeArc.isIgnitable(player, block) || block.getType() == Material.AIR || block.getType() == Material.STEP || block.getType() == Material.WOOD_STEP || this.bPlayer.isAvatarState()) { + if (BlazeArc.isIgnitable(player, block) || ElementalAbility.isAir(block.getType()) || block.getType() == Material.STONE_SLAB || block.getType() == Material.ACACIA_SLAB || block.getType() == Material.BIRCH_SLAB || block.getType() == Material.DARK_OAK_SLAB || block.getType() == Material.JUNGLE_SLAB || block.getType() == Material.OAK_SLAB || block.getType() == Material.SPRUCE_SLAB || isIlluminationTorch(block) || this.bPlayer.isAvatarState()) { player.setVelocity(player.getEyeLocation().getDirection().clone().normalize().multiply(this.speed)); - if (canFireGrief()) { - if (block.getType() == Material.AIR) { + if (!canFireGrief()) { + if (ElementalAbility.isAir(block.getType())) { createTempFire(block.getLocation()); } - } else if (block.getType() == Material.AIR) { + } else if (ElementalAbility.isAir(block.getType())) { block.setType(Material.FIRE); } - ProjectKorra.flightHandler.createInstance(player, this.getName()); + this.flightHandler.createInstance(player, this.getName()); player.setAllowFlight(true); this.time = System.currentTimeMillis(); this.start(); - this.bPlayer.addCooldown(this); + if (this.showGliding) { + this.previousGlidingState = player.isGliding(); + player.setGliding(true); + } } } @@ -80,8 +93,8 @@ public class FireJet extends FireAbility { playFirebendingSound(this.player.getLocation()); } - ParticleEffect.FLAME.display(this.player.getLocation(), 0.6F, 0.6F, 0.6F, 0, 20); - ParticleEffect.SMOKE.display(this.player.getLocation(), 0.6F, 0.6F, 0.6F, 0, 20); + ParticleEffect.FLAME.display(this.player.getLocation(), 20, 0.6, 0.6, 0.6); + ParticleEffect.SMOKE_NORMAL.display(this.player.getLocation(), 10, 0.6, 0.6, 0.6); double timefactor; if (this.bPlayer.isAvatarState() && this.avatarStateToggled) { @@ -99,7 +112,12 @@ public class FireJet extends FireAbility { @Override public void remove() { super.remove(); - ProjectKorra.flightHandler.removeInstance(this.player, this.getName()); + if (this.showGliding) { + this.player.setGliding(this.previousGlidingState); + } + this.flightHandler.removeInstance(this.player, this.getName()); + this.player.setFallDistance(0); + this.bPlayer.addCooldown(this); } @Override diff --git a/src/com/projectkorra/projectkorra/firebending/FireManipulation.java b/src/com/projectkorra/projectkorra/firebending/FireManipulation.java index c97c6ccf..63d63a57 100644 --- a/src/com/projectkorra/projectkorra/firebending/FireManipulation.java +++ b/src/com/projectkorra/projectkorra/firebending/FireManipulation.java @@ -113,8 +113,8 @@ public class FireManipulation extends FireAbility { this.points.remove(point); return; } - ParticleEffect.FLAME.display(point, 0.25F, 0.25F, 0.25F, 0, 12); - ParticleEffect.SMOKE.display(point, 0.25F, 0.25F, 0.25F, 0, 6); + ParticleEffect.FLAME.display(point, 12, 0.25, 0.25, 0.25); + ParticleEffect.SMOKE_NORMAL.display(point, 6, 0.25, 0.25, 0.25); for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(point, 1.2D)) { if (entity instanceof LivingEntity && entity.getUniqueId() != this.player.getUniqueId()) { DamageHandler.damageEntity(entity, this.shieldDamage, this); @@ -143,8 +143,8 @@ public class FireManipulation extends FireAbility { for (final Location point : this.points.keySet()) { final Vector direction = this.focalPoint.toVector().subtract(point.toVector()); point.add(direction.clone().multiply(this.streamSpeed / 5)); - ParticleEffect.FLAME.display(point, 0.25F, 0.25F, 0.25F, 0, this.shieldParticles); - ParticleEffect.SMOKE.display(point, 0.25F, 0.25F, 0.25F, 0, this.shieldParticles / 2); + ParticleEffect.FLAME.display(point, this.shieldParticles, 0.25, 0.25, 0.25); + ParticleEffect.SMOKE_NORMAL.display(point, this.shieldParticles / 2, 0.25, 0.25, 0.25); } } else { Vector direction = this.player.getLocation().getDirection().clone(); @@ -173,8 +173,8 @@ public class FireManipulation extends FireAbility { return; } - ParticleEffect.FLAME.display(this.shotPoint, 0.5F, 0.5F, 0.5F, 0.01F, this.streamParticles); - ParticleEffect.SMOKE.display(this.shotPoint, 0.5F, 0.5F, 0.5F, 0.01F, this.streamParticles / 2); + ParticleEffect.FLAME.display(this.shotPoint, this.streamParticles, 0.5, 0.5, 0.5, 0.01); + ParticleEffect.SMOKE_NORMAL.display(this.shotPoint, this.streamParticles / 2, 0.5, 0.5, 0.5, 0.01); for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(this.shotPoint, 2)) { if (entity instanceof LivingEntity && entity.getUniqueId() != this.player.getUniqueId()) { DamageHandler.damageEntity(entity, this.streamDamage, this); @@ -214,7 +214,9 @@ public class FireManipulation extends FireAbility { @Override public List getLocations() { final List locations = new ArrayList<>(); - locations.addAll(this.points.keySet()); + if (this.points != null) { + locations.addAll(this.points.keySet()); + } return locations; } diff --git a/src/com/projectkorra/projectkorra/firebending/FireShield.java b/src/com/projectkorra/projectkorra/firebending/FireShield.java index 864dc3fc..1c7ddc0c 100644 --- a/src/com/projectkorra/projectkorra/firebending/FireShield.java +++ b/src/com/projectkorra/projectkorra/firebending/FireShield.java @@ -15,21 +15,30 @@ import org.bukkit.util.Vector; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.FireAbility; import com.projectkorra.projectkorra.ability.util.Collision; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.firebending.util.FireDamageTimer; import com.projectkorra.projectkorra.util.ParticleEffect; public class FireShield extends FireAbility { private boolean shield; + @Attribute("IgniteEntities") private boolean ignite; + @Attribute("Disc" + Attribute.DURATION) private long discDuration; + @Attribute("Shield" + Attribute.DURATION) private long shieldDuration; - private long interval; + @Attribute("Disc" + Attribute.COOLDOWN) private long discCooldown; + @Attribute("Shield" + Attribute.COOLDOWN) private long shieldCooldown; - private double radius; + @Attribute("Shield" + Attribute.RADIUS) + private double shieldRadius; + @Attribute("Disc" + Attribute.RADIUS) private double discRadius; + @Attribute("Disc" + Attribute.FIRE_TICK) private double discFireTicks; + @Attribute("Shield" + Attribute.FIRE_TICK) private double shieldFireTicks; private Location location; private Random random; @@ -50,7 +59,7 @@ public class FireShield extends FireAbility { this.discFireTicks = getConfig().getDouble("Abilities.Fire.FireShield.Disc.FireTicks"); this.shieldCooldown = getConfig().getLong("Abilities.Fire.FireShield.Shield.Cooldown"); this.shieldDuration = getConfig().getLong("Abilities.Fire.FireShield.Shield.Duration"); - this.radius = getConfig().getDouble("Abilities.Fire.FireShield.Shield.Radius"); + this.shieldRadius = getConfig().getDouble("Abilities.Fire.FireShield.Shield.Radius"); this.shieldFireTicks = getConfig().getDouble("Abilities.Fire.FireShield.Shield.FireTicks"); this.random = new Random(); @@ -76,7 +85,7 @@ public class FireShield extends FireAbility { if (fshield.shield) { if (!playerLoc.getWorld().equals(loc.getWorld())) { return false; - } else if (playerLoc.distanceSquared(loc) <= fshield.radius * fshield.radius) { + } else if (playerLoc.distanceSquared(loc) <= fshield.shieldRadius * fshield.shieldRadius) { return true; } } else { @@ -94,12 +103,15 @@ public class FireShield extends FireAbility { @Override public void progress() { if (!this.bPlayer.canBendIgnoreCooldowns(this)) { + this.bPlayer.addCooldown(this); this.remove(); return; } else if ((!this.player.isSneaking() && this.shield) || (System.currentTimeMillis() > this.getStartTime() + this.shieldDuration && this.shield && this.shieldDuration > 0)) { + this.bPlayer.addCooldown(this); this.remove(); return; } else if (System.currentTimeMillis() > this.getStartTime() + this.discDuration && !this.shield) { + this.bPlayer.addCooldown(this); this.remove(); return; } @@ -112,12 +124,12 @@ public class FireShield extends FireAbility { final double rphi = Math.toRadians(phi); final double rtheta = Math.toRadians(theta); - final Location display = this.location.clone().add(this.radius / 1.5 * Math.cos(rphi) * Math.sin(rtheta), this.radius / 1.5 * Math.cos(rtheta), this.radius / 1.5 * Math.sin(rphi) * Math.sin(rtheta)); + final Location display = this.location.clone().add(this.shieldRadius / 1.5 * Math.cos(rphi) * Math.sin(rtheta), this.shieldRadius / 1.5 * Math.cos(rtheta), this.shieldRadius / 1.5 * Math.sin(rphi) * Math.sin(rtheta)); if (this.random.nextInt(6) == 0) { - ParticleEffect.SMOKE.display(display, 0, 0, 0, 0, 1); + ParticleEffect.SMOKE_NORMAL.display(display, 1, 0, 0, 0); } if (this.random.nextInt(4) == 0) { - ParticleEffect.FLAME.display(display, 0.1f, 0.1f, 0.1f, 0.013f, 1); + ParticleEffect.FLAME.display(display, 1, 0.1, 0.1, 0.1, 0.013); } if (this.random.nextInt(7) == 0) { playFirebendingSound(display); @@ -130,14 +142,14 @@ public class FireShield extends FireAbility { this.increment = 20; } - for (final Block testblock : GeneralMethods.getBlocksAroundPoint(this.player.getLocation(), this.radius)) { + for (final Block testblock : GeneralMethods.getBlocksAroundPoint(this.player.getLocation(), this.shieldRadius)) { if (testblock.getType() == Material.FIRE) { testblock.setType(Material.AIR); testblock.getWorld().playEffect(testblock.getLocation(), Effect.EXTINGUISH, 0); } } - for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(this.location, this.radius)) { + for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(this.location, this.shieldRadius)) { if (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation())) { continue; } else if (entity instanceof LivingEntity) { @@ -152,22 +164,23 @@ public class FireShield extends FireAbility { } else { this.location = this.player.getEyeLocation().clone(); final Vector direction = this.location.getDirection(); - this.location = this.location.clone().add(direction.multiply(this.radius)); - ParticleEffect.FLAME.display(this.location, 0.2f, 0.2f, 0.2f, 0.023f, 3); + this.location.add(direction.multiply(this.shieldRadius)); + ParticleEffect.FLAME.display(this.location, 3, 0.2, 0.2, 0.2, 0.00023); for (double theta = 0; theta < 360; theta += 20) { final Vector vector = GeneralMethods.getOrthogonalVector(direction, theta, this.discRadius / 1.5); - final Location display = this.location.clone().add(vector); + final Location display = this.location.add(vector); if (this.random.nextInt(6) == 0) { - ParticleEffect.SMOKE.display(display, 0, 0, 0, 0, 1); + ParticleEffect.SMOKE_NORMAL.display(display, 1, 0, 0, 0); } - ParticleEffect.FLAME.display(display, 0.3f, 0.2f, 0.3f, 0.023f, 2); + ParticleEffect.FLAME.display(display, 2, 0.3, 0.2, 0.3, 0.023); if (this.random.nextInt(4) == 0) { playFirebendingSound(display); } + this.location.subtract(vector); } - for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(this.location, this.discRadius)) { + for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(this.location, this.discRadius + 1)) { if (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation())) { continue; } else if (entity instanceof LivingEntity) { @@ -209,7 +222,7 @@ public class FireShield extends FireAbility { @Override public double getCollisionRadius() { - return this.shield ? this.radius : this.discRadius; + return this.shield ? this.shieldRadius : this.discRadius; } public boolean isShield() { @@ -240,20 +253,12 @@ public class FireShield extends FireAbility { this.shieldDuration = duration; } - public long getInterval() { - return this.interval; + public double getShieldRadius() { + return this.shieldRadius; } - public void setInterval(final long interval) { - this.interval = interval; - } - - public double getRadius() { - return this.radius; - } - - public void setRadius(final double radius) { - this.radius = radius; + public void setShieldRadius(final double shieldRadius) { + this.shieldRadius = shieldRadius; } public double getDiscRadius() { diff --git a/src/com/projectkorra/projectkorra/firebending/HeatControl.java b/src/com/projectkorra/projectkorra/firebending/HeatControl.java index 56759beb..6cbf61b8 100644 --- a/src/com/projectkorra/projectkorra/firebending/HeatControl.java +++ b/src/com/projectkorra/projectkorra/firebending/HeatControl.java @@ -15,6 +15,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.block.Block; +import org.bukkit.block.data.Levelled; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitRunnable; @@ -24,9 +25,9 @@ import com.projectkorra.projectkorra.BendingPlayer; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ability.FireAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.earthbending.lava.LavaFlow; import com.projectkorra.projectkorra.util.ParticleEffect; -import com.projectkorra.projectkorra.util.ReflectionHandler.PackageType; import com.projectkorra.projectkorra.util.TempBlock; import com.projectkorra.projectkorra.waterbending.SurgeWave; import com.projectkorra.projectkorra.waterbending.Torrent; @@ -42,20 +43,25 @@ public class HeatControl extends FireAbility { COOK, EXTINGUISH, MELT, SOLIDIFY } - private static final Material[] COOKABLE_MATERIALS = { Material.RAW_BEEF, Material.RAW_CHICKEN, Material.RAW_FISH, Material.PORK, Material.POTATO_ITEM, Material.RABBIT, Material.MUTTON }; + private static final Material[] COOKABLE_MATERIALS = { Material.BEEF, Material.CHICKEN, Material.COD, Material.PORKCHOP, Material.POTATO, Material.RABBIT, Material.MUTTON, Material.SALMON, Material.KELP }; private HeatControlType heatControlType; // HeatControl Cook variables. + @Attribute("CookTime") private long cookTime; private long cookInterval; // HeatControl Extinguish variables. + @Attribute("Extinguish" + Attribute.COOLDOWN) private long extinguishCooldown; + @Attribute("Extinguish" + Attribute.RADIUS) private double extinguishRadius; // HeatControl Melt variables. + @Attribute("Melt" + Attribute.RANGE) private double meltRange; + @Attribute("Melt" + Attribute.RADIUS) private double meltRadius; private Location meltLocation; private static final Map MELTED_BLOCKS = new HashMap<>(); @@ -65,7 +71,9 @@ public class HeatControl extends FireAbility { private long solidifyDelay; private long solidifyLastBlockTime; private long solidifyRevertTime; + @Attribute("Solidify" + Attribute.RADIUS) private double solidifyMaxRadius; + @Attribute("Solidify" + Attribute.RANGE) private double solidifyRange; private boolean solidifyRevert; private boolean solidifying; @@ -212,7 +220,7 @@ public class HeatControl extends FireAbility { final Location targetLocation = GeneralMethods.getTargetedLocation(this.player, this.solidifyRange); this.resetLocation(targetLocation); - final List area = GeneralMethods.getCircle(this.solidifyLocation, this.solidifyRadius, 3, true, true, 0); + final List area = GeneralMethods.getCircle(this.solidifyLocation, this.solidifyRadius, 3, false, true, 0); this.solidify(area); } @@ -238,25 +246,20 @@ public class HeatControl extends FireAbility { final Material material = is.getType(); switch (material) { - case RAW_BEEF: - cooked = new ItemStack(Material.COOKED_BEEF, 1); + case BEEF: + cooked = new ItemStack(Material.COOKED_BEEF); break; - case RAW_FISH: - final ItemStack salmon = new ItemStack(Material.RAW_FISH, 1, (short) 1); - if (is.getDurability() == salmon.getDurability()) { - cooked = new ItemStack(Material.COOKED_FISH, 1, (short) 1); - } else { - cooked = new ItemStack(Material.COOKED_FISH, 1); - } + case COD: + cooked = new ItemStack(Material.COOKED_COD); break; - case RAW_CHICKEN: - cooked = new ItemStack(Material.COOKED_CHICKEN, 1); + case CHICKEN: + cooked = new ItemStack(Material.COOKED_CHICKEN); break; - case PORK: - cooked = new ItemStack(Material.GRILLED_PORK, 1); + case PORKCHOP: + cooked = new ItemStack(Material.COOKED_PORKCHOP); break; - case POTATO_ITEM: - cooked = new ItemStack(Material.BAKED_POTATO, 1); + case POTATO: + cooked = new ItemStack(Material.BAKED_POTATO); break; case MUTTON: cooked = new ItemStack(Material.COOKED_MUTTON); @@ -264,6 +267,12 @@ public class HeatControl extends FireAbility { case RABBIT: cooked = new ItemStack(Material.COOKED_RABBIT); break; + case SALMON: + cooked = new ItemStack(Material.COOKED_SALMON); + break; + case KELP: + cooked = new ItemStack(Material.DRIED_KELP); + break; default: break; } @@ -272,8 +281,8 @@ public class HeatControl extends FireAbility { } public void displayCookParticles() { - ParticleEffect.FLAME.display(this.player.getLocation().clone().add(0, 1, 0), 0.5F, 0.5F, 0.5F, 0, 3); - ParticleEffect.SMOKE.display(this.player.getLocation().clone().add(0, 1, 0), 0.5F, 0.5F, 0.5F, 0, 2); + ParticleEffect.FLAME.display(this.player.getLocation().clone().add(0, 1, 0), 3, 0.5, 0.5, 0.5); + ParticleEffect.SMOKE_NORMAL.display(this.player.getLocation().clone().add(0, 1, 0), 2, 0.5, 0.5, 0.5); } public static boolean isCookable(final Material material) { @@ -309,8 +318,8 @@ public class HeatControl extends FireAbility { if (TempBlock.isTempBlock(block)) { final TempBlock tb = TempBlock.get(block); - if (PhaseChange.getFrozenBlocksAsTempBlock().contains(tb)) { - PhaseChange.thaw(tb); + if (PhaseChange.getFrozenBlocksMap().containsKey(tb)) { + new PhaseChange(player, PhaseChange.PhaseChangeType.MELT).melt(tb.getBlock()); } } @@ -322,13 +331,16 @@ public class HeatControl extends FireAbility { block.setType(Material.AIR); return; } else { - final TempBlock tb = new TempBlock(block, Material.WATER, (byte) 0); + final TempBlock tb = new TempBlock(block, Material.WATER); MELTED_BLOCKS.put(block, tb); new BukkitRunnable() { @Override public void run() { - MELTED_BLOCKS.get(block).revertBlock(); + final TempBlock melted = MELTED_BLOCKS.get(block); + if (melted != null) { + melted.revertBlock(); + } MELTED_BLOCKS.remove(block); } }.runTaskLater(ProjectKorra.plugin, 5 * 20 * 60); @@ -356,18 +368,14 @@ public class HeatControl extends FireAbility { final Block b = lava.get(this.randy.nextInt(lava.size())); - Material tempRevertMaterial = Material.STONE; - - if (Integer.parseInt(PackageType.getServerVersion().split("_")[1]) > 9) { - tempRevertMaterial = Material.valueOf("MAGMA"); - } + final Material tempRevertMaterial = Material.MAGMA_BLOCK; final TempBlock tempBlock; if (TempBlock.isTempBlock(b)) { tempBlock = TempBlock.get(b); - tempBlock.setType(tempRevertMaterial, (byte) 0); + tempBlock.setType(tempRevertMaterial); } else { - tempBlock = new TempBlock(b, tempRevertMaterial, (byte) 0); + tempBlock = new TempBlock(b, tempRevertMaterial); } if (LavaFlow.isLavaFlowBlock(tempBlock.getBlock())) { @@ -375,7 +383,7 @@ public class HeatControl extends FireAbility { @Override public void run() { if (tempBlock != null) { - ParticleEffect.SMOKE.display(tempBlock.getBlock().getLocation().clone().add(0.5, 1, 0.5), 0.1F, 0.1F, 0.1F, 0.01F, 3); + ParticleEffect.SMOKE_NORMAL.display(tempBlock.getBlock().getLocation().clone().add(0.5, 1, 0.5), 3, 0.1, 0.1, 0.1, 0.01); if (HeatControl.this.randy.nextInt(3) == 0) { tempBlock.getBlock().getWorld().playSound(tempBlock.getBlock().getLocation(), Sound.BLOCK_FIRE_EXTINGUISH, 0.5F, 1); } @@ -395,9 +403,9 @@ public class HeatControl extends FireAbility { final boolean bool = Math.random() > .5 ? true : false; if (HeatControl.this.solidifyRevert) { if (bool) { - tempBlock.setType(Material.STONE, (byte) 0); + tempBlock.setType(Material.STONE); } else { - tempBlock.setType(Material.COBBLESTONE, (byte) 0); + tempBlock.setType(Material.COBBLESTONE); } tempBlock.setRevertTime(HeatControl.this.solidifyRevertTime); } else { @@ -409,7 +417,7 @@ public class HeatControl extends FireAbility { } } - ParticleEffect.SMOKE.display(tempBlock.getBlock().getLocation().clone().add(0.5, 1, 0.5), 0.1F, 0.1F, 0.1F, 0.01F, 3); + ParticleEffect.SMOKE_NORMAL.display(tempBlock.getBlock().getLocation().clone().add(0.5, 1, 0.5), 3, 0.1, 0.1, 0.1, 0.01); if (HeatControl.this.randy.nextInt(3) == 0) { tempBlock.getBlock().getWorld().playSound(tempBlock.getBlock().getLocation(), Sound.BLOCK_FIRE_EXTINGUISH, 0.5F, 1); } @@ -469,10 +477,8 @@ public class HeatControl extends FireAbility { continue; } if (isLava(block)) { - if (TempBlock.isTempBlock(block)) { - final TempBlock tb = TempBlock.get(block); - final byte full = 0x0; - if (tb.getState().getRawData() != full && !isLava(tb.getState().getType())) { + if (block.getBlockData() instanceof Levelled) { + if (((Levelled) block.getBlockData()).getLevel() != 0) { continue; } } diff --git a/src/com/projectkorra/projectkorra/firebending/Illumination.java b/src/com/projectkorra/projectkorra/firebending/Illumination.java index e2074ab9..c7314a81 100644 --- a/src/com/projectkorra/projectkorra/firebending/Illumination.java +++ b/src/com/projectkorra/projectkorra/firebending/Illumination.java @@ -5,6 +5,7 @@ import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.Tag; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; @@ -12,6 +13,7 @@ import org.bukkit.entity.Player; import com.projectkorra.projectkorra.Element; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.FireAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.util.TempBlock; public class Illumination extends FireAbility { @@ -19,7 +21,9 @@ public class Illumination extends FireAbility { private static final Map BLOCKS = new ConcurrentHashMap<>(); private byte normalData; + @Attribute(Attribute.COOLDOWN) private long cooldown; + @Attribute(Attribute.RANGE) private double range; private int lightThreshold; private Material normalType; @@ -114,12 +118,14 @@ public class Illumination extends FireAbility { return; } else if (this.block != null && standingBlock.equals(this.block.getBlock())) { return; - } else if (standBlock.getType() == Material.LEAVES || standBlock.getType() == Material.LEAVES_2) { + } else if (Tag.LEAVES.isTagged(standBlock.getType())) { + return; + } else if (standingBlock.getType().name().endsWith("_FENCE") || standingBlock.getType().name().endsWith("_FENCE_GATE") || standingBlock.getType().name().endsWith("_WALL") || standingBlock.getType() == Material.IRON_BARS || standingBlock.getType().name().endsWith("_PANE")) { return; } this.revert(); - this.block = new TempBlock(standingBlock, Material.TORCH, (byte) 0); + this.block = new TempBlock(standingBlock, Material.TORCH); BLOCKS.put(this.block, this.player); } diff --git a/src/com/projectkorra/projectkorra/firebending/WallOfFire.java b/src/com/projectkorra/projectkorra/firebending/WallOfFire.java index c2c479a2..e11cd6c8 100644 --- a/src/com/projectkorra/projectkorra/firebending/WallOfFire.java +++ b/src/com/projectkorra/projectkorra/firebending/WallOfFire.java @@ -14,6 +14,7 @@ import org.bukkit.util.Vector; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.AirAbility; import com.projectkorra.projectkorra.ability.FireAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.firebending.util.FireDamageTimer; import com.projectkorra.projectkorra.util.DamageHandler; import com.projectkorra.projectkorra.util.ParticleEffect; @@ -24,15 +25,22 @@ public class WallOfFire extends FireAbility { private boolean active; private int damageTick; private int intervalTick; + @Attribute(Attribute.RANGE) private int range; + @Attribute(Attribute.HEIGHT) private int height; + @Attribute(Attribute.WIDTH) private int width; - private int damage; + @Attribute(Attribute.DAMAGE) + private double damage; + @Attribute(Attribute.COOLDOWN) private long cooldown; private long damageInterval; + @Attribute(Attribute.DURATION) private long duration; private long time; private long interval; + @Attribute(Attribute.FIRE_TICK) private double fireTicks; private double maxAngle; private Random random; @@ -48,7 +56,7 @@ public class WallOfFire extends FireAbility { this.range = getConfig().getInt("Abilities.Fire.WallOfFire.Range"); this.height = getConfig().getInt("Abilities.Fire.WallOfFire.Height"); this.width = getConfig().getInt("Abilities.Fire.WallOfFire.Width"); - this.damage = getConfig().getInt("Abilities.Fire.WallOfFire.Damage"); + this.damage = getConfig().getDouble("Abilities.Fire.WallOfFire.Damage"); this.cooldown = getConfig().getLong("Abilities.Fire.WallOfFire.Cooldown"); this.damageInterval = getConfig().getLong("Abilities.Fire.WallOfFire.DamageInterval"); this.duration = getConfig().getLong("Abilities.Fire.WallOfFire.Duration"); @@ -94,7 +102,6 @@ public class WallOfFire extends FireAbility { this.initializeBlocks(); this.start(); - this.bPlayer.addCooldown(this); } private void affect(final Entity entity) { @@ -140,8 +147,8 @@ public class WallOfFire extends FireAbility { if (!this.isTransparent(block)) { continue; } - ParticleEffect.FLAME.display(block.getLocation(), 0.6F, 0.6F, 0.6F, 0, 3); - ParticleEffect.SMOKE.display(block.getLocation(), 0.6F, 0.6F, 0.6F, 0, 1); + ParticleEffect.FLAME.display(block.getLocation(), 3, 0.6, 0.6, 0.6); + ParticleEffect.SMOKE_NORMAL.display(block.getLocation(), 2, 0.6, 0.6, 0.6); if (this.random.nextInt(7) == 0) { playFirebendingSound(block.getLocation()); @@ -202,6 +209,12 @@ public class WallOfFire extends FireAbility { } } + @Override + public void remove() { + super.remove(); + this.bPlayer.addCooldown(this); + } + @Override public String getName() { return "WallOfFire"; @@ -284,7 +297,7 @@ public class WallOfFire extends FireAbility { this.width = width; } - public int getDamage() { + public double getDamage() { return this.damage; } diff --git a/src/com/projectkorra/projectkorra/firebending/combo/FireComboStream.java b/src/com/projectkorra/projectkorra/firebending/combo/FireComboStream.java index d83fd2d2..dd11a98c 100644 --- a/src/com/projectkorra/projectkorra/firebending/combo/FireComboStream.java +++ b/src/com/projectkorra/projectkorra/firebending/combo/FireComboStream.java @@ -1,8 +1,10 @@ package com.projectkorra.projectkorra.firebending.combo; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + import org.bukkit.Effect; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -73,13 +75,13 @@ public class FireComboStream extends BukkitRunnable { @Override public void run() { final Block block = this.location.getBlock(); - if (block.getRelative(BlockFace.UP).getType() != Material.AIR && !ElementalAbility.isPlant(block)) { + if (!ElementalAbility.isAir(block.getRelative(BlockFace.UP).getType()) && !ElementalAbility.isPlant(block)) { this.remove(); return; } for (int i = 0; i < this.density; i++) { if (this.useNewParticles) { - this.particleEffect.display(this.location, this.spread, this.spread, this.spread, 0, 1); + this.particleEffect.display(this.location, 1, this.spread, this.spread, this.spread); } else { this.location.getWorld().playEffect(this.location, Effect.MOBSPAWNER_FLAMES, 0, 15); } @@ -170,6 +172,7 @@ public class FireComboStream extends BukkitRunnable { return this.location; } + @Override public boolean isCancelled() { return this.cancelled; } @@ -226,4 +229,9 @@ public class FireComboStream extends BukkitRunnable { public void setUseNewParticles(final boolean b) { this.useNewParticles = b; } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); + } } diff --git a/src/com/projectkorra/projectkorra/firebending/combo/FireKick.java b/src/com/projectkorra/projectkorra/firebending/combo/FireKick.java index 15b2ff0c..eb055423 100644 --- a/src/com/projectkorra/projectkorra/firebending/combo/FireKick.java +++ b/src/com/projectkorra/projectkorra/firebending/combo/FireKick.java @@ -16,13 +16,18 @@ import com.projectkorra.projectkorra.ability.ComboAbility; import com.projectkorra.projectkorra.ability.FireAbility; import com.projectkorra.projectkorra.ability.util.Collision; import com.projectkorra.projectkorra.ability.util.ComboManager.AbilityInformation; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.util.ClickType; public class FireKick extends FireAbility implements ComboAbility { + @Attribute(Attribute.COOLDOWN) private long cooldown; + @Attribute(Attribute.DAMAGE) private double damage; + @Attribute(Attribute.SPEED) private double speed; + @Attribute(Attribute.RANGE) private double range; private Location location; private Location destination; @@ -204,9 +209,4 @@ public class FireKick extends FireAbility implements ComboAbility { public void setTasks(final ArrayList tasks) { this.tasks = tasks; } - - @Override - public String getInstructions() { - return "FireBlast > FireBlast > (Hold sneak) > FireBlast"; - } } diff --git a/src/com/projectkorra/projectkorra/firebending/combo/FireSpin.java b/src/com/projectkorra/projectkorra/firebending/combo/FireSpin.java index 21160479..34cbe014 100644 --- a/src/com/projectkorra/projectkorra/firebending/combo/FireSpin.java +++ b/src/com/projectkorra/projectkorra/firebending/combo/FireSpin.java @@ -17,14 +17,20 @@ import com.projectkorra.projectkorra.ability.ComboAbility; import com.projectkorra.projectkorra.ability.FireAbility; import com.projectkorra.projectkorra.ability.util.Collision; import com.projectkorra.projectkorra.ability.util.ComboManager.AbilityInformation; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.util.ClickType; public class FireSpin extends FireAbility implements ComboAbility { + @Attribute(Attribute.COOLDOWN) private long cooldown; + @Attribute(Attribute.DAMAGE) private double damage; + @Attribute(Attribute.SPEED) private double speed; + @Attribute(Attribute.RANGE) private double range; + @Attribute(Attribute.KNOCKBACK) private double knockback; private Location destination; private ArrayList affectedEntities; @@ -37,7 +43,7 @@ public class FireSpin extends FireAbility implements ComboAbility { return; } - if (player.getLocation().getBlock().getType() == Material.WATER || player.getLocation().getBlock().getType() == Material.STATIONARY_WATER) { + if (player.getLocation().getBlock().getType() == Material.WATER) { return; } @@ -206,9 +212,4 @@ public class FireSpin extends FireAbility implements ComboAbility { public void setTasks(final ArrayList tasks) { this.tasks = tasks; } - - @Override - public String getInstructions() { - return "FireBlast > FireBlast > FireShield (Left Click) > FireShield (Tap Shift)"; - } } diff --git a/src/com/projectkorra/projectkorra/firebending/combo/FireWheel.java b/src/com/projectkorra/projectkorra/firebending/combo/FireWheel.java index 88cb8255..fcbbda38 100644 --- a/src/com/projectkorra/projectkorra/firebending/combo/FireWheel.java +++ b/src/com/projectkorra/projectkorra/firebending/combo/FireWheel.java @@ -17,6 +17,7 @@ import com.projectkorra.projectkorra.ability.ComboAbility; import com.projectkorra.projectkorra.ability.ElementalAbility; import com.projectkorra.projectkorra.ability.FireAbility; import com.projectkorra.projectkorra.ability.util.ComboManager.AbilityInformation; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.firebending.util.FireDamageTimer; import com.projectkorra.projectkorra.util.ClickType; import com.projectkorra.projectkorra.util.DamageHandler; @@ -27,12 +28,18 @@ public class FireWheel extends FireAbility implements ComboAbility { private Location origin; private Location location; private Vector direction; + @Attribute(Attribute.COOLDOWN) private long cooldown; + @Attribute(Attribute.RANGE) private double range; + @Attribute(Attribute.HEIGHT) private int height; private int radius; + @Attribute(Attribute.SPEED) private double speed; + @Attribute(Attribute.FIRE_TICK) private double fireTicks; + @Attribute(Attribute.DAMAGE) private double damage; private ArrayList affectedEntities; @@ -118,7 +125,7 @@ public class FireWheel extends FireAbility implements ComboAbility { } else if (ElementalAbility.isPlant(topBlock)) { topBlock.breakNaturally(); topBlock = topBlock.getRelative(BlockFace.DOWN); - } else if (topBlock.getType() == Material.AIR) { + } else if (ElementalAbility.isAir(topBlock.getType())) { this.remove(); return; } else if (GeneralMethods.isSolid(topBlock.getRelative(BlockFace.UP)) || isWater(topBlock.getRelative(BlockFace.UP))) { @@ -178,9 +185,4 @@ public class FireWheel extends FireAbility implements ComboAbility { public ArrayList getAffectedEntities() { return this.affectedEntities; } - - @Override - public String getInstructions() { - return "FireShield (Hold Shift) > Right Click a block in front of you twice > Switch to Blaze > Release Shift"; - } } diff --git a/src/com/projectkorra/projectkorra/firebending/combo/JetBlast.java b/src/com/projectkorra/projectkorra/firebending/combo/JetBlast.java index e4fb7887..ffb6efef 100644 --- a/src/com/projectkorra/projectkorra/firebending/combo/JetBlast.java +++ b/src/com/projectkorra/projectkorra/firebending/combo/JetBlast.java @@ -10,6 +10,7 @@ import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ability.ComboAbility; import com.projectkorra.projectkorra.ability.FireAbility; import com.projectkorra.projectkorra.ability.util.ComboManager.AbilityInformation; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.firebending.FireJet; import com.projectkorra.projectkorra.util.ClickType; import com.projectkorra.projectkorra.util.ParticleEffect; @@ -18,15 +19,18 @@ public class JetBlast extends FireAbility implements ComboAbility { private boolean firstTime; private long time; + @Attribute(Attribute.COOLDOWN) private long cooldown; + @Attribute(Attribute.SPEED) private double speed; private ArrayList tasks; + @Attribute(Attribute.DURATION) private long duration; public JetBlast(final Player player) { super(player); - if (!this.bPlayer.canBendIgnoreBindsCooldowns(this)) { + if (!this.bPlayer.canBendIgnoreBinds(this)) { return; } @@ -75,10 +79,9 @@ public class JetBlast extends FireAbility implements ComboAbility { return; } - this.bPlayer.addCooldown("JetBlast", this.cooldown); this.firstTime = false; final float spread = 0F; - ParticleEffect.LARGE_EXPLODE.display(this.player.getLocation(), spread, spread, spread, 0, 1); + ParticleEffect.EXPLOSION_LARGE.display(this.player.getLocation(), 1, spread, spread, spread, 0); this.player.getWorld().playSound(this.player.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 15, 0F); } final FireJet fj = getAbility(this.player, FireJet.class); @@ -96,6 +99,15 @@ public class JetBlast extends FireAbility implements ComboAbility { } } + @Override + public void remove() { + for (final FireComboStream task : this.tasks) { + task.remove(); + } + super.remove(); + this.bPlayer.addCooldown("JetBlast", this.cooldown); + } + @Override public boolean isSneakAbility() { return false; @@ -120,10 +132,4 @@ public class JetBlast extends FireAbility implements ComboAbility { public boolean isHarmlessAbility() { return false; } - - @Override - public String getInstructions() { - return "FireJet (Tap Shift) > FireJet (Tap Shift) > FireShield (Tap Shift) > FireJet"; - } - } diff --git a/src/com/projectkorra/projectkorra/firebending/combo/JetBlaze.java b/src/com/projectkorra/projectkorra/firebending/combo/JetBlaze.java index 24af5e5d..c04cb42a 100644 --- a/src/com/projectkorra/projectkorra/firebending/combo/JetBlaze.java +++ b/src/com/projectkorra/projectkorra/firebending/combo/JetBlaze.java @@ -12,6 +12,7 @@ import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ability.ComboAbility; import com.projectkorra.projectkorra.ability.FireAbility; import com.projectkorra.projectkorra.ability.util.ComboManager.AbilityInformation; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.firebending.FireJet; import com.projectkorra.projectkorra.util.ClickType; import com.projectkorra.projectkorra.util.ParticleEffect; @@ -21,19 +22,24 @@ public class JetBlaze extends FireAbility implements ComboAbility { private boolean firstTime; private int progressCounter; private long time; + @Attribute(Attribute.COOLDOWN) private long cooldown; + @Attribute(Attribute.DAMAGE) private double damage; + @Attribute(Attribute.SPEED) private double speed; + @Attribute(Attribute.FIRE_TICK) private double fireTicks; private Vector direction; private ArrayList affectedEntities; private ArrayList tasks; + @Attribute(Attribute.DURATION) private long duration; public JetBlaze(final Player player) { super(player); - if (!this.bPlayer.canBendIgnoreBindsCooldowns(this)) { + if (!this.bPlayer.canBendIgnoreBinds(this)) { return; } @@ -82,7 +88,6 @@ public class JetBlaze extends FireAbility implements ComboAbility { this.remove(); return; } - this.bPlayer.addCooldown("JetBlaze", this.cooldown); this.firstTime = false; } else if (System.currentTimeMillis() - this.time > this.duration) { this.remove(); @@ -97,8 +102,8 @@ public class JetBlaze extends FireAbility implements ComboAbility { fs.setDensity(8); fs.setSpread(1.0F); fs.setUseNewParticles(true); - fs.setCollisionRadius(3); - fs.setParticleEffect(ParticleEffect.LARGE_SMOKE); + fs.setCollisionRadius(2); + fs.setParticleEffect(ParticleEffect.SMOKE_LARGE); fs.setDamage(this.damage); fs.setFireTicks(this.fireTicks); fs.runTaskTimer(ProjectKorra.plugin, 0, 1L); @@ -109,6 +114,15 @@ public class JetBlaze extends FireAbility implements ComboAbility { } } + @Override + public void remove() { + for (final FireComboStream task : this.tasks) { + task.remove(); + } + super.remove(); + this.bPlayer.addCooldown("JetBlaze", this.cooldown); + } + @Override public boolean isSneakAbility() { return false; @@ -137,9 +151,4 @@ public class JetBlaze extends FireAbility implements ComboAbility { public ArrayList getAffectedEntities() { return this.affectedEntities; } - - @Override - public String getInstructions() { - return "FireJet (Tap Shift) > FireJet (Tap Shift) > Blaze (Tap Shift) > FireJet"; - } } diff --git a/src/com/projectkorra/projectkorra/firebending/combustion/Combustion.java b/src/com/projectkorra/projectkorra/firebending/combustion/Combustion.java index 00e2160f..000884ef 100644 --- a/src/com/projectkorra/projectkorra/firebending/combustion/Combustion.java +++ b/src/com/projectkorra/projectkorra/firebending/combustion/Combustion.java @@ -1,7 +1,6 @@ package com.projectkorra.projectkorra.firebending.combustion; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; @@ -12,7 +11,9 @@ import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ability.AirAbility; import com.projectkorra.projectkorra.ability.CombustionAbility; +import com.projectkorra.projectkorra.ability.ElementalAbility; import com.projectkorra.projectkorra.ability.util.Collision; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.avatar.AvatarState; import com.projectkorra.projectkorra.util.DamageHandler; import com.projectkorra.projectkorra.util.ParticleEffect; @@ -23,11 +24,17 @@ public class Combustion extends CombustionAbility { private boolean breakBlocks; private int ticks; + @Attribute(Attribute.COOLDOWN) private long cooldown; - private float power; + @Attribute("ExplosivePower") + private float explosivePower; + @Attribute(Attribute.DAMAGE) private double damage; + @Attribute(Attribute.RADIUS) private double radius; + @Attribute(Attribute.SPEED) private double speed; + @Attribute(Attribute.RANGE) private double range; private double speedFactor; private Location location; @@ -43,7 +50,7 @@ public class Combustion extends CombustionAbility { this.ticks = 0; this.breakBlocks = getConfig().getBoolean("Abilities.Fire.Combustion.BreakBlocks"); - this.power = (float) getConfig().getDouble("Abilities.Fire.Combustion.Power"); + this.explosivePower = (float) getConfig().getDouble("Abilities.Fire.Combustion.ExplosivePower"); this.cooldown = getConfig().getLong("Abilities.Fire.Combustion.Cooldown"); this.damage = getConfig().getDouble("Abilities.Fire.Combustion.Damage"); this.radius = getConfig().getDouble("Abilities.Fire.Combustion.Radius"); @@ -72,8 +79,8 @@ public class Combustion extends CombustionAbility { public static void explode(final Player player) { final Combustion combustion = getAbility(player, Combustion.class); if (combustion != null) { - combustion.createExplosion(combustion.location, combustion.power, combustion.breakBlocks); - ParticleEffect.EXPLODE.display(combustion.location, (float) Math.random(), (float) Math.random(), (float) Math.random(), 0, 3); + combustion.createExplosion(combustion.location, combustion.explosivePower, combustion.breakBlocks); + ParticleEffect.EXPLOSION_NORMAL.display(combustion.location, 3, Math.random(), Math.random(), Math.random(), 0); } } @@ -96,8 +103,8 @@ public class Combustion extends CombustionAbility { } private void advanceLocation() { - ParticleEffect.FIREWORKS_SPARK.display(this.location, (float) Math.random() / 2, (float) Math.random() / 2, (float) Math.random() / 2, 0, 5); - ParticleEffect.FLAME.display(this.location, (float) Math.random() / 2, (float) Math.random() / 2, (float) Math.random() / 2, 0, 2); + ParticleEffect.FIREWORKS_SPARK.display(this.location, 5, Math.random() / 2, Math.random() / 2, Math.random() / 2, 0); + ParticleEffect.FLAME.display(this.location, 2, Math.random() / 2, Math.random() / 2, Math.random() / 2); playCombustionSound(this.location); this.location = this.location.add(this.direction.clone().multiply(this.speedFactor)); } @@ -139,15 +146,15 @@ public class Combustion extends CombustionAbility { final Block block = this.location.getBlock(); if (block != null) { - if (block.getType() != Material.AIR && !isWater(block)) { - this.createExplosion(block.getLocation(), this.power, this.breakBlocks); + if (!ElementalAbility.isAir(block.getType()) && !isWater(block)) { + this.createExplosion(block.getLocation(), this.explosivePower, this.breakBlocks); } } for (final Entity entity : this.location.getWorld().getEntities()) { if (entity instanceof LivingEntity) { if (entity.getLocation().distanceSquared(this.location) <= 4 && !entity.equals(this.player)) { - this.createExplosion(this.location, this.power, this.breakBlocks); + this.createExplosion(this.location, this.explosivePower, this.breakBlocks); } } } @@ -203,12 +210,12 @@ public class Combustion extends CombustionAbility { this.ticks = ticks; } - public float getPower() { - return this.power; + public float getExplosivePower() { + return this.explosivePower; } - public void setPower(final float power) { - this.power = power; + public void setExplosivePower(final float explosivePower) { + this.explosivePower = explosivePower; } public double getDamage() { diff --git a/src/com/projectkorra/projectkorra/firebending/lightning/Lightning.java b/src/com/projectkorra/projectkorra/firebending/lightning/Lightning.java index 86c1c337..93393abc 100644 --- a/src/com/projectkorra/projectkorra/firebending/lightning/Lightning.java +++ b/src/com/projectkorra/projectkorra/firebending/lightning/Lightning.java @@ -3,6 +3,8 @@ package com.projectkorra.projectkorra.firebending.lightning; import java.util.ArrayList; import java.util.List; +import com.projectkorra.projectkorra.ability.CoreAbility; +import com.projectkorra.projectkorra.firebending.FireJet; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Entity; @@ -15,6 +17,7 @@ import com.projectkorra.projectkorra.Element; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ability.LightningAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.util.DamageHandler; import com.projectkorra.projectkorra.util.MovementHandler; @@ -26,26 +29,40 @@ public class Lightning extends LightningAbility { private static final int POINT_GENERATION = 5; + @Attribute("Charged") private boolean charged; private boolean hitWater; private boolean hitIce; private boolean selfHitWater; private boolean selfHitClose; + @Attribute("ArcOnIce") private boolean arcOnIce; private int waterArcs; + @Attribute(Attribute.RANGE) private double range; + @Attribute(Attribute.CHARGE_DURATION) private double chargeTime; + @Attribute("SubArcChance") private double subArcChance; + @Attribute(Attribute.DAMAGE) private double damage; + @Attribute("MaxChainArcs") private double maxChainArcs; + @Attribute("Chain" + Attribute.RANGE) private double chainRange; + @Attribute("WaterArc" + Attribute.RANGE) private double waterArcRange; + @Attribute("ChainArcChance") private double chainArcChance; + @Attribute("StunChance") private double stunChance; + @Attribute("Stun" + Attribute.DURATION) private double stunDuration; + @Attribute("MaxArcAngle") private double maxArcAngle; private double particleRotation; private long time; + @Attribute(Attribute.COOLDOWN) private long cooldown; private State state; private Location origin; @@ -108,10 +125,6 @@ public class Lightning extends LightningAbility { this.chargeTime = getConfig().getLong("Abilities.Avatar.AvatarState.Fire.Lightning.ChargeTime"); this.cooldown = getConfig().getLong("Abilities.Avatar.AvatarState.Fire.Lightning.Cooldown"); this.damage = getConfig().getDouble("Abilities.Avatar.AvatarState.Fire.Lightning.Damage"); - - } else if (isSozinsComet(player.getWorld())) { - this.chargeTime = 0; - this.cooldown = 0; } this.start(); } @@ -169,6 +182,9 @@ public class Lightning extends LightningAbility { } else if (!this.bPlayer.canBendIgnoreCooldowns(this)) { this.remove(); return; + } else if (CoreAbility.hasAbility(player, FireJet.class)){ + this.removeWithTasks(); + return; } this.locations.clear(); diff --git a/src/com/projectkorra/projectkorra/hooks/PlaceholderAPIHook.java b/src/com/projectkorra/projectkorra/hooks/PlaceholderAPIHook.java new file mode 100644 index 00000000..485334e2 --- /dev/null +++ b/src/com/projectkorra/projectkorra/hooks/PlaceholderAPIHook.java @@ -0,0 +1,84 @@ +package com.projectkorra.projectkorra.hooks; + +import static java.util.stream.Collectors.joining; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import com.projectkorra.projectkorra.BendingPlayer; +import com.projectkorra.projectkorra.Element; +import com.projectkorra.projectkorra.ProjectKorra; +import com.projectkorra.projectkorra.ability.CoreAbility; +import com.projectkorra.projectkorra.configuration.ConfigManager; + +import me.clip.placeholderapi.expansion.PlaceholderExpansion; + +public class PlaceholderAPIHook extends PlaceholderExpansion { + + private final ProjectKorra plugin; + + public PlaceholderAPIHook(final ProjectKorra plugin) { + this.plugin = plugin; + } + + @Override + public String onPlaceholderRequest(final Player player, final String params) { + final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); + if (bPlayer == null) { + return ""; + } + + if (params.startsWith("slot")) { + final String ability = bPlayer.getAbilities().get(Integer.parseInt(params.substring(params.length() - 1))); + final CoreAbility coreAbil = CoreAbility.getAbility(ability); + if (coreAbil == null) { + return ""; + } + return coreAbil.getElement().getColor() + coreAbil.getName(); + } else if (params.equals("element") || params.equals("elementcolor")) { + String e = "Nonbender"; + ChatColor c = ChatColor.WHITE; + if (player.hasPermission("bending.avatar") || (bPlayer.hasElement(Element.AIR) && bPlayer.hasElement(Element.EARTH) && bPlayer.hasElement(Element.FIRE) && bPlayer.hasElement(Element.WATER))) { + c = Element.AVATAR.getColor(); + e = Element.AVATAR.getName(); + } else if (bPlayer.getElements().size() > 0) { + c = bPlayer.getElements().get(0).getColor(); + e = bPlayer.getElements().get(0).getName(); + } + if (params.equals("element")) { + return e; + } else if (params.equals("elementcolor")) { + return c.toString(); + } + } else if (params.equals("elements")) { + return bPlayer.getElements().stream().map(item -> item.getColor() + item.getName()).collect(joining(" ")); + } + + return null; + } + + @Override + public boolean persist() { + return true; + } + + @Override + public boolean canRegister() { + return true; + } + + @Override + public String getAuthor() { + return this.plugin.getDescription().getAuthors().toString(); + } + + @Override + public String getIdentifier() { + return "ProjectKorra"; + } + + @Override + public String getVersion() { + return this.plugin.getDescription().getVersion(); + } +} diff --git a/src/com/projectkorra/projectkorra/hooks/WorldGuardFlag.java b/src/com/projectkorra/projectkorra/hooks/WorldGuardFlag.java new file mode 100644 index 00000000..9291790a --- /dev/null +++ b/src/com/projectkorra/projectkorra/hooks/WorldGuardFlag.java @@ -0,0 +1,19 @@ +package com.projectkorra.projectkorra.hooks; + +import com.sk89q.worldguard.WorldGuard; +import com.sk89q.worldguard.protection.flags.StateFlag; +import com.sk89q.worldguard.protection.flags.registry.FlagRegistry; + +import com.projectkorra.projectkorra.ProjectKorra; + +public class WorldGuardFlag { + public static void registerBendingWorldGuardFlag() { + final FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry(); + + try { + registry.register(new StateFlag("bending", false)); + } catch (final Exception e) { + ProjectKorra.log.severe("Unable to register bending WorldGuard flag: " + e); + } + } +} diff --git a/src/com/projectkorra/projectkorra/object/HorizontalVelocityTracker.java b/src/com/projectkorra/projectkorra/object/HorizontalVelocityTracker.java index 48d7ef8f..7a9cb453 100644 --- a/src/com/projectkorra/projectkorra/object/HorizontalVelocityTracker.java +++ b/src/com/projectkorra/projectkorra/object/HorizontalVelocityTracker.java @@ -4,11 +4,15 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -44,6 +48,10 @@ public class HorizontalVelocityTracker { return; } + if (!(e instanceof LivingEntity)) { + return; + } + remove(e); this.entity = e; this.instigator = instigator; @@ -52,7 +60,6 @@ public class HorizontalVelocityTracker { this.thisVelocity = e.getVelocity().clone(); this.launchLocation = e.getLocation().clone(); this.impactLocation = this.launchLocation.clone(); - this.delay = delay; this.abil = ability; this.update(); instances.put(this.entity, this); @@ -68,6 +75,12 @@ public class HorizontalVelocityTracker { return; } + if (System.currentTimeMillis() > (this.fireTime + 30000)) { + ProjectKorra.log.info("removed HorizontalVelocityTracker lasting over 30 seconds: " + this.instigator.getName() + " using " + this.abil.getName() + " on " + this.entity); + this.remove(); + return; + } + this.lastVelocity = this.thisVelocity.clone(); this.thisVelocity = this.entity.getVelocity().clone(); @@ -86,7 +99,7 @@ public class HorizontalVelocityTracker { if ((diff.getX() > 1 || diff.getX() < -1) || (diff.getZ() > 1 || diff.getZ() < -1)) { this.impactLocation = this.entity.getLocation(); for (final Block b : blocks) { - if (b.getType() == Material.BARRIER && this.barrier == false) { + if (b.getType() == Material.BARRIER && !this.barrier) { return; } if (GeneralMethods.isSolid(b) && (this.entity.getLocation().getBlock().getRelative(BlockFace.EAST, 1).equals(b) || this.entity.getLocation().getBlock().getRelative(BlockFace.NORTH, 1).equals(b) || this.entity.getLocation().getBlock().getRelative(BlockFace.WEST, 1).equals(b) || this.entity.getLocation().getBlock().getRelative(BlockFace.SOUTH, 1).equals(b))) { @@ -117,9 +130,7 @@ public class HorizontalVelocityTracker { } public static void remove(final Entity e) { - if (instances.containsKey(e)) { - instances.remove(e); - } + instances.remove(e); } public static boolean hasBeenDamagedByHorizontalVelocity(final Entity e) { @@ -128,4 +139,9 @@ public class HorizontalVelocityTracker { } return false; } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); + } } diff --git a/src/com/projectkorra/projectkorra/object/Preset.java b/src/com/projectkorra/projectkorra/object/Preset.java index 94f9c74e..f57cf592 100644 --- a/src/com/projectkorra/projectkorra/object/Preset.java +++ b/src/com/projectkorra/projectkorra/object/Preset.java @@ -103,12 +103,10 @@ public class Preset { } new Preset(uuid, rs.getString("name"), moves); i++; - } - while (rs.next()); + } while (rs.next()); ProjectKorra.log.info("Loaded " + i + " presets for " + player.getName()); } - } - catch (final SQLException ex) { + } catch (final SQLException ex) { ex.printStackTrace(); } } @@ -138,7 +136,7 @@ public class Preset { return false; } - final HashMap abilities = (HashMap) preset.abilities.clone(); + final HashMap abilities = new HashMap<>(preset.abilities); boolean boundAll = true; for (int i = 1; i <= 9; i++) { final CoreAbility coreAbil = CoreAbility.getAbility(abilities.get(i)); @@ -273,8 +271,7 @@ public class Preset { ps.setString(2, this.name); ps.execute(); presets.get(this.uuid).remove(this); - } - catch (final SQLException e) { + } catch (final SQLException e) { e.printStackTrace(); } } @@ -303,8 +300,7 @@ public class Preset { ps.setString(2, this.name); ps.execute(); } - } - catch (final SQLException e) { + } catch (final SQLException e) { e.printStackTrace(); } for (final Integer i : this.abilities.keySet()) { @@ -319,8 +315,7 @@ public class Preset { this.ps.setString(2, Preset.this.uuid.toString()); this.ps.setString(3, Preset.this.name); this.ps.execute(); - } - catch (final SQLException e) { + } catch (final SQLException e) { e.printStackTrace(); } } @@ -334,8 +329,7 @@ public class Preset { try { Thread.sleep(1500); reloadPreset(player); - } - catch (final InterruptedException e) { + } catch (final InterruptedException e) { e.printStackTrace(); } } diff --git a/src/com/projectkorra/projectkorra/storage/DBConnection.java b/src/com/projectkorra/projectkorra/storage/DBConnection.java index 73cd5c15..e1f32d1a 100644 --- a/src/com/projectkorra/projectkorra/storage/DBConnection.java +++ b/src/com/projectkorra/projectkorra/storage/DBConnection.java @@ -49,8 +49,7 @@ public class DBConnection { sql.getConnection().setAutoCommit(true); ProjectKorra.log.info("Database Updated."); } - } - catch (final SQLException e) { + } catch (final SQLException e) { e.printStackTrace(); } } @@ -66,7 +65,7 @@ public class DBConnection { } if (!sql.tableExists("pk_cooldowns")) { ProjectKorra.log.info("Creating pk_cooldowns table"); - final String query = "CREATE TABLE `pk_cooldowns` (uuid VARCHAR(36) PRIMARY KEY, cooldown_id INTEGER NOT NULL, value BIGINT);"; + final String query = "CREATE TABLE `pk_cooldowns` (uuid VARCHAR(36) NOT NULL, cooldown_id INTEGER NOT NULL, value BIGINT, PRIMARY KEY (uuid, cooldown_id));"; sql.modifyQuery(query, false); } } else { @@ -94,8 +93,7 @@ public class DBConnection { ProjectKorra.log.info("Database Updated."); } - } - catch (final SQLException e) { + } catch (final SQLException e) { e.printStackTrace(); } } @@ -111,7 +109,7 @@ public class DBConnection { } if (!sql.tableExists("pk_cooldowns")) { ProjectKorra.log.info("Creating pk_cooldowns table"); - final String query = "CREATE TABLE `pk_cooldowns` (uuid TEXT(36) PRIMARY KEY, cooldown_id INTEGER NOT NULL, value BIGINT);"; + final String query = "CREATE TABLE `pk_cooldowns` (uuid TEXT(36) NOT NULL, cooldown_id INTEGER NOT NULL, value BIGINT, PRIMARY KEY (uuid, cooldown_id));"; sql.modifyQuery(query, false); } } diff --git a/src/com/projectkorra/projectkorra/storage/Database.java b/src/com/projectkorra/projectkorra/storage/Database.java index efa2d52e..75352a48 100644 --- a/src/com/projectkorra/projectkorra/storage/Database.java +++ b/src/com/projectkorra/projectkorra/storage/Database.java @@ -71,8 +71,7 @@ public abstract class Database { if (this.connection != null) { try { this.connection.close(); - } - catch (final SQLException e) { + } catch (final SQLException e) { e.printStackTrace(); } } else { @@ -124,8 +123,7 @@ public abstract class Database { final ResultSet rs = stmt.executeQuery(); return rs; - } - catch (final SQLException e) { + } catch (final SQLException e) { e.printStackTrace(); return null; } @@ -146,8 +144,7 @@ public abstract class Database { final ResultSet rs = dmd.getTables(null, null, table, null); return rs.next(); - } - catch (final Exception e) { + } catch (final Exception e) { e.printStackTrace(); return false; } @@ -168,8 +165,7 @@ public abstract class Database { final DatabaseMetaData dmd = this.connection.getMetaData(); final ResultSet rs = dmd.getColumns(null, null, table, column); return rs.next(); - } - catch (final Exception e) { + } catch (final Exception e) { e.printStackTrace(); return false; } @@ -183,8 +179,7 @@ public abstract class Database { final PreparedStatement stmt = this.connection.prepareStatement(query); stmt.execute(); stmt.close(); - } - catch (final SQLException e) { + } catch (final SQLException e) { e.printStackTrace(); } } diff --git a/src/com/projectkorra/projectkorra/storage/MySQL.java b/src/com/projectkorra/projectkorra/storage/MySQL.java index cbf49015..a0a869cb 100644 --- a/src/com/projectkorra/projectkorra/storage/MySQL.java +++ b/src/com/projectkorra/projectkorra/storage/MySQL.java @@ -40,12 +40,10 @@ public class MySQL extends Database { this.printInfo("Connection established!"); return this.connection; - } - catch (final ClassNotFoundException e) { + } catch (final ClassNotFoundException e) { this.printErr("JDBC driver not found!", true); return null; - } - catch (final SQLException e) { + } catch (final SQLException e) { e.printStackTrace(); this.printErr("MYSQL exception during connection.", true); return null; diff --git a/src/com/projectkorra/projectkorra/storage/SQLite.java b/src/com/projectkorra/projectkorra/storage/SQLite.java index a891d109..82c22669 100644 --- a/src/com/projectkorra/projectkorra/storage/SQLite.java +++ b/src/com/projectkorra/projectkorra/storage/SQLite.java @@ -34,12 +34,10 @@ public class SQLite extends Database { this.printInfo("Connection established!"); return this.connection; - } - catch (final ClassNotFoundException e) { + } catch (final ClassNotFoundException e) { this.printErr("JDBC driver not found!", true); return null; - } - catch (final SQLException e) { + } catch (final SQLException e) { this.printErr("SQLite exception during connection.", true); return null; } diff --git a/src/com/projectkorra/projectkorra/util/ActionBar.java b/src/com/projectkorra/projectkorra/util/ActionBar.java index 24fa7120..90579d76 100644 --- a/src/com/projectkorra/projectkorra/util/ActionBar.java +++ b/src/com/projectkorra/projectkorra/util/ActionBar.java @@ -31,8 +31,7 @@ public class ActionBar { playerConnection = ReflectionHandler.getField("EntityPlayer", PackageType.MINECRAFT_SERVER, false, "playerConnection"); sendPacket = ReflectionHandler.getMethod(playerConnection.getType(), "sendPacket", PackageType.MINECRAFT_SERVER.getClass("Packet")); initialised = true; - } - catch (final ReflectiveOperationException e) { + } catch (final ReflectiveOperationException e) { initialised = false; } } @@ -54,8 +53,7 @@ public class ActionBar { packet = packetChat.newInstance(o, (byte) 2); } sendTo(packet, player); - } - catch (final ReflectiveOperationException e) { + } catch (final ReflectiveOperationException e) { e.printStackTrace(); initialised = false; } diff --git a/src/com/projectkorra/projectkorra/util/Attribute.java b/src/com/projectkorra/projectkorra/util/Attribute.java deleted file mode 100644 index 052da5b9..00000000 --- a/src/com/projectkorra/projectkorra/util/Attribute.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.projectkorra.projectkorra.util; - -import java.lang.reflect.Field; - -import com.projectkorra.projectkorra.ProjectKorra; -import com.projectkorra.projectkorra.ability.CoreAbility; - -public class Attribute { - - public static boolean setField(final CoreAbility ability, final String field, final Object value) { - try { - final Field _field = ability.getClass().getDeclaredField(field); - final boolean oldVisibility = _field.isAccessible(); - _field.setAccessible(true); - try { - _field.set(ability, value); - } - catch (IllegalArgumentException | IllegalAccessException e) { - e.printStackTrace(); - ProjectKorra.log.warning(e.getClass().getName() + ": Failed to set field '" + _field.getName() + "' (" + _field.getType().getSimpleName() + ") in " + ability.getClass().getSimpleName() + " to '" + value.toString() + "' (" + value.getClass().getSimpleName() + ") at"); - - return false; - } - _field.setAccessible(oldVisibility); - } - catch (NoSuchFieldException | SecurityException e) { - e.printStackTrace(); - ProjectKorra.log.warning(e.getClass().getName() + ": Failed to set field '" + field + "' in " + ability.getClass().getSimpleName() + " to '" + value.toString() + "' (" + value.getClass().getSimpleName() + ")"); - return false; - } - return true; - } - - public static Object getField(final CoreAbility ability, final String field) { - try { - final Field _field = ability.getClass().getDeclaredField(field); - final boolean oldVisibility = _field.isAccessible(); - _field.setAccessible(true); - try { - final Object object = _field.get(ability); - _field.setAccessible(oldVisibility); - return object; - } - catch (IllegalArgumentException | IllegalAccessException e) { - e.printStackTrace(); - ProjectKorra.log.warning(e.getClass().getName() + ": Failed to get field '" + _field.getName() + "' in " + ability.getClass().getSimpleName()); - return null; - } - } - catch (NoSuchFieldException | SecurityException e) { - e.printStackTrace(); - ProjectKorra.log.warning(e.getClass().getName() + ": Failed to get field '" + field + "' in " + ability.getClass().getSimpleName()); - return null; - } - } - -} diff --git a/src/com/projectkorra/projectkorra/util/BlockSource.java b/src/com/projectkorra/projectkorra/util/BlockSource.java index 0ed2f22e..5a56abbb 100644 --- a/src/com/projectkorra/projectkorra/util/BlockSource.java +++ b/src/com/projectkorra/projectkorra/util/BlockSource.java @@ -3,7 +3,6 @@ package com.projectkorra.projectkorra.util; import java.util.HashMap; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; @@ -269,7 +268,7 @@ public class BlockSource { } else { sourceBlock = WaterAbility.getWaterSourceBlock(player, range, allowPlant); } - if (sourceBlock != null && !sourceBlock.getType().equals(Material.AIR) && (ElementalAbility.isWater(sourceBlock) || ElementalAbility.isPlant(sourceBlock) || WaterAbility.isSnow(sourceBlock) || ElementalAbility.isIce(sourceBlock))) { + if (sourceBlock != null && !ElementalAbility.isAir(sourceBlock.getType()) && (ElementalAbility.isWater(sourceBlock) || ElementalAbility.isPlant(sourceBlock) || WaterAbility.isSnow(sourceBlock) || ElementalAbility.isIce(sourceBlock))) { if (TempBlock.isTempBlock(sourceBlock) && !WaterAbility.isBendableWaterTempBlock(sourceBlock)) { return null; } diff --git a/src/com/projectkorra/projectkorra/util/ColoredParticle.java b/src/com/projectkorra/projectkorra/util/ColoredParticle.java new file mode 100644 index 00000000..91672cdd --- /dev/null +++ b/src/com/projectkorra/projectkorra/util/ColoredParticle.java @@ -0,0 +1,22 @@ +package com.projectkorra.projectkorra.util; + +import org.bukkit.Color; +import org.bukkit.Location; +import org.bukkit.Particle.DustOptions; + +public class ColoredParticle { + + private final DustOptions dust; + + public ColoredParticle(final Color color, final float size) { + this.dust = new DustOptions(color, size); + } + + public DustOptions getDustOptions() { + return this.dust; + } + + public void display(final Location loc, final int amount, final double offsetX, final double offsetY, final double offsetZ) { + ParticleEffect.REDSTONE.display(loc, amount, offsetX, offsetY, offsetZ, this.dust); + } +} diff --git a/src/com/projectkorra/projectkorra/util/DBCooldownManager.java b/src/com/projectkorra/projectkorra/util/DBCooldownManager.java index f2ef2f1d..9c3ea034 100644 --- a/src/com/projectkorra/projectkorra/util/DBCooldownManager.java +++ b/src/com/projectkorra/projectkorra/util/DBCooldownManager.java @@ -3,13 +3,17 @@ package com.projectkorra.projectkorra.util; import java.sql.ResultSet; import java.sql.SQLException; +import com.projectkorra.projectkorra.Manager; import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.storage.DBConnection; import com.projectkorra.projectkorra.storage.MySQL; -public class DBCooldownManager { +public class DBCooldownManager extends Manager { - public DBCooldownManager() { + private DBCooldownManager() {} + + @Override + public void onActivate() { this.setupCooldowns(); } @@ -26,9 +30,9 @@ public class DBCooldownManager { // Create pk_cooldowns table. if (!DBConnection.sql.tableExists("pk_cooldowns")) { ProjectKorra.log.info("Creating pk_cooldowns table"); - String query = "CREATE TABLE `pk_cooldowns` (uuid TEXT(36) PRIMARY KEY, cooldown_id INTEGER NOT NULL, value BIGINT);"; + String query = "CREATE TABLE `pk_cooldowns` (uuid TEXT(36) NOT NULL, cooldown_id INTEGER NOT NULL, value BIGINT, PRIMARY KEY (uuid, cooldown_id));"; if (DBConnection.sql instanceof MySQL) { - query = "CREATE TABLE `pk_cooldowns` (uuid VARCHAR(36) PRIMARY KEY, cooldown_id INTEGER NOT NULL, value BIGINT);"; + query = "CREATE TABLE `pk_cooldowns` (uuid VARCHAR(36) NOT NULL, cooldown_id INTEGER NOT NULL, value BIGINT, PRIMARY KEY (uuid, cooldown_id));"; } DBConnection.sql.modifyQuery(query, false); } @@ -42,8 +46,7 @@ public class DBCooldownManager { DBConnection.sql.modifyQuery("INSERT INTO pk_cooldown_ids (cooldown_name) VALUES ('" + cooldown + "')", async); return this.getCooldownId(cooldown, async); } - } - catch (final SQLException e) { + } catch (final SQLException e) { e.printStackTrace(); } return -1; @@ -54,8 +57,7 @@ public class DBCooldownManager { if (rs.next()) { return rs.getString("cooldown_name"); } - } - catch (final SQLException e) { + } catch (final SQLException e) { e.printStackTrace(); } return ""; diff --git a/src/com/projectkorra/projectkorra/util/DamageHandler.java b/src/com/projectkorra/projectkorra/util/DamageHandler.java index 575c5698..7aa90c39 100644 --- a/src/com/projectkorra/projectkorra/util/DamageHandler.java +++ b/src/com/projectkorra/projectkorra/util/DamageHandler.java @@ -28,7 +28,7 @@ public class DamageHandler { * @param damage The amount of damage to deal */ public static void damageEntity(final Entity entity, Player source, double damage, final Ability ability, boolean ignoreArmor) { - if (TempArmor.hasTempArmor((LivingEntity) entity)) { + if (entity instanceof LivingEntity && TempArmor.hasTempArmor((LivingEntity) entity)) { ignoreArmor = true; } if (ability == null) { diff --git a/src/com/projectkorra/projectkorra/util/FlightHandler.java b/src/com/projectkorra/projectkorra/util/FlightHandler.java index 1fa485a1..07cf029c 100644 --- a/src/com/projectkorra/projectkorra/util/FlightHandler.java +++ b/src/com/projectkorra/projectkorra/util/FlightHandler.java @@ -1,6 +1,5 @@ package com.projectkorra.projectkorra.util; -import java.util.Comparator; import java.util.HashMap; import java.util.Map; import java.util.PriorityQueue; @@ -9,9 +8,10 @@ import java.util.UUID; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; +import com.projectkorra.projectkorra.Manager; import com.projectkorra.projectkorra.ProjectKorra; -public class FlightHandler { +public class FlightHandler extends Manager { /** * A Map containing all Flight instances. @@ -22,14 +22,12 @@ public class FlightHandler { * duration. This is used to reduce the number of iterations when cleaning * up dead instances. */ - private final PriorityQueue CLEANUP = new PriorityQueue<>(100, new Comparator() { - @Override - public int compare(final FlightAbility f1, final FlightAbility f2) { - return (int) (f1.duration - f2.duration); - } - }); + private final PriorityQueue CLEANUP = new PriorityQueue<>(100, (f1, f2) -> (int) (f1.duration - f2.duration)); - public FlightHandler() { + private FlightHandler() {} + + @Override + public void onActivate() { this.startCleanup(); } diff --git a/src/com/projectkorra/projectkorra/util/Metrics.java b/src/com/projectkorra/projectkorra/util/Metrics.java index 693defee..25f1f579 100644 --- a/src/com/projectkorra/projectkorra/util/Metrics.java +++ b/src/com/projectkorra/projectkorra/util/Metrics.java @@ -19,12 +19,13 @@ import java.util.zip.GZIPOutputStream; import javax.net.ssl.HttpsURLConnection; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; + import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.ServicePriority; import org.bukkit.plugin.java.JavaPlugin; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; /** * bStats collects some data for plugin authors. @@ -91,9 +92,7 @@ public class Metrics { 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 (final IOException ignored) { - } + } catch (final IOException ignored) {} } // Load the data. @@ -107,9 +106,7 @@ public class Metrics { service.getField("B_STATS_VERSION"); // Our identifier :) found = true; // We aren't the first. break; - } - catch (final NoSuchFieldException ignored) { - } + } catch (final NoSuchFieldException ignored) {} } // Register our service. Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal); @@ -146,12 +143,7 @@ public class Metrics { } // 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(Metrics.this.plugin, new Runnable() { - @Override - public void run() { - Metrics.this.submitData(); - } - }); + Bukkit.getScheduler().runTask(Metrics.this.plugin, (Runnable) () -> Metrics.this.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. @@ -233,33 +225,26 @@ public class Metrics { for (final Class service : Bukkit.getServicesManager().getKnownServices()) { try { service.getField("B_STATS_VERSION"); // Our identifier. - } - catch (final NoSuchFieldException ignored) { + } catch (final NoSuchFieldException ignored) { continue; // Continue "searching". } // Found one! try { pluginData.add(service.getMethod("getPluginData").invoke(Bukkit.getServicesManager().load(service))); - } - catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { - } + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {} } data.put("plugins", pluginData); // Create a new thread for the connection to the bStats server. - new Thread(new Runnable() { - @Override - public void run() { - try { - // Send the data. - sendData(data); - } - catch (final Exception e) { - // Something went wrong! :( - if (logFailedRequests) { - Metrics.this.plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + Metrics.this.plugin.getName(), e); - } + new Thread(() -> { + try { + // Send the data. + sendData(data); + } catch (final Exception e) { + // Something went wrong! :( + if (logFailedRequests) { + Metrics.this.plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + Metrics.this.plugin.getName(), e); } } }).start(); @@ -350,8 +335,7 @@ public class Metrics { return null; } chart.put("data", data); - } - catch (final Throwable t) { + } catch (final Throwable t) { if (logFailedRequests) { Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + this.chartId, t); } diff --git a/src/com/projectkorra/projectkorra/util/MovementHandler.java b/src/com/projectkorra/projectkorra/util/MovementHandler.java index 6aa27227..61b1d621 100644 --- a/src/com/projectkorra/projectkorra/util/MovementHandler.java +++ b/src/com/projectkorra/projectkorra/util/MovementHandler.java @@ -128,7 +128,11 @@ public class MovementHandler { */ public void reset() { if (this.runnable != null) { - this.runnable.cancel(); + try { + this.runnable.cancel(); + } catch (final IllegalStateException e) { //if a player hasn't landed on the ground yet this runnable wont be scheduled, and will give an error on server shutdown + this.runnable = null; + } } if (this.msg != null) { this.msg.cancel(); diff --git a/src/com/projectkorra/projectkorra/util/ParticleEffect.java b/src/com/projectkorra/projectkorra/util/ParticleEffect.java index 6239a8c1..92b9538b 100644 --- a/src/com/projectkorra/projectkorra/util/ParticleEffect.java +++ b/src/com/projectkorra/projectkorra/util/ParticleEffect.java @@ -1,1411 +1,159 @@ package com.projectkorra.projectkorra.util; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; +import org.bukkit.Particle; +import org.bukkit.Particle.DustOptions; +import org.bukkit.inventory.ItemStack; -import com.projectkorra.projectkorra.util.ReflectionHandler.PackageType; - -/** - * ParticleEffect Library - *

- * This library was created by @DarkBlade12 and allows you to display all - * Minecraft particle effects on a Bukkit server - *

- * You are welcome to use it, modify it and redistribute it under the following - * conditions: - *

    - *
  • Don't claim this class as your own - *
  • Don't remove this disclaimer - *
- *

- * Special thanks: - *

    - *
  • @microgeek (original idea, names and packet parameters) - *
  • @ShadyPotato (1.8 names, ids and packet parameters) - *
  • @RingOfStorms (specific particle direction) - *
- *

- * It would be nice if you provide credit to me if you use this class in a - * published project - * - * @author DarkBlade12 - * @version 1.6 - */ public enum ParticleEffect { + BARRIER (Particle.BARRIER), + /** - * A particle effect which is displayed by exploding tnt and creepers: - *

    - *
  • It looks like a white cloud - *
  • The speed value influences the velocity at which the particle flies - * off - *
+ * Applicable data: {@link BlockData} */ - EXPLOSION_NORMAL("explode", 0, -1), EXPLODE("explode", 0, -1), + BLOCK_CRACK (Particle.BLOCK_CRACK), + /** - * A particle effect which is displayed by exploding ghast fireballs and - * wither skulls: - *
    - *
  • It looks like a gray ball which is fading away - *
  • The speed value slightly influences the size of this particle effect - *
+ * Applicable data: {@link BlockData} */ - EXPLOSION_LARGE("largeexplode", 1, -1), LARGE_EXPLODE("largeexplode", 1, -1), + BLOCK_DUST (Particle.BLOCK_DUST), + BUBBLE_COLUMN_UP (Particle.BUBBLE_COLUMN_UP), + BUBBLE_POP (Particle.BUBBLE_POP), + CLOUD (Particle.CLOUD), + CRIT (Particle.CRIT), + CRIT_MAGIC (Particle.CRIT_MAGIC), @Deprecated MAGIC_CRIT (Particle.CRIT_MAGIC), + CURRENT_DOWN (Particle.CURRENT_DOWN), + DAMAGE_INDICATOR (Particle.DAMAGE_INDICATOR), + DOLPHIN (Particle.DOLPHIN), + DRAGON_BREATH (Particle.DRAGON_BREATH), + DRIP_LAVA (Particle.DRIP_LAVA), + DRIP_WATER (Particle.DRIP_WATER), + ENCHANTMENT_TABLE (Particle.ENCHANTMENT_TABLE), + END_ROD (Particle.END_ROD), + EXPLOSION_HUGE (Particle.EXPLOSION_HUGE), @Deprecated HUGE_EXPLOSION (Particle.EXPLOSION_HUGE), + EXPLOSION_LARGE (Particle.EXPLOSION_LARGE), @Deprecated LARGE_EXPLODE (Particle.EXPLOSION_LARGE), + EXPLOSION_NORMAL (Particle.EXPLOSION_NORMAL), @Deprecated EXPLODE (Particle.EXPLOSION_NORMAL), + /** - * A particle effect which is displayed by exploding tnt and creepers: - *
    - *
  • It looks like a crowd of gray balls which are fading away - *
  • The speed value has no influence on this particle effect - *
+ * Applicable data: {@link BlockData} */ - EXPLOSION_HUGE("hugeexplosion", 2, -1), HUGE_EXPLOSION("hugeexplosion", 2, -1), + FALLING_DUST (Particle.FALLING_DUST), + FIREWORKS_SPARK (Particle.FIREWORKS_SPARK), + FLAME (Particle.FLAME), + HEART (Particle.HEART), + /** - * A particle effect which is displayed by launching fireworks: - *
    - *
  • It looks like a white star which is sparkling - *
  • The speed value influences the velocity at which the particle flies - * off - *
+ * Applicable data: {@link ItemStack} */ - FIREWORKS_SPARK("fireworksSpark", 3, -1), + ITEM_CRACK (Particle.ITEM_CRACK), + LAVA (Particle.LAVA), + MOB_APPEARANCE (Particle.MOB_APPEARANCE), + NAUTILUS (Particle.NAUTILUS), + NOTE (Particle.NOTE), + PORTAL (Particle.PORTAL), + /** - * A particle effect which is displayed by swimming entities and arrows in - * water: - *
    - *
  • It looks like a bubble - *
  • The speed value influences the velocity at which the particle flies - * off - *
+ * Applicable data: {@link DustOptions} */ - WATER_BUBBLE("bubble", 4, -1, false, true), BUBBLE("bubble", 4, -1, false, true), - /** - * A particle effect which is displayed by swimming entities and shaking - * wolves: - *
    - *
  • It looks like a blue drop - *
  • The speed value has no influence on this particle effect - *
- */ - WATER_SPLASH("splash", 5, -1), SPLASH("splash", 5, -1), - /** - * A particle effect which is displayed on water when fishing: - *
    - *
  • It looks like a blue droplet - *
  • The speed value influences the velocity at which the particle flies - * off - *
- */ - WATER_WAKE("wake", 6, 7), WAKE("wake", 6, 7), - /** - * A particle effect which is displayed by water: - *
    - *
  • It looks like a tiny blue square - *
  • The speed value has no influence on this particle effect - *
- */ - SUSPENDED("suspended", 7, -1, false, true), SUSPEND("suspended", 7, -1, false, true), - /** - * A particle effect which is displayed by air when close to bedrock and the - * in the void: - *
    - *
  • It looks like a tiny gray square - *
  • The speed value has no influence on this particle effect - *
- */ - SUSPENDED_DEPTH("depthSuspend", 8, -1), DEPTH_SUSPEND("depthSuspend", 8, -1), - /** - * A particle effect which is displayed when landing a critical hit and by - * arrows: - *
    - *
  • It looks like a light brown cross - *
  • The speed value influences the velocity at which the particle flies - * off - *
- */ - CRIT("crit", 9, -1), - /** - * A particle effect which is displayed when landing a hit with an enchanted - * weapon: - *
    - *
  • It looks like a cyan star - *
  • The speed value influences the velocity at which the particle flies - * off - *
- */ - CRIT_MAGIC("magicCrit", 10, -1), MAGIC_CRIT("magicCrit", 10, -1), - /** - * A particle effect which is displayed by primed tnt, torches, droppers, - * dispensers, end portals, brewing stands and monster spawners: - *
    - *
  • It looks like a little gray cloud - *
  • The speed value influences the velocity at which the particle flies - * off - *
- */ - SMOKE_NORMAL("smoke", 11, -1), SMOKE("smoke", 11, -1), - /** - * A particle effect which is displayed by fire, minecarts with furnace and - * blazes: - *
    - *
  • It looks like a large gray cloud - *
  • The speed value influences the velocity at which the particle flies - * off - *
- */ - SMOKE_LARGE("largesmoke", 12, -1), LARGE_SMOKE("largesmoke", 12, -1), - /** - * A particle effect which is displayed when splash potions or bottles o' - * enchanting hit something: - *
    - *
  • It looks like a white swirl - *
  • The speed value causes the particle to only move upwards when set to - * 0 - *
- */ - SPELL("spell", 13, -1), - /** - * A particle effect which is displayed when instant splash potions hit - * something: - *
    - *
  • It looks like a white cross - *
  • The speed value causes the particle to only move upwards when set to - * 0 - *
- */ - SPELL_INSTANT("instantSpell", 14, -1), INSTANT_SPELL("instantSpell", 14, -1), - /** - * A particle effect which is displayed by entities with active potion - * effects: - *
    - *
  • It looks like a colored swirl - *
  • The speed value causes the particle to be colored black when set to 0 - *
  • The particle color gets lighter when increasing the speed and darker - * when decreasing the speed - *
- */ - SPELL_MOB("mobSpell", 15, -1), MOB_SPELL("mobSpell", 15, -1), - /** - * A particle effect which is displayed by entities with active potion - * effects applied through a beacon: - *
    - *
  • It looks like a transparent colored swirl - *
  • The speed value causes the particle to be always colored black when - * set to 0 - *
  • The particle color gets lighter when increasing the speed and darker - * when decreasing the speed - *
- */ - SPELL_MOB_AMBIENT("mobSpellAmbient", 16, -1), MOB_SPELL_AMBIENT("mobSpellAmbient", 16, -1), - /** - * A particle effect which is displayed by witches: - *
    - *
  • It looks like a purple cross - *
  • The speed value causes the particle to only move upwards when set to - * 0 - *
- */ - SPELL_WITCH("witchMagic", 17, -1), WITCH_MAGIC("witchMagic", 17, -1), - /** - * A particle effect which is displayed by blocks beneath a water source: - *
    - *
  • It looks like a blue drip - *
  • The speed value has no influence on this particle effect - *
- */ - DRIP_WATER("dripWater", 18, -1), - /** - * A particle effect which is displayed by blocks beneath a lava source: - *
    - *
  • It looks like an orange drip - *
  • The speed value has no influence on this particle effect - *
- */ - DRIP_LAVA("dripLava", 19, -1), - /** - * A particle effect which is displayed when attacking a villager in a - * village: - *
    - *
  • It looks like a cracked gray heart - *
  • The speed value has no influence on this particle effect - *
- */ - VILLAGER_ANGRY("angryVillager", 20, -1), ANGRY_VILLAGER("angryVillager", 20, -1), - /** - * A particle effect which is displayed when using bone meal and trading - * with a villager in a village: - *
    - *
  • It looks like a green star - *
  • The speed value has no influence on this particle effect - *
- */ - VILLAGER_HAPPY("happyVillager", 21, -1), HAPPY_VILLAGER("happyVillager", 21, -1), - /** - * A particle effect which is displayed by mycelium: - *
    - *
  • It looks like a tiny gray square - *
  • The speed value has no influence on this particle effect - *
- */ - TOWN_AURA("townaura", 22, -1), - /** - * A particle effect which is displayed by note blocks: - *
    - *
  • It looks like a colored note - *
  • The speed value causes the particle to be colored green when set to 0 - *
- */ - NOTE("note", 23, -1), - /** - * A particle effect which is displayed by nether portals, endermen, ender - * pearls, eyes of ender, ender chests and dragon eggs: - *
    - *
  • It looks like a purple cloud - *
  • The speed value influences the spread of this particle effect - *
- */ - PORTAL("portal", 24, -1), - /** - * A particle effect which is displayed by enchantment tables which are - * nearby bookshelves: - *
    - *
  • It looks like a cryptic white letter - *
  • The speed value influences the spread of this particle effect - *
- */ - ENCHANTMENT_TABLE("enchantmenttable", 25, -1), - /** - * A particle effect which is displayed by torches, active furnaces, magma - * cubes and monster spawners: - *
    - *
  • It looks like a tiny flame - *
  • The speed value influences the velocity at which the particle flies - * off - *
- */ - FLAME("flame", 26, -1), - /** - * A particle effect which is displayed by lava: - *
    - *
  • It looks like a spark - *
  • The speed value has no influence on this particle effect - *
- */ - LAVA("lava", 27, -1), - /** - * A particle effect which is currently unused: - *
    - *
  • It looks like a transparent gray square - *
  • The speed value has no influence on this particle effect - *
- */ - FOOTSTEP("footstep", 28, -1), - /** - * A particle effect which is displayed when a mob dies: - *
    - *
  • It looks like a large white cloud - *
  • The speed value influences the velocity at which the particle flies - * off - *
- */ - CLOUD("cloud", 29, -1), - /** - * A particle effect which is displayed by redstone ore, powered redstone, - * redstone torches and redstone repeaters: - *
    - *
  • It looks like a tiny colored cloud - *
  • The speed value causes the particle to be colored red when set to 0 - *
- */ - REDSTONE("reddust", 30, -1), RED_DUST("reddust", 30, -1), - /** - * A particle effect which is displayed when snowballs hit a block: - *
    - *
  • It looks like a little piece with the snowball texture - *
  • The speed value has no influence on this particle effect - *
- */ - SNOWBALL("snowballpoof", 31, -1), SNOWBALL_POOF("snowballpoof", 31, -1), - /** - * A particle effect which is currently unused: - *
    - *
  • It looks like a tiny white cloud - *
  • The speed value influences the velocity at which the particle flies - * off - *
- */ - SNOW_SHOVEL("snowshovel", 32, -1), - /** - * A particle effect which is displayed by slimes: - *
    - *
  • It looks like a tiny part of the slimeball icon - *
  • The speed value has no influence on this particle effect - *
- */ - SLIME("slime", 33, -1), - /** - * A particle effect which is displayed when breeding and taming animals: - *
    - *
  • It looks like a red heart - *
  • The speed value has no influence on this particle effect - *
- */ - HEART("heart", 34, -1), - /** - * A particle effect which is displayed by barriers: - *
    - *
  • It looks like a red box with a slash through it - *
  • The speed value has no influence on this particle effect - *
- */ - BARRIER("barrier", 35, 8), - /** - * A particle effect which is displayed when breaking a tool or eggs hit a - * block: - *
    - *
  • It looks like a little piece with an item texture - *
- */ - ITEM_CRACK("iconcrack", 36, -1, true), - /** - * A particle effect which is displayed when breaking blocks or sprinting: - *
    - *
  • It looks like a little piece with a block texture - *
  • The speed value has no influence on this particle effect - *
- */ - BLOCK_CRACK("blockcrack", 37, -1, true), - /** - * A particle effect which is displayed when falling: - *
    - *
  • It looks like a little piece with a block texture - *
- */ - BLOCK_DUST("blockdust", 38, 7, true), - /** - * A particle effect which is displayed when rain hits the ground: - *
    - *
  • It looks like a blue droplet - *
  • The speed value has no influence on this particle effect - *
- */ - WATER_DROP("droplet", 39, 8), - /** - * A particle effect which is currently unused: - *
    - *
  • It has no visual effect - *
- */ - ITEM_TAKE("take", 40, 8), - /** - * A particle effect (use unknown) - */ - MOB_APPEARANCE("mobappearance", 41, 8), - /** - * A particle effect displayed by end rods and shelker bullets: - *
    - *
  • Looks like a white twinkly star that rises - *
- */ - END_ROD("endRod", 43, 9), - /** - * A particle effect created by the Ender Dragon when it breathes acid: - *
    - *
  • Looks similar to portal particles but bigger - *
  • A purple varaint of the cloud effect - *
- */ - DRAGON_BREATH("dragonBreath", 42, 9), - /** - * A particle effect which is displayed when mobs are damaged: - *
    - *
  • Looks like a black heart - *
- */ - DAMAGE_INDICATOR("damageIndicator", 44, 9), - /** - * A particle effect displayed when mobs are attacked with a sword: - *
    - *
  • Looks like a sweep of air - *
- */ - SWEEP("sweepAttack", 45, 9), - /*** - * A particle effect displayed by floating sand and gravel blocks - *
    - *
  • Looks like a yellow/cream colored reddust - *
  • Has a downwards motion by default - *
- */ - FALLING_DUST("fallingDust", 46, 10, true), - /*** - * The particles given off when a totem of undying is used - *
    - *
  • Looks like endRod shaped particles - *
  • Are between a yellow and green in color - *
  • Has a downwards motion by default - *
- */ - TOTEM("talisman", 47, 11), - /*** - * A particle effect given off from llama spit entities - *
    - *
  • Looks like very large cloud - *
  • Has a downwards motion by default - *
- */ - SPIT("spit", 48, 11); - - private static final Map NAME_MAP = new HashMap(); - private static final Map ID_MAP = new HashMap(); - // If range is less than 257 it automatically reverts back to 16 blocks for some reason. - private static final int RANGE = 257; - private final String name; - private final int id; - private final int requiredVersion; - private final boolean requiresData; - private final boolean requiresWater; - - // Initialize map for quick name and id lookup. - static { - for (final ParticleEffect effect : values()) { - NAME_MAP.put(effect.name, effect); - ID_MAP.put(effect.id, effect); - } - ParticlePacket.initialize(); + REDSTONE (Particle.REDSTONE), @Deprecated RED_DUST (Particle.REDSTONE), + SLIME (Particle.SLIME), + SMOKE_NORMAL (Particle.SMOKE_NORMAL), @Deprecated SMOKE (Particle.SMOKE_NORMAL), + SMOKE_LARGE (Particle.SMOKE_LARGE), @Deprecated LARGE_SMOKE (Particle.SMOKE_LARGE), + SNOW_SHOVEL (Particle.SNOW_SHOVEL), + SNOWBALL (Particle.SNOWBALL), @Deprecated SNOWBALL_PROOF (Particle.SNOWBALL), + SPELL (Particle.SPELL), + SPELL_INSTANT (Particle.SPELL_INSTANT), @Deprecated INSTANT_SPELL (Particle.SPELL_INSTANT), + SPELL_MOB (Particle.SPELL_MOB), @Deprecated MOB_SPELL (Particle.SPELL_MOB), + SPELL_MOB_AMBIENT (Particle.SPELL_MOB_AMBIENT), @Deprecated MOB_SPELL_AMBIENT (Particle.SPELL_MOB_AMBIENT), + SPELL_WITCH (Particle.SPELL_WITCH), @Deprecated WITCH_SPELL (Particle.SPELL_WITCH), + SPIT (Particle.SPIT), + SQUID_INK (Particle.SQUID_INK), + SUSPENDED (Particle.SUSPENDED), @Deprecated SUSPEND (Particle.SUSPENDED), + SUSPENDED_DEPTH (Particle.SUSPENDED_DEPTH), @Deprecated DEPTH_SUSPEND (Particle.SUSPENDED_DEPTH), + SWEEP_ATTACK (Particle.SWEEP_ATTACK), + TOTEM (Particle.TOTEM), + TOWN_AURA (Particle.TOWN_AURA), + VILLAGER_ANGRY (Particle.VILLAGER_ANGRY), @Deprecated ANGRY_VILLAGER (Particle.VILLAGER_ANGRY), + VILLAGER_HAPPY (Particle.VILLAGER_HAPPY), @Deprecated HAPPY_VILLAGER (Particle.VILLAGER_HAPPY), + WATER_BUBBLE (Particle.WATER_BUBBLE), @Deprecated BUBBLE (Particle.WATER_BUBBLE), + WATER_DROP (Particle.WATER_DROP), + WATER_SPLASH (Particle.WATER_SPLASH), @Deprecated SPLASH (Particle.WATER_SPLASH), + WATER_WAKE (Particle.WATER_WAKE), @Deprecated WAKE (Particle.WATER_WAKE); + + Particle particle; + Class dataClass; + + private ParticleEffect(Particle particle) { + this.particle = particle; + this.dataClass = particle.getDataType(); } - - /** - * Construct a new particle effect - * - * @param name Name of this particle effect - * @param id Id of this particle effect - * @param requiredVersion Version which is required (1.x) - * @param requiresData Indicates whether additional data is required for - * this particle effect - * @param requiresWater Indicates whether water is required for this - * particle effect to display properly - */ - private ParticleEffect(final String name, final int id, final int requiredVersion, final boolean requiresData, final boolean requiresWater) { - this.name = name; - this.id = id; - this.requiredVersion = requiredVersion; - this.requiresData = requiresData; - this.requiresWater = requiresWater; + + public Particle getParticle() { + return particle; } - + /** - * Construct a new particle effect with {@link #requiresWater} set to - * false - * - * @param name Name of this particle effect - * @param id Id of this particle effect - * @param requiredVersion Version which is required (1.x) - * @param requiresData Indicates whether additional data is required for - * this particle effect - * @see #ParticleEffect(String, int, boolean, boolean) + * Displays the particle at the specified location without offsets + * @param loc Location to display the particle at + * @param amount how many of the particle to display */ - private ParticleEffect(final String name, final int id, final int requiredVersion, final boolean requiresData) { - this(name, id, requiredVersion, requiresData, false); + public void display(Location loc, int amount) { + display(loc, amount, 0, 0, 0); } - + /** - * Construct a new particle effect with {@link #requiresData} and - * {@link #requiresWater} set to false - * - * @param name Name of this particle effect - * @param id Id of this particle effect - * @param requiredVersion Version which is required (1.x) - * @param requiresData Indicates whether additional data is required for - * this particle effect - * @see #ParticleEffect(String, int, boolean) + * Displays the particle at the specified location with no extra data + * @param loc Location to spawn the particle + * @param amount how many of the particle to spawn + * @param offsetX random offset on the x axis + * @param offsetY random offset on the y axis + * @param offsetZ random offset on the z axis */ - private ParticleEffect(final String name, final int id, final int requiredVersion) { - this(name, id, requiredVersion, false); + public void display(Location loc, int amount, double offsetX, double offsetY, double offsetZ) { + display(loc, amount, offsetX, offsetY, offsetZ, 0); } - + /** - * Returns the name of this particle effect - * - * @return The name + * Displays the particle at the specified location with extra data + * @param loc Location to spawn the particle + * @param amount how many of the particle to spawn + * @param offsetX random offset on the x axis + * @param offsetY random offset on the y axis + * @param offsetZ random offset on the z axis + * @param extra extra data to affect the particle, usually affects speed or does nothing */ - public String getName() { - return this.name; + public void display(Location loc, int amount, double offsetX, double offsetY, double offsetZ, double extra) { + loc.getWorld().spawnParticle(particle, loc, amount, offsetX, offsetY, offsetZ, extra, null, true); } - + /** - * Returns the id of this particle effect - * - * @return The id + * Displays the particle at the specified location with data + * @param loc Location to spawn the particle + * @param amount how many of the particle to spawn + * @param offsetX random offset on the x axis + * @param offsetY random offset on the y axis + * @param offsetZ random offset on the z axis + * @param data data to display the particle with, only applicable on several particle types (check the enum) */ - public int getId() { - return this.id; + public void display(Location loc, int amount, double offsetX, double offsetY, double offsetZ, Object data) { + display(loc, amount, offsetX, offsetY, offsetZ, 0, data); } - + /** - * Returns the required version for this particle effect (1.x) - * - * @return The required version + * Displays the particle at the specified location with regular and extra data + * @param loc Location to spawn the particle + * @param amount how many of the particle to spawn + * @param offsetX random offset on the x axis + * @param offsetY random offset on the y axis + * @param offsetZ random offset on the z axis + * @param extra extra data to affect the particle, usually affects speed or does nothing + * @param data data to display the particle with, only applicable on several particle types (check the enum) */ - public int getRequiredVersion() { - return this.requiredVersion; - } - - /** - * Determine if additional data is required for this particle effect - * - * @return Whether additional data is required or not - */ - public boolean getRequiresData() { - return this.requiresData; - } - - /** - * Determine if water is required for this particle effect to display - * properly - * - * @return Whether water is required or not - */ - public boolean getRequiresWater() { - return this.requiresWater; - } - - /** - * Determine if this particle effect is supported by your current server - * version - * - * @return Whether the particle effect is supported or not - */ - public boolean isSupported() { - if (this.requiredVersion == -1) { - return true; - } - return ParticlePacket.getVersion() >= this.requiredVersion; - } - - /** - * Returns the particle effect with the given name - * - * @param name Name of the particle effect - * @return The particle effect - */ - public static ParticleEffect fromName(final String name) { - for (final Entry entry : NAME_MAP.entrySet()) { - if (!entry.getKey().equalsIgnoreCase(name)) { - continue; - } - return entry.getValue(); - } - return null; - } - - /** - * Returns the particle effect with the given id - * - * @param id Id of the particle effect - * @return The particle effect - */ - public static ParticleEffect fromId(final int id) { - for (final Entry entry : ID_MAP.entrySet()) { - if (entry.getKey() != id) { - continue; - } - return entry.getValue(); - } - return null; - } - - /** - * Determine if water is at a certain location - * - * @param location Location to check - * @return Whether water is at this location or not - */ - private static boolean isWater(final Location location) { - final Material material = location.getBlock().getType(); - return material == Material.WATER || material == Material.STATIONARY_WATER; - } - - /** - * Determine if the distance between @param location and one of the players - * exceeds 256 - * - * @param location Location to check - * @return Whether the distance exceeds 256 or not - */ - private static boolean isLongDistance(final Location location, final List players) { - for (final Player player : players) { - if (player.getWorld().equals(location.getWorld()) && player.getLocation().distance(location) < 256) { - continue; - } - return true; - } - return false; - } - - /** - * Displays a particle effect which is only visible for all players within a - * certain range in the world of @param center - * - * @param offsetX Maximum distance particles can fly away from the center on - * the x-axis - * @param offsetY Maximum distance particles can fly away from the center on - * the y-axis - * @param offsetZ Maximum distance particles can fly away from the center on - * the z-axis - * @param speed Display speed of the particles - * @param amount Amount of particles - * @param center Center location of the effect - * @param range Range of the visibility - * @throws ParticleVersionException If the particle effect is not supported - * by the server version - * @throws ParticleDataException If the particle effect requires additional - * data - * @throws IllegalArgumentException If the particle effect requires water - * and none is at the center location - * @see ParticlePacket - * @see ParticlePacket#sendTo(Location, double) - */ - public void display(final float offsetX, final float offsetY, final float offsetZ, final float speed, final int amount, final Location center, final double range) throws ParticleVersionException, ParticleDataException, IllegalArgumentException { - if (!this.isSupported()) { - throw new ParticleVersionException("This particle effect is not supported by your server version"); - } - if (this.requiresData) { - throw new ParticleDataException("This particle effect requires additional data"); - } - if (this.requiresWater && !isWater(center)) { - throw new IllegalArgumentException("There is no water at the center location"); - } - new ParticlePacket(this, offsetX, offsetY, offsetZ, speed, amount, range > 256, null).sendTo(center, range); - } - - /** - * Displays a particle effect which is only visible for all players within a - * certain range in the world of @param center - * - * @param offsetX Maximum distance particles can fly away from the center on - * the x-axis - * @param offsetY Maximum distance particles can fly away from the center on - * the y-axis - * @param offsetZ Maximum distance particles can fly away from the center on - * the z-axis - * @param speed Display speed of the particles - * @param amount Amount of particles - * @param center Center location of the effect - * @throws ParticleVersionException If the particle effect is not supported - * by the server version - * @throws ParticleDataException If the particle effect requires additional - * data - * @throws IllegalArgumentException If the particle effect requires water - * and none is at the center location - * @see ParticlePacket - * @see ParticlePacket#sendTo(Location, double) - */ - public void display(final Location center, final float offsetX, final float offsetY, final float offsetZ, final float speed, final int amount) { - this.display(offsetX, offsetY, offsetZ, speed, amount, center, RANGE); - } - - /** - * Displays a particle effect which is only visible for the specified - * players - * - * @param offsetX Maximum distance particles can fly away from the center on - * the x-axis - * @param offsetY Maximum distance particles can fly away from the center on - * the y-axis - * @param offsetZ Maximum distance particles can fly away from the center on - * the z-axis - * @param speed Display speed of the particles - * @param amount Amount of particles - * @param center Center location of the effect - * @param players Receivers of the effect - * @throws ParticleVersionException If the particle effect is not supported - * by the server version - * @throws ParticleDataException If the particle effect requires additional - * data - * @throws IllegalArgumentException If the particle effect requires water - * and none is at the center location - * @see ParticlePacket - * @see ParticlePacket#sendTo(Location, List) - */ - public void display(final float offsetX, final float offsetY, final float offsetZ, final float speed, final int amount, final Location center, final List players) throws ParticleVersionException, ParticleDataException, IllegalArgumentException { - if (!this.isSupported()) { - throw new ParticleVersionException("This particle effect is not supported by your server version"); - } - if (this.requiresData) { - throw new ParticleDataException("This particle effect requires additional data"); - } - if (this.requiresWater && !isWater(center)) { - throw new IllegalArgumentException("There is no water at the center location"); - } - new ParticlePacket(this, offsetX, offsetY, offsetZ, speed, amount, isLongDistance(center, players), null).sendTo(center, players); - } - - /** - * Displays a single particle which flies into a determined direction and is - * only visible for all players within a certain range in the world - * of @param center - * - * @param direction Direction of the particle - * @param speed Display speed of the particle - * @param center Center location of the effect - * @param range Range of the visibility - * @throws ParticleVersionException If the particle effect is not supported - * by the server version - * @throws ParticleDataException If the particle effect requires additional - * data - * @throws IllegalArgumentException If the particle effect requires water - * and none is at the center location - * @see ParticlePacket - * @see ParticlePacket#sendTo(Location, double) - */ - public void display(final Vector direction, final float speed, final Location center, final double range) throws ParticleVersionException, ParticleDataException, IllegalArgumentException { - if (!this.isSupported()) { - throw new ParticleVersionException("This particle effect is not supported by your server version"); - } - if (this.requiresData) { - throw new ParticleDataException("This particle effect requires additional data"); - } - if (this.requiresWater && !isWater(center)) { - throw new IllegalArgumentException("There is no water at the center location"); - } - new ParticlePacket(this, direction, speed, range > 256, null).sendTo(center, range); - } - - /** - * Displays a single particle which flies into a determined direction and is - * only visible for the specified players - * - * @param direction Direction of the particle - * @param speed Display speed of the particle - * @param center Center location of the effect - * @param players Receivers of the effect - * @throws ParticleVersionException If the particle effect is not supported - * by the server version - * @throws ParticleDataException If the particle effect requires additional - * data - * @throws IllegalArgumentException If the particle effect requires water - * and none is at the center location - * @see ParticlePacket - * @see ParticlePacket#sendTo(Location, List) - */ - public void display(final Vector direction, final float speed, final Location center, final List players) throws ParticleVersionException, ParticleDataException, IllegalArgumentException { - if (!this.isSupported()) { - throw new ParticleVersionException("This particle effect is not supported by your server version"); - } - if (this.requiresData) { - throw new ParticleDataException("This particle effect requires additional data"); - } - if (this.requiresWater && !isWater(center)) { - throw new IllegalArgumentException("There is no water at the center location"); - } - new ParticlePacket(this, direction, speed, isLongDistance(center, players), null).sendTo(center, players); - } - - /** - * Displays a particle effect which requires additional data and is only - * visible for all players within a certain range in the world of @param - * center - * - * @param data Data of the effect - * @param offsetX Maximum distance particles can fly away from the center on - * the x-axis - * @param offsetY Maximum distance particles can fly away from the center on - * the y-axis - * @param offsetZ Maximum distance particles can fly away from the center on - * the z-axis - * @param speed Display speed of the particles - * @param amount Amount of particles - * @param center Center location of the effect - * @param range Range of the visibility - * @throws ParticleVersionException If the particle effect is not supported - * by the server version - * @throws ParticleDataException If the particle effect does not require - * additional data - * @see ParticlePacket - * @see ParticlePacket#sendTo(Location, double) - */ - public void display(final ParticleData data, final float offsetX, final float offsetY, final float offsetZ, final float speed, final int amount, final Location center, final double range) throws ParticleVersionException, ParticleDataException { - if (!this.isSupported()) { - throw new ParticleVersionException("This particle effect is not supported by your server version"); - } - if (!this.requiresData) { - throw new ParticleDataException("This particle effect does not require additional data"); - } - new ParticlePacket(this, offsetX, offsetY, offsetZ, speed, amount, range > 256, data).sendTo(center, range); - } - - /** - * Displays a particle effect which requires additional data and is only - * visible for the specified players - * - * @param data Data of the effect - * @param offsetX Maximum distance particles can fly away from the center on - * the x-axis - * @param offsetY Maximum distance particles can fly away from the center on - * the y-axis - * @param offsetZ Maximum distance particles can fly away from the center on - * the z-axis - * @param speed Display speed of the particles - * @param amount Amount of particles - * @param center Center location of the effect - * @param players Receivers of the effect - * @throws ParticleVersionException If the particle effect is not supported - * by the server version - * @throws ParticleDataException If the particle effect does not require - * additional data - * @see ParticlePacket - * @see ParticlePacket#sendTo(Location, List) - */ - public void display(final ParticleData data, final float offsetX, final float offsetY, final float offsetZ, final float speed, final int amount, final Location center, final List players) throws ParticleVersionException, ParticleDataException { - if (!this.isSupported()) { - throw new ParticleVersionException("This particle effect is not supported by your server version"); - } - if (!this.requiresData) { - throw new ParticleDataException("This particle effect does not require additional data"); - } - new ParticlePacket(this, offsetX, offsetY, offsetZ, speed, amount, isLongDistance(center, players), data).sendTo(center, players); - } - - /** - * Displays a single particle which requires additional data that flies into - * a determined direction and is only visible for all players within a - * certain range in the world of @param center - * - * @param data Data of the effect - * @param direction Direction of the particle - * @param speed Display speed of the particles - * @param center Center location of the effect - * @param range Range of the visibility - * @throws ParticleVersionException If the particle effect is not supported - * by the server version - * @throws ParticleDataException If the particle effect does not require - * additional data - * @see ParticlePacket - * @see ParticlePacket#sendTo(Location, double) - */ - public void display(final ParticleData data, final Vector direction, final float speed, final Location center, final double range) throws ParticleVersionException, ParticleDataException { - if (!this.isSupported()) { - throw new ParticleVersionException("This particle effect is not supported by your server version"); - } - if (!this.requiresData) { - throw new ParticleDataException("This particle effect does not require additional data"); - } - new ParticlePacket(this, direction, speed, range > 256, data).sendTo(center, range); - } - - /** - * Displays a single particle which requires additional data that flies into - * a determined direction and is only visible for the specified players - * - * @param data Data of the effect - * @param direction Direction of the particle - * @param speed Display speed of the particles - * @param center Center location of the effect - * @param players Receivers of the effect - * @throws ParticleVersionException If the particle effect is not supported - * by the server version - * @throws ParticleDataException If the particle effect does not require - * additional data - * @see ParticlePacket - * @see ParticlePacket#sendTo(Location, List) - */ - public void display(final ParticleData data, final Vector direction, final float speed, final Location center, final List players) throws ParticleVersionException, ParticleDataException { - if (!this.isSupported()) { - throw new ParticleVersionException("This particle effect is not supported by your server version"); - } - if (!this.requiresData) { - throw new ParticleDataException("This particle effect does not require additional data"); - } - new ParticlePacket(this, direction, speed, isLongDistance(center, players), data).sendTo(center, players); - } - - /** - * Represents the particle data for effects like - * {@link ParticleEffect#ITEM_CRACK}, {@link ParticleEffect#BLOCK_CRACK} and - * {@link ParticleEffect#BLOCK_DUST} - *

- * This class is part of the ParticleEffect Library and follows the - * same usage conditions - * - * @author DarkBlade12 - * @since 1.6 - */ - public static abstract class ParticleData { - private final Material material; - private final byte data; - private int[] packetData; - - /** - * Construct a new particle data - * - * @param material Material of the item/block - * @param data Data value of the item/block - */ - public ParticleData(final Material material, final byte data) { - this.material = material; - this.data = data; - this.packetData = new int[] { material.getId(), data }; - } - - /** - * Returns the material of this data - * - * @return The material - */ - public Material getMaterial() { - return this.material; - } - - /** - * Returns the data value of this data - * - * @return The data value - */ - public byte getData() { - return this.data; - } - - /** - * Returns the data as an int array for packet construction - * - * @return The data for the packet - */ - public int[] getPacketData() { - return this.packetData; - } - - /** - * Returns the data as a string for pre 1.8 versions - * - * @return The data string for the packet - */ - public String getPacketDataString() { - return "_" + this.packetData[0] + "_" + this.packetData[1]; - } - - /** - * Sets the packet data. Should be an integer array. For ITEM_CRACK and - * BLOCK_DUST, it should be [id, meta] but for BLOCK_CRACK it should be - * [id + (meta * 4096)] - * - * @param data The packet data. - */ - public void setPacketData(final int[] data) { - this.packetData = data; - } - } - - /** - * Represents the item data for the {@link ParticleEffect#ITEM_CRACK} effect - *

- * This class is part of the ParticleEffect Library and follows the - * same usage conditions. - * - * @author DarkBlade12 - * @since 1.6 - */ - public static final class ItemData extends ParticleData { - /** - * Construct a new item data. - * - * @param material Material of the item - * @param data Data value of the item - * @see ParticleData#ParticleData(Material, byte) - */ - public ItemData(final Material material, final byte data) { - super(material, data); - } - } - - /** - * Represents the block data for the {@link ParticleEffect#BLOCK_CRACK} and - * {@link ParticleEffect#BLOCK_DUST} effects - *

- * This class is part of the ParticleEffect Library and follows the - * same usage conditions - * - * @author DarkBlade12 - * @since 1.6 - */ - public static final class BlockData extends ParticleData { - /** - * Construct a new block data - * - * @param material Material of the block - * @param data Data value of the block - * @throws IllegalArgumentException If the material is not a block - * @see ParticleData#ParticleData(Material, byte) - */ - public BlockData(final Material material, final byte data) throws IllegalArgumentException { - super(material, data); - if (!material.isBlock()) { - throw new IllegalArgumentException("The material is not a block"); - } - - this.setPacketData(new int[] { material.getId() + (data * 4096) }); - } - } - - /** - * Represents a runtime exception that is thrown if the displayed particle - * effect requires data and has none or vice-versa - *

- * This class is part of the ParticleEffect Library and follows the - * same usage conditions - * - * @author DarkBlade12 - * @since 1.6 - */ - private static final class ParticleDataException extends RuntimeException { - private static final long serialVersionUID = 3203085387160737484L; - - /** - * Construct a new particle data exception - * - * @param message Message that will be logged - * @param cause Cause of the exception - */ - public ParticleDataException(final String message) { - super(message); - } - } - - /** - * Represents a runtime exception that is thrown if the displayed particle - * effect requires a newer version - *

- * This class is part of the ParticleEffect Library and follows the - * same usage conditions - * - * @author DarkBlade12 - * @since 1.6 - */ - private static final class ParticleVersionException extends RuntimeException { - private static final long serialVersionUID = 3203085387160737484L; - - /** - * Construct a new particle version exception - * - * @param message Message that will be logged - * @param cause Cause of the exception - */ - public ParticleVersionException(final String message) { - super(message); - } - } - - /** - * Represents a particle effect packet with all attributes which is used for - * sending packets to the players - *

- * This class is part of the ParticleEffect Library and follows the - * same usage conditions - * - * @author DarkBlade12 - * @since 1.5 - */ - public static final class ParticlePacket { - private static int version; - private static Class enumParticle; - private static Constructor packetConstructor; - private static Method getHandle; - private static Field playerConnection; - private static Method sendPacket; - private static boolean initialized; - private final ParticleEffect effect; - private final float offsetX; - private final float offsetY; - private final float offsetZ; - private final float speed; - private final int amount; - private final boolean longDistance; - private final ParticleData data; - private Object packet; - - /** - * Construct a new particle packet - * - * @param effect Particle effect - * @param offsetX Maximum distance particles can fly away from the - * center on the x-axis - * @param offsetY Maximum distance particles can fly away from the - * center on the y-axis - * @param offsetZ Maximum distance particles can fly away from the - * center on the z-axis - * @param speed Display speed of the particles - * @param amount Amount of particles - * @param longDistance Indicates whether the maximum distance is - * increased from 256 to 65536 - * @param data Data of the effect - * @throws IllegalArgumentException If the speed is lower than 0 or the - * amount is lower than 1 - * @see #initialize() - */ - public ParticlePacket(final ParticleEffect effect, final float offsetX, final float offsetY, final float offsetZ, final float speed, final int amount, final boolean longDistance, final ParticleData data) throws IllegalArgumentException { - initialize(); - if (speed < 0) { - throw new IllegalArgumentException("The speed is lower than 0"); - } - this.effect = effect; - this.offsetX = offsetX; - this.offsetY = offsetY; - this.offsetZ = offsetZ; - this.speed = speed; - this.amount = amount; - this.longDistance = longDistance; - this.data = data; - } - - /** - * Construct a new particle packet of a single particle flying into a - * determined direction - * - * @param effect Particle effect - * @param direction Direction of the particle - * @param speed Display speed of the particle - * @param longDistance Indicates whether the maximum distance is - * increased from 256 to 65536 - * @param data Data of the effect - * @throws IllegalArgumentException If the speed is lower than 0 - * @see #initialize() - */ - public ParticlePacket(final ParticleEffect effect, final Vector direction, final float speed, final boolean longDistance, final ParticleData data) throws IllegalArgumentException { - initialize(); - if (speed < 0) { - throw new IllegalArgumentException("The speed is lower than 0"); - } - this.effect = effect; - this.offsetX = (float) direction.getX(); - this.offsetY = (float) direction.getY(); - this.offsetZ = (float) direction.getZ(); - this.speed = speed; - this.amount = 0; - this.longDistance = longDistance; - this.data = data; - } - - /** - * Initializes {@link #packetConstructor}, {@link #getHandle}, - * {@link #playerConnection} and {@link #sendPacket} and sets - * {@link #initialized} to true if it succeeds - *

- * Note: These fields only have to be initialized once, so it - * will return if {@link #initialized} is already set to - * true - * - * @throws VersionIncompatibleException if your bukkit version is not - * supported by this library - */ - public static void initialize() throws VersionIncompatibleException { - if (initialized) { - return; - } - try { - version = Integer.parseInt(PackageType.getServerVersion().split("_")[1]); - if (version > 7) { - enumParticle = PackageType.MINECRAFT_SERVER.getClass("EnumParticle"); - } - final Class packetClass = PackageType.MINECRAFT_SERVER.getClass(version < 7 ? "Packet63WorldParticles" : "PacketPlayOutWorldParticles"); - packetConstructor = ReflectionHandler.getConstructor(packetClass); - getHandle = ReflectionHandler.getMethod("CraftPlayer", PackageType.CRAFTBUKKIT_ENTITY, "getHandle"); - playerConnection = ReflectionHandler.getField("EntityPlayer", PackageType.MINECRAFT_SERVER, false, "playerConnection"); - sendPacket = ReflectionHandler.getMethod(playerConnection.getType(), "sendPacket", PackageType.MINECRAFT_SERVER.getClass("Packet")); - } - catch (final Exception exception) { - throw new VersionIncompatibleException("Your current bukkit version seems to be incompatible with this library", exception); - } - initialized = true; - } - - /** - * Returns the version of your server (1.x) - * - * @return The version number - */ - public static int getVersion() { - return version; - } - - /** - * Determine if {@link #packetConstructor}, {@link #getHandle}, - * {@link #playerConnection} and {@link #sendPacket} are initialized - * - * @return Whether these fields are initialized or not - * @see #initialize() - */ - public static boolean isInitialized() { - return initialized; - } - - /** - * Sends the packet to a single player and caches it - * - * @param center Center location of the effect - * @param player Receiver of the packet - * @throws PacketInstantiationException if instantion fails due to an - * unknown error - * @throws PacketSendingException if sending fails due to an unknown - * error - */ - public void sendTo(final Location center, final Player player) throws PacketInstantiationException, PacketSendingException { - if (this.packet == null) { - try { - this.packet = packetConstructor.newInstance(); - Object id; - if (version < 8) { - id = this.effect.getName(); - if (this.data != null) { - id += this.data.getPacketDataString(); - } - } else { - id = enumParticle.getEnumConstants()[this.effect.getId()]; - } - ReflectionHandler.setValue(this.packet, true, "a", id); - ReflectionHandler.setValue(this.packet, true, "b", (float) center.getX()); - ReflectionHandler.setValue(this.packet, true, "c", (float) center.getY()); - ReflectionHandler.setValue(this.packet, true, "d", (float) center.getZ()); - ReflectionHandler.setValue(this.packet, true, "e", this.offsetX); - ReflectionHandler.setValue(this.packet, true, "f", this.offsetY); - ReflectionHandler.setValue(this.packet, true, "g", this.offsetZ); - ReflectionHandler.setValue(this.packet, true, "h", this.speed); - ReflectionHandler.setValue(this.packet, true, "i", this.amount); - if (version > 7) { - ReflectionHandler.setValue(this.packet, true, "j", this.longDistance); - ReflectionHandler.setValue(this.packet, true, "k", this.data == null ? new int[0] : this.data.getPacketData()); - } - } - catch (final Exception exception) { - throw new PacketInstantiationException("Packet instantiation failed", exception); - } - } - try { - sendPacket.invoke(playerConnection.get(getHandle.invoke(player)), this.packet); - } - catch (final Exception exception) { - throw new PacketSendingException("Failed to send the packet to player '" + player.getName() + "'", exception); - } - } - - /** - * Sends the packet to all players in the list - * - * @param center Center location of the effect - * @param players Receivers of the packet - * @throws IllegalArgumentException If the player list is empty - * @see #sendTo(Location center, Player player) - */ - public void sendTo(final Location center, final List players) throws IllegalArgumentException { - if (players.isEmpty()) { - throw new IllegalArgumentException("The player list is empty"); - } - for (final Player player : players) { - this.sendTo(center, player); - } - } - - /** - * Sends the packet to all players in a certain range - * - * @param center Center location of the effect - * @param range Range in which players will receive the packet (Maximum - * range for particles is usually 16, but it can differ for - * some types) - * @throws IllegalArgumentException If the range is lower than 1 - * @see #sendTo(Location center, Player player) - */ - public void sendTo(final Location center, final double range) throws IllegalArgumentException { - if (range < 1) { - throw new IllegalArgumentException("The range is lower than 1"); - } - - final double squared = range * range; - for (final Player player : Bukkit.getOnlinePlayers()) { - if (player.getWorld() != center.getWorld() || player.getLocation().distanceSquared(center) > squared) { - continue; - } - this.sendTo(center, player); - } - } - - /** - * Represents a runtime exception that is thrown if a bukkit version is - * not compatible with this library - *

- * This class is part of the ParticleEffect Library and follows - * the same usage conditions - * - * @author DarkBlade12 - * @since 1.5 - */ - private static final class VersionIncompatibleException extends RuntimeException { - private static final long serialVersionUID = 3203085387160737484L; - - /** - * Construct a new version incompatible exception - * - * @param message Message that will be logged - * @param cause Cause of the exception - */ - public VersionIncompatibleException(final String message, final Throwable cause) { - super(message, cause); - } - } - - /** - * Represents a runtime exception that is thrown if packet instantiation - * fails - *

- * This class is part of the ParticleEffect Library and follows - * the same usage conditions - * - * @author DarkBlade12 - * @since 1.4 - */ - private static final class PacketInstantiationException extends RuntimeException { - private static final long serialVersionUID = 3203085387160737484L; - - /** - * Construct a new packet instantiation exception - * - * @param message Message that will be logged - * @param cause Cause of the exception - */ - public PacketInstantiationException(final String message, final Throwable cause) { - super(message, cause); - } - } - - /** - * Represents a runtime exception that is thrown if packet sending fails - *

- * This class is part of the ParticleEffect Library and follows - * the same usage conditions - * - * @author DarkBlade12 - * @since 1.4 - */ - private static final class PacketSendingException extends RuntimeException { - private static final long serialVersionUID = 3203085387160737484L; - - /** - * Construct a new packet sending exception - * - * @param message Message that will be logged - * @param cause Cause of the exception - */ - public PacketSendingException(final String message, final Throwable cause) { - super(message, cause); - } + public void display(Location loc, int amount, double offsetX, double offsetY, double offsetZ, double extra, Object data) { + if (dataClass.isAssignableFrom(Void.class) || data == null || !dataClass.isAssignableFrom(data.getClass())) { + display(loc, amount, offsetX, offsetY, offsetZ, extra); + } else { + loc.getWorld().spawnParticle(particle, loc, amount, offsetX, offsetY, offsetZ, extra, data, true); } } } diff --git a/src/com/projectkorra/projectkorra/util/PassiveHandler.java b/src/com/projectkorra/projectkorra/util/PassiveHandler.java index 443308a6..636ec584 100644 --- a/src/com/projectkorra/projectkorra/util/PassiveHandler.java +++ b/src/com/projectkorra/projectkorra/util/PassiveHandler.java @@ -34,7 +34,10 @@ public class PassiveHandler { } public static void checkExhaustionPassives(final Player player) { - if (!CoreAbility.getAbility(AirSaturation.class).isEnabled() && !CoreAbility.getAbility(ChiSaturation.class).isEnabled()) { + CoreAbility airsat = CoreAbility.getAbility(AirSaturation.class); + CoreAbility chisat = CoreAbility.getAbility(ChiSaturation.class); + + if ((airsat == null || !airsat.isEnabled()) && (chisat == null || !chisat.isEnabled())) { return; } @@ -55,11 +58,11 @@ public class PassiveHandler { return; } - if (!PassiveManager.hasPassive(player, CoreAbility.getAbility(AirSaturation.class))) { + if (!PassiveManager.hasPassive(player, airsat)) { air = 0; } - if (!PassiveManager.hasPassive(player, CoreAbility.getAbility(ChiSaturation.class))) { + if (!PassiveManager.hasPassive(player, chisat)) { chi = 0; } diff --git a/src/com/projectkorra/projectkorra/util/ReflectionHandler.java b/src/com/projectkorra/projectkorra/util/ReflectionHandler.java index 04f7d261..d83c87a9 100644 --- a/src/com/projectkorra/projectkorra/util/ReflectionHandler.java +++ b/src/com/projectkorra/projectkorra/util/ReflectionHandler.java @@ -30,8 +30,7 @@ import org.bukkit.Bukkit; */ public final class ReflectionHandler { // Prevent accidental construction. - private ReflectionHandler() { - } + private ReflectionHandler() {} /** * Returns the constructor of a given class with the given parameter types diff --git a/src/com/projectkorra/projectkorra/util/RevertChecker.java b/src/com/projectkorra/projectkorra/util/RevertChecker.java index d238272d..df122483 100644 --- a/src/com/projectkorra/projectkorra/util/RevertChecker.java +++ b/src/com/projectkorra/projectkorra/util/RevertChecker.java @@ -1,13 +1,13 @@ package com.projectkorra.projectkorra.util; -import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Future; -import org.bukkit.Chunk; import org.bukkit.Server; import org.bukkit.block.Block; import org.bukkit.configuration.file.FileConfiguration; @@ -17,6 +17,8 @@ import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ability.EarthAbility; import com.projectkorra.projectkorra.configuration.ConfigManager; +import io.papermc.lib.PaperLib; + public class RevertChecker implements Runnable { private final ProjectKorra plugin; @@ -34,19 +36,19 @@ public class RevertChecker implements Runnable { public static void revertAirBlocks() { for (final int ID : airRevertQueue.keySet()) { - EarthAbility.revertAirBlock(ID); + PaperLib.getChunkAtAsync(EarthAbility.getTempAirLocations().get(ID).getState().getBlock().getLocation()).thenAccept(result -> EarthAbility.revertAirBlock(ID)); RevertChecker.airRevertQueue.remove(ID); } } public static void revertEarthBlocks() { for (final Block block : earthRevertQueue.keySet()) { - EarthAbility.revertBlock(block); + PaperLib.getChunkAtAsync(block.getLocation()).thenAccept(result -> EarthAbility.revertBlock(block)); earthRevertQueue.remove(block); } } - private Future> returnFuture; + private Future>> returnFuture; private void addToAirRevertQueue(final int i) { if (!airRevertQueue.containsKey(i)) { @@ -72,50 +74,51 @@ public class RevertChecker implements Runnable { try { this.returnFuture = this.plugin.getServer().getScheduler().callSyncMethod(this.plugin, new getOccupiedChunks(this.plugin.getServer())); - final ArrayList chunks = this.returnFuture.get(); + final Set> chunks = this.returnFuture.get(); - final Map earth = new HashMap(); - earth.putAll(EarthAbility.getMovedEarth()); + final Map earth = new HashMap<>(EarthAbility.getMovedEarth()); for (final Block block : earth.keySet()) { if (earthRevertQueue.containsKey(block)) { continue; } - boolean remove = true; + final Information info = earth.get(block); - if (this.time < info.getTime() + config.getLong("Properties.Earth.RevertCheckTime") || (chunks.contains(block.getChunk()) && safeRevert)) { - remove = false; - } - if (remove) { + + final Map chunkcoord = new HashMap<>(); + chunkcoord.put("x", block.getX() >> 4); + chunkcoord.put("z", block.getZ() >> 4); + + if (this.time > (info.getTime() + config.getLong("Properties.Earth.RevertCheckTime")) && !(chunks.contains(chunkcoord) && safeRevert)) { this.addToRevertQueue(block); } } - final Map air = new HashMap(); - air.putAll(EarthAbility.getTempAirLocations()); + final Map air = new HashMap<>(EarthAbility.getTempAirLocations()); for (final Integer i : air.keySet()) { if (airRevertQueue.containsKey(i)) { continue; } - boolean remove = true; + final Information info = air.get(i); final Block block = info.getBlock(); - if (this.time < info.getTime() + config.getLong("Properties.Earth.RevertCheckTime") || (chunks.contains(block.getChunk()) && safeRevert)) { - remove = false; - } - if (remove) { + + final Map chunkcoord = new HashMap<>(); + chunkcoord.put("x", block.getX() >> 4); + chunkcoord.put("z", block.getZ() >> 4); + + if (this.time > (info.getTime() + config.getLong("Properties.Earth.RevertCheckTime")) && !(chunks.contains(chunkcoord) && safeRevert)) { this.addToAirRevertQueue(i); } } - } - catch (final Exception e) { + } catch (final Exception e) { e.printStackTrace(); } } } - private class getOccupiedChunks implements Callable> { + private class getOccupiedChunks implements Callable>> { private final Server server; public getOccupiedChunks(final Server server) { @@ -123,16 +126,17 @@ public class RevertChecker implements Runnable { } @Override - public ArrayList call() throws Exception { - - final ArrayList chunks = new ArrayList(); + public Set> call() { + final Set> chunks = new HashSet<>(); for (final Player player : this.server.getOnlinePlayers()) { - final Chunk chunk = player.getLocation().getChunk(); - if (!chunks.contains(chunk)) { - chunks.add(chunk); - } + final Map chunkcoord = new HashMap<>(); + chunkcoord.put("x", player.getLocation().getBlockX() >> 4); + chunkcoord.put("z", player.getLocation().getBlockZ() >> 4); + + chunks.add(chunkcoord); } + return chunks; } diff --git a/src/com/projectkorra/projectkorra/util/StatisticsManager.java b/src/com/projectkorra/projectkorra/util/StatisticsManager.java index b01d5840..baeb77fd 100644 --- a/src/com/projectkorra/projectkorra/util/StatisticsManager.java +++ b/src/com/projectkorra/projectkorra/util/StatisticsManager.java @@ -11,13 +11,14 @@ import java.util.UUID; import org.bukkit.entity.Player; +import com.projectkorra.projectkorra.Manager; import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ability.CoreAbility; import com.projectkorra.projectkorra.storage.DBConnection; import com.projectkorra.projectkorra.storage.MySQL; import com.projectkorra.projectkorra.storage.SQLite; -public class StatisticsManager implements Runnable { +public class StatisticsManager extends Manager implements Runnable { /** * HashMap which contains all current statistic values (Map STORAGE = new HashSet<>(); private final int INTERVAL = 5; - public StatisticsManager() { + private StatisticsManager() {} + + @Override + public void onActivate() { if (!ProjectKorra.isStatisticsEnabled()) { ProjectKorra.plugin.getServer().getScheduler().scheduleSyncRepeatingTask(ProjectKorra.plugin, this, 20 * this.INTERVAL, 20 * this.INTERVAL); } @@ -86,8 +90,7 @@ public class StatisticsManager implements Runnable { if (!rs.next()) { DBConnection.sql.modifyQuery("INSERT INTO pk_statKeys (statName) VALUES ('" + statName + "')", false); } - } - catch (final SQLException e) { + } catch (final SQLException e) { e.printStackTrace(); } } @@ -99,8 +102,7 @@ public class StatisticsManager implements Runnable { this.KEYS_BY_NAME.put(rs.getString("statName"), rs.getInt("id")); this.KEYS_BY_ID.put(rs.getInt("id"), rs.getString("statName")); } - } - catch (final SQLException e) { + } catch (final SQLException e) { e.printStackTrace(); } } @@ -113,8 +115,7 @@ public class StatisticsManager implements Runnable { this.STATISTICS.get(uuid).put(rs.getInt("statId"), rs.getLong("statValue")); this.DELTA.get(uuid).put(rs.getInt("statId"), 0L); } - } - catch (final SQLException e) { + } catch (final SQLException e) { e.printStackTrace(); } } @@ -133,8 +134,7 @@ public class StatisticsManager implements Runnable { } else { DBConnection.sql.modifyQuery("UPDATE pk_stats SET statValue = statValue + " + statValue + " WHERE uuid = '" + uuid.toString() + "' AND statId = " + statId + ";", async); } - } - catch (final SQLException e) { + } catch (final SQLException e) { e.printStackTrace(); } } @@ -157,8 +157,7 @@ public class StatisticsManager implements Runnable { if (rs.next()) { return rs.getLong("statValue"); } - } - catch (final SQLException e) { + } catch (final SQLException e) { e.printStackTrace(); } return 0; @@ -187,8 +186,7 @@ public class StatisticsManager implements Runnable { final long statValue = rs.getLong("statValue"); map.put(statId, statValue); } - } - catch (final SQLException e) { + } catch (final SQLException e) { e.printStackTrace(); } return map; diff --git a/src/com/projectkorra/projectkorra/util/StatisticsMethods.java b/src/com/projectkorra/projectkorra/util/StatisticsMethods.java index cebf7458..8e026e15 100644 --- a/src/com/projectkorra/projectkorra/util/StatisticsMethods.java +++ b/src/com/projectkorra/projectkorra/util/StatisticsMethods.java @@ -7,6 +7,7 @@ import java.util.UUID; import org.bukkit.entity.Player; import com.projectkorra.projectkorra.Element; +import com.projectkorra.projectkorra.Manager; import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ability.CoreAbility; import com.projectkorra.projectkorra.storage.DBConnection; @@ -32,7 +33,7 @@ public class StatisticsMethods { return 0; } final int statId = getId(statistic.getStatisticName(ability)); - return ProjectKorra.statistics.getStatisticCurrent(uuid, statId); + return Manager.getManager(StatisticsManager.class).getStatisticCurrent(uuid, statId); } /** @@ -52,7 +53,7 @@ public class StatisticsMethods { return; } final int statId = getId(statistic.getStatisticName(ability)); - ProjectKorra.statistics.addStatistic(uuid, statId, statDelta); + Manager.getManager(StatisticsManager.class).addStatistic(uuid, statId, statDelta); } /** @@ -73,7 +74,7 @@ public class StatisticsMethods { return 0; } long totalValue = 0; - for (final int statId : ProjectKorra.statistics.getStatisticsMap(uuid).keySet()) { + for (final int statId : Manager.getManager(StatisticsManager.class).getStatisticsMap(uuid).keySet()) { final String abilName = getAbilityName(statId); final CoreAbility ability = CoreAbility.getAbility(abilName); if (ability == null) { @@ -107,7 +108,7 @@ public class StatisticsMethods { return 0; } long totalValue = 0; - for (final int statId : ProjectKorra.statistics.getStatisticsMap(uuid).keySet()) { + for (final int statId : Manager.getManager(StatisticsManager.class).getStatisticsMap(uuid).keySet()) { final String abilName = getAbilityName(statId); final CoreAbility ability = CoreAbility.getAbility(abilName); if (ability == null) { @@ -169,19 +170,18 @@ public class StatisticsMethods { if (!ProjectKorra.isStatisticsEnabled()) { return 0; } - if (!ProjectKorra.statistics.getKeysByName().containsKey(statName)) { + if (!Manager.getManager(StatisticsManager.class).getKeysByName().containsKey(statName)) { DBConnection.sql.modifyQuery("INSERT INTO pk_statKeys (statName) VALUES ('" + statName + "')", false); try (ResultSet rs = DBConnection.sql.readQuery("SELECT * FROM pk_statKeys WHERE statName = '" + statName + "'")) { if (rs.next()) { - ProjectKorra.statistics.getKeysByName().put(rs.getString("statName"), rs.getInt("id")); - ProjectKorra.statistics.getKeysById().put(rs.getInt("id"), rs.getString("statName")); + Manager.getManager(StatisticsManager.class).getKeysByName().put(rs.getString("statName"), rs.getInt("id")); + Manager.getManager(StatisticsManager.class).getKeysById().put(rs.getInt("id"), rs.getString("statName")); } - } - catch (final SQLException e) { + } catch (final SQLException e) { e.printStackTrace(); } } - return ProjectKorra.statistics.getKeysByName().containsKey(statName) ? ProjectKorra.statistics.getKeysByName().get(statName) : -1; + return Manager.getManager(StatisticsManager.class).getKeysByName().containsKey(statName) ? Manager.getManager(StatisticsManager.class).getKeysByName().get(statName) : -1; } /** @@ -196,10 +196,10 @@ public class StatisticsMethods { if (!ProjectKorra.isStatisticsEnabled()) { return ""; } - if (!ProjectKorra.statistics.getKeysById().containsKey(id)) { + if (!Manager.getManager(StatisticsManager.class).getKeysById().containsKey(id)) { return ""; } - final String statName = ProjectKorra.statistics.getKeysById().get(id); + final String statName = Manager.getManager(StatisticsManager.class).getKeysById().get(id); final String[] split = statName.split("_"); if (split.length < 2) { return ""; diff --git a/src/com/projectkorra/projectkorra/util/TempArmor.java b/src/com/projectkorra/projectkorra/util/TempArmor.java index c192e064..beae12cb 100644 --- a/src/com/projectkorra/projectkorra/util/TempArmor.java +++ b/src/com/projectkorra/projectkorra/util/TempArmor.java @@ -2,13 +2,15 @@ package com.projectkorra.projectkorra.util; import java.util.ArrayList; import java.util.Collections; -import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.PriorityQueue; import java.util.concurrent.ConcurrentHashMap; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + import org.bukkit.Material; import org.bukkit.entity.LivingEntity; import org.bukkit.inventory.ItemStack; @@ -86,16 +88,11 @@ public class TempArmor { if (!INSTANCES.containsKey(entity)) { ORIGINAL.put(entity, this.oldArmor); - final PriorityQueue queue = new PriorityQueue<>(10, new Comparator() { - - @Override - public int compare(final TempArmor a, final TempArmor b) { - final long current = System.currentTimeMillis(); - final long remainingA = a.getStartTime() + a.getDuration() - current; - final long remainingB = b.getStartTime() + b.getDuration() - current; - return (int) (remainingA - remainingB); - } - + final PriorityQueue queue = new PriorityQueue<>(10, (a, b) -> { + final long current = System.currentTimeMillis(); + final long remainingA = a.getStartTime() + a.getDuration() - current; + final long remainingB = b.getStartTime() + b.getDuration() - current; + return (int) (remainingA - remainingB); }); INSTANCES.put(entity, queue); @@ -118,7 +115,7 @@ public class TempArmor { for (final ItemStack drop : drops) { boolean match = false; for (final ItemStack armorPiece : this.newArmor) { - if (armorPiece.isSimilar(drop)) { + if (armorPiece != null && armorPiece.isSimilar(drop)) { match = true; break; } @@ -208,10 +205,6 @@ public class TempArmor { * TempArmor instance was started, if the display queue is empty. */ public void revert() { - if (this.removeAbilOnForceRevert && this.ability != null && !this.ability.isRemoved()) { - this.ability.remove(); - } - final PriorityQueue queue = INSTANCES.get(this.entity); if (queue.contains(this)) { @@ -231,6 +224,10 @@ public class TempArmor { INSTANCES.remove(this.entity); ORIGINAL.remove(this.entity); } + + if (this.removeAbilOnForceRevert && this.ability != null && !this.ability.isRemoved()) { + this.ability.remove(); + } } public static void cleanup() { @@ -290,4 +287,9 @@ public class TempArmor { } return new ArrayList<>(INSTANCES.get(entity)); } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); + } } diff --git a/src/com/projectkorra/projectkorra/util/TempArmorStand.java b/src/com/projectkorra/projectkorra/util/TempArmorStand.java index 8b433725..516e682f 100644 --- a/src/com/projectkorra/projectkorra/util/TempArmorStand.java +++ b/src/com/projectkorra/projectkorra/util/TempArmorStand.java @@ -11,7 +11,7 @@ import com.projectkorra.projectkorra.ProjectKorra; /** * Object to represent an ArmorStand that is not used for normal functionality - * + * * @author Simplicitee * */ diff --git a/src/com/projectkorra/projectkorra/util/TempBlock.java b/src/com/projectkorra/projectkorra/util/TempBlock.java index 2b838e61..077c31f6 100644 --- a/src/com/projectkorra/projectkorra/util/TempBlock.java +++ b/src/com/projectkorra/projectkorra/util/TempBlock.java @@ -10,15 +10,19 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; +import org.bukkit.block.Container; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Levelled; import org.bukkit.scheduler.BukkitRunnable; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ProjectKorra; -public class TempBlock { +import io.papermc.lib.PaperLib; +public class TempBlock { public static Map instances = new ConcurrentHashMap(); - public static final PriorityQueue REVERT_QUEUE = new PriorityQueue<>(100, new Comparator() { + public static final PriorityQueue REVERT_QUEUE = new PriorityQueue(100, new Comparator() { @Override public int compare(final TempBlock t1, final TempBlock t2) { return (int) (t1.revertTime - t2.revertTime); @@ -26,31 +30,39 @@ public class TempBlock { }); private final Block block; - private byte newdata; + private BlockData newdata; private BlockState state; private long revertTime; private boolean inRevertQueue; private RevertTask revertTask = null; - public TempBlock(final Block block, final Material newtype, final byte newdata) { + public TempBlock(final Block block, final Material newtype) { + this(block, newtype.createBlockData()); + } + + @Deprecated + public TempBlock(final Block block, final Material newtype, final BlockData newdata) { + this(block, newdata); + } + + public TempBlock(final Block block, final BlockData newdata) { this.block = block; this.newdata = newdata; if (instances.containsKey(block)) { final TempBlock temp = instances.get(block); - if (newtype != temp.block.getType()) { - temp.block.setType(newtype); - } - if (newdata != temp.block.getData()) { - temp.block.setData(newdata); + if (!newdata.equals(temp.block.getBlockData())) { + temp.block.setBlockData(newdata, GeneralMethods.isLightEmitting(newdata.getMaterial())); temp.newdata = newdata; } this.state = temp.state; instances.put(block, temp); } else { this.state = block.getState(); + if (this.state instanceof Container || this.state.getType() == Material.JUKEBOX) { + return; + } instances.put(block, this); - block.setType(newtype); - block.setData(newdata); + block.setBlockData(newdata, GeneralMethods.isLightEmitting(newdata.getMaterial())); } if (this.state.getType() == Material.FIRE) { this.state.setType(Material.AIR); @@ -65,7 +77,7 @@ public class TempBlock { } public static boolean isTempBlock(final Block block) { - return block != null ? instances.containsKey(block) : false; + return block != null && instances.containsKey(block); } public static boolean isTouchingTempBlock(final Block block) { @@ -83,11 +95,16 @@ public class TempBlock { revertBlock(block, Material.AIR); } for (final TempBlock tempblock : REVERT_QUEUE) { - tempblock.revertBlock(); + tempblock.state.update(true, GeneralMethods.isLightEmitting(tempblock.state.getType())); + if (tempblock.revertTask != null) { + tempblock.revertTask.run(); + } } + REVERT_QUEUE.clear(); } public static void removeBlock(final Block block) { + REVERT_QUEUE.remove(instances.get(block)); instances.remove(block); } @@ -95,14 +112,24 @@ public class TempBlock { if (instances.containsKey(block)) { instances.get(block).revertBlock(); } else { - if ((defaulttype == Material.LAVA || defaulttype == Material.STATIONARY_LAVA) && GeneralMethods.isAdjacentToThreeOrMoreSources(block)) { - block.setType(Material.LAVA); - block.setData((byte) 0x0); - } else if ((defaulttype == Material.WATER || defaulttype == Material.STATIONARY_WATER) && GeneralMethods.isAdjacentToThreeOrMoreSources(block)) { - block.setType(Material.WATER); - block.setData((byte) 0x0); + if ((defaulttype == Material.LAVA) && GeneralMethods.isAdjacentToThreeOrMoreSources(block, true)) { + final BlockData data = Material.LAVA.createBlockData(); + + if (data instanceof Levelled) { + ((Levelled) data).setLevel(0); + } + + block.setBlockData(data, GeneralMethods.isLightEmitting(data.getMaterial())); + } else if ((defaulttype == Material.WATER) && GeneralMethods.isAdjacentToThreeOrMoreSources(block)) { + final BlockData data = Material.WATER.createBlockData(); + + if (data instanceof Levelled) { + ((Levelled) data).setLevel(0); + } + + block.setBlockData(data, GeneralMethods.isLightEmitting(data.getMaterial())); } else { - block.setType(defaulttype); + block.setType(defaulttype, GeneralMethods.isLightEmitting(defaulttype)); } } } @@ -111,6 +138,10 @@ public class TempBlock { return this.block; } + public BlockData getBlockData() { + return this.newdata; + } + public Location getLocation() { return this.block.getLocation(); } @@ -141,11 +172,9 @@ public class TempBlock { } public void revertBlock() { - this.state.update(true); + PaperLib.getChunkAtAsync(this.block.getLocation()).thenAccept(result -> this.state.update(true, GeneralMethods.isLightEmitting(this.state.getType()))); instances.remove(this.block); - if (REVERT_QUEUE.contains(this)) { - REVERT_QUEUE.remove(this); - } + REVERT_QUEUE.remove(this); if (this.revertTask != null) { this.revertTask.run(); } @@ -156,13 +185,17 @@ public class TempBlock { } public void setType(final Material material) { - this.setType(material, this.newdata); + this.setType(material.createBlockData()); } - public void setType(final Material material, final byte data) { + @Deprecated + public void setType(final Material material, final BlockData data) { + this.setType(data); + } + + public void setType(final BlockData data) { this.newdata = data; - this.block.setType(material); - this.block.setData(data); + this.block.setBlockData(data, GeneralMethods.isLightEmitting(data.getMaterial())); } public static void startReversion() { diff --git a/src/com/projectkorra/projectkorra/util/Updater.java b/src/com/projectkorra/projectkorra/util/Updater.java index 73a6e4b0..a6b1525f 100644 --- a/src/com/projectkorra/projectkorra/util/Updater.java +++ b/src/com/projectkorra/projectkorra/util/Updater.java @@ -71,12 +71,10 @@ public class Updater { break; } } - } - catch (final IOException e) { + } catch (final IOException e) { e.printStackTrace(); } - } - catch (final IOException e) { + } catch (final IOException e) { plugin.getLogger().info("Could not connect to projectkorra.com"); } this.checkUpdate(); diff --git a/src/com/projectkorra/projectkorra/util/logging/LogFilter.java b/src/com/projectkorra/projectkorra/util/logging/LogFilter.java index 2192e04e..740e672c 100644 --- a/src/com/projectkorra/projectkorra/util/logging/LogFilter.java +++ b/src/com/projectkorra/projectkorra/util/logging/LogFilter.java @@ -64,12 +64,7 @@ public class LogFilter implements Filter { } final String toRecord = recordString; - Bukkit.getScheduler().runTaskLater(ProjectKorra.plugin, new Runnable() { - @Override - public void run() { - LogFilter.this.loggedRecords.add(toRecord); - } - }, 10); + Bukkit.getScheduler().runTaskLater(ProjectKorra.plugin, (Runnable) () -> LogFilter.this.loggedRecords.add(toRecord), 10); return true; } diff --git a/src/com/projectkorra/projectkorra/waterbending/OctopusForm.java b/src/com/projectkorra/projectkorra/waterbending/OctopusForm.java index d3a5f271..99f0ff26 100644 --- a/src/com/projectkorra/projectkorra/waterbending/OctopusForm.java +++ b/src/com/projectkorra/projectkorra/waterbending/OctopusForm.java @@ -17,6 +17,7 @@ import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ability.AirAbility; import com.projectkorra.projectkorra.ability.WaterAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.avatar.AvatarState; import com.projectkorra.projectkorra.util.BlockSource; import com.projectkorra.projectkorra.util.ClickType; @@ -30,13 +31,13 @@ import com.projectkorra.projectkorra.waterbending.util.WaterReturn; public class OctopusForm extends WaterAbility { - private static final byte FULL = 8; - private boolean sourceSelected; private boolean settingUp; private boolean forming; private boolean formed; + @Attribute(Attribute.RANGE) private int range; + @Attribute(Attribute.DAMAGE) private int damage; private int currentAnimationStep; private int stepCounter; @@ -44,11 +45,17 @@ public class OctopusForm extends WaterAbility { private long time; private long startTime; private long interval; + @Attribute(Attribute.COOLDOWN) private long cooldown; + @Attribute(Attribute.DURATION) private long duration; + @Attribute("Attack" + Attribute.RANGE) private double attackRange; + @Attribute("Usage" + Attribute.COOLDOWN) private long usageCooldown; + @Attribute(Attribute.KNOCKBACK) private double knockback; + @Attribute(Attribute.RADIUS) private double radius; private double startAngle; private double angle; @@ -150,7 +157,7 @@ public class OctopusForm extends WaterAbility { if (isTransparent(player, block) && isTransparent(player, eyeLoc.getBlock())) { block.setType(Material.WATER); - block.setData(FULL); + block.setBlockData(GeneralMethods.getWaterData(0)); final OctopusForm form = new OctopusForm(player); form.setSourceBlock(block); form.form(); @@ -172,7 +179,7 @@ public class OctopusForm extends WaterAbility { } else if (!GeneralMethods.isAdjacentToThreeOrMoreSources(this.sourceBlock) && this.sourceBlock != null) { this.sourceBlock.setType(Material.AIR); } - this.source = new TempBlock(this.sourceBlock, Material.STATIONARY_WATER, (byte) 8); + this.source = new TempBlock(this.sourceBlock, Material.WATER, GeneralMethods.getWaterData(0)); } private void attack() { @@ -246,7 +253,7 @@ public class OctopusForm extends WaterAbility { this.sourceLocation = newBlock.getLocation(); if (!GeneralMethods.isSolid(newBlock)) { - this.source = new TempBlock(newBlock, Material.STATIONARY_WATER, (byte) 8); + this.source = new TempBlock(newBlock, Material.WATER, GeneralMethods.getWaterData(0)); this.sourceBlock = newBlock; } else { this.remove(); @@ -259,7 +266,7 @@ public class OctopusForm extends WaterAbility { this.sourceLocation = newBlock.getLocation(); if (!GeneralMethods.isSolid(newBlock)) { - this.source = new TempBlock(newBlock, Material.STATIONARY_WATER, (byte) 8); + this.source = new TempBlock(newBlock, Material.WATER, GeneralMethods.getWaterData(0)); this.sourceBlock = newBlock; } else { this.remove(); @@ -275,7 +282,7 @@ public class OctopusForm extends WaterAbility { this.source.revertBlock(); } if (!GeneralMethods.isSolid(newBlock)) { - this.source = new TempBlock(newBlock, Material.STATIONARY_WATER, (byte) 8); + this.source = new TempBlock(newBlock, Material.WATER, GeneralMethods.getWaterData(0)); this.sourceBlock = newBlock; } } @@ -419,16 +426,16 @@ public class OctopusForm extends WaterAbility { if (!SurgeWave.canThaw(block)) { SurgeWave.thaw(block); } - tblock.setType(Material.STATIONARY_WATER, (byte) 8); + tblock.setType(Material.WATER, GeneralMethods.getWaterData(0)); this.newBlocks.add(tblock); } else if (this.blocks.contains(tblock)) { this.newBlocks.add(tblock); } - } else if (this.isWaterbendable(this.player, block) || block.getType() == Material.FIRE || block.getType() == Material.AIR) { + } else if (this.isWaterbendable(this.player, block) || block.getType() == Material.FIRE || isAir(block.getType())) { if (isWater(block) && !TempBlock.isTempBlock(block)) { - ParticleEffect.WATER_BUBBLE.display((float) Math.random(), (float) Math.random(), (float) Math.random(), 0f, 5, block.getLocation().clone().add(0.5, 0.5, 0.5), 255.0); + ParticleEffect.WATER_BUBBLE.display(block.getLocation().clone().add(0.5, 0.5, 0.5), 5, Math.random(), Math.random(), Math.random(), 0); } - this.newBlocks.add(new TempBlock(block, Material.STATIONARY_WATER, (byte) 8)); + this.newBlocks.add(new TempBlock(block, Material.WATER, GeneralMethods.getWaterData(0))); } } diff --git a/src/com/projectkorra/projectkorra/waterbending/SurgeWall.java b/src/com/projectkorra/projectkorra/waterbending/SurgeWall.java index 63531cee..9f6fead2 100644 --- a/src/com/projectkorra/projectkorra/waterbending/SurgeWall.java +++ b/src/com/projectkorra/projectkorra/waterbending/SurgeWall.java @@ -8,7 +8,6 @@ import java.util.Map; import java.util.Random; import java.util.concurrent.ConcurrentHashMap; -import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -17,10 +16,13 @@ import org.bukkit.util.Vector; import com.projectkorra.projectkorra.BendingPlayer; import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.ability.ElementalAbility; import com.projectkorra.projectkorra.ability.WaterAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.firebending.FireBlast; import com.projectkorra.projectkorra.util.BlockSource; import com.projectkorra.projectkorra.util.ClickType; +import com.projectkorra.projectkorra.util.ParticleEffect; import com.projectkorra.projectkorra.util.TempBlock; import com.projectkorra.projectkorra.waterbending.plant.PlantRegrowth; import com.projectkorra.projectkorra.waterbending.util.WaterReturn; @@ -38,9 +40,13 @@ public class SurgeWall extends WaterAbility { private boolean frozen; private long time; private long interval; + @Attribute(Attribute.COOLDOWN) private long cooldown; + @Attribute(Attribute.DURATION) private long duration; + @Attribute(Attribute.RADIUS) private double radius; + @Attribute(Attribute.RANGE) private double range; private Block sourceBlock; private Location location; @@ -95,7 +101,7 @@ public class SurgeWall extends WaterAbility { final Block block = eyeLoc.add(eyeLoc.getDirection().normalize()).getBlock(); if (isTransparent(player, block) && isTransparent(player, eyeLoc.getBlock())) { - final TempBlock tempBlock = new TempBlock(block, Material.STATIONARY_WATER, (byte) 0); + final TempBlock tempBlock = new TempBlock(block, Material.WATER, GeneralMethods.getWaterData(0)); SOURCE_BLOCKS.add(tempBlock); wave = new SurgeWave(player); @@ -128,7 +134,7 @@ public class SurgeWall extends WaterAbility { this.frozen = true; for (final Block block : WALL_BLOCKS.keySet()) { if (WALL_BLOCKS.get(block) == this.player) { - new TempBlock(block, Material.ICE, (byte) 0); + new TempBlock(block, Material.ICE); playIcebendingSound(block.getLocation()); } } @@ -138,7 +144,7 @@ public class SurgeWall extends WaterAbility { this.frozen = false; for (final Block block : WALL_BLOCKS.keySet()) { if (WALL_BLOCKS.get(block) == this.player) { - new TempBlock(block, Material.STATIONARY_WATER, (byte) 8); + new TempBlock(block, Material.WATER, GeneralMethods.getWaterData(0)); } } } @@ -187,7 +193,7 @@ public class SurgeWall extends WaterAbility { if (isPlant(this.sourceBlock) || isSnow(this.sourceBlock)) { new PlantRegrowth(this.player, this.sourceBlock); - this.sourceBlock.setType(Material.AIR); + this.sourceBlock.setType(Material.AIR, false); } this.addWater(this.sourceBlock); } @@ -239,7 +245,7 @@ public class SurgeWall extends WaterAbility { this.remove(); return; } else if (!this.progressing) { - this.sourceBlock.getWorld().playEffect(this.location, Effect.SMOKE, 4, (int) this.range); + ParticleEffect.SMOKE_NORMAL.display(this.sourceBlock.getLocation().add(0.5, 0.5, 0.5), 1); return; } @@ -249,12 +255,11 @@ public class SurgeWall extends WaterAbility { } final ArrayList blocks = new ArrayList(); - final Location targetLoc = GeneralMethods.getTargetedLocation(this.player, (int) this.range, Material.WATER, Material.STATIONARY_WATER, Material.ICE); + final Location targetLoc = GeneralMethods.getTargetedLocation(this.player, (int) this.range, false, false, Material.WATER, Material.ICE); this.location = targetLoc.clone(); final Vector eyeDir = this.player.getEyeLocation().getDirection(); Vector vector; Block block; - for (double i = 0; i <= this.getNightFactor(this.radius); i += 0.5) { for (double angle = 0; angle < 360; angle += 10) { vector = GeneralMethods.getOrthogonalVector(eyeDir.clone(), angle, i); @@ -264,7 +269,7 @@ public class SurgeWall extends WaterAbility { continue; } else if (WALL_BLOCKS.containsKey(block)) { blocks.add(block); - } else if (!blocks.contains(block) && (block.getType() == Material.AIR || block.getType() == Material.FIRE || this.isWaterbendable(block)) && this.isTransparent(block)) { + } else if (!blocks.contains(block) && (ElementalAbility.isAir(block.getType()) || block.getType() == Material.FIRE || this.isWaterbendable(block)) && this.isTransparent(block)) { WALL_BLOCKS.put(block, this.player); this.addWallBlock(block); blocks.add(block); @@ -301,7 +306,7 @@ public class SurgeWall extends WaterAbility { block = this.location.getBlock(); } - if (block.getType() != Material.AIR) { + if (!ElementalAbility.isAir(block.getType())) { this.remove(); return; } else if (!this.progressing) { @@ -326,9 +331,9 @@ public class SurgeWall extends WaterAbility { } if (this.frozen) { - new TempBlock(block, Material.ICE, (byte) 0); + new TempBlock(block, Material.ICE); } else { - new TempBlock(block, Material.STATIONARY_WATER, (byte) 8); + new TempBlock(block, Material.WATER, GeneralMethods.getWaterData(0)); } } @@ -352,7 +357,9 @@ public class SurgeWall extends WaterAbility { if (!GeneralMethods.isAdjacentToThreeOrMoreSources(block)) { if (this.oldTemps.containsKey(block)) { final TempBlock tb = TempBlock.get(block); - tb.setType(this.oldTemps.get(block)); + if (tb != null) { + tb.setType(this.oldTemps.get(block)); + } } else { TempBlock.revertBlock(block, Material.AIR); } @@ -367,7 +374,9 @@ public class SurgeWall extends WaterAbility { if (AFFECTED_BLOCKS.containsKey(block)) { if (this.oldTemps.containsKey(block)) { final TempBlock tb = TempBlock.get(block); - tb.setType(this.oldTemps.get(block)); + if (tb != null) { + tb.setType(this.oldTemps.get(block)); + } } else { TempBlock.revertBlock(block, Material.AIR); } @@ -376,7 +385,9 @@ public class SurgeWall extends WaterAbility { if (WALL_BLOCKS.containsKey(block)) { if (this.oldTemps.containsKey(block)) { final TempBlock tb = TempBlock.get(block); - tb.setType(this.oldTemps.get(block)); + if (tb != null) { + tb.setType(this.oldTemps.get(block)); + } } else { TempBlock.revertBlock(block, Material.AIR); } @@ -389,7 +400,7 @@ public class SurgeWall extends WaterAbility { if (GeneralMethods.isRegionProtectedFromBuild(this, block.getLocation())) { return; } else if (!TempBlock.isTempBlock(block)) { - new TempBlock(block, Material.STATIONARY_WATER, (byte) 8); + new TempBlock(block, Material.WATER, GeneralMethods.getWaterData(0)); AFFECTED_BLOCKS.put(block, block); } } @@ -431,7 +442,7 @@ public class SurgeWall extends WaterAbility { final Block block = eyeLoc.add(eyeLoc.getDirection().normalize()).getBlock(); if (isTransparent(player, block) && isTransparent(player, eyeLoc.getBlock())) { - final TempBlock tempBlock = new TempBlock(block, Material.STATIONARY_WATER, (byte) 0); + final TempBlock tempBlock = new TempBlock(block, Material.WATER, GeneralMethods.getWaterData(0)); SOURCE_BLOCKS.add(tempBlock); wall = new SurgeWall(player); @@ -496,7 +507,7 @@ public class SurgeWall extends WaterAbility { private void returnWater() { if (this.location != null) { if (this.frozen) { - this.location.getBlock().setType(Material.WATER); + this.thaw(); } new WaterReturn(this.player, this.location.getBlock()); } diff --git a/src/com/projectkorra/projectkorra/waterbending/SurgeWave.java b/src/com/projectkorra/projectkorra/waterbending/SurgeWave.java index f5de04c5..90611298 100644 --- a/src/com/projectkorra/projectkorra/waterbending/SurgeWave.java +++ b/src/com/projectkorra/projectkorra/waterbending/SurgeWave.java @@ -17,13 +17,16 @@ import org.bukkit.util.Vector; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.AirAbility; +import com.projectkorra.projectkorra.ability.ElementalAbility; import com.projectkorra.projectkorra.ability.WaterAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.avatar.AvatarState; +import com.projectkorra.projectkorra.command.Commands; import com.projectkorra.projectkorra.firebending.FireBlast; import com.projectkorra.projectkorra.util.BlockSource; import com.projectkorra.projectkorra.util.ClickType; +import com.projectkorra.projectkorra.util.ParticleEffect; import com.projectkorra.projectkorra.util.TempBlock; -import com.projectkorra.projectkorra.util.TempBlock.RevertTask; import com.projectkorra.projectkorra.waterbending.plant.PlantRegrowth; import com.projectkorra.projectkorra.waterbending.util.WaterReturn; @@ -34,15 +37,23 @@ public class SurgeWave extends WaterAbility { private boolean progressing; private boolean canHitSelf; private long time; + @Attribute(Attribute.COOLDOWN) private long cooldown; private long interval; + @Attribute("IceRevertTime") private long iceRevertTime; private double currentRadius; + @Attribute(Attribute.RADIUS) private double maxRadius; + @Attribute(Attribute.RANGE) private double range; + @Attribute(Attribute.SELECT_RANGE) private double selectRange; - private double pushFactor; - private double verticalFactor; + @Attribute(Attribute.KNOCKBACK) + private double knockback; + @Attribute(Attribute.KNOCKUP) + private double knockup; + @Attribute("Freeze" + Attribute.RADIUS) private double maxFreezeRadius; private Block sourceBlock; private Location location; @@ -68,8 +79,8 @@ public class SurgeWave extends WaterAbility { this.cooldown = getConfig().getLong("Abilities.Water.Surge.Wave.Cooldown"); this.interval = getConfig().getLong("Abilities.Water.Surge.Wave.Interval"); this.maxRadius = getConfig().getDouble("Abilities.Water.Surge.Wave.Radius"); - this.pushFactor = getConfig().getDouble("Abilities.Water.Surge.Wave.HorizontalPush"); - this.verticalFactor = getConfig().getDouble("Abilities.Water.Surge.Wave.VerticalPush"); + this.knockback = getConfig().getDouble("Abilities.Water.Surge.Wave.Knockback"); + this.knockup = getConfig().getDouble("Abilities.Water.Surge.Wave.Knockup"); this.maxFreezeRadius = getConfig().getDouble("Abilities.Water.Surge.Wave.MaxFreezeRadius"); this.iceRevertTime = getConfig().getLong("Abilities.Water.Surge.Wave.IceRevertTime"); this.range = getConfig().getDouble("Abilities.Water.Surge.Wave.Range"); @@ -96,7 +107,7 @@ public class SurgeWave extends WaterAbility { if (GeneralMethods.isRegionProtectedFromBuild(this, block.getLocation())) { return; } else if (!TempBlock.isTempBlock(block)) { - new TempBlock(block, Material.STATIONARY_WATER, (byte) 8); + new TempBlock(block, Material.WATER, GeneralMethods.getWaterData(0)); this.waveBlocks.put(block, block); } } @@ -136,35 +147,42 @@ public class SurgeWave extends WaterAbility { if (freezeradius > this.maxFreezeRadius) { freezeradius = this.maxFreezeRadius; } - - for (final Block block : GeneralMethods.getBlocksAroundPoint(this.frozenLocation, freezeradius)) { - if (GeneralMethods.isRegionProtectedFromBuild(this, block.getLocation()) || GeneralMethods.isRegionProtectedFromBuild(this.player, "PhaseChange", block.getLocation())) { + final List trapped = GeneralMethods.getEntitiesAroundPoint(this.frozenLocation, freezeradius); + ICE_SETTING: for (final Block block : GeneralMethods.getBlocksAroundPoint(this.frozenLocation, freezeradius)) { + if (GeneralMethods.isRegionProtectedFromBuild(this, block.getLocation())) { continue; } else if (TempBlock.isTempBlock(block)) { continue; } - final Block oldBlock = block; - final TempBlock tblock = new TempBlock(block, block.getType(), (byte) 0); - if (block.getType() == Material.AIR || block.getType() == Material.SNOW || isWater(block)) { - tblock.setType(Material.ICE); - } else if (isPlant(block) && block.getType() != Material.LEAVES) { - block.breakNaturally(); - tblock.setType(Material.ICE); - } else { - tblock.revertBlock(); - continue; - } - tblock.setRevertTask(new RevertTask() { - - @Override - public void run() { - SurgeWave.this.frozenBlocks.remove(block); + for (final Entity entity : trapped) { + if (entity instanceof Player) { + if (Commands.invincible.contains(((Player) entity).getName())) { + return; + } + if (!getConfig().getBoolean("Properties.Water.FreezePlayerHead") && GeneralMethods.playerHeadIsInBlock((Player) entity, block)) { + continue ICE_SETTING; + } + if (!getConfig().getBoolean("Properties.Water.FreezePlayerFeet") && GeneralMethods.playerFeetIsInBlock((Player) entity, block)) { + continue ICE_SETTING; + } } + } + + final Block oldBlock = block; + if (!ElementalAbility.isAir(block.getType()) && block.getType() != Material.SNOW && !isWater(block) && !isPlant(block)) { + continue; + } else if (isPlant(block)) { + block.breakNaturally(); + } + + final TempBlock tblock = new TempBlock(block, Material.ICE); + + tblock.setRevertTask(() -> SurgeWave.this.frozenBlocks.remove(block)); - }); tblock.setRevertTime(this.iceRevertTime + (new Random().nextInt(1000))); this.frozenBlocks.put(block, oldBlock.getType()); + for (final Block sound : this.frozenBlocks.keySet()) { if ((new Random()).nextInt(4) == 0) { playWaterbendingSound(sound.getLocation()); @@ -201,7 +219,7 @@ public class SurgeWave extends WaterAbility { this.range = this.getNightFactor(this.range); if (this.bPlayer.isAvatarState()) { - this.pushFactor = AvatarState.getValue(this.pushFactor); + this.knockback = AvatarState.getValue(this.knockback); } final Entity target = GeneralMethods.getTargetedEntity(this.player, this.range); @@ -221,7 +239,14 @@ public class SurgeWave extends WaterAbility { if (isPlant(this.sourceBlock) || isSnow(this.sourceBlock)) { new PlantRegrowth(this.player, this.sourceBlock); - this.sourceBlock.setType(Material.AIR); + this.sourceBlock.setType(Material.AIR, false); + } + + if (TempBlock.isTempBlock(this.sourceBlock)) { + final TempBlock tb = TempBlock.get(this.sourceBlock); + if (Torrent.getFrozenBlocks().containsKey(tb)) { + Torrent.massThaw(tb); + } } this.addWater(this.sourceBlock); } @@ -252,7 +277,7 @@ public class SurgeWave extends WaterAbility { this.remove(); return; } else if (!this.progressing) { - this.sourceBlock.getWorld().playEffect(this.location, Effect.SMOKE, 4, (int) this.range); + ParticleEffect.SMOKE_NORMAL.display(this.sourceBlock.getLocation().add(0.5, 0.5, 0.5), 4); return; } @@ -268,13 +293,13 @@ public class SurgeWave extends WaterAbility { final Block blockl = this.location.getBlock(); final ArrayList blocks = new ArrayList(); - if (!GeneralMethods.isRegionProtectedFromBuild(this, this.location) && (((blockl.getType() == Material.AIR || blockl.getType() == Material.FIRE || isPlant(blockl) || isWater(blockl) || this.isWaterbendable(this.player, blockl))) && blockl.getType() != Material.LEAVES)) { + if (!GeneralMethods.isRegionProtectedFromBuild(this, this.location) && (((ElementalAbility.isAir(blockl.getType()) || blockl.getType() == Material.FIRE || isPlant(blockl) || isWater(blockl) || this.isWaterbendable(this.player, blockl))))) { for (double i = 0; i <= this.currentRadius; i += .5) { for (double angle = 0; angle < 360; angle += 10) { final Vector vec = GeneralMethods.getOrthogonalVector(this.targetDirection, angle, i); final Block block = this.location.clone().add(vec).getBlock(); - if (!blocks.contains(block) && (block.getType() == Material.AIR || block.getType() == Material.FIRE) || this.isWaterbendable(block)) { + if (!blocks.contains(block) && (ElementalAbility.isAir(block.getType()) || block.getType() == Material.FIRE) || this.isWaterbendable(block)) { blocks.add(block); FireBlast.removeFireBlastsAroundPoint(block.getLocation(), 2); } @@ -320,9 +345,12 @@ public class SurgeWave extends WaterAbility { } } if (knockback) { + if (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation()) || ((entity instanceof Player) && Commands.invincible.contains(((Player) entity).getName()))) { + continue; + } final Vector dir = direction.clone(); - dir.setY(dir.getY() * this.verticalFactor); - GeneralMethods.setVelocity(entity, entity.getVelocity().clone().add(dir.clone().multiply(this.getNightFactor(this.pushFactor)))); + dir.setY(dir.getY() * this.knockup); + GeneralMethods.setVelocity(entity, entity.getVelocity().clone().add(dir.clone().multiply(this.getNightFactor(this.knockback)))); entity.setFallDistance(0); if (entity.getFireTicks() > 0) { @@ -391,7 +419,7 @@ public class SurgeWave extends WaterAbility { public static void removeAllCleanup() { for (final SurgeWave surgeWave : getAbilities(SurgeWave.class)) { for (final Block block : surgeWave.waveBlocks.keySet()) { - block.setType(Material.AIR); + block.setType(Material.AIR, false); surgeWave.waveBlocks.remove(block); } for (final Block block : surgeWave.frozenBlocks.keySet()) { @@ -541,20 +569,20 @@ public class SurgeWave extends WaterAbility { this.range = range; } - public double getPushFactor() { - return this.pushFactor; + public double getKnockback() { + return this.knockback; } - public void setPushFactor(final double pushFactor) { - this.pushFactor = pushFactor; + public void setKnockback(final double knockback) { + this.knockback = knockback; } - public double getVerticalFactor() { - return this.verticalFactor; + public double getKnockup() { + return this.knockup; } - public void setVerticalFactor(final double verticalFactor) { - this.verticalFactor = verticalFactor; + public void setKnockup(final double knockup) { + this.knockup = knockup; } public double getMaxFreezeRadius() { diff --git a/src/com/projectkorra/projectkorra/waterbending/Torrent.java b/src/com/projectkorra/projectkorra/waterbending/Torrent.java index 99ce31a0..582621bd 100644 --- a/src/com/projectkorra/projectkorra/waterbending/Torrent.java +++ b/src/com/projectkorra/projectkorra/waterbending/Torrent.java @@ -1,11 +1,14 @@ package com.projectkorra.projectkorra.waterbending; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Random; import java.util.concurrent.ConcurrentHashMap; +import org.apache.commons.lang3.tuple.Pair; + import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -18,7 +21,9 @@ import com.projectkorra.projectkorra.BendingPlayer; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.AirAbility; import com.projectkorra.projectkorra.ability.WaterAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.avatar.AvatarState; +import com.projectkorra.projectkorra.command.Commands; import com.projectkorra.projectkorra.util.BlockSource; import com.projectkorra.projectkorra.util.ClickType; import com.projectkorra.projectkorra.util.DamageHandler; @@ -30,7 +35,7 @@ import com.projectkorra.projectkorra.waterbending.util.WaterReturn; public class Torrent extends WaterAbility { private static final double CLEANUP_RANGE = 50; - private static final Map FROZEN_BLOCKS = new ConcurrentHashMap<>(); + private static final Map> FROZEN_BLOCKS = new ConcurrentHashMap<>(); private boolean sourceSelected; private boolean settingUp; @@ -46,17 +51,26 @@ public class Torrent extends WaterAbility { private int hits = 1; private long time; private long interval; + @Attribute(Attribute.COOLDOWN) private long cooldown; private long revertTime; private double startAngle; private double angle; + @Attribute(Attribute.RADIUS) private double radius; - private double push; - private double maxUpwardForce; + @Attribute(Attribute.KNOCKBACK) + private double knockback; + @Attribute(Attribute.KNOCKUP) + private double knockup; + @Attribute(Attribute.DAMAGE) private double damage; + @Attribute("Successive" + Attribute.DAMAGE) private double successiveDamage; + @Attribute("Deflect" + Attribute.DAMAGE) private double deflectDamage; + @Attribute(Attribute.RANGE) private double range; + @Attribute(Attribute.SELECT_RANGE) private double selectRange; private Block sourceBlock; private TempBlock source; @@ -71,10 +85,10 @@ public class Torrent extends WaterAbility { this.layer = 0; this.startAngle = 0; this.maxLayer = getConfig().getInt("Abilities.Water.Torrent.MaxLayer"); - this.push = getConfig().getDouble("Abilities.Water.Torrent.Push"); + this.knockback = getConfig().getDouble("Abilities.Water.Torrent.Knockback"); this.angle = getConfig().getDouble("Abilities.Water.Torrent.Angle"); this.radius = getConfig().getDouble("Abilities.Water.Torrent.Radius"); - this.maxUpwardForce = getConfig().getDouble("Abilities.Water.Torrent.MaxUpwardForce"); + this.knockup = getConfig().getDouble("Abilities.Water.Torrent.Knockup"); this.interval = getConfig().getLong("Abilities.Water.Torrent.Interval"); this.damage = getConfig().getDouble("Abilities.Water.Torrent.InitialDamage"); this.successiveDamage = getConfig().getDouble("Abilities.Water.Torrent.SuccessiveDamage"); @@ -105,7 +119,7 @@ public class Torrent extends WaterAbility { } if (this.bPlayer.isAvatarState()) { - this.push = getConfig().getDouble("Abilities.Avatar.AvatarState.Water.Torrent.Push"); + this.knockback = getConfig().getDouble("Abilities.Avatar.AvatarState.Water.Torrent.Push"); this.damage = getConfig().getDouble("Abilities.Avatar.AvatarState.Water.Torrent.InitialDamage"); this.successiveDamage = getConfig().getDouble("Abilities.Avatar.AvatarState.Water.Torrent.SuccessiveDamage"); this.maxHits = getConfig().getInt("Abilities.Avatar.AvatarState.Water.Torrent.MaxHits"); @@ -125,12 +139,25 @@ public class Torrent extends WaterAbility { } else if (!this.bPlayer.canBendIgnoreBindsCooldowns(getAbility("PhaseChange"))) { return; } - final List ice = GeneralMethods.getBlocksAroundPoint(this.location, this.layer); - for (final Block block : ice) { + final List trapped = GeneralMethods.getEntitiesAroundPoint(this.location, this.layer); + ICE_SETTING: for (final Block block : ice) { if (isTransparent(this.player, block) && block.getType() != Material.ICE) { - final TempBlock tblock = new TempBlock(block, Material.ICE, (byte) 0); - FROZEN_BLOCKS.put(tblock, this.player); + for (final Entity entity : trapped) { + if (entity instanceof Player) { + if (Commands.invincible.contains(((Player) entity).getName())) { + return; + } + if (!getConfig().getBoolean("Properties.Water.FreezePlayerHead") && GeneralMethods.playerHeadIsInBlock((Player) entity, block)) { + continue ICE_SETTING; + } + if (!getConfig().getBoolean("Properties.Water.FreezePlayerFeet") && GeneralMethods.playerFeetIsInBlock((Player) entity, block)) { + continue ICE_SETTING; + } + } + } + final TempBlock tblock = new TempBlock(block, Material.ICE); + FROZEN_BLOCKS.put(tblock, Pair.of(this.player, this.getId())); if (this.revert) { tblock.setRevertTime(this.revertTime + (new Random().nextInt((500 + 500) + 1) - 500)); } @@ -163,13 +190,24 @@ public class Torrent extends WaterAbility { this.sourceSelected = false; this.settingUp = true; + if (TempBlock.isTempBlock(this.sourceBlock)) { + final TempBlock origin = TempBlock.get(this.sourceBlock); + + if (FROZEN_BLOCKS.containsKey(origin)) { + massThaw(origin); + } else if (isBendableWaterTempBlock(origin)) { + origin.revertBlock(); + } + } + if (isPlant(this.sourceBlock) || isSnow(this.sourceBlock)) { new PlantRegrowth(this.player, this.sourceBlock); this.sourceBlock.setType(Material.AIR); } else if (!GeneralMethods.isAdjacentToThreeOrMoreSources(this.sourceBlock)) { this.sourceBlock.setType(Material.AIR); } - this.source = new TempBlock(this.sourceBlock, Material.STATIONARY_WATER, (byte) 8); + + this.source = new TempBlock(this.sourceBlock, Material.WATER, GeneralMethods.getWaterData(0)); this.location = this.sourceBlock.getLocation(); } else { playFocusWaterEffect(this.sourceBlock); @@ -223,7 +261,7 @@ public class Torrent extends WaterAbility { this.remove(); return; } - this.source = new TempBlock(this.location.getBlock(), Material.STATIONARY_WATER, (byte) 8); + this.source = new TempBlock(this.location.getBlock(), Material.WATER, GeneralMethods.getWaterData(0)); } } if (this.forming && !this.player.isSneaking()) { @@ -244,7 +282,7 @@ public class Torrent extends WaterAbility { final double dz = Math.sin(phi) * this.radius; loc.add(dx, dy, dz); if (isWater(loc.getBlock()) && GeneralMethods.isAdjacentToThreeOrMoreSources(loc.getBlock())) { - ParticleEffect.WATER_BUBBLE.display((float) Math.random(), (float) Math.random(), (float) Math.random(), 0f, 5, loc.getBlock().getLocation().clone().add(.5, .5, .5), 255.0); + ParticleEffect.WATER_BUBBLE.display(loc.getBlock().getLocation().clone().add(.5, .5, .5), 5, Math.random(), Math.random(), Math.random(), 0); } loc.subtract(dx, dy, dz); } @@ -316,7 +354,7 @@ public class Torrent extends WaterAbility { final Block block = blockloc.getBlock(); if (!doneBlocks.contains(block) && !GeneralMethods.isRegionProtectedFromBuild(this, blockloc)) { if (isTransparent(this.player, block)) { - this.launchedBlocks.add(new TempBlock(block, Material.STATIONARY_WATER, (byte) 8)); + this.launchedBlocks.add(new TempBlock(block, Material.WATER, GeneralMethods.getWaterData(0))); doneBlocks.add(block); } else if (!isTransparent(this.player, block)) { break; @@ -382,9 +420,9 @@ public class Torrent extends WaterAbility { } if (locBlock.getLocation().distanceSquared(targetLoc) > 1) { if (isWater(locBlock)) { - ParticleEffect.WATER_BUBBLE.display((float) Math.random(), (float) Math.random(), (float) Math.random(), 0f, 5, locBlock.getLocation().clone().add(.5, .5, .5), 255.0); + ParticleEffect.WATER_BUBBLE.display(locBlock.getLocation().clone().add(.5, .5, .5), 5, Math.random(), Math.random(), Math.random(), 0); } - newBlocks.add(new TempBlock(locBlock, Material.STATIONARY_WATER, (byte) 8)); + newBlocks.add(new TempBlock(locBlock, Material.WATER, GeneralMethods.getWaterData(0))); } else { if (this.layer < this.maxLayer) { if (this.layer == 0) { @@ -449,7 +487,7 @@ public class Torrent extends WaterAbility { final Block block = blockLoc.getBlock(); if (!doneBlocks.contains(block)) { if (isTransparent(this.player, block)) { - this.blocks.add(new TempBlock(block, Material.STATIONARY_WATER, (byte) 8)); + this.blocks.add(new TempBlock(block, Material.WATER, GeneralMethods.getWaterData(0))); doneBlocks.add(block); for (final Entity entity : entities) { if (entity.getWorld() != blockLoc.getWorld()) { @@ -503,16 +541,15 @@ public class Torrent extends WaterAbility { final Block block = eyeLoc.add(eyeLoc.getDirection().normalize()).getBlock(); if (isTransparent(player, block) && isTransparent(player, eyeLoc.getBlock())) { if (block.getType() != Material.WATER) { - block.setType(Material.STATIONARY_WATER); - block.setData((byte) 8); + block.setType(Material.WATER); + block.setBlockData(GeneralMethods.getWaterData(0)); } final Torrent tor = new Torrent(player); if (tor.sourceSelected || tor.settingUp) { WaterReturn.emptyWaterBottle(player); - } else { - block.setType(Material.AIR); } + block.setType(Material.AIR); } } } @@ -528,6 +565,9 @@ public class Torrent extends WaterAbility { if (entity.getEntityId() == this.player.getEntityId()) { return; } + if (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation()) || ((entity instanceof Player) && Commands.invincible.contains(((Player) entity).getName()))) { + return; + } double x, z, vx, vz, mag; double angle = 50; angle = Math.toRadians(angle); @@ -540,7 +580,7 @@ public class Torrent extends WaterAbility { vx = (x * Math.cos(angle) - z * Math.sin(angle)) / mag; vz = (x * Math.sin(angle) + z * Math.cos(angle)) / mag; - final Vector vec = new Vector(vx, 0, vz).normalize().multiply(this.push); + final Vector vec = new Vector(vx, 0, vz).normalize().multiply(this.knockback); final Vector velocity = entity.getVelocity(); if (this.bPlayer.isAvatarState()) { @@ -564,11 +604,14 @@ public class Torrent extends WaterAbility { if (entity.getEntityId() == this.player.getEntityId()) { return; } - if (direction.getY() > this.maxUpwardForce) { - direction.setY(this.maxUpwardForce); + if (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation()) || (entity instanceof Player && Commands.invincible.contains(((Player) entity).getName()))) { + return; + } + if (direction.getY() > this.knockup) { + direction.setY(this.knockup); } if (!this.freeze) { - entity.setVelocity(direction.multiply(this.push)); + entity.setVelocity(direction.multiply(this.knockback)); } if (entity instanceof LivingEntity && !this.hurtEntities.contains(entity)) { double damageDealt = this.getNightFactor(this.damage); @@ -589,7 +632,7 @@ public class Torrent extends WaterAbility { public static void progressAllCleanup() { for (final TempBlock block : FROZEN_BLOCKS.keySet()) { - final Player player = FROZEN_BLOCKS.get(block); + final Player player = FROZEN_BLOCKS.get(block).getLeft(); final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); if (bPlayer == null) { FROZEN_BLOCKS.remove(block); @@ -623,6 +666,33 @@ public class Torrent extends WaterAbility { FROZEN_BLOCKS.remove(block); } + /** + * Thaws the entire mass of ice created by a torrent that the given block is + * part of + * + * @param origin part of the ice mass created by a torrent + */ + public static void massThaw(final TempBlock origin) { + if (FROZEN_BLOCKS.containsKey(origin)) { + final Player creator = FROZEN_BLOCKS.get(origin).getLeft(); + final int id = FROZEN_BLOCKS.get(origin).getRight(); + + for (final TempBlock tb : FROZEN_BLOCKS.keySet()) { + if (tb.equals(origin)) { + continue; + } + + final Player check = FROZEN_BLOCKS.get(tb).getLeft(); + final int id2 = FROZEN_BLOCKS.get(tb).getRight(); + if (creator.equals(check) && id == id2) { + thaw(tb); + } + } + + thaw(origin); + } + } + public static boolean canThaw(final Block block) { if (TempBlock.isTempBlock(block)) { final TempBlock tblock = TempBlock.get(block); @@ -810,19 +880,19 @@ public class Torrent extends WaterAbility { } public double getPush() { - return this.push; + return this.knockback; } public void setPush(final double push) { - this.push = push; + this.knockback = push; } public double getMaxUpwardForce() { - return this.maxUpwardForce; + return this.knockup; } public void setMaxUpwardForce(final double maxUpwardForce) { - this.maxUpwardForce = maxUpwardForce; + this.knockup = maxUpwardForce; } public double getDamage() { @@ -886,7 +956,11 @@ public class Torrent extends WaterAbility { } public static Map getFrozenBlocks() { - return FROZEN_BLOCKS; + final Map blocks = new HashMap<>(); + for (final TempBlock tb : FROZEN_BLOCKS.keySet()) { + blocks.put(tb, FROZEN_BLOCKS.get(tb).getLeft()); + } + return blocks; } public ArrayList getLaunchedBlocks() { diff --git a/src/com/projectkorra/projectkorra/waterbending/TorrentWave.java b/src/com/projectkorra/projectkorra/waterbending/TorrentWave.java index 8493a9a2..3f38645d 100644 --- a/src/com/projectkorra/projectkorra/waterbending/TorrentWave.java +++ b/src/com/projectkorra/projectkorra/waterbending/TorrentWave.java @@ -15,6 +15,8 @@ import org.bukkit.util.Vector; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.WaterAbility; +import com.projectkorra.projectkorra.attribute.Attribute; +import com.projectkorra.projectkorra.command.Commands; import com.projectkorra.projectkorra.util.TempBlock; import com.projectkorra.projectkorra.waterbending.util.WaterReturn; @@ -22,11 +24,16 @@ public class TorrentWave extends WaterAbility { private long time; private long interval; + @Attribute(Attribute.COOLDOWN) private long cooldown; private double radius; + @Attribute(Attribute.RADIUS) private double maxRadius; + @Attribute(Attribute.KNOCKBACK) private double knockback; + @Attribute(Attribute.HEIGHT) private double maxHeight; + @Attribute("Grow" + Attribute.SPEED) private double growSpeed; private Location origin; private ArrayList blocks; @@ -133,7 +140,7 @@ public class TorrentWave extends WaterAbility { } if (isTransparent(this.player, block)) { - final TempBlock tempBlock = new TempBlock(block, Material.STATIONARY_WATER, (byte) 8); + final TempBlock tempBlock = new TempBlock(block, Material.WATER, GeneralMethods.getWaterData(0)); this.blocks.add(tempBlock); torrentBlocks.add(block); } else { @@ -144,6 +151,9 @@ public class TorrentWave extends WaterAbility { for (final Entity entity : indexList) { if (!this.affectedEntities.contains(entity)) { if (entity.getLocation().distanceSquared(location) <= 4) { + if (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation()) || ((entity instanceof Player) && Commands.invincible.contains(((Player) entity).getName()))) { + continue; + } this.affectedEntities.add(entity); this.affect(entity); } diff --git a/src/com/projectkorra/projectkorra/waterbending/WaterBubble.java b/src/com/projectkorra/projectkorra/waterbending/WaterBubble.java index 8fec4454..e81ecddd 100644 --- a/src/com/projectkorra/projectkorra/waterbending/WaterBubble.java +++ b/src/com/projectkorra/projectkorra/waterbending/WaterBubble.java @@ -10,25 +10,32 @@ import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.block.data.Waterlogged; import org.bukkit.entity.Player; -import org.bukkit.material.MaterialData; import com.projectkorra.projectkorra.ability.CoreAbility; +import com.projectkorra.projectkorra.ability.ElementalAbility; import com.projectkorra.projectkorra.ability.WaterAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.configuration.ConfigManager; import com.projectkorra.projectkorra.util.TempBlock; public class WaterBubble extends WaterAbility { - private static long clickDuration; // How long the click variant lasts. - private static double maxRadius; - private static double speed; - private static boolean requireAir = false; + @Attribute("Click" + Attribute.DURATION) + private long clickDuration; + @Attribute(Attribute.RADIUS) + private double maxRadius; + @Attribute(Attribute.SPEED) + private double speed; + @Attribute("RequireAir") + private boolean requireAir; private boolean isShift; private double radius; private boolean removing = false; // Is true when the radius is shrinking. - private final Map waterOrigins = new ConcurrentHashMap(); + private final Map waterOrigins = new ConcurrentHashMap<>(); private Location location; private long lastActivation; // When the last click happened. @@ -41,7 +48,7 @@ public class WaterBubble extends WaterAbility { final WaterBubble bubble = CoreAbility.getAbility(player, this.getClass()); if (bubble.location.getWorld().equals(player.getWorld())) { - if (bubble.location.distanceSquared(player.getLocation()) < maxRadius * maxRadius) { + if (bubble.location.distanceSquared(player.getLocation()) < this.maxRadius * this.maxRadius) { if (bubble.removing) { bubble.removing = false; } @@ -53,7 +60,7 @@ public class WaterBubble extends WaterAbility { } } bubble.removing = true; - } else if (requireAir && !(!player.getEyeLocation().getBlock().getType().isSolid() && !player.getEyeLocation().getBlock().isLiquid())) { + } else if (this.requireAir && !(!player.getEyeLocation().getBlock().getType().isSolid() && !player.getEyeLocation().getBlock().isLiquid())) { return; } @@ -70,10 +77,10 @@ public class WaterBubble extends WaterAbility { } public void setFields() { - clickDuration = ConfigManager.defaultConfig.get().getLong("Abilities.Water.WaterBubble.ClickDuration"); - maxRadius = ConfigManager.defaultConfig.get().getDouble("Abilities.Water.WaterBubble.Radius"); - speed = ConfigManager.defaultConfig.get().getDouble("Abilities.Water.WaterBubble.Speed"); - requireAir = ConfigManager.defaultConfig.get().getBoolean("Abilities.Water.WaterBubble.MustStartAboveWater"); + this.clickDuration = ConfigManager.defaultConfig.get().getLong("Abilities.Water.WaterBubble.ClickDuration"); + this.maxRadius = ConfigManager.defaultConfig.get().getDouble("Abilities.Water.WaterBubble.Radius"); + this.speed = ConfigManager.defaultConfig.get().getDouble("Abilities.Water.WaterBubble.Speed"); + this.requireAir = ConfigManager.defaultConfig.get().getBoolean("Abilities.Water.WaterBubble.MustStartAboveWater"); } @Override @@ -87,28 +94,28 @@ public class WaterBubble extends WaterAbility { this.removing = true; } - if (System.currentTimeMillis() - this.lastActivation > clickDuration && !this.isShift) { + if (System.currentTimeMillis() - this.lastActivation > this.clickDuration && !this.isShift) { this.removing = true; } if (this.removing) { - this.radius -= speed; + this.radius -= this.speed; if (this.radius <= 0.1) { this.radius = 0.1; this.remove(); } } else { - this.radius += speed; + this.radius += this.speed; - if (this.radius > maxRadius) { - this.radius = maxRadius; + if (this.radius > this.maxRadius) { + this.radius = this.maxRadius; } } final List list = new ArrayList(); - if (this.radius < maxRadius || !this.location.getBlock().equals(this.player.getLocation().getBlock())) { + if (this.radius < this.maxRadius || !this.location.getBlock().equals(this.player.getLocation().getBlock())) { for (double x = -this.radius; x < this.radius; x += 0.5) { for (double y = -this.radius; y < this.radius; y += 0.5) { @@ -117,11 +124,17 @@ public class WaterBubble extends WaterAbility { final Block b = this.location.add(x, y, z).getBlock(); if (!this.waterOrigins.containsKey(b)) { - if (b.getType() == Material.STATIONARY_WATER || b.getType() == Material.WATER) { + if (isWater(b)) { if (!TempBlock.isTempBlock(b)) { - this.waterOrigins.put(b, b.getState().getData()); + this.waterOrigins.put(b, b.getState()); + if (b.getBlockData() instanceof Waterlogged) { + final Waterlogged logged = (Waterlogged) b.getBlockData(); + logged.setWaterlogged(false); + b.setBlockData(logged); + } else if (isWater(b.getType())) { + b.setType(Material.AIR); + } } - b.setType(Material.AIR); } } list.add(b); // Store it to say that it should be there. @@ -137,9 +150,13 @@ public class WaterBubble extends WaterAbility { set.removeAll(list); for (final Block b : set) { - if (b.getType() == Material.AIR) { - b.setType(this.waterOrigins.get(b).getItemType()); - b.setData(this.waterOrigins.get(b).getData()); + if (b.getBlockData() instanceof Waterlogged) { + final Waterlogged logged = (Waterlogged) b.getBlockData(); + logged.setWaterlogged(true); + b.setBlockData(logged); + } else if (ElementalAbility.isAir(b.getType())) { + b.setType(this.waterOrigins.get(b).getType()); + b.setBlockData(this.waterOrigins.get(b).getBlockData()); } this.waterOrigins.remove(b); } @@ -173,11 +190,17 @@ public class WaterBubble extends WaterAbility { super.remove(); for (final Block b : this.waterOrigins.keySet()) { - if (b.getType() == Material.AIR) { - b.setType(this.waterOrigins.get(b).getItemType()); - b.setData(this.waterOrigins.get(b).getData()); + if (b.getBlockData() instanceof Waterlogged) { + final Waterlogged logged = (Waterlogged) b.getBlockData(); + logged.setWaterlogged(true); + b.setBlockData(logged); + } else if (ElementalAbility.isAir(b.getType())) { + b.setType(this.waterOrigins.get(b).getType()); + b.setBlockData(this.waterOrigins.get(b).getBlockData()); } } + + this.waterOrigins.clear(); } /** @@ -190,10 +213,10 @@ public class WaterBubble extends WaterAbility { public static boolean isAir(final Block block) { for (final WaterBubble bubble : CoreAbility.getAbilities(WaterBubble.class)) { if (bubble.waterOrigins.containsKey(block)) { - return false; + return true; } } - return true; + return false; } } diff --git a/src/com/projectkorra/projectkorra/waterbending/WaterManipulation.java b/src/com/projectkorra/projectkorra/waterbending/WaterManipulation.java index c855d04c..11c7b197 100644 --- a/src/com/projectkorra/projectkorra/waterbending/WaterManipulation.java +++ b/src/com/projectkorra/projectkorra/waterbending/WaterManipulation.java @@ -6,7 +6,6 @@ import java.util.Map; import java.util.Random; import java.util.concurrent.ConcurrentHashMap; -import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -20,6 +19,8 @@ import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.AirAbility; import com.projectkorra.projectkorra.ability.WaterAbility; import com.projectkorra.projectkorra.ability.util.Collision; +import com.projectkorra.projectkorra.attribute.Attribute; +import com.projectkorra.projectkorra.command.Commands; import com.projectkorra.projectkorra.util.BlockSource; import com.projectkorra.projectkorra.util.ClickType; import com.projectkorra.projectkorra.util.DamageHandler; @@ -40,12 +41,20 @@ public class WaterManipulation extends WaterAbility { private boolean prepared; private int dispelRange; private long time; + @Attribute(Attribute.COOLDOWN) private long cooldown; private long interval; - private double selectRange, range; - private double pushFactor; + @Attribute(Attribute.SELECT_RANGE) + private double selectRange; + @Attribute(Attribute.RANGE) + private double range; + @Attribute(Attribute.KNOCKBACK) + private double knockback; + @Attribute(Attribute.DAMAGE) private double damage; + @Attribute(Attribute.SPEED) private double speed; + @Attribute("Deflect" + Attribute.RANGE) private double deflectRange; private double collisionRadius; private Block sourceBlock; @@ -73,7 +82,7 @@ public class WaterManipulation extends WaterAbility { this.cooldown = getConfig().getLong("Abilities.Water.WaterManipulation.Cooldown"); this.selectRange = getConfig().getDouble("Abilities.Water.WaterManipulation.SelectRange"); this.range = getConfig().getDouble("Abilities.Water.WaterManipulation.Range"); - this.pushFactor = getConfig().getDouble("Abilities.Water.WaterManipulation.Push"); + this.knockback = getConfig().getDouble("Abilities.Water.WaterManipulation.Knockback"); this.damage = getConfig().getDouble("Abilities.Water.WaterManipulation.Damage"); this.speed = getConfig().getDouble("Abilities.Water.WaterManipulation.Speed"); this.deflectRange = getConfig().getDouble("Abilities.Water.WaterManipulation.DeflectRange"); @@ -200,7 +209,7 @@ public class WaterManipulation extends WaterAbility { this.remove(); return; } - this.sourceBlock.getWorld().playEffect(this.location, Effect.SMOKE, 4, (int) this.selectRange); + ParticleEffect.SMOKE_NORMAL.display(this.sourceBlock.getLocation().clone().add(0.5, 0.5, 0.5), 4, 0, 0, 0); return; } @@ -269,9 +278,12 @@ public class WaterManipulation extends WaterAbility { if (!this.displacing) { for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(this.location, this.collisionRadius)) { if (entity instanceof LivingEntity && entity.getEntityId() != this.player.getEntityId()) { + if (GeneralMethods.isRegionProtectedFromBuild(this.player, "WaterManipulation", entity.getLocation()) || ((entity instanceof Player) && Commands.invincible.contains(((Player) entity).getName()))) { + continue; + } final Location location = this.player.getEyeLocation(); final Vector vector = location.getDirection(); - entity.setVelocity(vector.normalize().multiply(this.pushFactor)); + entity.setVelocity(vector.normalize().multiply(this.knockback)); if (this.bPlayer.isAvatarState()) { this.damage = getConfig().getDouble("Abilities.Avatar.AvatarState.Water.WaterManipulation.Damage"); @@ -299,9 +311,9 @@ public class WaterManipulation extends WaterAbility { } if (this.trail != null) { this.trail2 = this.trail; - this.trail2.setType(Material.STATIONARY_WATER, (byte) 2); + this.trail2.setType(Material.WATER, GeneralMethods.getWaterData(6)); } - this.trail = new TempBlock(this.sourceBlock, Material.STATIONARY_WATER, (byte) 1); + this.trail = new TempBlock(this.sourceBlock, Material.WATER, GeneralMethods.getWaterData(7)); this.sourceBlock = block; if (this.location.distanceSquared(this.targetDestination) <= 1 || this.location.distanceSquared(this.firstDestination) > this.range * this.range) { @@ -354,10 +366,10 @@ public class WaterManipulation extends WaterAbility { if (PhaseChange.getFrozenBlocksAsBlock().contains(block)) { PhaseChange.getFrozenBlocksAsBlock().remove(block); } - new TempBlock(block, Material.WATER, (byte) 0); + new TempBlock(block, Material.WATER, GeneralMethods.getWaterData(0)); } else { if (isWater(block) && !AFFECTED_BLOCKS.containsKey(block)) { - ParticleEffect.WATER_BUBBLE.display((float) Math.random(), (float) Math.random(), (float) Math.random(), 0f, 5, block.getLocation().clone().add(.5, .5, .5), 255.0); + ParticleEffect.WATER_BUBBLE.display(block.getLocation().clone().add(.5, .5, .5), 5, Math.random(), Math.random(), Math.random(), 0); } } @@ -488,7 +500,7 @@ public class WaterManipulation extends WaterAbility { if (isTransparent(player, block) && isTransparent(player, eyeLoc.getBlock())) { if (getTargetLocation(player, range).distanceSquared(block.getLocation()) > 1) { - final TempBlock tb = new TempBlock(block, Material.WATER, (byte) 0); + final TempBlock tb = new TempBlock(block, Material.WATER, GeneralMethods.getWaterData(0)); final WaterManipulation waterManip = new WaterManipulation(player, block); waterManip.moveWater(); @@ -678,11 +690,11 @@ public class WaterManipulation extends WaterAbility { } public double getPushFactor() { - return this.pushFactor; + return this.knockback; } public void setPushFactor(final double pushFactor) { - this.pushFactor = pushFactor; + this.knockback = pushFactor; } public double getDamage() { diff --git a/src/com/projectkorra/projectkorra/waterbending/WaterSpout.java b/src/com/projectkorra/projectkorra/waterbending/WaterSpout.java index fffacf8b..52629a45 100644 --- a/src/com/projectkorra/projectkorra/waterbending/WaterSpout.java +++ b/src/com/projectkorra/projectkorra/waterbending/WaterSpout.java @@ -13,7 +13,7 @@ import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffectType; import com.projectkorra.projectkorra.GeneralMethods; -import com.projectkorra.projectkorra.ProjectKorra; +import com.projectkorra.projectkorra.ability.ElementalAbility; import com.projectkorra.projectkorra.ability.WaterAbility; import com.projectkorra.projectkorra.ability.util.Collision; import com.projectkorra.projectkorra.attribute.Attribute; @@ -25,6 +25,7 @@ public class WaterSpout extends WaterAbility { private static final Map AFFECTED_BLOCKS = new ConcurrentHashMap(); private final List blocks = new ArrayList(); + @Attribute("CanBendOnPackedIce") private boolean canBendOnPackedIce; private boolean useParticles; private boolean useBlockSpiral; @@ -33,10 +34,12 @@ public class WaterSpout extends WaterAbility { private long interval; @Attribute(Attribute.COOLDOWN) private long cooldown; + @Attribute(Attribute.DURATION) private long duration; private long startTime; private double rotation; private double height; + @Attribute(Attribute.HEIGHT) private double maxHeight; private Block base; private TempBlock baseBlock; @@ -80,7 +83,7 @@ public class WaterSpout extends WaterAbility { if (!this.isWithinMaxSpoutHeight(topBlock.getLocation(), heightRemoveThreshold)) { return; } - ProjectKorra.flightHandler.createInstance(player, this.getName()); + this.flightHandler.createInstance(player, this.getName()); player.setAllowFlight(true); this.spoutableWaterHeight(player.getLocation()); // Sets base. this.start(); @@ -107,8 +110,8 @@ public class WaterSpout extends WaterAbility { loc.add(x, height, z); final Block block = loc.getBlock(); - if ((!TempBlock.isTempBlock(block)) && (block.getType().equals(Material.AIR) || !GeneralMethods.isSolid(block))) { - this.blocks.add(new TempBlock(block, Material.STATIONARY_WATER, (byte) 1)); + if ((!TempBlock.isTempBlock(block)) && (ElementalAbility.isAir(block.getType()) || !GeneralMethods.isSolid(block))) { + this.blocks.add(new TempBlock(block, Material.WATER, GeneralMethods.getWaterData(7))); AFFECTED_BLOCKS.put(block, block); } } @@ -154,7 +157,7 @@ public class WaterSpout extends WaterAbility { block = location.clone().add(0, i, 0).getBlock(); if (!TempBlock.isTempBlock(block)) { - this.blocks.add(new TempBlock(block, Material.STATIONARY_WATER, (byte) 8)); + this.blocks.add(new TempBlock(block, Material.WATER, GeneralMethods.getWaterData(0))); AFFECTED_BLOCKS.put(block, block); } this.rotateParticles(block); @@ -162,10 +165,14 @@ public class WaterSpout extends WaterAbility { this.displayWaterSpiral(location.clone().add(.5, 0, .5)); if (this.player.getLocation().getBlockY() > block.getY()) { - this.player.setFlying(false); + if (this.player.isFlying()) { + this.player.setFlying(false); + } } else { - this.player.setAllowFlight(true); - this.player.setFlying(true); + if (!this.player.isFlying()) { + this.player.setAllowFlight(true); + this.player.setFlying(true); + } } } else { this.bPlayer.addCooldown(this); @@ -183,7 +190,7 @@ public class WaterSpout extends WaterAbility { AFFECTED_BLOCKS.remove(tb.getBlock()); tb.revertBlock(); } - ProjectKorra.flightHandler.removeInstance(this.player, this.getName()); + this.flightHandler.removeInstance(this.player, this.getName()); } public void revertBaseBlock() { @@ -222,7 +229,7 @@ public class WaterSpout extends WaterAbility { dy = this.height; } - final float[] directions = { -0.5f, 0.325f, 0.25f, 0.125f, 0.f, 0.125f, 0.25f, 0.325f, 0.5f }; + final double[] directions = { -0.5, 0.325, 0.25, 0.125, 0.0, 0.125, 0.25, 0.325, 0.5 }; int index = this.angle; this.angle++; if (this.angle >= directions.length) { @@ -235,7 +242,7 @@ public class WaterSpout extends WaterAbility { } final Location effectLoc2 = new Location(location.getWorld(), location.getX(), block.getY() + i, location.getZ()); - ParticleEffect.WATER_SPLASH.display(effectLoc2, directions[index], directions[index], directions[index], 5, (int) (this.height + 5)); + ParticleEffect.WATER_SPLASH.display(effectLoc2, 5, directions[index], directions[index], directions[index]); } } } @@ -279,7 +286,7 @@ public class WaterSpout extends WaterAbility { if (!TempBlock.isTempBlock(blocki)) { this.revertBaseBlock(); - this.baseBlock = new TempBlock(blocki, Material.STATIONARY_WATER, (byte) 8); + this.baseBlock = new TempBlock(blocki, Material.WATER, GeneralMethods.getWaterData(0)); } this.base = blocki; @@ -289,7 +296,7 @@ public class WaterSpout extends WaterAbility { return i; } - if ((blocki.getType() != Material.AIR && (!isPlant(blocki) || !this.bPlayer.canPlantbend()))) { + if ((!ElementalAbility.isAir(blocki.getType()) && (!isPlant(blocki) || !this.bPlayer.canPlantbend()))) { this.revertBaseBlock(); return -1; } @@ -354,6 +361,9 @@ public class WaterSpout extends WaterAbility { @Override public List getLocations() { + if (this.getBase() == null) { + return new ArrayList<>(); + } final ArrayList locations = new ArrayList<>(); final Location top = this.getLocation(); final Location iterLoc = this.getBase().getLocation(); diff --git a/src/com/projectkorra/projectkorra/waterbending/WaterSpoutWave.java b/src/com/projectkorra/projectkorra/waterbending/WaterSpoutWave.java index 2ecbf5d2..1184b6c4 100644 --- a/src/com/projectkorra/projectkorra/waterbending/WaterSpoutWave.java +++ b/src/com/projectkorra/projectkorra/waterbending/WaterSpoutWave.java @@ -11,6 +11,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.block.data.BlockData; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -21,7 +22,10 @@ import com.projectkorra.projectkorra.Element; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ability.CoreAbility; +import com.projectkorra.projectkorra.ability.ElementalAbility; import com.projectkorra.projectkorra.ability.WaterAbility; +import com.projectkorra.projectkorra.attribute.Attribute; +import com.projectkorra.projectkorra.command.Commands; import com.projectkorra.projectkorra.util.DamageHandler; import com.projectkorra.projectkorra.util.TempBlock; import com.projectkorra.projectkorra.waterbending.combo.IceWave; @@ -39,6 +43,7 @@ public class WaterSpoutWave extends WaterAbility { private static final Map FROZEN_BLOCKS = new ConcurrentHashMap<>(); + @Attribute(Attribute.RADIUS) private double radius; private boolean charging; private boolean iceWave; @@ -49,14 +54,22 @@ public class WaterSpoutWave extends WaterAbility { private boolean revertIceSphere; private int progressCounter; private long time; + @Attribute(Attribute.COOLDOWN) private long cooldown; private long revertSphereTime; + @Attribute(Attribute.SELECT_RANGE) private double selectRange; + @Attribute(Attribute.SPEED) private double speed; + @Attribute(Attribute.CHARGE_DURATION) private double chargeTime; - private double flightTime; + @Attribute("Flight" + Attribute.DURATION) + private double flightDuration; + @Attribute("Wave" + Attribute.RADIUS) private double waveRadius; + @Attribute("Thaw" + Attribute.RADIUS) private double thawRadius; + @Attribute(Attribute.DAMAGE) private double damage; private double animationSpeed; private AbilityType type; @@ -84,7 +97,7 @@ public class WaterSpoutWave extends WaterAbility { this.speed = getConfig().getDouble("Abilities.Water.WaterSpout.Wave.Speed"); this.damage = getConfig().getDouble("Abilities.Water.IceWave.Damage"); this.chargeTime = getConfig().getLong("Abilities.Water.WaterSpout.Wave.ChargeTime"); - this.flightTime = getConfig().getLong("Abilities.Water.WaterSpout.Wave.FlightTime"); + this.flightDuration = getConfig().getLong("Abilities.Water.WaterSpout.Wave.FlightDuration"); this.cooldown = getConfig().getLong("Abilities.Water.WaterSpout.Wave.Cooldown"); this.revertSphereTime = getConfig().getLong("Abilities.Water.IceWave.RevertSphereTime"); this.revertIceSphere = getConfig().getBoolean("Abilities.Water.IceWave.RevertSphere"); @@ -100,7 +113,7 @@ public class WaterSpoutWave extends WaterAbility { if (this.bPlayer.isAvatarState()) { this.chargeTime = 0; - this.flightTime = getConfig().getDouble("Abilities.Avatar.AvatarState.Water.WaterWave.FlightTime"); + this.flightDuration = getConfig().getDouble("Abilities.Avatar.AvatarState.Water.WaterWave.FlightDuration"); this.damage = getConfig().getDouble("Abilities.Avatar.AvatarState.Water.IceWave.Damage"); this.cooldown = 0; } @@ -158,7 +171,7 @@ public class WaterSpoutWave extends WaterAbility { } final Block blockAbove = block.getRelative(BlockFace.UP); - if (blockAbove.getType() != Material.AIR && !this.isWaterbendable(blockAbove)) { + if (!ElementalAbility.isAir(blockAbove.getType()) && !this.isWaterbendable(blockAbove)) { this.remove(); return; } @@ -200,6 +213,17 @@ public class WaterSpoutWave extends WaterAbility { new PlantRegrowth(this.player, this.origin.getBlock()); this.origin.getBlock().setType(Material.AIR); } + + if (TempBlock.isTempBlock(this.origin.getBlock())) { + final TempBlock tb = TempBlock.get(this.origin.getBlock()); + + if (Torrent.getFrozenBlocks().containsKey(tb)) { + Torrent.massThaw(tb); + } else if (!isBendableWaterTempBlock(tb)) { + this.remove(); + return; + } + } } this.removeOldType(this.player, AbilityType.CLICK); @@ -218,11 +242,11 @@ public class WaterSpoutWave extends WaterAbility { this.location.add(0, this.animationSpeed, 0); final Block block = this.location.getBlock(); - if (!(this.isWaterbendable(block) || block.getType() == Material.AIR) || GeneralMethods.isRegionProtectedFromBuild(this, block.getLocation())) { + if (!(this.isWaterbendable(block) || ElementalAbility.isAir(block.getType()) || GeneralMethods.isRegionProtectedFromBuild(this, block.getLocation()))) { this.remove(); return; } - this.createBlock(block, Material.STATIONARY_WATER); + this.createBlock(block, Material.WATER); if (this.location.distanceSquared(this.origin) > 4) { this.animation = AnimateState.TOWARD_PLAYER; } @@ -234,12 +258,12 @@ public class WaterSpoutWave extends WaterAbility { this.location.add(vec.normalize().multiply(this.animationSpeed)); final Block block = this.location.getBlock(); - if (!(this.isWaterbendable(block) || block.getType() == Material.AIR) || GeneralMethods.isRegionProtectedFromBuild(this, block.getLocation())) { + if (!(this.isWaterbendable(block) || ElementalAbility.isAir(block.getType()) || GeneralMethods.isRegionProtectedFromBuild(this, block.getLocation()))) { this.remove(); return; } - this.createBlock(block, Material.STATIONARY_WATER); + this.createBlock(block, Material.WATER); if (this.location.distanceSquared(eyeLoc) < 1.7) { this.animation = AnimateState.CIRCLE; final Vector tempDir = this.player.getLocation().getDirection(); @@ -263,13 +287,13 @@ public class WaterSpoutWave extends WaterAbility { } else { this.moving = true; this.collidable = true; - if ((System.currentTimeMillis() - this.time > this.flightTime && !this.bPlayer.isAvatarState()) || this.player.isSneaking()) { + if ((System.currentTimeMillis() - this.time > this.flightDuration && !this.bPlayer.isAvatarState()) || this.player.isSneaking()) { this.remove(); return; } this.player.setFallDistance(0f); - double currentSpeed = this.speed - (this.speed * (System.currentTimeMillis() - this.time) / this.flightTime); + double currentSpeed = this.speed - (this.speed * (System.currentTimeMillis() - this.time) / this.flightDuration); final double nightSpeed = this.getNightFactor(currentSpeed * 0.9); currentSpeed = nightSpeed > currentSpeed ? nightSpeed : currentSpeed; if (this.bPlayer.isAvatarState()) { @@ -278,11 +302,11 @@ public class WaterSpoutWave extends WaterAbility { this.player.setVelocity(this.player.getEyeLocation().getDirection().normalize().multiply(currentSpeed)); for (final Block block : GeneralMethods.getBlocksAroundPoint(this.player.getLocation().add(0, -1, 0), this.waveRadius)) { - if (block.getType() == Material.AIR && !GeneralMethods.isRegionProtectedFromBuild(this, block.getLocation())) { + if (ElementalAbility.isAir(block.getType()) && !GeneralMethods.isRegionProtectedFromBuild(this, block.getLocation())) { if (this.iceWave) { - this.createBlockDelay(block, Material.ICE, (byte) 0, 2L); + this.createBlockDelay(block, Material.ICE, Material.ICE.createBlockData(), 2L); } else { - this.createBlock(block, Material.STATIONARY_WATER, (byte) 0); + this.createBlock(block, Material.WATER, GeneralMethods.getWaterData(0)); } } } @@ -326,8 +350,8 @@ public class WaterSpoutWave extends WaterAbility { dir.setY(0); final Block block = this.player.getEyeLocation().add(dir).getBlock(); this.location = block.getLocation(); - if (block.getType() == Material.AIR && !GeneralMethods.isRegionProtectedFromBuild(this, block.getLocation())) { - this.createBlock(block, Material.STATIONARY_WATER, (byte) 8); + if (ElementalAbility.isAir(block.getType()) && !GeneralMethods.isRegionProtectedFromBuild(this, block.getLocation())) { + this.createBlock(block, Material.WATER, GeneralMethods.getWaterData(0)); } } } @@ -344,7 +368,7 @@ public class WaterSpoutWave extends WaterAbility { } } - public void createBlockDelay(final Block block, final Material mat, final byte data, final long delay) { + public void createBlockDelay(final Block block, final Material mat, final BlockData data, final long delay) { final BukkitRunnable br = new BukkitRunnable() { @Override public void run() { @@ -356,10 +380,10 @@ public class WaterSpoutWave extends WaterAbility { } public void createBlock(final Block block, final Material mat) { - this.createBlock(block, mat, (byte) 0); + this.createBlock(block, mat, mat.createBlockData()); } - public void createBlock(final Block block, final Material mat, final byte data) { + public void createBlock(final Block block, final Material mat, final BlockData data) { this.affectedBlocks.put(block, new TempBlock(block, mat, data)); } @@ -398,10 +422,23 @@ public class WaterSpoutWave extends WaterAbility { if (block.getLocation().distanceSquared(entity.getLocation().getBlock().getLocation()) > radius * radius) { continue; } - - if (block.getType() == Material.AIR || block.getType() == Material.ICE || this.isWaterbendable(block)) { + if (GeneralMethods.isRegionProtectedFromBuild(this, block.getLocation())) { + continue; + } + if (entity instanceof Player) { + if (Commands.invincible.contains(((Player) entity).getName())) { + return; + } + if (!getConfig().getBoolean("Properties.Water.FreezePlayerHead") && GeneralMethods.playerHeadIsInBlock((Player) entity, block)) { + continue; + } + if (!getConfig().getBoolean("Properties.Water.FreezePlayerFeet") && GeneralMethods.playerFeetIsInBlock((Player) entity, block)) { + continue; + } + } + if (ElementalAbility.isAir(block.getType()) || block.getType() == Material.ICE || this.isWaterbendable(block)) { if (!FROZEN_BLOCKS.containsKey(block)) { - final TempBlock tblock = new TempBlock(block, Material.ICE, (byte) 1); + final TempBlock tblock = new TempBlock(block, Material.ICE); FROZEN_BLOCKS.put(block, tblock); if (this.revertIceSphere) { tblock.setRevertTime(this.revertSphereTime + (new Random().nextInt(1000) - 500)); @@ -607,12 +644,12 @@ public class WaterSpoutWave extends WaterAbility { this.chargeTime = chargeTime; } - public double getFlightTime() { - return this.flightTime; + public double getFlightDuration() { + return this.flightDuration; } - public void setFlightTime(final double flightTime) { - this.flightTime = flightTime; + public void setFlightDuration(final double flightDuration) { + this.flightDuration = flightDuration; } public double getWaveRadius() { diff --git a/src/com/projectkorra/projectkorra/waterbending/blood/Bloodbending.java b/src/com/projectkorra/projectkorra/waterbending/blood/Bloodbending.java index fd66986e..fc203eec 100644 --- a/src/com/projectkorra/projectkorra/waterbending/blood/Bloodbending.java +++ b/src/com/projectkorra/projectkorra/waterbending/blood/Bloodbending.java @@ -1,13 +1,13 @@ package com.projectkorra.projectkorra.waterbending.blood; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; import org.bukkit.Location; +import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Creature; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; @@ -20,6 +20,7 @@ import com.projectkorra.projectkorra.BendingPlayer; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.AirAbility; import com.projectkorra.projectkorra.ability.BloodAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.avatar.AvatarState; import com.projectkorra.projectkorra.object.HorizontalVelocityTracker; import com.projectkorra.projectkorra.util.DamageHandler; @@ -30,14 +31,20 @@ public class Bloodbending extends BloodAbility { private static final Map TARGETED_ENTITIES = new ConcurrentHashMap(); private boolean canOnlyBeUsedAtNight; + @Attribute("CanBeUsedOnUndeadMobs") private boolean canBeUsedOnUndeadMobs; private boolean onlyUsableDuringMoon; + @Attribute("CanBloodbendOtherBloodbenders") private boolean canBloodbendOtherBloodbenders; + @Attribute(Attribute.RANGE) private int range; private long time; - private long holdTime; + @Attribute(Attribute.DURATION) + private long duration; + @Attribute(Attribute.COOLDOWN) private long cooldown; - private double throwFactor; + @Attribute(Attribute.KNOCKBACK) + private double knockback; private Entity target; private Vector vector; @@ -55,9 +62,9 @@ public class Bloodbending extends BloodAbility { this.onlyUsableDuringMoon = getConfig().getBoolean("Abilities.Water.Bloodbending.CanOnlyBeUsedDuringFullMoon"); this.canBloodbendOtherBloodbenders = getConfig().getBoolean("Abilities.Water.Bloodbending.CanBloodbendOtherBloodbenders"); this.range = getConfig().getInt("Abilities.Water.Bloodbending.Range"); - this.holdTime = getConfig().getInt("Abilities.Water.Bloodbending.HoldTime"); + this.duration = getConfig().getInt("Abilities.Water.Bloodbending.Duration"); this.cooldown = getConfig().getInt("Abilities.Water.Bloodbending.Cooldown"); - this.throwFactor = getConfig().getDouble("Abilities.Water.Bloodbending.ThrowFactor"); + this.knockback = getConfig().getDouble("Abilities.Water.Bloodbending.Knockback"); this.vector = new Vector(0, 0, 0); if (this.canOnlyBeUsedAtNight && !isNight(player.getWorld()) && !this.bPlayer.canBloodbendAtAnytime()) { @@ -90,19 +97,15 @@ public class Bloodbending extends BloodAbility { for (int i = 0; i < this.range; i++) { final Location location = GeneralMethods.getTargetedLocation(player, i, getTransparentMaterials()); entities = GeneralMethods.getEntitiesAroundPoint(location, 1.7); - if (entities.contains(player)) { - entities.remove(player); - } - for (final Iterator iterator = entities.iterator(); iterator.hasNext();) { - if (!(iterator.next() instanceof LivingEntity)) { - iterator.remove(); - } - } - if (entities != null && !entities.isEmpty() && !entities.contains(player)) { + + entities.remove(player); + entities.removeIf(e -> !(e instanceof LivingEntity) || e instanceof ArmorStand); + + if (!entities.isEmpty() && !entities.contains(player)) { break; } } - if (entities == null || entities.isEmpty()) { + if (entities.isEmpty()) { return; } this.target = entities.get(0); @@ -120,7 +123,7 @@ public class Bloodbending extends BloodAbility { return; } } - } else if (!this.canBeUsedOnUndeadMobs && isUndead(this.target)) { + } else if (!this.canBeUsedOnUndeadMobs && GeneralMethods.isUndead(this.target)) { return; } @@ -150,7 +153,7 @@ public class Bloodbending extends BloodAbility { vector = GeneralMethods.getDirection(location, GeneralMethods.getTargetedLocation(this.player, location.distance(target))); } vector.normalize(); - entity.setVelocity(vector.multiply(this.throwFactor)); + entity.setVelocity(vector.multiply(this.knockback)); new HorizontalVelocityTracker(entity, this.player, 200, this); } this.remove(); @@ -164,7 +167,7 @@ public class Bloodbending extends BloodAbility { if (!this.player.isSneaking()) { this.remove(); return; - } else if (this.holdTime > 0 && System.currentTimeMillis() - this.time > this.holdTime) { + } else if (this.duration > 0 && System.currentTimeMillis() - this.time > this.duration) { this.remove(); this.bPlayer.addCooldown(this); return; @@ -172,7 +175,7 @@ public class Bloodbending extends BloodAbility { if (!this.canBeUsedOnUndeadMobs) { for (final Entity entity : TARGETED_ENTITIES.keySet()) { - if (isUndead(entity)) { + if (GeneralMethods.isUndead(entity)) { TARGETED_ENTITIES.remove(entity); } } @@ -417,20 +420,20 @@ public class Bloodbending extends BloodAbility { this.time = time; } - public long getHoldTime() { - return this.holdTime; + public long getDuration() { + return this.duration; } - public void setHoldTime(final long holdTime) { - this.holdTime = holdTime; + public void setDuration(final long duration) { + this.duration = duration; } - public double getThrowFactor() { - return this.throwFactor; + public double getKnockback() { + return this.knockback; } - public void setThrowFactor(final double throwFactor) { - this.throwFactor = throwFactor; + public void setKnockback(final double knockback) { + this.knockback = knockback; } public Entity getTarget() { diff --git a/src/com/projectkorra/projectkorra/waterbending/combo/IceBullet.java b/src/com/projectkorra/projectkorra/waterbending/combo/IceBullet.java index a219266f..be954f76 100644 --- a/src/com/projectkorra/projectkorra/waterbending/combo/IceBullet.java +++ b/src/com/projectkorra/projectkorra/waterbending/combo/IceBullet.java @@ -1,7 +1,6 @@ package com.projectkorra.projectkorra.waterbending.combo; import java.util.ArrayList; -import java.util.Collection; import java.util.Enumeration; import java.util.List; import java.util.Map; @@ -10,6 +9,7 @@ import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -19,10 +19,11 @@ import org.bukkit.util.Vector; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ability.ComboAbility; -import com.projectkorra.projectkorra.ability.CoreAbility; +import com.projectkorra.projectkorra.ability.ElementalAbility; import com.projectkorra.projectkorra.ability.IceAbility; import com.projectkorra.projectkorra.ability.util.Collision; import com.projectkorra.projectkorra.ability.util.ComboManager.AbilityInformation; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.avatar.AvatarState; import com.projectkorra.projectkorra.firebending.combo.FireComboStream; import com.projectkorra.projectkorra.util.BlockSource; @@ -40,15 +41,22 @@ public class IceBullet extends IceAbility implements ComboAbility { private int leftClicks; private int rightClicks; + @Attribute(Attribute.DAMAGE) private double damage; + @Attribute(Attribute.SPEED) private double speed; + @Attribute(Attribute.RANGE) private double range; + @Attribute(Attribute.RADIUS) private double radius; private double shootTime; private double shots; + @Attribute("MaxShots") private double maxShots; private double animationSpeed; + @Attribute(Attribute.COOLDOWN) private long cooldown; + private long shotcooldown; private long time; private String name; private AbilityState state; @@ -74,6 +82,7 @@ public class IceBullet extends IceAbility implements ComboAbility { this.range = getConfig().getDouble("Abilities.Water.IceBullet.Range"); this.radius = getConfig().getDouble("Abilities.Water.IceBullet.Radius"); this.cooldown = getConfig().getLong("Abilities.Water.IceBullet.Cooldown"); + this.shotcooldown = getConfig().getLong("Abilities.Water.IceBullet.ShotCooldown"); this.shootTime = getConfig().getLong("Abilities.Water.IceBullet.ShootTime"); this.maxShots = getConfig().getInt("Abilities.Water.IceBullet.MaxShots"); this.animationSpeed = getConfig().getDouble("Abilities.Water.IceBullet.AnimationSpeed"); @@ -92,7 +101,7 @@ public class IceBullet extends IceAbility implements ComboAbility { this.radius *= aug; if (this.bPlayer.isAvatarState()) { - this.cooldown = 0; + this.cooldown = getConfig().getLong("Abilities.Avatar.AvatarState.Water.IceBullet.Cooldown"); this.damage = AvatarState.getValue(this.damage); this.range = AvatarState.getValue(this.range); this.shootTime = AvatarState.getValue(this.shootTime); @@ -147,34 +156,6 @@ public class IceBullet extends IceAbility implements ComboAbility { return locations; } - public static class IceBulletLeftClick extends IceBullet { - - public IceBulletLeftClick(final Player player) { - super(player); - this.setName("IceBulletLeftClick"); - } - - @Override - public String getName() { - return "IceBullet"; - } - - } - - public static class IceBulletRightClick extends IceBullet { - - public IceBulletRightClick(final Player player) { - super(player); - this.setName("IceBulletRightClick"); - } - - @Override - public String getName() { - return "IceBullet"; - } - - } - public void manageShots() { for (int i = 0; i < this.tasks.size(); i++) { if (((FireComboStream) this.tasks.get(i)).isCancelled()) { @@ -211,18 +192,18 @@ public class IceBullet extends IceAbility implements ComboAbility { } public void createBlock(final Block block, final Material mat) { - this.createBlock(block, mat, (byte) 0); + this.createBlock(block, mat, mat.createBlockData()); } - public void createBlock(final Block block, final Material mat, final byte data) { + public void createBlock(final Block block, final Material mat, final BlockData data) { this.affectedBlocks.put(block, new TempBlock(block, mat, data)); } public void drawWaterCircle(final Location loc, final double theta, final double increment, final double radius) { - this.drawWaterCircle(loc, theta, increment, radius, Material.STATIONARY_WATER, (byte) 0); + this.drawWaterCircle(loc, theta, increment, radius, Material.WATER, GeneralMethods.getWaterData(0)); } - public void drawWaterCircle(final Location loc, final double theta, final double increment, final double radius, final Material mat, final byte data) { + public void drawWaterCircle(final Location loc, final double theta, final double increment, final double radius, final Material mat, final BlockData data) { final double rotateSpeed = theta; this.direction = GeneralMethods.rotateXZ(this.direction, rotateSpeed); @@ -232,7 +213,7 @@ public class IceBullet extends IceAbility implements ComboAbility { final Block block = loc.clone().add(dir).getBlock(); this.location = block.getLocation(); - if (block.getType() == Material.AIR && !GeneralMethods.isRegionProtectedFromBuild(this.player, "WaterManipulation", block.getLocation())) { + if (ElementalAbility.isAir(block.getType()) && !GeneralMethods.isRegionProtectedFromBuild(this.player, "WaterManipulation", block.getLocation())) { this.createBlock(block, mat, data); } } @@ -250,30 +231,13 @@ public class IceBullet extends IceAbility implements ComboAbility { return; } - if (this.name.equalsIgnoreCase("IceBulletLeftClick") || this.name.equalsIgnoreCase("IceBulletRightClick")) { - final Collection bullets = CoreAbility.getAbilities(this.player, IceBullet.class); - if (bullets.size() == 0) { - return; - } - for (final IceBullet bullet : bullets) { - if (this.name.equalsIgnoreCase("IceBulletLeftClick")) { - if (bullet.leftClicks <= bullet.rightClicks) { - bullet.leftClicks += 1; - } - } else if (bullet.leftClicks >= bullet.rightClicks) { - bullet.rightClicks += 1; - } - } - return; - } - if (this.origin == null) { - if (this.bPlayer.isOnCooldown("IceBullet") && !this.bPlayer.isAvatarState()) { + if (this.bPlayer.isOnCooldown("IceBullet")) { this.remove(); return; } - final Block waterBlock = BlockSource.getWaterSourceBlock(this.player, this.range, ClickType.LEFT_CLICK, true, true, this.bPlayer.canPlantbend()); + final Block waterBlock = BlockSource.getWaterSourceBlock(this.player, this.range, ClickType.SHIFT_DOWN, true, true, this.bPlayer.canPlantbend()); if (waterBlock == null) { this.remove(); return; @@ -283,7 +247,6 @@ public class IceBullet extends IceAbility implements ComboAbility { this.origin = waterBlock.getLocation(); this.location = this.origin.clone(); this.state = AbilityState.ICE_BULLET_FORMING; - this.bPlayer.addCooldown("IceBullet", this.cooldown); this.direction = new Vector(1, 0, 1); this.waterGrabber = new WaterSourceGrabber(this.player, this.origin.clone()); } else if (this.waterGrabber.getState() == WaterSourceGrabber.AnimationState.FAILED) { @@ -306,13 +269,21 @@ public class IceBullet extends IceAbility implements ComboAbility { } else if (timeDiff < 2500 * this.animationSpeed) { this.revertBlocks(); for (double i = 0; i < this.radius; i++) { - this.drawWaterCircle(this.player.getEyeLocation().clone().add(0, i, 0), 360, 5, this.radius - i, Material.ICE, (byte) 0); - this.drawWaterCircle(this.player.getEyeLocation().clone().add(0, -i, 0), 360, 5, this.radius - i, Material.ICE, (byte) 0); + this.drawWaterCircle(this.player.getEyeLocation().clone().add(0, i, 0), 360, 5, this.radius - i, Material.ICE, Material.ICE.createBlockData()); + this.drawWaterCircle(this.player.getEyeLocation().clone().add(0, -i, 0), 360, 5, this.radius - i, Material.ICE, Material.ICE.createBlockData()); } } if (timeDiff < this.shootTime) { - if (this.shots < this.rightClicks + this.leftClicks) { + if (this.rightClicks > 0 || this.leftClicks > 0) { + if (this.leftClicks > 0) { + this.leftClicks = 0; + this.bPlayer.addCooldown("IceBullet Left", this.shotcooldown); + } else if (this.rightClicks > 0) { + this.rightClicks = 0; + this.bPlayer.addCooldown("IceBullet Right", this.shotcooldown); + } + this.shots++; final Vector vec = this.player.getEyeLocation().getDirection().normalize(); final Location loc = this.player.getEyeLocation().add(vec.clone().multiply(this.radius + 1.3)); @@ -337,6 +308,20 @@ public class IceBullet extends IceAbility implements ComboAbility { } } + public void doLeftClick() { + if (this.bPlayer.isOnCooldown("IceBullet Left")) { + return; + } + this.leftClicks++; + } + + public void doRightClick() { + if (this.bPlayer.isOnCooldown("IceBullet Right")) { + return; + } + this.rightClicks++; + } + @Override public boolean isSneakAbility() { return true; @@ -538,9 +523,4 @@ public class IceBullet extends IceAbility implements ComboAbility { public void setName(final String name) { this.name = name; } - - @Override - public String getInstructions() { - return "WaterBubble (Tap Shift) > IceBlast (Hold Shift) > Wait for ice to Form > Then alternate between Left and Right click with IceBlast"; - } } diff --git a/src/com/projectkorra/projectkorra/waterbending/combo/IceWave.java b/src/com/projectkorra/projectkorra/waterbending/combo/IceWave.java index 9a4d245d..ef29923d 100644 --- a/src/com/projectkorra/projectkorra/waterbending/combo/IceWave.java +++ b/src/com/projectkorra/projectkorra/waterbending/combo/IceWave.java @@ -11,6 +11,7 @@ import org.bukkit.entity.Player; import com.projectkorra.projectkorra.ability.ComboAbility; import com.projectkorra.projectkorra.ability.IceAbility; import com.projectkorra.projectkorra.ability.util.ComboManager.AbilityInformation; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.util.ClickType; import com.projectkorra.projectkorra.util.TempBlock; import com.projectkorra.projectkorra.waterbending.WaterSpoutWave; @@ -19,6 +20,7 @@ public class IceWave extends IceAbility implements ComboAbility { private static final Map FROZEN_BLOCKS = new ConcurrentHashMap<>(); + @Attribute(Attribute.COOLDOWN) private long cooldown; private Location origin; @@ -123,9 +125,4 @@ public class IceWave extends IceAbility implements ComboAbility { iceWave.add(new AbilityInformation("PhaseChange", ClickType.LEFT_CLICK)); return iceWave; } - - @Override - public String getInstructions() { - return "Create a WaterSpout Wave > PhaseChange (Left Click)"; - } } diff --git a/src/com/projectkorra/projectkorra/waterbending/healing/HealingWaters.java b/src/com/projectkorra/projectkorra/waterbending/healing/HealingWaters.java index d819e221..d9328624 100644 --- a/src/com/projectkorra/projectkorra/waterbending/healing/HealingWaters.java +++ b/src/com/projectkorra/projectkorra/waterbending/healing/HealingWaters.java @@ -18,6 +18,7 @@ import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.AirAbility; import com.projectkorra.projectkorra.ability.ElementalAbility; import com.projectkorra.projectkorra.ability.HealingAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.chiblocking.Smokescreen; import com.projectkorra.projectkorra.util.TempBlock; import com.projectkorra.projectkorra.waterbending.util.WaterReturn; @@ -25,12 +26,16 @@ import com.projectkorra.projectkorra.waterbending.util.WaterReturn; public class HealingWaters extends HealingAbility { // Configurable Variables. + @Attribute(Attribute.COOLDOWN) private long cooldown; + @Attribute(Attribute.RANGE) private double range; private long interval; + @Attribute(Attribute.CHARGE_DURATION) private long chargeTime; - private int power; - private int potDuration; + @Attribute("PotionPotency") + private int potionPotency; + @Attribute(Attribute.DURATION) private long duration; private boolean enableParticles; @@ -76,8 +81,7 @@ public class HealingWaters extends HealingAbility { this.range = getConfig().getDouble("Abilities.Water.HealingWaters.Range"); this.interval = getConfig().getLong("Abilities.Water.HealingWaters.Interval"); this.chargeTime = getConfig().getLong("Abilities.Water.HealingWaters.ChargeTime"); - this.power = getConfig().getInt("Abilities.Water.HealingWaters.Power"); - this.potDuration = getConfig().getInt("Abilities.Water.HealingWaters.HealingDuration"); + this.potionPotency = getConfig().getInt("Abilities.Water.HealingWaters.PotionPotency"); this.duration = getConfig().getLong("Abilities.Water.HealingWaters.Duration"); this.enableParticles = getConfig().getBoolean("Abilities.Water.HealingWaters.EnableParticles"); this.hex = "00ffff"; @@ -122,7 +126,7 @@ public class HealingWaters extends HealingAbility { WaterReturn.emptyWaterBottle(this.player); } } else { - GeneralMethods.displayColoredParticle(this.origin, this.hex); + GeneralMethods.displayColoredParticle(this.hex, this.origin); } // If the ability is charged, try healing. @@ -210,7 +214,7 @@ public class HealingWaters extends HealingAbility { private void applyHealing(final Player player) { if (!GeneralMethods.isRegionProtectedFromBuild(player, "HealingWaters", player.getLocation())) { - player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, this.potDuration, this.power)); + player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 30, this.potionPotency)); AirAbility.breakBreathbendingHold(player); this.healing = true; this.healingSelf = true; @@ -219,7 +223,7 @@ public class HealingWaters extends HealingAbility { private void applyHealing(final LivingEntity livingEntity) { if (livingEntity.getHealth() < livingEntity.getMaxHealth()) { - livingEntity.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, this.potDuration, this.power)); + livingEntity.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 30, this.potionPotency)); AirAbility.breakBreathbendingHold(livingEntity); this.healing = true; this.healingSelf = false; @@ -238,7 +242,7 @@ public class HealingWaters extends HealingAbility { final double angle = this.pstage * increment; final double x = centre.getX() + (0.75 * Math.cos(angle)); final double z = centre.getZ() + (0.75 * Math.sin(angle)); - GeneralMethods.displayColoredParticle(new Location(centre.getWorld(), x, centre.getY(), z), this.hex); + GeneralMethods.displayColoredParticle(this.hex, new Location(centre.getWorld(), x, centre.getY(), z)); if (this.pstage >= 36) { this.pstage = 0; @@ -259,8 +263,8 @@ public class HealingWaters extends HealingAbility { final double x2 = centre.getX() + (0.75 * Math.cos(angle2)); final double z2 = centre.getZ() + (0.75 * Math.sin(angle2)); - GeneralMethods.displayColoredParticle(new Location(centre.getWorld(), x1, centre.getY() + (0.75 * Math.cos(angle1)), z1), this.hex); - GeneralMethods.displayColoredParticle(new Location(centre.getWorld(), x2, centre.getY() + (0.75 * -Math.cos(angle2)), z2), this.hex); + GeneralMethods.displayColoredParticle(this.hex, new Location(centre.getWorld(), x1, centre.getY() + (0.75 * Math.cos(angle1)), z1)); + GeneralMethods.displayColoredParticle(this.hex, new Location(centre.getWorld(), x2, centre.getY() + (0.75 * -Math.cos(angle2)), z2)); if (this.tstage1 >= 36) { this.tstage1 = 0; @@ -295,7 +299,7 @@ public class HealingWaters extends HealingAbility { } } - GeneralMethods.displayColoredParticle(this.location, this.hex); + GeneralMethods.displayColoredParticle(this.hex, this.location); } private void fillBottle() { @@ -304,12 +308,14 @@ public class HealingWaters extends HealingAbility { final int index = inventory.first(Material.GLASS_BOTTLE); final ItemStack item = inventory.getItem(index); + final ItemStack water = WaterReturn.waterBottleItem(); + if (item.getAmount() == 1) { - inventory.setItem(index, new ItemStack(Material.POTION)); + inventory.setItem(index, water); } else { item.setAmount(item.getAmount() - 1); inventory.setItem(index, item); - final HashMap leftover = inventory.addItem(new ItemStack(Material.POTION)); + final HashMap leftover = inventory.addItem(water); for (final int left : leftover.keySet()) { this.player.getWorld().dropItemNaturally(this.player.getLocation(), leftover.get(left)); } diff --git a/src/com/projectkorra/projectkorra/waterbending/ice/IceBlast.java b/src/com/projectkorra/projectkorra/waterbending/ice/IceBlast.java index 20278159..cefee2f2 100644 --- a/src/com/projectkorra/projectkorra/waterbending/ice/IceBlast.java +++ b/src/com/projectkorra/projectkorra/waterbending/ice/IceBlast.java @@ -10,6 +10,7 @@ import org.bukkit.block.Block; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; @@ -18,6 +19,7 @@ import com.projectkorra.projectkorra.BendingPlayer; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.AirAbility; import com.projectkorra.projectkorra.ability.IceAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.util.BlockSource; import com.projectkorra.projectkorra.util.ClickType; import com.projectkorra.projectkorra.util.DamageHandler; @@ -33,16 +35,21 @@ public class IceBlast extends IceAbility { private boolean progressing; private byte data; private long time; + @Attribute(Attribute.COOLDOWN) private long cooldown; private long interval; + @Attribute(Attribute.RANGE) private double range; + @Attribute(Attribute.DAMAGE) private double damage; private double collisionRadius; + @Attribute("Deflect" + Attribute.RANGE) private double deflectRange; private Block sourceBlock; private Location location; private Location firstDestination; private Location destination; + private boolean allowSnow; public TempBlock source; public IceBlast(final Player player) { @@ -55,6 +62,7 @@ public class IceBlast extends IceAbility { this.range = getConfig().getDouble("Abilities.Water.IceBlast.Range"); this.damage = getConfig().getInt("Abilities.Water.IceBlast.Damage"); this.cooldown = getConfig().getInt("Abilities.Water.IceBlast.Cooldown"); + this.allowSnow = getConfig().getBoolean("Abilities.Water.IceBlast.AllowSnow"); this.damage = getNightFactor(this.damage, player.getWorld()); @@ -63,14 +71,14 @@ public class IceBlast extends IceAbility { } if (this.bPlayer.isAvatarState()) { - this.cooldown = 0; + this.cooldown = getConfig().getLong("Abilities.Avatar.AvatarState.Water.IceBlast.Cooldown"); this.range = getConfig().getDouble("Abilities.Avatar.AvatarState.Water.IceBlast.Range"); this.damage = getConfig().getInt("Abilities.Avatar.AvatarState.Water.IceBlast.Damage"); } block(player); this.range = getNightFactor(this.range, player.getWorld()); - final Block sourceBlock = BlockSource.getWaterSourceBlock(player, this.range, ClickType.SHIFT_DOWN, false, true, false, false, false); + final Block sourceBlock = BlockSource.getWaterSourceBlock(player, this.range, ClickType.SHIFT_DOWN, false, true, false, this.allowSnow, false); final IceBlast oldAbil = getAbility(player, IceBlast.class); if (oldAbil != null) { oldAbil.setSourceBlock(sourceBlock == null ? oldAbil.getSourceBlock() : sourceBlock); @@ -174,7 +182,7 @@ public class IceBlast extends IceAbility { AirAbility.breakBreathbendingHold(entity); for (int x = 0; x < 30; x++) { - ParticleEffect.ITEM_CRACK.display(new ParticleEffect.ItemData(Material.ICE, (byte) 0), new Vector(((Math.random() - 0.5) * .5), ((Math.random() - 0.5) * .5), ((Math.random() - 0.5) * .5)), .3f, this.location, 255.0); + ParticleEffect.ITEM_CRACK.display(this.location, 5, Math.random() / 4, Math.random() / 4, Math.random() / 4, new ItemStack(Material.ICE)); } } @@ -208,11 +216,11 @@ public class IceBlast extends IceAbility { this.prepared = false; if (TempBlock.isTempBlock(this.sourceBlock)) { - TempBlock.get(this.sourceBlock).setType(Material.PACKED_ICE, this.data); + TempBlock.get(this.sourceBlock).setType(Material.PACKED_ICE); this.source = TempBlock.get(this.sourceBlock); } else { - new TempBlock(this.sourceBlock, Material.AIR, (byte) 0); - this.source = new TempBlock(this.sourceBlock, Material.PACKED_ICE, this.data); + new TempBlock(this.sourceBlock, Material.AIR); + this.source = new TempBlock(this.sourceBlock, Material.PACKED_ICE); } } @@ -302,15 +310,15 @@ public class IceBlast extends IceAbility { this.sourceBlock = block; if (TempBlock.isTempBlock(this.sourceBlock)) { - TempBlock.get(this.sourceBlock).setType(Material.PACKED_ICE, this.data); + TempBlock.get(this.sourceBlock).setType(Material.PACKED_ICE); this.source = TempBlock.get(this.sourceBlock); } else { - this.source = new TempBlock(this.sourceBlock, Material.PACKED_ICE, this.data); + this.source = new TempBlock(this.sourceBlock, Material.PACKED_ICE); } for (int x = 0; x < 10; x++) { - ParticleEffect.ITEM_CRACK.display(new ParticleEffect.ItemData(Material.ICE, (byte) 0), new Vector(((Math.random() - 0.5) * .5), ((Math.random() - 0.5) * .5), ((Math.random() - 0.5) * .5)), .5f, this.location, 255.0); - ParticleEffect.SNOW_SHOVEL.display(this.location, (float) (Math.random() - 0.5), (float) (Math.random() - 0.5), (float) (Math.random() - 0.5), 0, 5); + ParticleEffect.ITEM_CRACK.display(this.location, 5, Math.random() / 2, Math.random() / 2, Math.random() / 2, new ItemStack(Material.ICE)); + ParticleEffect.SNOW_SHOVEL.display(this.location, 5, Math.random() / 2, Math.random() / 2, Math.random() / 2, 0); } if ((new Random()).nextInt(4) == 0) { playIcebendingSound(this.location); @@ -323,8 +331,8 @@ public class IceBlast extends IceAbility { public void breakParticles(final int amount) { for (int x = 0; x < amount; x++) { - ParticleEffect.ITEM_CRACK.display(new ParticleEffect.ItemData(Material.ICE, (byte) 0), new Vector(((Math.random() - 0.5) * .5), ((Math.random() - 0.5) * .5), ((Math.random() - 0.5) * .5)), 2f, this.location, 255.0); - ParticleEffect.SNOW_SHOVEL.display(this.location, (float) Math.random(), (float) Math.random(), (float) Math.random(), 0, 2); + ParticleEffect.ITEM_CRACK.display(this.location, 2, Math.random(), Math.random(), Math.random(), new ItemStack(Material.ICE)); + ParticleEffect.SNOW_SHOVEL.display(this.location, 2, Math.random(), Math.random(), Math.random(), 0); } this.location.getWorld().playSound(this.location, Sound.BLOCK_GLASS_BREAK, 5, 1.3f); } diff --git a/src/com/projectkorra/projectkorra/waterbending/ice/IceSpikeBlast.java b/src/com/projectkorra/projectkorra/waterbending/ice/IceSpikeBlast.java index 74afcecf..29eea0e4 100644 --- a/src/com/projectkorra/projectkorra/waterbending/ice/IceSpikeBlast.java +++ b/src/com/projectkorra/projectkorra/waterbending/ice/IceSpikeBlast.java @@ -5,10 +5,10 @@ import java.util.Random; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.BlockState; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; -import org.bukkit.material.MaterialData; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; @@ -17,6 +17,7 @@ import com.projectkorra.projectkorra.BendingPlayer; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.AirAbility; import com.projectkorra.projectkorra.ability.IceAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.util.DamageHandler; import com.projectkorra.projectkorra.util.TempBlock; import com.projectkorra.projectkorra.util.TempPotionEffect; @@ -29,21 +30,29 @@ public class IceSpikeBlast extends IceAbility { private boolean settingUp; private boolean progressing; private byte data; - private int slowPower; + @Attribute("SlowPotency") + private int slowPotency; + @Attribute("Slow" + Attribute.DURATION) private int slowDuration; private long time; private long interval; + @Attribute(Attribute.COOLDOWN) private long cooldown; + @Attribute("Slow" + Attribute.COOLDOWN) private long slowCooldown; + @Attribute(Attribute.RANGE) private double range; + @Attribute(Attribute.DAMAGE) private double damage; private double collisionRadius; + @Attribute("Deflect" + Attribute.RANGE) private double deflectRange; private Block sourceBlock; private Location location; private Location firstDestination; private Location destination; private TempBlock source; + private Material sourceType; public IceSpikeBlast(final Player player) { super(player); @@ -60,7 +69,7 @@ public class IceSpikeBlast extends IceAbility { this.range = getConfig().getDouble("Abilities.Water.IceSpike.Blast.Range"); this.damage = getConfig().getDouble("Abilities.Water.IceSpike.Blast.Damage"); this.cooldown = getConfig().getLong("Abilities.Water.IceSpike.Blast.Cooldown"); - this.slowPower = getConfig().getInt("Abilities.Water.IceSpike.Blast.SlowPower"); + this.slowPotency = getConfig().getInt("Abilities.Water.IceSpike.Blast.SlowPotency"); this.slowDuration = getConfig().getInt("Abilities.Water.IceSpike.Blast.SlowDuration"); if (!this.bPlayer.canBend(this) || !this.bPlayer.canIcebend()) { @@ -72,14 +81,14 @@ public class IceSpikeBlast extends IceAbility { this.slowCooldown = 0; this.range = getConfig().getDouble("Abilities.Avatar.AvatarState.Water.IceSpike.Blast.Range"); this.damage = getConfig().getDouble("Abilities.Avatar.AvatarState.Water.IceSpike.Blast.Damage"); - this.slowPower = getConfig().getInt("Abilities.Avatar.AvatarState.Water.IceSpike.Blast.SlowPower"); + this.slowPotency = getConfig().getInt("Abilities.Avatar.AvatarState.Water.IceSpike.Blast.SlowPotency"); this.slowDuration = getConfig().getInt("Abilities.Avatar.AvatarState.Water.IceSpike.Blast.SlowDuration"); } block(player); this.range = this.getNightFactor(this.range); this.damage = this.getNightFactor(this.damage); - this.slowPower = (int) this.getNightFactor(this.slowPower); + this.slowPotency = (int) this.getNightFactor(this.slowPotency); this.sourceBlock = getWaterSourceBlock(player, this.range, this.bPlayer.canPlantbend()); if (this.sourceBlock == null) { this.sourceBlock = getIceSourceBlock(player, this.range); @@ -101,13 +110,13 @@ public class IceSpikeBlast extends IceAbility { return; } if (targetBPlayer.canBeSlowed()) { - final PotionEffect effect = new PotionEffect(PotionEffectType.SLOW, this.slowDuration, this.slowPower); + final PotionEffect effect = new PotionEffect(PotionEffectType.SLOW, this.slowDuration, this.slowPotency); new TempPotionEffect(entity, effect); targetBPlayer.slow(this.slowCooldown); DamageHandler.damageEntity(entity, this.damage, this); } } else { - final PotionEffect effect = new PotionEffect(PotionEffectType.SLOW, this.slowDuration, this.slowPower); + final PotionEffect effect = new PotionEffect(PotionEffectType.SLOW, this.slowDuration, this.slowPotency); new TempPotionEffect(entity, effect); DamageHandler.damageEntity(entity, this.damage, this); } @@ -122,6 +131,11 @@ public class IceSpikeBlast extends IceAbility { } this.sourceBlock = block; + if (!isIce(block)) { + this.sourceType = Material.ICE; + } else { + this.sourceType = block.getType(); + } this.location = this.sourceBlock.getLocation(); this.prepared = true; this.start(); @@ -175,8 +189,6 @@ public class IceSpikeBlast extends IceAbility { return; } - this.source = null; - if (isTransparent(this.player, block) && !block.isLiquid()) { GeneralMethods.breakBlock(block); } else if (!isWater(block)) { @@ -191,7 +203,7 @@ public class IceSpikeBlast extends IceAbility { return; } - for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(this.location, this.collisionRadius)) { + for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(this.location, this.collisionRadius + 0.5)) { if (entity.getEntityId() != this.player.getEntityId() && entity instanceof LivingEntity) { this.affect((LivingEntity) entity); this.progressing = false; @@ -209,8 +221,8 @@ public class IceSpikeBlast extends IceAbility { } this.sourceBlock = block; - this.source = new TempBlock(this.sourceBlock, Material.ICE, this.data); - this.source.setRevertTime(140); + this.source = new TempBlock(this.sourceBlock, this.sourceType); + this.source.setRevertTime(130); } else if (this.prepared) { if (this.sourceBlock != null) { playFocusWaterEffect(this.sourceBlock); @@ -226,12 +238,10 @@ public class IceSpikeBlast extends IceAbility { @Override public void remove() { super.remove(); - if (this.progressing) { - if (this.source != null) { - this.source.revertBlock(); - } - this.progressing = false; + if (this.source != null) { + this.source.revertBlock(); } + this.progressing = false; } private void returnWater() { @@ -245,9 +255,9 @@ public class IceSpikeBlast extends IceAbility { final LivingEntity target = (LivingEntity) GeneralMethods.getTargetedEntity(this.player, this.range); if (target == null) { - this.destination = GeneralMethods.getTargetedLocation(this.player, this.range, getTransparentMaterials()); + this.destination = GeneralMethods.getTargetedLocation(this.player, this.range, true, getTransparentMaterials()); } else { - this.destination = target.getEyeLocation(); + this.destination = target.getLocation(); } if (this.sourceBlock == null) { @@ -273,8 +283,16 @@ public class IceSpikeBlast extends IceAbility { if (isPlant(this.sourceBlock) || isSnow(this.sourceBlock)) { new PlantRegrowth(this.player, this.sourceBlock); this.sourceBlock.setType(Material.AIR); + } else if (isWater(this.sourceBlock)) { + if (!GeneralMethods.isAdjacentToThreeOrMoreSources(this.sourceBlock)) { + this.sourceBlock.setType(Material.AIR); + } + } else if (TempBlock.isTempBlock(this.sourceBlock)) { + final TempBlock tb = TempBlock.get(this.sourceBlock); + if (isBendableWaterTempBlock(tb)) { + tb.revertBlock(); + } } - } public static void activate(final Player player) { @@ -358,7 +376,7 @@ public class IceSpikeBlast extends IceAbility { Location loc; final Entity target = GeneralMethods.getTargetedEntity(player, iceSpike.range); if (target == null) { - loc = GeneralMethods.getTargetedLocation(player, iceSpike.range); + loc = GeneralMethods.getTargetedLocation(player, iceSpike.range, true); } else { loc = ((LivingEntity) target).getEyeLocation(); } @@ -390,9 +408,9 @@ public class IceSpikeBlast extends IceAbility { return; } - final MaterialData data = block.getState().getData(); + final BlockState state = block.getState(); block.setType(Material.WATER); - block.setData((byte) 0); + block.setBlockData(GeneralMethods.getWaterData(0)); final IceSpikeBlast iceSpike = new IceSpikeBlast(player); iceSpike.throwIce(); iceSpike.sourceBlock = null; @@ -400,8 +418,8 @@ public class IceSpikeBlast extends IceAbility { if (iceSpike.progressing) { WaterReturn.emptyWaterBottle(player); } - block.setType(data.getItemType()); - block.setData(data.getData()); + block.setType(state.getType()); + block.setBlockData(state.getBlockData()); } } @@ -479,12 +497,12 @@ public class IceSpikeBlast extends IceAbility { this.data = data; } - public int getSlowPower() { - return this.slowPower; + public int getSlowPotency() { + return this.slowPotency; } - public void setSlowPower(final int slowPower) { - this.slowPower = slowPower; + public void setSlowPotency(final int slowPotency) { + this.slowPotency = slowPotency; } public int getSlowDuration() { diff --git a/src/com/projectkorra/projectkorra/waterbending/ice/IceSpikePillar.java b/src/com/projectkorra/projectkorra/waterbending/ice/IceSpikePillar.java index 4ba2a257..55a497fc 100644 --- a/src/com/projectkorra/projectkorra/waterbending/ice/IceSpikePillar.java +++ b/src/com/projectkorra/projectkorra/waterbending/ice/IceSpikePillar.java @@ -18,8 +18,10 @@ import org.bukkit.util.Vector; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.AirAbility; +import com.projectkorra.projectkorra.ability.ElementalAbility; import com.projectkorra.projectkorra.ability.IceAbility; import com.projectkorra.projectkorra.ability.WaterAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.util.DamageHandler; import com.projectkorra.projectkorra.util.TempBlock; import com.projectkorra.projectkorra.util.TempPotionEffect; @@ -29,18 +31,27 @@ public class IceSpikePillar extends IceAbility { /** The list of blocks IceSpike uses */ private final Map ice_blocks = new HashMap(); + @Attribute(Attribute.HEIGHT) private int height; private int progress; + @Attribute("SlowPotency") private int slowPower; + @Attribute("Slow" + Attribute.DURATION) private int slowDuration; + @Attribute(Attribute.COOLDOWN) private long cooldown; private long time; private long removeTimestamp; - private long removeTimer; + @Attribute(Attribute.DURATION) + private long duration; private long interval; + @Attribute("Slow" + Attribute.COOLDOWN) private long slowCooldown; + @Attribute(Attribute.DAMAGE) private double damage; + @Attribute(Attribute.RANGE) private double range; + @Attribute(Attribute.SPEED) private double speed; private Block source_block; // The block clicked on. private Block base_block; // The block at the bottom of the pillar. @@ -86,8 +97,7 @@ public class IceSpikePillar extends IceAbility { } this.origin = this.source_block.getLocation(); this.location = this.origin.clone(); - } - catch (final IllegalStateException e) { + } catch (final IllegalStateException e) { return; } @@ -174,7 +184,7 @@ public class IceSpikePillar extends IceAbility { Block b; for (int i = 1; i <= this.height; i++) { b = this.source_block.getWorld().getBlockAt(this.location.clone().add(this.direction.clone().multiply(i))); - if (b.getType() != Material.AIR) { + if (!ElementalAbility.isAir(b.getType())) { return false; } @@ -194,7 +204,7 @@ public class IceSpikePillar extends IceAbility { this.removeTimestamp = System.currentTimeMillis(); } else { // If it's time to remove. - if (this.removeTimestamp != 0 && this.removeTimestamp + this.removeTimer <= System.currentTimeMillis()) { + if (this.removeTimestamp != 0 && this.removeTimestamp + this.duration <= System.currentTimeMillis()) { if (!this.sinkPillar()) { this.remove(); return; @@ -225,7 +235,7 @@ public class IceSpikePillar extends IceAbility { } } - final TempBlock b = new TempBlock(affectedBlock, Material.ICE, (byte) 0); + final TempBlock b = new TempBlock(affectedBlock, Material.ICE); this.ice_blocks.put(affectedBlock, b); if (!this.inField || new Random().nextInt((int) ((this.height + 1) * 1.5)) == 0) { @@ -344,12 +354,12 @@ public class IceSpikePillar extends IceAbility { this.removeTimestamp = removeTimestamp; } - public long getRemoveTimer() { - return this.removeTimer; + public long getDuration() { + return this.duration; } - public void setRemoveTimer(final long removeTimer) { - this.removeTimer = removeTimer; + public void setDuration(final long duration) { + this.duration = duration; } public long getInterval() { diff --git a/src/com/projectkorra/projectkorra/waterbending/ice/IceSpikePillarField.java b/src/com/projectkorra/projectkorra/waterbending/ice/IceSpikePillarField.java index 62275845..bed947b3 100644 --- a/src/com/projectkorra/projectkorra/waterbending/ice/IceSpikePillarField.java +++ b/src/com/projectkorra/projectkorra/waterbending/ice/IceSpikePillarField.java @@ -14,16 +14,24 @@ import org.bukkit.entity.Player; import org.bukkit.util.Vector; import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.ability.ElementalAbility; import com.projectkorra.projectkorra.ability.IceAbility; import com.projectkorra.projectkorra.ability.WaterAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.util.TempBlock; public class IceSpikePillarField extends IceAbility { + @Attribute(Attribute.DAMAGE) private double damage; + @Attribute(Attribute.RADIUS) private double radius; + @Attribute("NumberOfSpikes") private int numberOfSpikes; + @Attribute(Attribute.COOLDOWN) private long cooldown; + @Attribute(Attribute.KNOCKUP) + private double knockup; private Vector thrownForce; public IceSpikePillarField(final Player player) { @@ -36,28 +44,37 @@ public class IceSpikePillarField extends IceAbility { this.damage = getConfig().getDouble("Abilities.Water.IceSpike.Field.Damage"); this.radius = getConfig().getDouble("Abilities.Water.IceSpike.Field.Radius"); this.cooldown = getConfig().getLong("Abilities.Water.IceSpike.Field.Cooldown"); - this.thrownForce = new Vector(0, getConfig().getDouble("Abilities.Water.IceSpike.Field.Push"), 0); + this.knockup = getConfig().getDouble("Abilities.Water.IceSpike.Field.Knockup"); if (this.bPlayer.isAvatarState()) { this.damage = getConfig().getDouble("Abilities.Avatar.AvatarState.Water.IceSpike.Field.Damage"); this.radius = getConfig().getDouble("Abilities.Avatar.AvatarState.Water.IceSpike.Field.Radius"); - this.thrownForce = new Vector(0, getConfig().getDouble("Abilities.Avatar.AvatarState.Water.IceSpike.Field.Push"), 0); } - this.numberOfSpikes = (int) (((this.radius * 2) * (this.radius * 2)) / 16); + this.numberOfSpikes = (int) (((this.radius) * (this.radius)) / 4); + this.start(); + } + @Override + public String getName() { + return "IceSpike"; + } + + @Override + public void progress() { + this.thrownForce = new Vector(0, this.knockup, 0); final Random random = new Random(); - final int locX = player.getLocation().getBlockX(); - final int locY = player.getLocation().getBlockY(); - final int locZ = player.getLocation().getBlockZ(); + final int locX = this.player.getLocation().getBlockX(); + final int locY = this.player.getLocation().getBlockY(); + final int locZ = this.player.getLocation().getBlockZ(); final List iceBlocks = new ArrayList(); for (int x = (int) -(this.radius - 1); x <= (this.radius - 1); x++) { for (int z = (int) -(this.radius - 1); z <= (this.radius - 1); z++) { for (int y = -1; y <= 1; y++) { - final Block testBlock = player.getWorld().getBlockAt(locX + x, locY + y, locZ + z); + final Block testBlock = this.player.getWorld().getBlockAt(locX + x, locY + y, locZ + z); - if (WaterAbility.isIcebendable(player, testBlock.getType(), false) && testBlock.getRelative(BlockFace.UP).getType() == Material.AIR && !(testBlock.getX() == player.getEyeLocation().getBlock().getX() && testBlock.getZ() == player.getEyeLocation().getBlock().getZ()) || (TempBlock.isTempBlock(testBlock) && WaterAbility.isBendableWaterTempBlock(testBlock))) { + if (((WaterAbility.isIcebendable(this.player, testBlock.getType(), false) && !TempBlock.isTempBlock(testBlock)) || (TempBlock.isTempBlock(testBlock) && WaterAbility.isBendableWaterTempBlock(testBlock))) && ElementalAbility.isAir(testBlock.getRelative(BlockFace.UP).getType()) && !(testBlock.getX() == this.player.getEyeLocation().getBlock().getX() && testBlock.getZ() == this.player.getEyeLocation().getBlock().getZ())) { iceBlocks.add(testBlock); for (int i = 0; i < iceBlocks.size() / 2 + 1; i++) { final Random rand = new Random(); @@ -70,16 +87,18 @@ public class IceSpikePillarField extends IceAbility { } } - final List entities = GeneralMethods.getEntitiesAroundPoint(player.getLocation(), this.radius); - for (int i = 0; i < this.numberOfSpikes; i++) { + int pillars; + + final List entities = GeneralMethods.getEntitiesAroundPoint(this.player.getLocation(), this.radius); + for (pillars = 0; pillars < this.numberOfSpikes; pillars++) { if (iceBlocks.isEmpty()) { - return; + break; } Entity target = null; Block targetBlock = null; for (final Entity entity : entities) { - if (entity instanceof LivingEntity && entity.getEntityId() != player.getEntityId()) { + if (entity instanceof LivingEntity && entity.getEntityId() != this.player.getEntityId()) { for (final Block block : iceBlocks) { if (block.getX() == entity.getLocation().getBlockX() && block.getZ() == entity.getLocation().getBlockZ()) { target = entity; @@ -99,22 +118,18 @@ public class IceSpikePillarField extends IceAbility { } if (targetBlock.getRelative(BlockFace.UP).getType() != Material.ICE) { - - final IceSpikePillar pillar = new IceSpikePillar(player, targetBlock.getLocation(), (int) this.damage, this.thrownForce, this.cooldown); + final IceSpikePillar pillar = new IceSpikePillar(this.player, targetBlock.getLocation(), (int) this.damage, this.thrownForce, this.cooldown); pillar.inField = true; - this.bPlayer.addCooldown("IceSpikePillarField", this.cooldown); iceBlocks.remove(targetBlock); + } else { + pillars--; } } - } - @Override - public String getName() { - return "IceSpike"; - } - - @Override - public void progress() { + if (pillars > 0) { + this.bPlayer.addCooldown("IceSpikePillarField", this.cooldown); + } + this.remove(); } @Override diff --git a/src/com/projectkorra/projectkorra/waterbending/ice/PhaseChange.java b/src/com/projectkorra/projectkorra/waterbending/ice/PhaseChange.java index b17d074f..2fa55db1 100644 --- a/src/com/projectkorra/projectkorra/waterbending/ice/PhaseChange.java +++ b/src/com/projectkorra/projectkorra/waterbending/ice/PhaseChange.java @@ -11,11 +11,14 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.block.data.type.Snow; import org.bukkit.entity.Player; import org.bukkit.util.Vector; import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.ability.ElementalAbility; import com.projectkorra.projectkorra.ability.IceAbility; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.util.TempBlock; import com.projectkorra.projectkorra.waterbending.SurgeWall; import com.projectkorra.projectkorra.waterbending.SurgeWave; @@ -46,19 +49,27 @@ public class PhaseChange extends IceAbility { private final CopyOnWriteArrayList blocks = new CopyOnWriteArrayList<>(); private final Random r = new Random(); + @Attribute(Attribute.SELECT_RANGE) private int sourceRange = 8; // Freeze Variables. + @Attribute("Freeze" + Attribute.COOLDOWN) private long freezeCooldown = 500; + @Attribute("Freeze" + Attribute.RADIUS) private int freezeRadius = 3; + @Attribute("FreezeDepth") private int depth = 1; + @Attribute("Control" + Attribute.RADIUS) private double controlRadius = 25; // Melt Variables. private Location meltLoc; + @Attribute("Melt" + Attribute.COOLDOWN) private long meltCooldown = 7000; private int meltRadius; + @Attribute("Melt" + Attribute.RADIUS) private int meltMaxRadius = 7; + @Attribute("Melt" + Attribute.SPEED) private double meltSpeed = 8; private double meltTicks = 0; private boolean allowMeltFlow; @@ -145,7 +156,7 @@ public class PhaseChange extends IceAbility { public void setFields(final PhaseChangeType type) { int night = 1; if (isNight(this.player.getWorld())) { - night = (int) Math.round(this.getNightFactor()); + night = (int) Math.round(getNightFactor()); } this.sourceRange = night * getConfig().getInt("Abilities.Water.PhaseChange.SourceRange"); @@ -183,7 +194,7 @@ public class PhaseChange extends IceAbility { return; } - if (this.meltLoc.distance(loc) < 1) { + if (this.meltLoc.getWorld().equals(loc.getWorld()) && this.meltLoc.distance(loc) < 1) { return; } @@ -213,7 +224,7 @@ public class PhaseChange extends IceAbility { final Block b = l.getBlock(); loop: for (int i = 1; i <= this.depth; i++) { for (final BlockFace face : this.getBlockFacesTowardsPlayer(center)) { - if (b.getRelative(face, i).getType() == Material.AIR) { + if (ElementalAbility.isAir(b.getRelative(face, i).getType())) { blocks.add(b); break loop; } @@ -286,7 +297,7 @@ public class PhaseChange extends IceAbility { } } if (tb == null) { - tb = new TempBlock(b, Material.ICE, (byte) 0); + tb = new TempBlock(b, Material.ICE); } this.blocks.add(tb); PLAYER_BY_BLOCK.put(tb, this.player); @@ -364,26 +375,41 @@ public class PhaseChange extends IceAbility { } if (b.getType() == Material.SNOW) { - if (b.getData() == 0) { - tb.revertBlock(); - new TempBlock(b, Material.AIR, (byte) 0).setRevertTime(120 * 1000L); - } else { - final byte data = b.getData(); - tb.revertBlock(); - new TempBlock(b, Material.SNOW, (byte) (data - 1)).setRevertTime(120 * 1000L); + if (b.getBlockData() instanceof Snow) { + final Snow snow = (Snow) b.getBlockData(); + if (snow.getLayers() == snow.getMinimumLayers()) { + tb.revertBlock(); + new TempBlock(b, Material.AIR).setRevertTime(120 * 1000L); + } else { + tb.revertBlock(); + snow.setLayers(snow.getLayers() - 1); + new TempBlock(b, Material.SNOW, snow).setRevertTime(120 * 1000L); + } } } + + if (isIce(tb.getBlock()) && ElementalAbility.isWater(tb.getState().getBlockData().getMaterial())) { + tb.revertBlock(); + } } else if (isWater(b)) { // Figure out what to do here also. } else if (isIce(b)) { - final Material m = this.allowMeltFlow ? Material.WATER : Material.STATIONARY_WATER; - b.setType(m); + if (this.allowMeltFlow) { + b.setType(Material.WATER); + b.setBlockData(GeneralMethods.getWaterData(0)); + } else { + new TempBlock(b, Material.WATER, GeneralMethods.getWaterData(0)); + } this.melted_blocks.add(b); } else if (b.getType() == Material.SNOW_BLOCK || b.getType() == Material.SNOW) { - if (b.getData() == 0) { - new TempBlock(b, Material.AIR, (byte) 0).setRevertTime(120 * 1000L); - } else { - new TempBlock(b, Material.SNOW, (byte) (b.getData() - 1)).setRevertTime(120 * 1000L); + if (b.getBlockData() instanceof Snow) { + final Snow snow = (Snow) b.getBlockData(); + if (snow.getLayers() == snow.getMinimumLayers()) { + new TempBlock(b, Material.AIR).setRevertTime(120 * 1000L); + } else { + snow.setLayers(snow.getLayers() - 1); + new TempBlock(b, Material.SNOW, snow).setRevertTime(120 * 1000L); + } } this.melted_blocks.add(b); @@ -434,12 +460,6 @@ public class PhaseChange extends IceAbility { return PLAYER_BY_BLOCK; } - public static List getFrozenBlocksAsTempBlock() { - final List list = new ArrayList<>(); - list.addAll(PLAYER_BY_BLOCK.keySet()); - return list; - } - public static List getFrozenBlocksAsBlock() { final List list = new ArrayList<>(); for (final TempBlock tb : PLAYER_BY_BLOCK.keySet()) { diff --git a/src/com/projectkorra/projectkorra/waterbending/multiabilities/WaterArms.java b/src/com/projectkorra/projectkorra/waterbending/multiabilities/WaterArms.java index b7855493..da9ab596 100644 --- a/src/com/projectkorra/projectkorra/waterbending/multiabilities/WaterArms.java +++ b/src/com/projectkorra/projectkorra/waterbending/multiabilities/WaterArms.java @@ -1,7 +1,6 @@ package com.projectkorra.projectkorra.waterbending.multiabilities; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -11,13 +10,16 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; import org.bukkit.entity.Player; import com.projectkorra.projectkorra.Element; import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.ability.ElementalAbility; import com.projectkorra.projectkorra.ability.FireAbility; import com.projectkorra.projectkorra.ability.WaterAbility; import com.projectkorra.projectkorra.ability.util.MultiAbilityManager; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.configuration.ConfigManager; import com.projectkorra.projectkorra.firebending.lightning.Lightning; import com.projectkorra.projectkorra.util.DamageHandler; @@ -36,26 +38,34 @@ public class WaterArms extends WaterAbility { RIGHT, LEFT; } - private static final Integer[] UNBREAKABLES = { 7, 10, 11, 49, 54, 90, 119, 120, 130, 146 }; - private boolean cooldownLeft; private boolean cooldownRight; private boolean fullSource; // used to determine whip length in WaterArmsWhip. private boolean leftArmConsumed; private boolean rightArmConsumed; + @Attribute("CanUsePlantSource") private boolean canUsePlantSource; + @Attribute("CanLightningStrikeArms") private boolean lightningEnabled; + @Attribute("LightningOneHitKO") private boolean lightningKill; private int lengthReduction; + @Attribute("InitialLength") private int initLength; + @Attribute(Attribute.SELECT_RANGE) private int sourceGrabRange; + @Attribute("MaxPunches") private int maxPunches; + @Attribute("MaxIceBlasts") private int maxIceBlasts; + @Attribute("MaxUses") private int maxUses; private int selectedSlot; private int freezeSlot; + @Attribute(Attribute.COOLDOWN) private long cooldown; private long lastClickTime; + @Attribute("LightningDamage") private double lightningDamage; private World world; private String sneakMsg; @@ -159,7 +169,7 @@ public class WaterArms extends WaterAbility { this.fullSource = false; } - ParticleEffect.LARGE_SMOKE.display(sourceBlock.getLocation().clone().add(0.5, 0.5, 0.5), 0, 0, 0, 0F, 4); + ParticleEffect.SMOKE_LARGE.display(sourceBlock.getLocation().clone().add(0.5, 0.5, 0.5), 4, 0, 0, 0); return true; } else if (WaterReturn.hasWaterBottle(this.player)) { WaterReturn.emptyWaterBottle(this.player); @@ -201,7 +211,7 @@ public class WaterArms extends WaterAbility { } } - return isWaterbendable(block.getType()) || isIce(block) || isWater(block) || block.getType() == Material.AIR; + return isWaterbendable(block.getType()) || isIce(block) || isWater(block) || ElementalAbility.isAir(block.getType()); } /** @@ -223,7 +233,7 @@ public class WaterArms extends WaterAbility { } if (!(this.getRightHandPos().getBlock().getLocation().equals(r1.getBlock().getLocation()))) { - this.addBlock(r1.getBlock(), Material.STATIONARY_WATER, (byte) 5, 100); + this.addBlock(r1.getBlock(), Material.WATER, GeneralMethods.getWaterData(3), 100); newBlocks.add(r1.getBlock()); } @@ -234,7 +244,7 @@ public class WaterArms extends WaterAbility { return false; } - this.addBlock(r2.getBlock(), Material.STATIONARY_WATER, (byte) 8, 100); + this.addBlock(r2.getBlock(), Material.WATER, GeneralMethods.getWaterData(0), 100); newBlocks.add(r2.getBlock()); for (int j = 1; j <= this.initLength; j++) { @@ -247,9 +257,9 @@ public class WaterArms extends WaterAbility { newBlocks.add(r3.getBlock()); if (j >= 1 && this.selectedSlot == this.freezeSlot && this.bPlayer.canIcebend()) { - this.addBlock(r3.getBlock(), Material.ICE, (byte) 0, 100); + this.addBlock(r3.getBlock(), Material.ICE, Material.ICE.createBlockData(), 100); } else { - this.addBlock(r3.getBlock(), Material.STATIONARY_WATER, (byte) 8, 100); + this.addBlock(r3.getBlock(), Material.WATER, GeneralMethods.getWaterData(0), 100); } } @@ -278,7 +288,7 @@ public class WaterArms extends WaterAbility { } if (!(this.getLeftHandPos().getBlock().getLocation().equals(l1.getBlock().getLocation()))) { - this.addBlock(l1.getBlock(), Material.STATIONARY_WATER, (byte) 5, 100); + this.addBlock(l1.getBlock(), Material.WATER, GeneralMethods.getWaterData(3), 100); newBlocks.add(l1.getBlock()); } @@ -289,7 +299,7 @@ public class WaterArms extends WaterAbility { return false; } - this.addBlock(l2.getBlock(), Material.STATIONARY_WATER, (byte) 8, 100); + this.addBlock(l2.getBlock(), Material.WATER, GeneralMethods.getWaterData(0), 100); newBlocks.add(l2.getBlock()); for (int j = 1; j <= this.initLength; j++) { @@ -302,9 +312,9 @@ public class WaterArms extends WaterAbility { newBlocks.add(l3.getBlock()); if (j >= 1 && this.selectedSlot == this.freezeSlot && this.bPlayer.canIcebend()) { - this.addBlock(l3.getBlock(), Material.ICE, (byte) 0, 100); + this.addBlock(l3.getBlock(), Material.ICE, Material.ICE.createBlockData(), 100); } else { - this.addBlock(l3.getBlock(), Material.STATIONARY_WATER, (byte) 8, 100); + this.addBlock(l3.getBlock(), Material.WATER, GeneralMethods.getWaterData(0), 100); } } @@ -314,18 +324,18 @@ public class WaterArms extends WaterAbility { return true; } - public void addBlock(final Block b, final Material m, final byte i, final long revertTime) { + public void addBlock(final Block b, final Material m, final BlockData data, final long revertTime) { if (TempBlock.isTempBlock(b)) { final TempBlock tb = TempBlock.get(b); if (this.right.contains(b) || this.left.contains(b)) { - tb.setType(m, i); + tb.setType(m, data); tb.setRevertTime(revertTime); } else { this.external.add(tb); } } else { - new TempBlock(b, m, i).setRevertTime(revertTime); + new TempBlock(b, m, data).setRevertTime(revertTime); } } @@ -452,7 +462,7 @@ public class WaterArms extends WaterAbility { } public static boolean isUnbreakable(final Block block) { - if (Arrays.asList(UNBREAKABLES).contains(block.getTypeId())) { + if (block.getType().getBlastResistance() >= 9.0F) { return true; } return false; @@ -653,22 +663,6 @@ public class WaterArms extends WaterAbility { return false; } - public boolean isCooldownLeft() { - return this.cooldownLeft; - } - - public void setCooldownLeft(final boolean cooldownLeft) { - this.cooldownLeft = cooldownLeft; - } - - public boolean isCooldownRight() { - return this.cooldownRight; - } - - public void setCooldownRight(final boolean cooldownRight) { - this.cooldownRight = cooldownRight; - } - public boolean isCanUsePlantSource() { return this.canUsePlantSource; } @@ -749,10 +743,6 @@ public class WaterArms extends WaterAbility { this.sneakMsg = sneakMsg; } - public static Integer[] getUnbreakables() { - return UNBREAKABLES; - } - public void setFullSource(final boolean fullSource) { this.fullSource = fullSource; } diff --git a/src/com/projectkorra/projectkorra/waterbending/multiabilities/WaterArmsFreeze.java b/src/com/projectkorra/projectkorra/waterbending/multiabilities/WaterArmsFreeze.java index cf6b4699..4003d103 100644 --- a/src/com/projectkorra/projectkorra/waterbending/multiabilities/WaterArmsFreeze.java +++ b/src/com/projectkorra/projectkorra/waterbending/multiabilities/WaterArmsFreeze.java @@ -13,6 +13,8 @@ import org.bukkit.util.Vector; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.IceAbility; +import com.projectkorra.projectkorra.attribute.Attribute; +import com.projectkorra.projectkorra.command.Commands; import com.projectkorra.projectkorra.util.DamageHandler; import com.projectkorra.projectkorra.util.ParticleEffect; import com.projectkorra.projectkorra.util.TempBlock; @@ -23,9 +25,12 @@ public class WaterArmsFreeze extends IceAbility { private boolean cancelled; private boolean usageCooldownEnabled; + @Attribute(Attribute.RANGE) private int iceRange; private int distanceTravelled; + @Attribute(Attribute.DAMAGE) private double iceDamage; + @Attribute(Attribute.COOLDOWN) private long usageCooldown; private Arm arm; private Location location; @@ -75,7 +80,7 @@ public class WaterArmsFreeze extends IceAbility { final Vector dir = this.player.getLocation().getDirection(); this.location = this.waterArms.getActiveArmEnd().add(dir.normalize().multiply(1)); - this.direction = GeneralMethods.getDirection(this.location, GeneralMethods.getTargetedLocation(this.player, this.iceRange, Material.WATER, Material.STATIONARY_WATER, Material.ICE, Material.PACKED_ICE)).normalize(); + this.direction = GeneralMethods.getDirection(this.location, GeneralMethods.getTargetedLocation(this.player, this.iceRange, Material.WATER, Material.ICE, Material.PACKED_ICE)).normalize(); } else { return; } @@ -121,11 +126,14 @@ public class WaterArmsFreeze extends IceAbility { } private void progressIce() { - ParticleEffect.SNOW_SHOVEL.display(this.location, (float) Math.random(), (float) Math.random(), (float) Math.random(), (float) 0.05, 5); - new TempBlock(this.location.getBlock(), Material.ICE, (byte) 0).setRevertTime(10); + ParticleEffect.SNOW_SHOVEL.display(this.location, 5, Math.random(), Math.random(), Math.random(), 0.05); + new TempBlock(this.location.getBlock(), Material.ICE).setRevertTime(10); for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(this.location, 2.5)) { if (entity instanceof LivingEntity && entity.getEntityId() != this.player.getEntityId() && !(entity instanceof ArmorStand)) { + if (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation()) || ((entity instanceof Player) && Commands.invincible.contains(((Player) entity).getName()))) { + continue; + } DamageHandler.damageEntity(entity, this.iceDamage, this); final PotionEffect effect = new PotionEffect(PotionEffectType.SLOW, 40, 2); new TempPotionEffect((LivingEntity) entity, effect); diff --git a/src/com/projectkorra/projectkorra/waterbending/multiabilities/WaterArmsSpear.java b/src/com/projectkorra/projectkorra/waterbending/multiabilities/WaterArmsSpear.java index 53e0d2c1..861510cb 100644 --- a/src/com/projectkorra/projectkorra/waterbending/multiabilities/WaterArmsSpear.java +++ b/src/com/projectkorra/projectkorra/waterbending/multiabilities/WaterArmsSpear.java @@ -17,6 +17,8 @@ import org.bukkit.util.Vector; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.WaterAbility; +import com.projectkorra.projectkorra.attribute.Attribute; +import com.projectkorra.projectkorra.command.Commands; import com.projectkorra.projectkorra.util.DamageHandler; import com.projectkorra.projectkorra.util.TempBlock; import com.projectkorra.projectkorra.waterbending.multiabilities.WaterArms.Arm; @@ -28,19 +30,26 @@ public class WaterArmsSpear extends WaterAbility { private boolean hitEntity; private boolean canFreeze; private boolean usageCooldownEnabled; + @Attribute("DamageEnabled") private boolean spearDamageEnabled; + @Attribute("Length") private int spearLength; + @Attribute(Attribute.RANGE) private int spearRange; private int spearRangeNight; private int spearRangeFullMoon; - private int spearSphere; + @Attribute("SphereRadius") + private int spearSphereRadius; private int spearSphereNight; private int spearSphereFullMoon; private int distanceTravelled; + @Attribute(Attribute.DURATION) private long spearDuration; private long spearDurationNight; private long spearDurationFullMoon; + @Attribute(Attribute.COOLDOWN) private long usageCooldown; + @Attribute(Attribute.DAMAGE) private double spearDamage; private Arm arm; private Location location; @@ -58,7 +67,7 @@ public class WaterArmsSpear extends WaterAbility { this.spearRange = getConfig().getInt("Abilities.Water.WaterArms.Spear.Range"); this.spearRangeNight = getConfig().getInt("Abilities.Water.WaterArms.Spear.NightAugments.Range.Normal"); this.spearRangeFullMoon = getConfig().getInt("Abilities.Water.WaterArms.Spear.NightAugments.Range.FullMoon"); - this.spearSphere = getConfig().getInt("Abilities.Water.WaterArms.Spear.Sphere"); + this.spearSphereRadius = getConfig().getInt("Abilities.Water.WaterArms.Spear.SphereRadius"); this.spearSphereNight = getConfig().getInt("Abilities.Water.WaterArms.Spear.NightAugments.Sphere.Normal"); this.spearSphereFullMoon = getConfig().getInt("Abilities.Water.WaterArms.Spear.NightAugments.Sphere.FullMoon"); this.spearDuration = getConfig().getLong("Abilities.Water.WaterArms.Spear.Duration"); @@ -75,30 +84,14 @@ public class WaterArmsSpear extends WaterAbility { private void getNightAugments() { final World world = this.player.getWorld(); if (isNight(world)) { - if (GeneralMethods.hasRPG()) { - if (isLunarEclipse(world)) { - this.spearRange = this.spearRangeFullMoon; - this.spearSphere = this.spearSphereFullMoon; - this.spearDuration = this.spearDurationFullMoon; - } else if (isFullMoon(world)) { - this.spearRange = this.spearRangeFullMoon; - this.spearSphere = this.spearSphereFullMoon; - this.spearDuration = this.spearDurationFullMoon; - } else { - this.spearRange = this.spearRangeNight; - this.spearSphere = this.spearSphereNight; - this.spearDuration = this.spearDurationNight; - } + if (isFullMoon(world) && !GeneralMethods.hasRPG()) { + this.spearRange = this.spearRangeFullMoon; + this.spearSphereRadius = this.spearSphereFullMoon; + this.spearDuration = this.spearDurationFullMoon; } else { - if (isFullMoon(world)) { - this.spearRange = this.spearRangeFullMoon; - this.spearSphere = this.spearSphereFullMoon; - this.spearDuration = this.spearDurationFullMoon; - } else { - this.spearRange = this.spearRangeNight; - this.spearSphere = this.spearSphereNight; - this.spearDuration = this.spearDurationNight; - } + this.spearRange = this.spearRangeNight; + this.spearSphereRadius = this.spearSphereNight; + this.spearDuration = this.spearDurationNight; } } } @@ -185,7 +178,7 @@ public class WaterArmsSpear extends WaterAbility { return; } - new TempBlock(this.location.getBlock(), Material.STATIONARY_WATER, (byte) 8); + new TempBlock(this.location.getBlock(), Material.WATER, GeneralMethods.getWaterData(0)); getIceBlocks().put(this.location.getBlock(), System.currentTimeMillis() + 600L); final Vector direction = GeneralMethods.getDirection(this.initLocation, GeneralMethods.getTargetedLocation(this.player, this.spearRange, getTransparentMaterials())).normalize(); @@ -206,7 +199,7 @@ public class WaterArmsSpear extends WaterAbility { getIceBlocks().remove(block); } - final TempBlock tempBlock = new TempBlock(block, Material.AIR, (byte) 0); + final TempBlock tempBlock = new TempBlock(block, Material.AIR); tempBlock.setType(Material.ICE); getIceBlocks().put(block, System.currentTimeMillis() + this.spearDuration + (long) (Math.random() * 500)); @@ -231,16 +224,30 @@ public class WaterArmsSpear extends WaterAbility { } private void createIceBall() { - if (this.spearSphere <= 0) { + if (this.spearSphereRadius <= 0) { if (this.canFreeze) { this.createSpear(); } return; } - for (final Block block : GeneralMethods.getBlocksAroundPoint(this.location, this.spearSphere)) { + final List trapped = GeneralMethods.getEntitiesAroundPoint(this.location, this.spearSphereRadius); + ICE_SETTING: for (final Block block : GeneralMethods.getBlocksAroundPoint(this.location, this.spearSphereRadius)) { if (isTransparent(this.player, block) && block.getType() != Material.ICE && !WaterArms.isUnbreakable(block)) { + for (final Entity entity : trapped) { + if (entity instanceof Player) { + if (Commands.invincible.contains(((Player) entity).getName())) { + return; + } + if (!getConfig().getBoolean("Properties.Water.FreezePlayerHead") && GeneralMethods.playerHeadIsInBlock((Player) entity, block, true)) { + continue ICE_SETTING; + } + if (!getConfig().getBoolean("Properties.Water.FreezePlayerFeet") && GeneralMethods.playerFeetIsInBlock((Player) entity, block, true)) { + continue ICE_SETTING; + } + } + } playIcebendingSound(block.getLocation()); - new TempBlock(block, Material.ICE, (byte) 0); + new TempBlock(block, Material.ICE); getIceBlocks().put(block, System.currentTimeMillis() + this.spearDuration + (long) (Math.random() * 500)); } } @@ -364,11 +371,11 @@ public class WaterArmsSpear extends WaterAbility { } public int getSpearSphere() { - return this.spearSphere; + return this.spearSphereRadius; } public void setSpearSphere(final int spearSphere) { - this.spearSphere = spearSphere; + this.spearSphereRadius = spearSphere; } public int getSpearSphereNight() { diff --git a/src/com/projectkorra/projectkorra/waterbending/multiabilities/WaterArmsWhip.java b/src/com/projectkorra/projectkorra/waterbending/multiabilities/WaterArmsWhip.java index b9dc8a7e..1bf79d3d 100644 --- a/src/com/projectkorra/projectkorra/waterbending/multiabilities/WaterArmsWhip.java +++ b/src/com/projectkorra/projectkorra/waterbending/multiabilities/WaterArmsWhip.java @@ -15,6 +15,7 @@ import org.bukkit.util.Vector; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.WaterAbility; import com.projectkorra.projectkorra.ability.util.MultiAbilityManager; +import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.command.Commands; import com.projectkorra.projectkorra.util.DamageHandler; import com.projectkorra.projectkorra.util.TempBlock; @@ -37,20 +38,27 @@ public class WaterArmsWhip extends WaterAbility { private boolean grabbed; private boolean grappleRespectRegions; private boolean usageCooldownEnabled; + @Attribute("WhipLength") private int whipLength; private int whipLengthWeak; private int whipLengthNight; private int whipLengthFullMoon; + @Attribute("InitialLength") private int initLength; + @Attribute("PunchLength") private int punchLength; private int punchLengthNight; private int punchLengthFullMoon; private int activeLength; + @Attribute("WhipSpeed") private int whipSpeed; - private long holdTime; + @Attribute("GrabDuration") + private long grabDuration; + @Attribute(Attribute.COOLDOWN) private long usageCooldown; private long time; private double pullMultiplier; + @Attribute("PunchDamage") private double punchDamage; private double playerHealth; private Arm arm; @@ -79,12 +87,11 @@ public class WaterArmsWhip extends WaterAbility { this.punchLengthFullMoon = getConfig().getInt("Abilities.Water.WaterArms.Whip.Punch.NightAugments.MaxLength.FullMoon"); this.activeLength = this.initLength; this.whipSpeed = 1; - this.holdTime = getConfig().getLong("Abilities.Water.WaterArms.Whip.Grab.HoldTime"); + this.grabDuration = getConfig().getLong("Abilities.Water.WaterArms.Whip.Grab.Duration"); this.pullMultiplier = getConfig().getDouble("Abilities.Water.WaterArms.Whip.Pull.Multiplier"); - this.punchDamage = getConfig().getDouble("Abilities.Water.WaterArms.Whip.Punch.PunchDamage"); + this.punchDamage = getConfig().getDouble("Abilities.Water.WaterArms.Whip.Punch.Damage"); switch (ability) { - case PULL: this.usageCooldown = getConfig().getLong("Abilities.Water.WaterArms.Arms.Cooldowns.UsageCooldown.Pull"); break; @@ -126,39 +133,17 @@ public class WaterArmsWhip extends WaterAbility { } final World world = this.player.getWorld(); if (isNight(world)) { - if (GeneralMethods.hasRPG()) { - if (isLunarEclipse(world)) { - if (this.ability.equals(Whip.PUNCH)) { - this.whipLength = this.punchLengthFullMoon; - } else { - this.whipLength = this.whipLengthFullMoon; - } - } else if (isFullMoon(world)) { - if (this.ability.equals(Whip.PUNCH)) { - this.whipLength = this.punchLengthFullMoon; - } else { - this.whipLength = this.whipLengthFullMoon; - } + if (this.ability.equals(Whip.PUNCH)) { + if (isFullMoon(world) && !GeneralMethods.hasRPG()) { + this.whipLength = this.punchLengthFullMoon; } else { - if (this.ability.equals(Whip.PUNCH)) { - this.whipLength = this.punchLengthNight; - } else { - this.whipLength = this.whipLengthNight; - } + this.whipLength = this.punchLengthNight; } } else { - if (isFullMoon(world)) { - if (this.ability.equals(Whip.PUNCH)) { - this.whipLength = this.punchLengthFullMoon; - } else { - this.whipLength = this.whipLengthFullMoon; - } + if (isFullMoon(world) && !GeneralMethods.hasRPG()) { + this.whipLength = this.whipLengthFullMoon; } else { - if (this.ability.equals(Whip.PUNCH)) { - this.whipLength = this.punchLengthNight; - } else { - this.whipLength = this.whipLengthNight; - } + this.whipLength = this.whipLengthNight; } } } @@ -169,7 +154,7 @@ public class WaterArmsWhip extends WaterAbility { if (this.waterArms != null) { this.waterArms.switchPreferredArm(); this.arm = this.waterArms.getActiveArm(); - this.time = System.currentTimeMillis() + this.holdTime; + this.time = System.currentTimeMillis() + this.grabDuration; this.playerHealth = this.player.getHealth(); if (this.arm.equals(Arm.LEFT)) { @@ -238,7 +223,9 @@ public class WaterArmsWhip extends WaterAbility { } this.useArm(); - this.dragEntity(this.end); + if (this.end != null) { //not 100% sure if this null check is a root cause fix or not + this.dragEntity(this.end); + } } private boolean canPlaceBlock(final Block block) { @@ -273,9 +260,9 @@ public class WaterArmsWhip extends WaterAbility { break; } - final byte b = (byte) Math.ceil(8 / (Math.pow(i, 1 / 3))); + final int j = (int) Math.ceil(8 / (Math.pow(i, 1 / 3))); this.waterArms.addToArm(l2.getBlock(), this.arm); - this.waterArms.addBlock(l2.getBlock(), Material.STATIONARY_WATER, b, 40); + this.waterArms.addBlock(l2.getBlock(), Material.WATER, GeneralMethods.getWaterData(j), 40); if (i == this.activeLength) { this.end = l2.clone(); @@ -295,7 +282,7 @@ public class WaterArmsWhip extends WaterAbility { } this.waterArms.addToArm(this.end.getBlock(), this.arm); - this.waterArms.addBlock(this.end.getBlock(), Material.STATIONARY_WATER, (byte) 2, 40); + this.waterArms.addBlock(this.end.getBlock(), Material.WATER, GeneralMethods.getWaterData(5), 40); this.performAction(this.end); } else { this.performAction(l2); @@ -309,7 +296,7 @@ public class WaterArmsWhip extends WaterAbility { switch (this.ability) { case PULL: for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(location, 2)) { - if (entity instanceof Player && Commands.invincible.contains(((Player) entity).getName())) { + if (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation()) || ((entity instanceof Player) && Commands.invincible.contains(((Player) entity).getName()))) { continue; } final Vector vector = endOfArm.toVector().subtract(entity.getLocation().toVector()); @@ -318,7 +305,7 @@ public class WaterArmsWhip extends WaterAbility { break; case PUNCH: for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(location, 2)) { - if (entity instanceof Player && Commands.invincible.contains(((Player) entity).getName())) { + if (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation()) || ((entity instanceof Player) && Commands.invincible.contains(((Player) entity).getName()))) { continue; } @@ -339,6 +326,9 @@ public class WaterArmsWhip extends WaterAbility { if (this.grabbedEntity == null) { for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(location, 2)) { if (entity instanceof LivingEntity && entity.getEntityId() != this.player.getEntityId() && !GRABBED_ENTITIES.containsKey(entity)) { + if (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation()) || ((entity instanceof Player) && Commands.invincible.contains(((Player) entity).getName()))) { + continue; + } GRABBED_ENTITIES.put((LivingEntity) entity, this); this.grabbedEntity = (LivingEntity) entity; this.grabbed = true; @@ -408,16 +398,7 @@ public class WaterArmsWhip extends WaterAbility { } public static void checkValidEntities() { - for (final LivingEntity livingEnt : GRABBED_ENTITIES.keySet()) { - final WaterArmsWhip whip = GRABBED_ENTITIES.get(livingEnt); - if (!whip.isRemoved()) { - if (whip.grabbedEntity == null) { - GRABBED_ENTITIES.remove(livingEnt); - } - } else { - GRABBED_ENTITIES.remove(livingEnt); - } - } + GRABBED_ENTITIES.entrySet().removeIf(entry -> entry.getValue().isRemoved() || entry.getValue().grabbedEntity == null); } @Override @@ -598,12 +579,12 @@ public class WaterArmsWhip extends WaterAbility { this.whipSpeed = whipSpeed; } - public long getHoldTime() { - return this.holdTime; + public long getGrabDuration() { + return this.grabDuration; } - public void setHoldTime(final long holdTime) { - this.holdTime = holdTime; + public void setGrabDuration(final long grabDuration) { + this.grabDuration = grabDuration; } public long getUsageCooldown() { diff --git a/src/com/projectkorra/projectkorra/waterbending/passive/FastSwim.java b/src/com/projectkorra/projectkorra/waterbending/passive/FastSwim.java index de4b7372..eba89961 100644 --- a/src/com/projectkorra/projectkorra/waterbending/passive/FastSwim.java +++ b/src/com/projectkorra/projectkorra/waterbending/passive/FastSwim.java @@ -4,7 +4,6 @@ import org.bukkit.Location; import org.bukkit.entity.Player; import com.projectkorra.projectkorra.ability.CoreAbility; -import com.projectkorra.projectkorra.ability.ElementalAbility; import com.projectkorra.projectkorra.ability.PassiveAbility; import com.projectkorra.projectkorra.ability.WaterAbility; import com.projectkorra.projectkorra.configuration.ConfigManager; @@ -13,6 +12,7 @@ import com.projectkorra.projectkorra.waterbending.WaterSpout; import com.projectkorra.projectkorra.waterbending.multiabilities.WaterArms; public class FastSwim extends WaterAbility implements PassiveAbility { + private long cooldown; private double swimSpeed; private long duration; @@ -23,26 +23,38 @@ public class FastSwim extends WaterAbility implements PassiveAbility { return; } + if (player.isSneaking()) { // the sneak event calls before they actually start sneaking + return; + } + this.cooldown = ConfigManager.getConfig().getLong("Abilities.Water.Passive.FastSwim.Cooldown"); this.swimSpeed = ConfigManager.getConfig().getDouble("Abilities.Water.Passive.FastSwim.SpeedFactor"); this.duration = ConfigManager.getConfig().getLong("Abilities.Water.Passive.FastSwim.Duration"); + + this.start(); } @Override public void progress() { if (!this.bPlayer.canUsePassive(this) || !this.bPlayer.canBendPassive(this) || CoreAbility.hasAbility(this.player, WaterSpout.class) || CoreAbility.hasAbility(this.player, EarthArmor.class) || CoreAbility.hasAbility(this.player, WaterArms.class)) { + this.remove(); + return; + } + + if (this.duration > 0 && System.currentTimeMillis() > this.getStartTime() + this.duration) { + this.bPlayer.addCooldown(this); + this.remove(); return; } if (this.bPlayer.getBoundAbility() == null || (this.bPlayer.getBoundAbility() != null && !this.bPlayer.getBoundAbility().isSneakAbility())) { - if (this.player.isSneaking() && ElementalAbility.isWater(this.player.getLocation().getBlock()) && !this.bPlayer.isOnCooldown(this)) { - if (this.duration != 0 && System.currentTimeMillis() > this.getStartTime() + this.duration) { - this.bPlayer.addCooldown(this); - return; + if (this.player.isSneaking()) { + if (isWater(this.player.getLocation().getBlock()) && !this.bPlayer.isOnCooldown(this)) { + this.player.setVelocity(this.player.getEyeLocation().getDirection().clone().normalize().multiply(this.swimSpeed)); } - this.player.setVelocity(this.player.getEyeLocation().getDirection().clone().normalize().multiply(this.swimSpeed)); - } else if (!this.player.isSneaking()) { + } else { this.bPlayer.addCooldown(this); + this.remove(); } } } @@ -78,7 +90,7 @@ public class FastSwim extends WaterAbility implements PassiveAbility { @Override public boolean isInstantiable() { - return true; + return false; } @Override diff --git a/src/com/projectkorra/projectkorra/waterbending/passive/HydroSink.java b/src/com/projectkorra/projectkorra/waterbending/passive/HydroSink.java index 943ea2b9..8b6f10a5 100644 --- a/src/com/projectkorra/projectkorra/waterbending/passive/HydroSink.java +++ b/src/com/projectkorra/projectkorra/waterbending/passive/HydroSink.java @@ -29,7 +29,7 @@ public class HydroSink extends WaterAbility implements PassiveAbility { return true; } else if (WaterAbility.isWaterbendable(player, null, block) && !ElementalAbility.isPlant(block)) { return true; - } else if (fallBlock.getType() == Material.AIR) { + } else if (ElementalAbility.isAir(fallBlock.getType())) { return true; } else if ((WaterAbility.isWaterbendable(player, null, fallBlock) && !ElementalAbility.isPlant(fallBlock)) || fallBlock.getType() == Material.SNOW_BLOCK) { return true; @@ -39,8 +39,7 @@ public class HydroSink extends WaterAbility implements PassiveAbility { } @Override - public void progress() { - } + public void progress() {} @Override public boolean isSneakAbility() { diff --git a/src/com/projectkorra/projectkorra/waterbending/plant/PlantRegrowth.java b/src/com/projectkorra/projectkorra/waterbending/plant/PlantRegrowth.java index b44ad18f..8a3a5174 100644 --- a/src/com/projectkorra/projectkorra/waterbending/plant/PlantRegrowth.java +++ b/src/com/projectkorra/projectkorra/waterbending/plant/PlantRegrowth.java @@ -4,14 +4,16 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.block.data.BlockData; import org.bukkit.entity.Player; import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.ability.ElementalAbility; import com.projectkorra.projectkorra.ability.PlantAbility; public class PlantRegrowth extends PlantAbility { - private byte data; + private BlockData data; private long time; private long regrowTime; private Material type; @@ -24,12 +26,12 @@ public class PlantRegrowth extends PlantAbility { if (this.regrowTime != 0) { this.block = block; this.type = block.getType(); - this.data = block.getData(); + this.data = block.getBlockData(); - if (block.getType() == Material.DOUBLE_PLANT) { - if (block.getRelative(BlockFace.DOWN).getType() == Material.DOUBLE_PLANT) { + if (block.getType() == Material.TALL_GRASS) { + if (block.getRelative(BlockFace.DOWN).getType() == Material.TALL_GRASS) { this.block = block.getRelative(BlockFace.DOWN); - this.data = block.getRelative(BlockFace.DOWN).getData(); + this.data = block.getRelative(BlockFace.DOWN).getBlockData(); block.getRelative(BlockFace.DOWN).setType(Material.AIR); block.setType(Material.AIR); @@ -47,16 +49,15 @@ public class PlantRegrowth extends PlantAbility { @Override public void remove() { super.remove(); - if (this.block.getType() == Material.AIR) { + if (ElementalAbility.isAir(this.block.getType())) { this.block.setType(this.type); - this.block.setData(this.data); - if (this.type == Material.DOUBLE_PLANT) { - this.block.getRelative(BlockFace.UP).setType(Material.DOUBLE_PLANT); - this.block.getRelative(BlockFace.UP).setData((byte) 10); + this.block.setBlockData(this.data); + if (this.type == Material.TALL_GRASS) { + this.block.getRelative(BlockFace.UP).setType(Material.TALL_GRASS); } } else { - GeneralMethods.dropItems(this.block, GeneralMethods.getDrops(this.block, this.type, this.data, null)); + GeneralMethods.dropItems(this.block, GeneralMethods.getDrops(this.block, this.type, this.data)); } } @@ -97,11 +98,11 @@ public class PlantRegrowth extends PlantAbility { return true; } - public byte getData() { + public BlockData getData() { return this.data; } - public void setData(final byte data) { + public void setData(final BlockData data) { this.data = data; } diff --git a/src/com/projectkorra/projectkorra/waterbending/util/WaterReturn.java b/src/com/projectkorra/projectkorra/waterbending/util/WaterReturn.java index 5b158aa6..c0784ece 100644 --- a/src/com/projectkorra/projectkorra/waterbending/util/WaterReturn.java +++ b/src/com/projectkorra/projectkorra/waterbending/util/WaterReturn.java @@ -9,6 +9,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.meta.PotionMeta; +import org.bukkit.potion.PotionData; import org.bukkit.potion.PotionType; import org.bukkit.util.Vector; @@ -43,7 +44,7 @@ public class WaterReturn extends WaterAbility { if (this.bPlayer.canBendIgnoreBindsCooldowns(this)) { if (isTransparent(player, block) && ((TempBlock.isTempBlock(block) && block.isLiquid()) || !block.isLiquid()) && this.hasEmptyWaterBottle()) { - this.block = new TempBlock(block, Material.WATER, (byte) 0); + this.block = new TempBlock(block, Material.WATER, GeneralMethods.getWaterData(0)); } } this.start(); @@ -83,10 +84,10 @@ public class WaterReturn extends WaterAbility { final Block newblock = this.location.getBlock(); if (isTransparent(this.player, newblock) && !newblock.isLiquid()) { this.block.revertBlock(); - this.block = new TempBlock(newblock, Material.WATER, (byte) 0); + this.block = new TempBlock(newblock, Material.WATER, GeneralMethods.getWaterData(0)); } else if (isTransparent(this.player, newblock)) { if (isWater(newblock)) { - ParticleEffect.WATER_BUBBLE.display((float) Math.random(), (float) Math.random(), (float) Math.random(), 0f, 5, newblock.getLocation().clone().add(.5, .5, .5), 255.0); + ParticleEffect.WATER_BUBBLE.display(newblock.getLocation().clone().add(.5, .5, .5), 5, Math.random(), Math.random(), Math.random(), 0); } } else { this.remove(); @@ -113,16 +114,18 @@ public class WaterReturn extends WaterAbility { private void fillBottle() { final PlayerInventory inventory = this.player.getInventory(); - if (inventory.contains(Material.GLASS_BOTTLE)) { - final int index = inventory.first(Material.GLASS_BOTTLE); + final int index = inventory.first(Material.GLASS_BOTTLE); + if (index >= 0) { final ItemStack item = inventory.getItem(index); + final ItemStack water = waterBottleItem(); + if (item.getAmount() == 1) { - inventory.setItem(index, new ItemStack(Material.POTION)); + inventory.setItem(index, water); } else { item.setAmount(item.getAmount() - 1); inventory.setItem(index, item); - final HashMap leftover = inventory.addItem(new ItemStack(Material.POTION)); + final HashMap leftover = inventory.addItem(water); for (final int left : leftover.keySet()) { this.player.getWorld().dropItemNaturally(this.player.getLocation(), leftover.get(left)); } @@ -143,27 +146,15 @@ public class WaterReturn extends WaterAbility { return false; } - public static boolean hasWaterBottle(final Player player) { - if (hasAbility(player, WaterReturn.class) || isBending(player)) { - return false; - } - final PlayerInventory inventory = player.getInventory(); - if (inventory.contains(Material.POTION)) { - final ItemStack item = inventory.getItem(inventory.first(Material.POTION)); - final PotionMeta meta = (PotionMeta) item.getItemMeta(); - return meta.getBasePotionData().getType() == PotionType.WATER; - } - return false; - } - - public static void emptyWaterBottle(final Player player) { - final PlayerInventory inventory = player.getInventory(); + public static int firstWaterBottle(final PlayerInventory inventory) { int index = inventory.first(Material.POTION); // Check that the first one found is actually a WATER bottle. We aren't implementing potion bending just yet. - if (index != -1 && !((PotionMeta) inventory.getItem(index).getItemMeta()).getBasePotionData().getType().equals(PotionType.WATER)) { - for (int i = 0; i < inventory.getSize(); i++) { - if (inventory.getItem(i).getType() == Material.POTION) { + if (index != -1) { + int aux = index; + index = -1; + for (int i = aux; i < inventory.getSize(); i++) { + if (inventory.getItem(i) != null && inventory.getItem(i).getType() == Material.POTION && inventory.getItem(i).hasItemMeta()) { final PotionMeta meta = (PotionMeta) inventory.getItem(i).getItemMeta(); if (meta.getBasePotionData().getType().equals(PotionType.WATER)) { index = i; @@ -173,6 +164,22 @@ public class WaterReturn extends WaterAbility { } } + return index; + } + + public static boolean hasWaterBottle(final Player player) { + if (hasAbility(player, WaterReturn.class) || isBending(player)) { + return false; + } + final PlayerInventory inventory = player.getInventory(); + + return WaterReturn.firstWaterBottle(inventory) >= 0; + } + + public static void emptyWaterBottle(final Player player) { + final PlayerInventory inventory = player.getInventory(); + int index = WaterReturn.firstWaterBottle(inventory); + if (index != -1) { final ItemStack item = inventory.getItem(index); if (item.getAmount() == 1) { @@ -189,6 +196,16 @@ public class WaterReturn extends WaterAbility { } } + public static ItemStack waterBottleItem() { + final ItemStack water = new ItemStack(Material.POTION); + final PotionMeta meta = (PotionMeta) water.getItemMeta(); + + meta.setBasePotionData(new PotionData(PotionType.WATER)); + water.setItemMeta(meta); + + return water; + } + public long getTime() { return this.time; } diff --git a/src/com/projectkorra/projectkorra/waterbending/util/WaterSourceGrabber.java b/src/com/projectkorra/projectkorra/waterbending/util/WaterSourceGrabber.java index 489da3f1..cec2f76b 100644 --- a/src/com/projectkorra/projectkorra/waterbending/util/WaterSourceGrabber.java +++ b/src/com/projectkorra/projectkorra/waterbending/util/WaterSourceGrabber.java @@ -8,10 +8,12 @@ import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; import org.bukkit.entity.Player; import org.bukkit.util.Vector; import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.ability.ElementalAbility; import com.projectkorra.projectkorra.ability.WaterAbility; import com.projectkorra.projectkorra.util.TempBlock; @@ -26,7 +28,7 @@ public class WaterSourceGrabber { } private Player player; - private byte data; + private BlockData data; private double animimationSpeed; private AnimationState state; private Material material; @@ -40,8 +42,8 @@ public class WaterSourceGrabber { public WaterSourceGrabber(final Player player, final Location origin, final double animationSpeed) { this.player = player; this.animimationSpeed = animationSpeed; - this.material = Material.STATIONARY_WATER; - this.data = 0; + this.material = Material.WATER; + this.data = GeneralMethods.getWaterData(0); this.currentLoc = origin.clone(); this.state = AnimationState.RISING; this.affectedBlocks = new ConcurrentHashMap<>(); @@ -56,7 +58,7 @@ public class WaterSourceGrabber { this.currentLoc.add(0, this.animimationSpeed * Math.signum(locDiff), 0); final Block block = this.currentLoc.getBlock(); - if (!(WaterAbility.isWaterbendable(this.player, null, block) || block.getType() == Material.AIR) || GeneralMethods.isRegionProtectedFromBuild(this.player, "WaterSpout", block.getLocation())) { + if (!(WaterAbility.isWaterbendable(this.player, null, block) || ElementalAbility.isAir(block.getType())) || GeneralMethods.isRegionProtectedFromBuild(this.player, "WaterSpout", block.getLocation())) { this.remove(); return; } @@ -73,7 +75,7 @@ public class WaterSourceGrabber { this.currentLoc.add(vec.normalize().multiply(this.animimationSpeed)); final Block block = this.currentLoc.getBlock(); - if (!(WaterAbility.isWaterbendable(this.player, null, block) || block.getType() == Material.AIR) || GeneralMethods.isRegionProtectedFromBuild(this.player, "WaterManipulation", block.getLocation())) { + if (!(WaterAbility.isWaterbendable(this.player, null, block) || ElementalAbility.isAir(block.getType())) || GeneralMethods.isRegionProtectedFromBuild(this.player, "WaterManipulation", block.getLocation())) { this.remove(); return; } @@ -104,10 +106,10 @@ public class WaterSourceGrabber { } public void createBlock(final Block block, final Material mat) { - this.createBlock(block, mat, (byte) 0); + this.createBlock(block, mat, mat.createBlockData()); } - public void createBlock(final Block block, final Material mat, final byte data) { + public void createBlock(final Block block, final Material mat, final BlockData data) { this.affectedBlocks.put(block, new TempBlock(block, mat, data)); } @@ -119,11 +121,11 @@ public class WaterSourceGrabber { this.player = player; } - public byte getData() { + public BlockData getData() { return this.data; } - public void setData(final byte data) { + public void setData(final BlockData data) { this.data = data; } diff --git a/src/plugin.yml b/src/plugin.yml index 109c901e..b0fc6a94 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,8 +1,9 @@ name: ProjectKorra author: ProjectKorra +api-version: 1.13 version: ${project.version} main: com.projectkorra.projectkorra.ProjectKorra -softdepend: [PreciousStones, WorldGuard, WorldEdit, Factions, MassiveCore, GriefPrevention, Towny, NoCheatPlus, LWC, Residence, Kingdoms] +softdepend: [PreciousStones, WorldGuard, WorldEdit, FactionsFramework, GriefPrevention, Towny, NoCheatPlus, LWC, Residence, Kingdoms, RedProtect, PlaceholderAPI] commands: projectkorra: aliases: [b,bending,mtla,tla,korra,pk,bend] @@ -15,7 +16,6 @@ permissions: bending.player: true bending.command.reload: true bending.admin.permaremove: true - bending.command.avatar: true bending.command.add.others: true bending.command.add: true bending.command.rechoose: true @@ -28,10 +28,8 @@ permissions: bending.ability.MetalClips.loot: true bending.ability.MetalClips.4clips: true bending.ability.MetalClips.throw: true - bending.command.import: true bending.command.toggle.all: true bending.admin.toggle: true - bending.command.give: true bending.command.invincible: true bending.command.check: true bending.command.preset.bind.assign: true @@ -193,6 +191,14 @@ permissions: bending.ability.AirSweep: true bending.ability.AirStream: true bending.ability.Twister: true + bending.ability.Flight: + default: false + description: Grants access to Flight sub-abilities. + children: + bending.ability.Flight.Soar: true + bending.ability.Flight.Glide: true + bending.ability.Flight.Levitate: true + bending.ability.Flight.Ending: true bending.ability.WaterCombo: default: false description: Grants access to all WaterCombos. @@ -227,7 +233,7 @@ permissions: description: Grants access to all air passives. children: bending.ability.AirAgility: true - bending.ability.AirSatiation: true + bending.ability.AirSaturation: true bending.ability.GracefulDescent: true bending.chi.passive: default: false @@ -235,7 +241,7 @@ permissions: children: bending.ability.Acrobatics: true bending.ability.ChiAgility: true - bending.ability.ChiSatiation: true + bending.ability.ChiSaturation: true bending.earth.passive: default: false description: Grants access to all earth passives. @@ -251,7 +257,7 @@ permissions: description: Grants access to all water passives. children: bending.ability.FastSwim: true - bending.ability.Hydrosink: true + bending.ability.HydroSink: true bending.donor: default: false - description: Grants the Donor tag. \ No newline at end of file + description: Grants the Donor tag.