├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitattributes ├── libs └── PUT-HERE ├── src └── main │ └── java │ └── net │ └── bendercraft │ └── spigot │ └── bending │ ├── utils │ ├── MathUtils.java │ ├── BendingAbilityLogFormatter.java │ ├── RollingFileHandler.java │ ├── ProtectionManager.java │ ├── PluginTools.java │ ├── abilities │ │ └── Bubble.java │ └── Tools.java │ ├── integrations │ ├── citizens │ │ └── BendableTrait.java │ └── protocollib │ │ └── BendingPacketAdapter.java │ ├── controller │ ├── LanguageParameter.java │ ├── ConfigurationParameter.java │ └── FlyingPlayer.java │ ├── abilities │ ├── BendingElement.java │ ├── BendingAbilityState.java │ ├── BendingPlayerSkillsData.java │ ├── ABendingAbility.java │ ├── BendingAbilityCooldown.java │ ├── BendingAffinity.java │ ├── water │ │ ├── Drainbending.java │ │ ├── WaterBalance.java │ │ ├── WaterPassive.java │ │ ├── FastSwimming.java │ │ ├── WaterBubble.java │ │ └── Frozen.java │ ├── earth │ │ ├── EarthCore.java │ │ ├── MetalWire.java │ │ ├── EarthTunnel.java │ │ ├── EarthPassive.java │ │ └── Collapse.java │ ├── BendingPassiveAbility.java │ ├── arts │ │ ├── Speed.java │ │ ├── DaggerFall.java │ │ ├── HighJump.java │ │ ├── Supply.java │ │ ├── Mark.java │ │ ├── Dash.java │ │ ├── DirectHit.java │ │ ├── NebularChain.java │ │ ├── BlankPoint.java │ │ └── Concussion.java │ ├── BendingPlayerData.java │ ├── BendingActiveAbility.java │ ├── fire │ │ ├── FirePower.java │ │ ├── Illumination.java │ │ ├── Enflamed.java │ │ └── FireBlade.java │ ├── air │ │ ├── AirSpeed.java │ │ ├── AirBubble.java │ │ └── AirSink.java │ ├── RegisteredAbility.java │ └── energy │ │ └── AvatarState.java │ ├── db │ └── SkillTree.java │ ├── event │ ├── BendingAbilityEvent.java │ ├── BendingDamageEvent.java │ └── BendingHitEvent.java │ ├── commands │ ├── IBendingCommand.java │ ├── subcommands │ │ ├── VersionExecution.java │ │ ├── ReloadExecution.java │ │ ├── DebugExecution.java │ │ ├── ClearExecution.java │ │ ├── CredentialsExecution.java │ │ ├── HelpExecution.java │ │ ├── RemoveExecution.java │ │ ├── ToggleExecution.java │ │ ├── PerkExecution.java │ │ ├── AddExecution.java │ │ ├── DisplayExecution.java │ │ ├── AvailableExecution.java │ │ ├── BindExecution.java │ │ ├── ChooseExecution.java │ │ └── DeckExecution.java │ └── BendingCommand.java │ └── learning │ ├── PermissionListener.java │ ├── MasterListener.java │ └── BendingLearning.java ├── .gitignore ├── settings.gradle ├── migration ├── wgcustomflags_to_embedded.py ├── v5_x_x_to_v6_0_0.py ├── create_db.sql ├── v6_1_0_to_v7_1_0.py └── v6_0_0_to_v6_1_0.py ├── LICENSE.md ├── spigot-bending.iml ├── README.md └── gradlew.bat /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bendercraft/spigot-bending/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # 2 | # https://help.github.com/articles/dealing-with-line-endings/ 3 | # 4 | # These are explicitly windows files and should use crlf 5 | *.bat text eol=crlf 6 | 7 | -------------------------------------------------------------------------------- /libs/PUT-HERE: -------------------------------------------------------------------------------- 1 | Citizens 2.0.26 2 | CoreProtect 2.18.2 3 | ProtocolLib latest 4 | Spigot 1.15.2 5 | WorldEdit 7.1.0 6 | Worlguard 7.0.3 7 | Fastutils 8 http://fastutil.di.unimi.it/fastutil-8.2.3-bin.tar.gz 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/utils/MathUtils.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.utils; 2 | 3 | public abstract class MathUtils { 4 | public static boolean doubleEquals(double d1, double d2) { 5 | return Double.compare(d1, d2) == 0; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/integrations/citizens/BendableTrait.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.integrations.citizens; 2 | 3 | import net.citizensnpcs.api.trait.Trait; 4 | 5 | public class BendableTrait extends Trait { 6 | 7 | public BendableTrait() { 8 | super("bendable"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .classpath 2 | .gitignore 3 | .gitignore~ 4 | .project 5 | dependency-reduced-pom.xml 6 | .settings 7 | build.xml 8 | /target 9 | /bin/ 10 | /save/ 11 | /.externalToolBuilders/ 12 | /.sonar/ 13 | /.idea/ 14 | *.jar 15 | /out/ 16 | # Ignore Gradle project-specific cache directory 17 | .gradle 18 | 19 | # Ignore Gradle build output directory 20 | build 21 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | * 4 | * The settings file is used to specify which projects to include in your build. 5 | * 6 | * Detailed information about configuring a multi-project build in Gradle can be found 7 | * in the user manual at https://docs.gradle.org/6.3/userguide/multi_project_builds.html 8 | */ 9 | 10 | rootProject.name = 'spigot-bending' 11 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/controller/LanguageParameter.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.controller; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.FIELD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface LanguageParameter { 11 | 12 | public String value(); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/controller/ConfigurationParameter.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.controller; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.FIELD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface ConfigurationParameter { 11 | 12 | public String value(); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/BendingElement.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities; 2 | 3 | public enum BendingElement { 4 | 5 | NONE, MASTER, AIR, WATER, EARTH, FIRE, ENERGY; 6 | 7 | public static BendingElement getType(String string) { 8 | for (BendingElement type : BendingElement.values()) { 9 | if (type.toString().equalsIgnoreCase(string)) { 10 | return type; 11 | } 12 | } 13 | return null; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/BendingAbilityState.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities; 2 | 3 | public enum BendingAbilityState { 4 | 5 | START(0), PREPARING(1), PREPARED(2), PROGRESSING(3), 6 | /** 7 | * When the state is on Ended, the ability will be removed in the next tick 8 | */ 9 | ENDED(4); 10 | 11 | private int step; 12 | 13 | BendingAbilityState(int step) { 14 | this.step = step; 15 | } 16 | 17 | public boolean isBefore(BendingAbilityState state) { 18 | if (this.step < state.step) { 19 | return true; 20 | } 21 | return false; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /migration/wgcustomflags_to_embedded.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import yaml 4 | import json 5 | 6 | def main(): 7 | with open('customFlags.yml') as f: 8 | old = yaml.load(f) 9 | new = [] 10 | for region in old['regions']: 11 | for flag,value in region['flags'].items(): 12 | new.append({'region':region['region'],'flag':flag,'value':value}) 13 | with open('flags.json', 'w') as f: 14 | json.dump(new, f) 15 | print('Done. Rename and move "flags.json" to bending data folder -> "plugins/Bending/flags/.json"') 16 | 17 | if __name__ == "__main__": 18 | main() 19 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright 2014-2016 Noko, Koudja 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/BendingPlayerSkillsData.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities; 2 | 3 | import java.util.List; 4 | import java.util.UUID; 5 | 6 | public class BendingPlayerSkillsData { 7 | private UUID player; 8 | private List skills; 9 | 10 | public UUID getPlayer() { 11 | return this.player; 12 | } 13 | 14 | public void setPlayer(UUID player) { 15 | this.player = player; 16 | } 17 | 18 | public List getSkills() { 19 | return skills; 20 | } 21 | 22 | public void setSkills(List skills) { 23 | this.skills = skills; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/ABendingAbility.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.TYPE) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface ABendingAbility { 11 | public String name(); 12 | 13 | public BendingElement element() default BendingElement.NONE; 14 | 15 | public BendingAffinity affinity() default BendingAffinity.NONE; 16 | 17 | public boolean shift() default true; 18 | 19 | public boolean passive() default false; 20 | 21 | public boolean canBeUsedWithTools() default false; 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/db/SkillTree.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.db; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import net.bendercraft.spigot.bending.abilities.BendingElement; 7 | import net.bendercraft.spigot.bending.abilities.BendingPerk; 8 | 9 | public class SkillTree { 10 | private Map points; 11 | private List skills; 12 | public Map getPoints() { 13 | return points; 14 | } 15 | public void setPoints(Map points) { 16 | this.points = points; 17 | } 18 | public List getSkills() { 19 | return skills; 20 | } 21 | public void setSkills(List skills) { 22 | this.skills = skills; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/event/BendingAbilityEvent.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.event; 2 | 3 | import org.bukkit.event.Event; 4 | import org.bukkit.event.HandlerList; 5 | 6 | import net.bendercraft.spigot.bending.abilities.BendingAbility; 7 | 8 | public class BendingAbilityEvent extends Event { 9 | protected static final HandlerList handlers = new HandlerList(); 10 | 11 | private final BendingAbility ability; 12 | 13 | public BendingAbilityEvent(BendingAbility ability) { 14 | this.ability = ability; 15 | } 16 | 17 | public BendingAbility getAbility() { 18 | return ability; 19 | } 20 | 21 | @Override 22 | public HandlerList getHandlers() { 23 | return handlers; 24 | } 25 | 26 | public static HandlerList getHandlerList() { 27 | return handlers; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/BendingAbilityCooldown.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities; 2 | 3 | public class BendingAbilityCooldown { 4 | private final String ability; 5 | private final long start; 6 | private long duration; 7 | 8 | public BendingAbilityCooldown(String ability, long start, long duration) { 9 | this.ability = ability; 10 | this.start = start; 11 | this.duration = duration; 12 | } 13 | 14 | public long getDuration() { 15 | return duration; 16 | } 17 | 18 | public void setDuration(long duration) { 19 | this.duration = duration; 20 | } 21 | 22 | public String getAbility() { 23 | return ability; 24 | } 25 | 26 | public long getStart() { 27 | return start; 28 | } 29 | 30 | public long timeLeft(long when) { 31 | long left = (start + duration) - when; 32 | return left < 0 ? 0 : left; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/commands/IBendingCommand.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.commands; 2 | 3 | import java.util.List; 4 | 5 | import org.bukkit.command.CommandSender; 6 | 7 | public interface IBendingCommand { 8 | 9 | boolean execute(CommandSender sender, List args); 10 | 11 | void printUsage(CommandSender sender); 12 | 13 | void printUsage(CommandSender sender, boolean permission); 14 | 15 | boolean isCommand(String command); 16 | 17 | String getCommand(); 18 | 19 | /** 20 | * Get all possibles values for a given command and given arguments 21 | * 22 | * @param sender 23 | * The sender of the command 24 | * @param args 25 | * The args that the sender sent (without the first arg being the 26 | * subcommand) 27 | * @return List of possible values 28 | */ 29 | public List autoComplete(CommandSender sender, List args); 30 | 31 | public boolean hasBasePermission(CommandSender sender); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/event/BendingDamageEvent.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.event; 2 | 3 | import java.util.Map; 4 | 5 | import org.bukkit.entity.Entity; 6 | import org.bukkit.event.entity.EntityDamageByEntityEvent; 7 | 8 | import com.google.common.base.Function; 9 | 10 | import net.bendercraft.spigot.bending.abilities.BendingAbility; 11 | import net.bendercraft.spigot.bending.abilities.BendingPlayer; 12 | 13 | public class BendingDamageEvent extends EntityDamageByEntityEvent { 14 | private final BendingAbility ability; 15 | 16 | @SuppressWarnings("deprecation") 17 | public BendingDamageEvent(BendingPlayer damager, Entity damagee, BendingAbility ability, Map modifiers, Map> modifierFunctions) { 18 | super(damager.getPlayer(), damagee, DamageCause.CUSTOM, modifiers, modifierFunctions); 19 | this.ability = ability; 20 | } 21 | 22 | public BendingAbility getAbility() { 23 | return ability; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/BendingAffinity.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities; 2 | 3 | public enum BendingAffinity { 4 | NONE(BendingElement.NONE), 5 | 6 | TORNADO(BendingElement.AIR), SUFFOCATE(BendingElement.AIR), 7 | 8 | BLOOD(BendingElement.WATER), DRAIN(BendingElement.WATER), 9 | 10 | LIGHTNING(BendingElement.FIRE), COMBUSTION(BendingElement.FIRE), 11 | 12 | METAL(BendingElement.EARTH), LAVA(BendingElement.EARTH), 13 | 14 | CHI(BendingElement.MASTER), BOW(BendingElement.MASTER), SWORD(BendingElement.MASTER); 15 | 16 | private BendingElement element; 17 | 18 | BendingAffinity(BendingElement element) { 19 | this.element = element; 20 | } 21 | 22 | public static BendingAffinity getType(String string) { 23 | for (BendingAffinity type : BendingAffinity.values()) { 24 | if (type.toString().equalsIgnoreCase(string)) { 25 | return type; 26 | } 27 | } 28 | return null; 29 | } 30 | 31 | public BendingElement getElement() { 32 | return this.element; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /spigot-bending.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/utils/BendingAbilityLogFormatter.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.utils; 2 | 3 | import java.io.PrintWriter; 4 | import java.io.StringWriter; 5 | import java.text.SimpleDateFormat; 6 | import java.util.logging.Formatter; 7 | import java.util.logging.LogRecord; 8 | 9 | public class BendingAbilityLogFormatter extends Formatter { 10 | 11 | private final SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 12 | 13 | @Override 14 | public String format(LogRecord log) { 15 | StringBuilder builder = new StringBuilder(); 16 | Throwable thrown = log.getThrown(); 17 | 18 | builder.append(date.format(log.getMillis())); 19 | builder.append(" [" + log.getLevel().getLocalizedName().toUpperCase() + "] "); 20 | builder.append(formatMessage(log)); 21 | builder.append('\n'); 22 | 23 | if (thrown != null) { 24 | StringWriter writer = new StringWriter(); 25 | thrown.printStackTrace(new PrintWriter(writer)); 26 | builder.append(writer); 27 | } 28 | 29 | return builder.toString(); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/commands/subcommands/VersionExecution.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.commands.subcommands; 2 | 3 | import java.util.List; 4 | 5 | import org.bukkit.ChatColor; 6 | import org.bukkit.command.CommandSender; 7 | 8 | import net.bendercraft.spigot.bending.Bending; 9 | import net.bendercraft.spigot.bending.Messages; 10 | import net.bendercraft.spigot.bending.commands.BendingCommand; 11 | 12 | public class VersionExecution extends BendingCommand { 13 | 14 | public VersionExecution() { 15 | super(); 16 | this.command = "version"; 17 | this.aliases.add("v"); 18 | this.aliases.add("ver"); 19 | this.basePermission = "bending.command.version"; 20 | } 21 | 22 | @Override 23 | public boolean execute(CommandSender sender, List args) { 24 | sender.sendMessage("Bending v" + Bending.getInstance().getDescription().getVersion()); 25 | sender.sendMessage("Authors : Koudja & Noko"); 26 | return true; 27 | } 28 | 29 | @Override 30 | public void printUsage(CommandSender sender, boolean permission) { 31 | if (sender.hasPermission("bending.command.version")) { 32 | sender.sendMessage("/bending version"); 33 | } 34 | else if (permission) { 35 | sender.sendMessage(ChatColor.RED + Messages.NO_PERMISSION); 36 | } 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/learning/PermissionListener.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.learning; 2 | 3 | import org.bukkit.event.EventHandler; 4 | import org.bukkit.event.Listener; 5 | import org.bukkit.event.player.PlayerJoinEvent; 6 | import net.bendercraft.spigot.bending.abilities.AbilityManager; 7 | import net.bendercraft.spigot.bending.abilities.BendingPlayer; 8 | import net.bendercraft.spigot.bending.abilities.RegisteredAbility; 9 | 10 | public class PermissionListener implements Listener { 11 | private BendingLearning plugin; 12 | 13 | public PermissionListener(BendingLearning plugin) { 14 | this.plugin = plugin; 15 | 16 | } 17 | 18 | @EventHandler 19 | public void onPlayerJoin(PlayerJoinEvent event) { 20 | for(RegisteredAbility ab : AbilityManager.getManager().getRegisteredAbilities()) { 21 | // Add default perm to allow base ability to be used 22 | if(plugin.isBasicBendingAbility(ab.getName())) { 23 | plugin.addPermission(event.getPlayer(), ab.getName()); 24 | } 25 | 26 | // Also allow all abilities if it is link to an affinity and player has it 27 | BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(event.getPlayer()); 28 | if(ab.getAffinity() != null && bPlayer != null && bPlayer.hasAffinity(ab.getAffinity())) { 29 | plugin.addPermission(event.getPlayer(), ab.getName()); 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/water/Drainbending.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.water; 2 | 3 | import org.bukkit.block.Block; 4 | import org.bukkit.entity.Player; 5 | 6 | import net.bendercraft.spigot.bending.abilities.BendingAffinity; 7 | import net.bendercraft.spigot.bending.abilities.BendingPlayer; 8 | import net.bendercraft.spigot.bending.controller.ConfigurationParameter; 9 | import net.bendercraft.spigot.bending.utils.BlockTools; 10 | import net.bendercraft.spigot.bending.utils.EntityTools; 11 | import net.bendercraft.spigot.bending.utils.TempBlock; 12 | 13 | /** 14 | * Is not an ability as is, but can still be on cooldown 15 | * @author Koudja 16 | * 17 | */ 18 | public class Drainbending { 19 | public static final String NAME = "Drainbending"; 20 | 21 | @ConfigurationParameter("Cooldown") 22 | public static long COOLDOWN = 1500; 23 | 24 | public static boolean canDrainBend(Player player) { 25 | if (player == null) { 26 | return false; 27 | } 28 | 29 | BendingPlayer bender = BendingPlayer.getBendingPlayer(player); 30 | if (bender == null || !bender.hasAffinity(BendingAffinity.DRAIN) || EntityTools.speToggled(player)) { 31 | return false; 32 | } 33 | 34 | return true; 35 | } 36 | 37 | public static boolean canBeSource(Block block) { 38 | if (TempBlock.isTempBlock(block)) { 39 | return false; 40 | } 41 | return BlockTools.isAir(block); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Spigot-bending 2 | Spigot plugins allowings players to bend elements at their will. Based on "Avatar" franchise. This plugin is officially hosted and used on "Bendercraft _.net_ ", french community of the franchise. 3 | 4 | ## Warning 5 | We dropped the development of this plugin 6 | 7 | ## Features 8 | - Allow players to choose their element, either once or whenever they want 9 | - Choose if player unlocks gradually their abilities by using the ones they start with, or if they know everything before hands using permissions 10 | - Choose to deepen your bending with a specialization 11 | - Tweak your existing bending at your will with a perk system: "path" 12 | - Choose the Avatar, the one that can bend all 4 elements ! 13 | 14 | ## Integration 15 | - Protect regions from specific bendings or all of them with WorldGuard and new flags 16 | - Allow your Citizens NPC to be "bendable" by adding a new trait to them 17 | 18 | ## Build & install 19 | We used gradle to generate our JAR file. 20 | To be able to effectively use it, you need to find and download the libraries listed in `/libs/PUT-HERE` and put them in the /libs folder. 21 | Once the libraries are set, you need to run the command (in the plugin root folder) : 22 | ```bash 23 | ./gradlew build 24 | ``` 25 | The resulting .jar can be put in the /plugins/ folder of your minecraft server alongside the libraries. 26 | Note that you need a mysql database to store the plugin's data. 27 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/event/BendingHitEvent.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.event; 2 | 3 | import org.bukkit.entity.Entity; 4 | import org.bukkit.event.Cancellable; 5 | import org.bukkit.event.Event; 6 | import org.bukkit.event.HandlerList; 7 | 8 | import net.bendercraft.spigot.bending.abilities.BendingAbility; 9 | 10 | /** 11 | * Unlike BendingDamageEvent, this one is fired when something affect an entity other than damage. 12 | * Change in velocity, potions effects and everything is do not damage directly an entity. 13 | * @author Koudja 14 | * 15 | */ 16 | public class BendingHitEvent extends Event implements Cancellable { 17 | protected static final HandlerList handlers = new HandlerList(); 18 | 19 | private final BendingAbility ability; 20 | private final Entity target; 21 | private boolean cancelled; 22 | 23 | public BendingHitEvent(BendingAbility ability, Entity target) { 24 | this.ability = ability; 25 | this.target = target; 26 | } 27 | 28 | public BendingAbility getAbility() { 29 | return ability; 30 | } 31 | 32 | public Entity getTarget() { 33 | return target; 34 | } 35 | 36 | public boolean isCancelled() { 37 | return cancelled; 38 | } 39 | 40 | public void setCancelled(boolean cancelled) { 41 | this.cancelled = cancelled; 42 | } 43 | 44 | @Override 45 | public HandlerList getHandlers() { 46 | return handlers; 47 | } 48 | 49 | public static HandlerList getHandlerList() { 50 | return handlers; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/earth/EarthCore.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.earth; 2 | 3 | import net.bendercraft.spigot.bending.abilities.BendingPerk; 4 | import net.bendercraft.spigot.bending.abilities.BendingPlayer; 5 | import net.bendercraft.spigot.bending.controller.ConfigurationParameter; 6 | 7 | public class EarthCore { 8 | @ConfigurationParameter("Max") 9 | private static int MAX = 4; 10 | 11 | @ConfigurationParameter("Penality-Per-Point") 12 | public static double PENALITY_PER_POINT = 0.1; 13 | 14 | private long lastDamageDone; 15 | private long lastPreventedDeath; 16 | 17 | private BendingPlayer bender; 18 | 19 | public EarthCore(BendingPlayer bender) { 20 | this.bender = bender; 21 | this.lastDamageDone = System.currentTimeMillis(); 22 | } 23 | 24 | public void damageDone() { 25 | this.lastDamageDone = System.currentTimeMillis(); 26 | } 27 | 28 | public void preventDeath() { 29 | this.lastPreventedDeath = System.currentTimeMillis(); 30 | } 31 | 32 | public boolean hasPreventDeath() { 33 | if(bender.hasPerk(BendingPerk.EARTH_RESISTANCE)) { 34 | if(System.currentTimeMillis() > lastPreventedDeath+120000) { 35 | return true; 36 | } 37 | } 38 | return false; 39 | } 40 | 41 | public double getBonus() { 42 | return 2; 43 | } 44 | 45 | public boolean hasBonus() { 46 | if(bender.hasPerk(BendingPerk.EARTH_PATIENCE)) { 47 | if(System.currentTimeMillis() > lastDamageDone+5000) { 48 | return true; 49 | } 50 | } 51 | return false; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/commands/subcommands/ReloadExecution.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.commands.subcommands; 2 | 3 | import java.util.List; 4 | 5 | import org.bukkit.ChatColor; 6 | import org.bukkit.command.CommandSender; 7 | 8 | import net.bendercraft.spigot.bending.Bending; 9 | import net.bendercraft.spigot.bending.Messages; 10 | import net.bendercraft.spigot.bending.abilities.AbilityManager; 11 | import net.bendercraft.spigot.bending.commands.BendingCommand; 12 | import net.bendercraft.spigot.bending.controller.Settings; 13 | import net.bendercraft.spigot.bending.utils.PluginTools; 14 | 15 | public class ReloadExecution extends BendingCommand { 16 | 17 | public ReloadExecution() { 18 | super(); 19 | this.command = "reload"; 20 | this.basePermission = "bending.command.reload"; 21 | } 22 | 23 | @Override 24 | public boolean execute(CommandSender sender, List args) { 25 | PluginTools.stopAllBending(); 26 | AbilityManager.getManager().stopAllAbilities(); 27 | Settings.applyConfiguration(Bending.getInstance().getDataFolder()); 28 | AbilityManager.getManager().applyConfiguration(Bending.getInstance().getDataFolder()); 29 | sender.sendMessage(ChatColor.GREEN + Messages.RELOADED); 30 | return true; 31 | } 32 | 33 | @Override 34 | public void printUsage(CommandSender sender, boolean permission) { 35 | if (!sender.hasPermission("bending.command.reload")) { 36 | sender.sendMessage("/bending reload"); 37 | } 38 | else if (permission) { 39 | sender.sendMessage(ChatColor.RED + Messages.NO_PERMISSION); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/BendingPassiveAbility.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import net.bendercraft.spigot.bending.utils.ProtectionManager; 6 | 7 | public abstract class BendingPassiveAbility extends BendingAbility { 8 | 9 | public BendingPassiveAbility(RegisteredAbility register, Player player) { 10 | super(register, player); 11 | } 12 | 13 | @Override 14 | public boolean canBeInitialized() { 15 | if (!super.canBeInitialized()) { 16 | return false; 17 | } 18 | 19 | if (ProtectionManager.isRegionProtectedFromBendingPassives(this.player, this.player.getLocation())) { 20 | return false; 21 | } 22 | 23 | return true; 24 | } 25 | 26 | /** 27 | * Start the new instance of the passive ability 28 | * 29 | * @return true if the passive properly worked 30 | * false if the passive did NOT properly work 31 | */ 32 | public abstract boolean start(); 33 | 34 | @Override 35 | public boolean canTick() { 36 | if(!super.canTick()) { 37 | return false; 38 | } 39 | if (ProtectionManager.isRegionProtectedFromBendingPassives(this.player, this.player.getLocation()) 40 | || !getState().equals(BendingAbilityState.PROGRESSING)) { 41 | return false; 42 | } 43 | return true; 44 | } 45 | 46 | @Override 47 | protected long getMaxMillis() { 48 | return 0; 49 | } 50 | 51 | public static boolean isPassive(RegisteredAbility register) { 52 | return BendingPassiveAbility.class.isAssignableFrom(register.getAbility()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/water/WaterBalance.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.water; 2 | 3 | import net.bendercraft.spigot.bending.abilities.BendingPerk; 4 | import net.bendercraft.spigot.bending.abilities.BendingPlayer; 5 | import net.bendercraft.spigot.bending.controller.ConfigurationParameter; 6 | 7 | public class WaterBalance { 8 | @ConfigurationParameter("Max") 9 | private static int MAX = 4; 10 | 11 | @ConfigurationParameter("Penality-Per-Point") 12 | public static double PENALITY_PER_POINT = 0.1; 13 | 14 | private int balance = 0; 15 | private int max; 16 | private double penalty; 17 | 18 | public WaterBalance(BendingPlayer bender) { 19 | this.max = MAX; 20 | if(bender.hasPerk(BendingPerk.WATER_EQUILIBIRUM)) { 21 | this.max -= 1; 22 | } 23 | 24 | this.penalty = PENALITY_PER_POINT; 25 | if(bender.hasPerk(BendingPerk.WATER_COMMUNION)) { 26 | this.penalty *= 0.5; 27 | } 28 | } 29 | 30 | public void liquid() { 31 | balance++; 32 | if(balance > max) { 33 | balance = max; 34 | } 35 | } 36 | 37 | public void ice() { 38 | balance--; 39 | if(balance <= -max) { 40 | balance = -max; 41 | } 42 | } 43 | 44 | public double damage(Damage type, double value) { 45 | if(toward(type)) { 46 | value *= 1-(penalty*Math.abs(balance)); 47 | } 48 | return value; 49 | } 50 | 51 | public boolean toward(Damage type) { 52 | if((balance < 0 && type == Damage.ICE) || (balance > 0 && type == Damage.LIQUID)) { 53 | return true; 54 | } 55 | return false; 56 | } 57 | 58 | public int getBalance() { 59 | return balance; 60 | } 61 | 62 | public void setBalance(int balance) { 63 | this.balance = balance; 64 | } 65 | 66 | public static enum Damage { 67 | LIQUID, ICE 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/arts/Speed.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.arts; 2 | 3 | import org.bukkit.entity.Player; 4 | import org.bukkit.potion.PotionEffect; 5 | import org.bukkit.potion.PotionEffectType; 6 | 7 | import net.bendercraft.spigot.bending.abilities.ABendingAbility; 8 | import net.bendercraft.spigot.bending.abilities.BendingAbilityState; 9 | import net.bendercraft.spigot.bending.abilities.BendingElement; 10 | import net.bendercraft.spigot.bending.abilities.BendingPassiveAbility; 11 | import net.bendercraft.spigot.bending.abilities.BendingPerk; 12 | import net.bendercraft.spigot.bending.abilities.RegisteredAbility; 13 | 14 | @ABendingAbility(name = Speed.NAME, element = BendingElement.MASTER, shift = false, passive = true) 15 | public class Speed extends BendingPassiveAbility { 16 | public final static String NAME = "Speed"; 17 | 18 | private int speedAmplifier = 0; 19 | public Speed(RegisteredAbility register, Player player) { 20 | super(register, player); 21 | } 22 | 23 | @Override 24 | public Object getIdentifier() { 25 | return this.player; 26 | } 27 | 28 | @Override 29 | public boolean start() { 30 | setState(BendingAbilityState.PROGRESSING); 31 | return true; 32 | } 33 | 34 | @Override 35 | public void progress() { 36 | if (this.player.isSprinting()) { 37 | if (this.bender.isBender(BendingElement.MASTER)) { 38 | applySpeed(); 39 | return; 40 | } 41 | } 42 | 43 | remove(); 44 | } 45 | 46 | private void applySpeed() { 47 | if(bender.hasPerk(BendingPerk.MASTER_TRAINING)) { 48 | PotionEffect speed = new PotionEffect(PotionEffectType.SPEED, 70, this.speedAmplifier); 49 | PotionEffect jump = new PotionEffect(PotionEffectType.JUMP, 70, 1); 50 | this.player.addPotionEffect(speed); 51 | this.player.addPotionEffect(jump); 52 | } 53 | } 54 | 55 | @Override 56 | public void stop() { 57 | 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/BendingPlayerData.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | import java.util.UUID; 6 | 7 | public class BendingPlayerData { 8 | private UUID player; 9 | private List bendings; 10 | private List affinities; 11 | private Map> decks; 12 | private String currentDeck; 13 | private List perks; 14 | private List abilities; 15 | 16 | public UUID getPlayer() { 17 | return this.player; 18 | } 19 | 20 | public void setPlayer(UUID player) { 21 | this.player = player; 22 | } 23 | 24 | public List getBendings() { 25 | return this.bendings; 26 | } 27 | 28 | public void setBendings(List bending) { 29 | this.bendings = bending; 30 | } 31 | 32 | public Map> getDecks() { 33 | return this.decks; 34 | } 35 | 36 | public void setDecks(Map> slotAbilities) { 37 | this.decks = slotAbilities; 38 | } 39 | 40 | public List getAffinities() { 41 | return this.affinities; 42 | } 43 | 44 | public void setAffinities(List affinities) { 45 | this.affinities = affinities; 46 | } 47 | 48 | public String getCurrentDeck() { 49 | return this.currentDeck; 50 | } 51 | 52 | public void setCurrentDeck(String currentDeck) { 53 | this.currentDeck = currentDeck; 54 | } 55 | 56 | public List getPerks() { 57 | return perks; 58 | } 59 | 60 | public void setPerks(List perks) { 61 | this.perks = perks; 62 | } 63 | 64 | public List getAbilities() { 65 | return abilities; 66 | } 67 | 68 | public void setAbilities(List abilities) { 69 | this.abilities = abilities; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/BendingActiveAbility.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import net.bendercraft.spigot.bending.utils.ProtectionManager; 6 | 7 | public abstract class BendingActiveAbility extends BendingAbility { 8 | 9 | public BendingActiveAbility(RegisteredAbility register, Player player) { 10 | super(register, player); 11 | } 12 | 13 | /** 14 | * What should the ability do when the player click 15 | * 16 | * @return true if we should create a new version of the 17 | * ability false otherwise 18 | */ 19 | public boolean swing() { 20 | return false; 21 | } 22 | 23 | /** 24 | * What should the ability do when the player jump. Not used for the moment 25 | * as no way to detect player jump. 26 | * 27 | * @return true if we should create a new version of the 28 | * ability false otherwise 29 | */ 30 | public boolean jump() { 31 | return false; 32 | } 33 | 34 | /** 35 | * What should the ability do when the player sneaks. 36 | * 37 | * @return true if we should create a new version of the 38 | * ability false otherwise 39 | */ 40 | public boolean sneak() { 41 | return false; 42 | } 43 | 44 | /** 45 | * What should the ability do when the player falls. 46 | * 47 | * @return true if we should create a new version of the 48 | * ability false otherwise 49 | */ 50 | public boolean fall() { 51 | return false; 52 | } 53 | 54 | @Override 55 | public boolean canTick() { 56 | if(!super.canTick()) { 57 | return false; 58 | } 59 | if (ProtectionManager.isLocationProtectedFromBending(this.player, register, this.player.getLocation())) { 60 | return false; 61 | } 62 | return true; 63 | } 64 | 65 | @Override 66 | protected long getMaxMillis() { 67 | return 60000; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/commands/subcommands/DebugExecution.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.commands.subcommands; 2 | 3 | import java.util.List; 4 | import org.bukkit.ChatColor; 5 | import org.bukkit.command.CommandSender; 6 | 7 | import net.bendercraft.spigot.bending.Messages; 8 | import net.bendercraft.spigot.bending.abilities.AbilityManager; 9 | import net.bendercraft.spigot.bending.abilities.BendingAbility; 10 | import net.bendercraft.spigot.bending.commands.BendingCommand; 11 | import net.bendercraft.spigot.bending.utils.TempBlock; 12 | 13 | public class DebugExecution extends BendingCommand { 14 | 15 | public DebugExecution() { 16 | super(); 17 | this.command = "debug"; 18 | this.basePermission = "bending.command.debug"; 19 | } 20 | 21 | @Override 22 | public boolean execute(CommandSender sender, List args) { 23 | List runnings = AbilityManager.getManager().getRunnings(); 24 | runnings.sort((o1, o2) -> (int) (o1.getStartedTime() - o2.getStartedTime())); 25 | 26 | long now = System.currentTimeMillis(); 27 | sender.sendMessage("Total temp block : "+ChatColor.GOLD+TempBlock.count()); 28 | sender.sendMessage("Total runnings abilities : "+ChatColor.GOLD+runnings.size()); 29 | for(BendingAbility running : runnings) { 30 | sender.sendMessage(" - "+ChatColor.DARK_PURPLE+running.getName()+ChatColor.RESET+" from "+ChatColor.GREEN+running.getPlayer().getName()+ChatColor.RESET+" since "+ChatColor.RED+((now - running.getStartedTime())/1000)+"s"); 31 | } 32 | 33 | return true; 34 | } 35 | 36 | @Override 37 | public void printUsage(CommandSender sender, boolean permission) { 38 | if (sender.hasPermission("bending.command.debug")) { 39 | sender.sendMessage("/bending debug"); 40 | } else if (permission) { 41 | sender.sendMessage(ChatColor.RED + Messages.NO_PERMISSION); 42 | } 43 | } 44 | 45 | @Override 46 | public List autoComplete(CommandSender sender, List args) { 47 | return null; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/fire/FirePower.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.fire; 2 | 3 | import net.bendercraft.spigot.bending.controller.ConfigurationParameter; 4 | 5 | public class FirePower { 6 | @ConfigurationParameter("Max") 7 | public static int MAX = 20; 8 | 9 | @ConfigurationParameter("Regen") 10 | private static int REGEN = 1; 11 | 12 | @ConfigurationParameter("Penality") 13 | private static int PENALITY = 2; 14 | 15 | @ConfigurationParameter("Tick") 16 | private static long TICK = 1000; 17 | 18 | private boolean halt = false; 19 | private int power = 0; 20 | private long time = System.currentTimeMillis(); 21 | private String lastAbility; 22 | 23 | public void progress() { 24 | long now = System.currentTimeMillis(); 25 | if(time + TICK < now) { 26 | time = now; 27 | if(!halt && power < MAX) { 28 | power += REGEN; 29 | } 30 | } 31 | } 32 | 33 | public void halt() { 34 | halt = true; 35 | } 36 | 37 | public void resume() { 38 | halt = false; 39 | } 40 | 41 | public void set(int value) { 42 | power = value; 43 | } 44 | 45 | public void grant(int value) { 46 | power += value; 47 | if(power > MAX) { 48 | power = MAX; 49 | } 50 | } 51 | 52 | public void consume(String ability, int amount) { 53 | consume(ability, amount, true); 54 | } 55 | 56 | public void consume(String ability, int amount, boolean penality) { 57 | if(lastAbility != null && lastAbility.equals(ability)) { 58 | amount *= PENALITY; 59 | } 60 | power -= amount; 61 | lastAbility = ability; 62 | } 63 | 64 | public boolean can(String ability, int amount) { 65 | if(lastAbility != null && lastAbility.equals(ability)) { 66 | amount *= PENALITY; 67 | } 68 | return (power >= amount); 69 | } 70 | 71 | public int getPower() { 72 | return power; 73 | } 74 | 75 | public String getLastAbility() { 76 | return lastAbility; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /migration/v5_x_x_to_v6_0_0.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | 4 | def main(): 5 | print "Start converting..." 6 | old = {} 7 | with open("benders.json", "r") as f: 8 | old = json.load(f)["datas"] 9 | try: 10 | os.mkdir("bender") 11 | except OSError: 12 | pass 13 | players = 0 14 | chi = 0 15 | for key,value in old.iteritems(): 16 | try: 17 | converted = {} 18 | converted["player"] = value["player"] 19 | converted["bendings"] = value["bendings"] 20 | converted["affinities"] = value["specialization"] 21 | if "ChiBlocker" in converted["bendings"]: 22 | if "Air" in converted["bendings"]: 23 | converted["affinities"] = ["ChiAir"] 24 | elif "Fire" in converted["bendings"]: 25 | converted["affinities"] = ["ChiFire"] 26 | elif "Earth" in converted["bendings"]: 27 | converted["affinities"] = ["ChiEarth"] 28 | elif "Water" in converted["bendings"]: 29 | converted["affinities"] = ["ChiWater"] 30 | converted["bendings"] = ["ChiBlocker"] 31 | 32 | converted["paths"] = [] 33 | converted["decks"] = {} 34 | converted["decks"]["default"] = {} 35 | converted["currentDeck"] = "default" 36 | converted["lastTime"] = value["lastTime"] 37 | with open("bender/{}.json".format(key), "w") as f: 38 | json.dump(converted, f) 39 | players += 1 40 | if "ChiBlocker" in converted["bendings"] and "Inventor" not in value["specialization"]: 41 | chi += 1 42 | except Excption as e: 43 | print " Player {} failed to be converted : {}".format(key, e) 44 | print "{} players has been converted. {} were chi inventor.".format(players, chi) 45 | print "... finished !" 46 | 47 | if __name__ == "__main__": 48 | main() -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/commands/subcommands/ClearExecution.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.commands.subcommands; 2 | 3 | import java.util.List; 4 | 5 | import org.bukkit.ChatColor; 6 | import org.bukkit.command.CommandSender; 7 | import org.bukkit.entity.Player; 8 | 9 | import net.bendercraft.spigot.bending.Messages; 10 | import net.bendercraft.spigot.bending.abilities.BendingPlayer; 11 | import net.bendercraft.spigot.bending.commands.BendingCommand; 12 | 13 | public class ClearExecution extends BendingCommand { 14 | 15 | public ClearExecution() { 16 | super(); 17 | this.command = "clear"; 18 | this.aliases.add("cl"); 19 | this.basePermission = "bending.command.clear"; 20 | } 21 | 22 | @Override 23 | public boolean execute(CommandSender sender, List args) { 24 | if (!(sender instanceof Player)) { 25 | sender.sendMessage(ChatColor.RED + Messages.NOT_CONSOLE_COMMAND); 26 | return true; 27 | } 28 | 29 | Player player = (Player) sender; 30 | 31 | BendingPlayer bender = BendingPlayer.getBendingPlayer(player); 32 | 33 | if (args.isEmpty()) { 34 | bender.clearAbilities(); 35 | sender.sendMessage(Messages.CLEARED); 36 | } 37 | else { 38 | try { 39 | int slot = Integer.parseInt(args.get(0)); 40 | if (slot < 1 || slot > 9) { 41 | sender.sendMessage(ChatColor.RED + Messages.INVALID_SLOT); 42 | return true; 43 | } 44 | bender.unbind(slot-1); 45 | String msg = Messages.SLOT_CLEARED; 46 | msg = msg.replaceAll("\\{0\\}", "" + slot); 47 | sender.sendMessage(msg); 48 | } 49 | catch (NumberFormatException ex) { 50 | sender.sendMessage(ChatColor.RED + Messages.INVALID_SLOT); 51 | } 52 | 53 | } 54 | 55 | return true; 56 | } 57 | 58 | @Override 59 | public void printUsage(CommandSender sender, boolean permission) { 60 | if (sender.hasPermission("bending.command.clear")) { 61 | sender.sendMessage("/bending clear [slot#]"); 62 | } 63 | else if (permission) { 64 | sender.sendMessage(ChatColor.RED + Messages.NO_PERMISSION); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/air/AirSpeed.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.air; 2 | 3 | import org.bukkit.entity.Player; 4 | import org.bukkit.potion.PotionEffect; 5 | import org.bukkit.potion.PotionEffectType; 6 | 7 | import net.bendercraft.spigot.bending.abilities.ABendingAbility; 8 | import net.bendercraft.spigot.bending.abilities.BendingAbilityState; 9 | import net.bendercraft.spigot.bending.abilities.BendingElement; 10 | import net.bendercraft.spigot.bending.abilities.BendingPassiveAbility; 11 | import net.bendercraft.spigot.bending.abilities.RegisteredAbility; 12 | import net.bendercraft.spigot.bending.utils.EntityTools; 13 | 14 | @ABendingAbility(name = AirSpeed.NAME, element = BendingElement.AIR, passive = true) 15 | public class AirSpeed extends BendingPassiveAbility { 16 | public final static String NAME = "AirSpeed"; 17 | 18 | public AirSpeed(RegisteredAbility register, Player player) { 19 | super(register, player); 20 | } 21 | 22 | @Override 23 | public Object getIdentifier() { 24 | return this.player; 25 | } 26 | 27 | @Override 28 | public boolean start() { 29 | setState(BendingAbilityState.PROGRESSING); 30 | return true; 31 | } 32 | 33 | @Override 34 | public void progress() { 35 | if (this.player.isSprinting() 36 | && this.bender.isBender(BendingElement.AIR) 37 | && EntityTools.canBendPassive(this.player, BendingElement.AIR)) { 38 | applySpeed(); 39 | } 40 | } 41 | 42 | private void applySpeed() { 43 | PotionEffect speed = new PotionEffect(PotionEffectType.SPEED, 70, 1); 44 | 45 | this.player.addPotionEffect(speed); 46 | if (!AirScooter.NAME.equals(EntityTools.getBendingAbility(player))) { 47 | PotionEffect jump = new PotionEffect(PotionEffectType.JUMP, 70, 2); 48 | this.player.addPotionEffect(jump); 49 | } 50 | } 51 | 52 | @Override 53 | public boolean canBeInitialized() { 54 | if (!super.canBeInitialized()) { 55 | return false; 56 | } 57 | 58 | if (!(this.bender.isBender(BendingElement.AIR))) { 59 | return false; 60 | } 61 | 62 | return true; 63 | } 64 | 65 | @Override 66 | public void stop() { 67 | 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/commands/subcommands/CredentialsExecution.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.commands.subcommands; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | 6 | import org.apache.commons.lang.RandomStringUtils; 7 | import org.bukkit.ChatColor; 8 | import org.bukkit.command.CommandSender; 9 | import org.bukkit.entity.Player; 10 | 11 | import net.bendercraft.spigot.bending.Messages; 12 | import net.bendercraft.spigot.bending.commands.BendingCommand; 13 | import net.bendercraft.spigot.bending.db.MySQLDB; 14 | 15 | public class CredentialsExecution extends BendingCommand { 16 | 17 | public CredentialsExecution() { 18 | super(); 19 | this.command = "credentials"; 20 | this.aliases.add("c"); 21 | this.basePermission = "bending.command.credentials"; 22 | } 23 | 24 | @Override 25 | public boolean execute(CommandSender sender, List args) { 26 | if (!(sender instanceof Player)) { 27 | sender.sendMessage(ChatColor.RED + Messages.NOT_CONSOLE_COMMAND); 28 | return true; 29 | } 30 | 31 | Player player = (Player) sender; 32 | String token = RandomStringUtils.randomAlphanumeric((int) (6 + Math.random()*3)); 33 | MySQLDB.credentials(player.getUniqueId(), player.getName(), token); 34 | 35 | String prefix = ChatColor.GREEN+"["+ChatColor.AQUA+"Bending"+ChatColor.GREEN+"] "; 36 | 37 | sender.sendMessage(prefix+"Adresse : "+ChatColor.GOLD+"https://talents.avatar-horizon.world"); 38 | sender.sendMessage(prefix+"Nom d'utilisateur : "+ChatColor.GOLD+player.getName()); 39 | sender.sendMessage(prefix+"Mot de passe : "+ChatColor.GOLD+token); 40 | 41 | return true; 42 | } 43 | 44 | @Override 45 | public void printUsage(CommandSender sender, boolean permission) { 46 | if (sender.hasPermission("bending.command.credentials")) { 47 | sender.sendMessage("/bending credentials"); 48 | } else if (permission) { 49 | sender.sendMessage(ChatColor.RED + Messages.NO_PERMISSION); 50 | } 51 | } 52 | 53 | @Override 54 | public List autoComplete(CommandSender sender, List args) { 55 | return new LinkedList(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/arts/DaggerFall.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.arts; 2 | 3 | import java.util.Arrays; 4 | 5 | import org.bukkit.Material; 6 | import org.bukkit.entity.Player; 7 | import org.bukkit.inventory.ItemStack; 8 | import org.bukkit.inventory.meta.ItemMeta; 9 | 10 | import net.bendercraft.spigot.bending.abilities.ABendingAbility; 11 | import net.bendercraft.spigot.bending.abilities.BendingActiveAbility; 12 | import net.bendercraft.spigot.bending.abilities.BendingAffinity; 13 | import net.bendercraft.spigot.bending.abilities.RegisteredAbility; 14 | import net.bendercraft.spigot.bending.controller.ConfigurationParameter; 15 | import net.bendercraft.spigot.bending.utils.EntityTools; 16 | 17 | @ABendingAbility(name = DaggerFall.NAME, affinity = BendingAffinity.SWORD) 18 | public class DaggerFall extends BendingActiveAbility { 19 | public final static String NAME = "DaggerFall"; 20 | 21 | @ConfigurationParameter("Cooldown") 22 | private static long COOLDOWN = 15000; 23 | 24 | @ConfigurationParameter("Range") 25 | private static int RANGE = 3; 26 | 27 | public DaggerFall(RegisteredAbility register, Player player) { 28 | super(register, player); 29 | } 30 | 31 | @Override 32 | public boolean swing() { 33 | 34 | return false; 35 | } 36 | 37 | @Override 38 | public boolean sneak() { 39 | ItemStack dagger = new ItemStack(Material.IRON_SWORD, 1); 40 | ItemMeta metaDagger = dagger.getItemMeta(); 41 | metaDagger.setLore(Arrays.asList("Dagger")); 42 | dagger.setItemMeta(metaDagger); 43 | 44 | ItemStack shield = new ItemStack(Material.SHIELD, 1); 45 | ItemMeta metaShield = shield.getItemMeta(); 46 | metaShield.setLore(Arrays.asList("Shield")); 47 | shield.setItemMeta(metaShield); 48 | 49 | EntityTools.giveItemInMainHand(player, dagger); 50 | EntityTools.giveItemInOffHand(player, shield); 51 | 52 | bender.cooldown(this, COOLDOWN); 53 | return false; 54 | } 55 | 56 | @Override 57 | public void progress() { 58 | 59 | } 60 | 61 | @Override 62 | public Object getIdentifier() { 63 | return this.player; 64 | } 65 | 66 | @Override 67 | public void stop() { 68 | 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/commands/subcommands/HelpExecution.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.commands.subcommands; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | 6 | import org.bukkit.ChatColor; 7 | import org.bukkit.command.CommandSender; 8 | import org.bukkit.entity.Player; 9 | 10 | import net.bendercraft.spigot.bending.Messages; 11 | import net.bendercraft.spigot.bending.commands.BendingCommand; 12 | import net.bendercraft.spigot.bending.commands.IBendingCommand; 13 | 14 | public class HelpExecution extends BendingCommand { 15 | 16 | private List commands; 17 | 18 | public HelpExecution(List commands) { 19 | super(); 20 | this.commands = commands; 21 | this.command = "help"; 22 | this.aliases.add("?"); 23 | this.aliases.add("h"); 24 | this.basePermission = "bending.command.help"; 25 | } 26 | 27 | @Override 28 | public boolean execute(CommandSender sender, List args) { 29 | 30 | if (args.isEmpty()) { 31 | if (!(sender instanceof Player)) { 32 | sender.sendMessage(ChatColor.RED + Messages.NOT_CONSOLE_COMMAND); 33 | return true; 34 | } 35 | for (IBendingCommand cmd : this.commands) { 36 | cmd.printUsage(sender, false); 37 | } 38 | } 39 | else { 40 | String subCommand = args.remove(0); 41 | for (IBendingCommand cmd : this.commands) { 42 | if (cmd.isCommand(subCommand)) { 43 | cmd.printUsage(sender); 44 | break; 45 | } 46 | } 47 | } 48 | return true; 49 | } 50 | 51 | @Override 52 | public void printUsage(CommandSender sender, boolean permission) { 53 | if (sender.hasPermission("bending.command.help")) { 54 | sender.sendMessage("/bending help [command]"); 55 | } 56 | else if (permission) { 57 | sender.sendMessage(ChatColor.RED + Messages.NO_PERMISSION); 58 | } 59 | } 60 | 61 | @Override 62 | public List autoComplete(CommandSender sender, List args) { 63 | LinkedList values = new LinkedList(); 64 | if (args.size() == 1) { 65 | for (IBendingCommand cmd : this.commands) { 66 | if (sender.hasPermission("bending.command." + cmd.getCommand())) { 67 | values.add(cmd.getCommand()); 68 | } 69 | } 70 | } 71 | return values; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/arts/HighJump.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.arts; 2 | 3 | import org.bukkit.block.BlockFace; 4 | import org.bukkit.entity.Player; 5 | import org.bukkit.util.Vector; 6 | 7 | import net.bendercraft.spigot.bending.abilities.ABendingAbility; 8 | import net.bendercraft.spigot.bending.abilities.BendingActiveAbility; 9 | import net.bendercraft.spigot.bending.abilities.BendingElement; 10 | import net.bendercraft.spigot.bending.abilities.BendingPerk; 11 | import net.bendercraft.spigot.bending.abilities.RegisteredAbility; 12 | import net.bendercraft.spigot.bending.controller.ConfigurationParameter; 13 | import net.bendercraft.spigot.bending.utils.BlockTools; 14 | import net.bendercraft.spigot.bending.utils.Tools; 15 | 16 | @ABendingAbility(name = HighJump.NAME, element = BendingElement.MASTER, shift=false) 17 | public class HighJump extends BendingActiveAbility { 18 | public final static String NAME = "HighJump"; 19 | 20 | @ConfigurationParameter("Height") 21 | private static int JUMP_HEIGHT = 7; 22 | 23 | @ConfigurationParameter("Cooldown") 24 | private static long COOLDOWN = 3500; 25 | 26 | private int height; 27 | 28 | private long cooldown; 29 | 30 | public HighJump(RegisteredAbility register, Player player) { 31 | super(register, player); 32 | 33 | this.height = JUMP_HEIGHT; 34 | if(bender.hasPerk(BendingPerk.MASTER_HIGHJUMP_HEIGHT)) { 35 | this.height += 1; 36 | } 37 | this.cooldown = COOLDOWN; 38 | if(bender.hasPerk(BendingPerk.MASTER_HIGHJUMP_COOLDOWN)) { 39 | this.cooldown -= 500; 40 | } 41 | } 42 | 43 | @Override 44 | public boolean swing() { 45 | if (makeJump()) { 46 | this.bender.cooldown(NAME, cooldown); 47 | } 48 | return true; 49 | } 50 | 51 | private boolean makeJump() { 52 | if (!BlockTools.isSolid(this.player.getLocation().getBlock().getRelative(BlockFace.DOWN))) { 53 | return false; 54 | } 55 | Vector vec = Tools.getVectorForPoints(this.player.getLocation(), this.player.getLocation().add(this.player.getVelocity()).add(0, height, 0)); 56 | this.player.setVelocity(vec); 57 | return true; 58 | } 59 | 60 | @Override 61 | public Object getIdentifier() { 62 | return this.player; 63 | } 64 | 65 | @Override 66 | public void progress() { 67 | 68 | } 69 | 70 | @Override 71 | public void stop() { 72 | 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/water/WaterPassive.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.water; 2 | 3 | import org.bukkit.Material; 4 | import org.bukkit.block.Block; 5 | import org.bukkit.block.BlockFace; 6 | import org.bukkit.entity.Player; 7 | import org.bukkit.util.Vector; 8 | 9 | import net.bendercraft.spigot.bending.abilities.ABendingAbility; 10 | import net.bendercraft.spigot.bending.abilities.BendingElement; 11 | import net.bendercraft.spigot.bending.abilities.BendingPassiveAbility; 12 | import net.bendercraft.spigot.bending.abilities.RegisteredAbility; 13 | import net.bendercraft.spigot.bending.utils.BlockTools; 14 | import net.bendercraft.spigot.bending.utils.EntityTools; 15 | 16 | @ABendingAbility(name = "WaterPassive", element = BendingElement.WATER, passive = true) 17 | public class WaterPassive extends BendingPassiveAbility { 18 | public final static String NAME = "WaterPassive"; 19 | 20 | public WaterPassive(RegisteredAbility register, Player player) { 21 | super(register, player); 22 | } 23 | 24 | public static Vector handle(Player player, Vector velocity) { 25 | Vector vec = velocity.clone(); 26 | return vec; 27 | } 28 | 29 | @Override 30 | public boolean start() { 31 | Block block = this.player.getLocation().getBlock(); 32 | Block fallblock = block.getRelative(BlockFace.DOWN); 33 | 34 | if (BlockTools.isAir(fallblock)) { 35 | return true; 36 | } 37 | 38 | if (BlockTools.isWaterbendable(block, this.player) && !BlockTools.isPlant(block)) { 39 | return true; 40 | } 41 | 42 | if ((BlockTools.isWaterbendable(fallblock, this.player) && !BlockTools.isPlant(fallblock)) || (fallblock.getType() == Material.SNOW_BLOCK)) { 43 | return true; 44 | } 45 | 46 | return false; 47 | } 48 | 49 | @Override 50 | public Object getIdentifier() { 51 | return this.player; 52 | } 53 | 54 | @Override 55 | public boolean canBeInitialized() { 56 | if (!super.canBeInitialized()) { 57 | return false; 58 | } 59 | 60 | if (!this.bender.isBender(BendingElement.WATER)) { 61 | return false; 62 | } 63 | 64 | if (!EntityTools.canBendPassive(this.player, BendingElement.WATER)) { 65 | return false; 66 | } 67 | 68 | return true; 69 | } 70 | 71 | @Override 72 | public void progress() { 73 | 74 | } 75 | 76 | @Override 77 | public void stop() { 78 | 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/commands/subcommands/RemoveExecution.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.commands.subcommands; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | 6 | import org.bukkit.Bukkit; 7 | import org.bukkit.ChatColor; 8 | import org.bukkit.command.CommandSender; 9 | import org.bukkit.entity.Player; 10 | 11 | import net.bendercraft.spigot.bending.Messages; 12 | import net.bendercraft.spigot.bending.abilities.BendingPlayer; 13 | import net.bendercraft.spigot.bending.commands.BendingCommand; 14 | 15 | public class RemoveExecution extends BendingCommand { 16 | 17 | public RemoveExecution() { 18 | super(); 19 | this.command = "remove"; 20 | this.aliases.add("r"); 21 | this.aliases.add("rem"); 22 | this.aliases.add("rm"); 23 | this.basePermission = "bending.command.remove"; 24 | } 25 | 26 | @Override 27 | public boolean execute(CommandSender sender, List args) { 28 | 29 | if (args.isEmpty()) { 30 | sender.sendMessage(ChatColor.RED + Messages.INVALID_PLAYER); 31 | printUsage(sender); 32 | return true; 33 | } 34 | 35 | String playerName = args.get(0); 36 | Player player = getPlayer(playerName); 37 | 38 | if (player == null) { 39 | sender.sendMessage(ChatColor.RED + Messages.INVALID_PLAYER); 40 | return true; 41 | } 42 | 43 | BendingPlayer bender = BendingPlayer.getBendingPlayer(player); 44 | bender.removeBender(); 45 | 46 | player.sendMessage(Messages.OTHER_REMOVE_YOU); 47 | String msg = Messages.YOU_REMOVE_OTHER; 48 | msg = msg.replaceAll("\\{0\\}", playerName); 49 | sender.sendMessage(msg); 50 | return true; 51 | } 52 | 53 | @Override 54 | public void printUsage(CommandSender sender, boolean permission) { 55 | if (sender.hasPermission("bending.command.remove")) { 56 | sender.sendMessage(ChatColor.RED + "/bending remove "); 57 | } 58 | else if (permission) { 59 | sender.sendMessage(ChatColor.RED + Messages.NO_PERMISSION); 60 | } 61 | } 62 | 63 | @Override 64 | public List autoComplete(CommandSender sender, List args) { 65 | LinkedList values = new LinkedList(); 66 | 67 | if (sender.hasPermission("bending.command.remove")) { 68 | for (Player player : Bukkit.getServer().getOnlinePlayers()) { 69 | values.add(player.getName()); 70 | } 71 | } 72 | return values; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/commands/subcommands/ToggleExecution.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.commands.subcommands; 2 | 3 | import java.util.List; 4 | 5 | import org.bukkit.ChatColor; 6 | import org.bukkit.command.CommandSender; 7 | import org.bukkit.entity.Player; 8 | 9 | import net.bendercraft.spigot.bending.Messages; 10 | import net.bendercraft.spigot.bending.commands.BendingCommand; 11 | import net.bendercraft.spigot.bending.utils.EntityTools; 12 | 13 | public class ToggleExecution extends BendingCommand { 14 | 15 | public ToggleExecution() { 16 | super(); 17 | this.command = "toggle"; 18 | this.aliases.add("t"); 19 | this.basePermission = "bending.command.toggle"; 20 | } 21 | 22 | @Override 23 | public boolean execute(CommandSender sender, List args) { 24 | if (!(sender instanceof Player)) { 25 | sender.sendMessage(ChatColor.RED + Messages.NOT_CONSOLE_COMMAND); 26 | return true; 27 | } 28 | 29 | Player player = (Player) sender; 30 | 31 | if (args.size() >= 1 && isAffinityToggle(args.get(0))) { 32 | if (EntityTools.getToggledAffinities().contains(player.getUniqueId())) { 33 | EntityTools.getToggledAffinities().remove(player.getUniqueId()); 34 | player.sendMessage("You toggled back your affinity"); 35 | } else { 36 | EntityTools.getToggledAffinities().add(player.getUniqueId()); 37 | player.sendMessage("You toggled your affinity"); 38 | } 39 | } else { 40 | if (!EntityTools.getToggledBendings().contains(player.getUniqueId())) { 41 | EntityTools.getToggledBendings().add(player.getUniqueId()); 42 | Messages.sendMessage(player, "general.toggle_off", ChatColor.AQUA); 43 | } else { 44 | EntityTools.getToggledBendings().remove(player.getUniqueId()); 45 | Messages.sendMessage(player, "general.toggle_on", ChatColor.AQUA); 46 | } 47 | } 48 | 49 | return true; 50 | } 51 | 52 | @Override 53 | public void printUsage(CommandSender sender, boolean permission) { 54 | if (sender.hasPermission("bending.command.toggle")) { 55 | sender.sendMessage("/bending toggle (aff)"); 56 | } 57 | else if (permission) { 58 | sender.sendMessage(ChatColor.RED + Messages.NO_PERMISSION); 59 | } 60 | } 61 | 62 | private boolean isAffinityToggle(String arg) { 63 | if (arg.equalsIgnoreCase("spe") || arg.equalsIgnoreCase("aff") || arg.equalsIgnoreCase("affinity")) { 64 | return true; 65 | } 66 | return false; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/utils/RollingFileHandler.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.utils; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.text.SimpleDateFormat; 6 | import java.util.Date; 7 | import java.util.logging.ErrorManager; 8 | import java.util.logging.FileHandler; 9 | import java.util.logging.Handler; 10 | import java.util.logging.Level; 11 | import java.util.logging.LogRecord; 12 | 13 | public class RollingFileHandler extends Handler { 14 | 15 | private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); 16 | 17 | private String fileName; 18 | private File folder; 19 | 20 | private FileHandler handler; 21 | private String current; 22 | 23 | public RollingFileHandler(File folder, String fileName) throws IOException, SecurityException { 24 | this.folder = folder; 25 | this.fileName = fileName; 26 | this.current = getFileName(new Date()); 27 | } 28 | 29 | private String getFileName(Date date) { 30 | return this.folder.getPath()+"/"+fileName.replaceAll("%d", format.format(new Date())); 31 | } 32 | 33 | private FileHandler getHandler() throws SecurityException, IOException { 34 | String check = getFileName(new Date()); 35 | if(!check.equals(current)) { 36 | handler.flush(); 37 | handler.close(); 38 | handler = null; 39 | current = check; 40 | } 41 | 42 | if(handler == null) { 43 | handler = new FileHandler(current, true); 44 | handler.setLevel(getLevel()); 45 | handler.setEncoding(getEncoding()); 46 | handler.setFilter(getFilter()); 47 | handler.setFormatter(getFormatter()); 48 | handler.setErrorManager(getErrorManager()); 49 | } 50 | return handler; 51 | } 52 | 53 | @Override 54 | public synchronized void publish(LogRecord r) { 55 | if (isLoggable(r)) { 56 | try { 57 | FileHandler h = getHandler(); 58 | 59 | h.publish(r); 60 | } catch (IOException | SecurityException jm) { 61 | this.reportError(null, jm, ErrorManager.WRITE_FAILURE); 62 | } 63 | } 64 | } 65 | 66 | @Override 67 | public void close() throws SecurityException { 68 | super.setLevel(Level.OFF); 69 | if(handler != null) { 70 | handler.close(); 71 | } 72 | } 73 | 74 | @Override 75 | public void flush() { 76 | if(handler != null) { 77 | handler.flush(); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/integrations/protocollib/BendingPacketAdapter.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.integrations.protocollib; 2 | 3 | import java.util.List; 4 | import com.comphenix.protocol.PacketType; 5 | import com.comphenix.protocol.events.PacketAdapter; 6 | import com.comphenix.protocol.events.PacketContainer; 7 | import com.comphenix.protocol.events.PacketEvent; 8 | import com.comphenix.protocol.reflect.FieldAccessException; 9 | import com.comphenix.protocol.wrappers.WrappedWatchableObject; 10 | 11 | import net.bendercraft.spigot.bending.Bending; 12 | import net.bendercraft.spigot.bending.abilities.arts.Mark; 13 | import net.bendercraft.spigot.bending.abilities.earth.TremorSense; 14 | 15 | public class BendingPacketAdapter extends PacketAdapter { 16 | 17 | public BendingPacketAdapter(Bending plugin) { 18 | super(plugin, PacketType.Play.Server.ENTITY_METADATA); 19 | } 20 | 21 | @Override 22 | public void onPacketSending(PacketEvent event) { 23 | PacketContainer packet = event.getPacket(); 24 | // Because we listen for "ENTITY_METADATA", packet we should have is "PacketPlayOutEntityMetadata" 25 | // it has one integer filed : entity id 26 | int entityID = packet.getIntegers().readSafely(0); 27 | 28 | if (Mark.isMarked(entityID)) { 29 | //If the entity is marked, everyone must see it -> no filter 30 | return; 31 | } 32 | 33 | if (TremorSense.isEntityTremorsensedByPlayer(entityID, event.getPlayer())) { 34 | //If that entity is tremorsensed by this player, he needs to see it -> no filter 35 | return; 36 | } 37 | 38 | //This packet also have a collection of datawatcher with only one on it 39 | List metadatas = packet.getWatchableCollectionModifier().readSafely(0); 40 | WrappedWatchableObject status = null; 41 | for (WrappedWatchableObject metadata : metadatas) { 42 | //See http://wiki.vg/Entities for explanation on why index 0 43 | try { 44 | if (metadata.getIndex() == 0) { 45 | status = metadata; 46 | break; 47 | } 48 | } 49 | catch(FieldAccessException e) { 50 | } 51 | } 52 | 53 | if(status != null) { 54 | byte mask = (byte) status.getValue(); //0x40 = Glowing effect mask 55 | mask &= ~0x40;//0x40 = Glowing effect mask 56 | status.setValue(mask); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/water/FastSwimming.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.water; 2 | 3 | import org.bukkit.Material; 4 | import org.bukkit.entity.Player; 5 | import org.bukkit.util.Vector; 6 | 7 | import net.bendercraft.spigot.bending.abilities.ABendingAbility; 8 | import net.bendercraft.spigot.bending.abilities.AbilityManager; 9 | import net.bendercraft.spigot.bending.abilities.BendingAbilityState; 10 | import net.bendercraft.spigot.bending.abilities.BendingElement; 11 | import net.bendercraft.spigot.bending.abilities.BendingPassiveAbility; 12 | import net.bendercraft.spigot.bending.abilities.RegisteredAbility; 13 | import net.bendercraft.spigot.bending.controller.ConfigurationParameter; 14 | import net.bendercraft.spigot.bending.utils.EntityTools; 15 | import net.bendercraft.spigot.bending.utils.TempBlock; 16 | 17 | @ABendingAbility(name = FastSwimming.NAME, element = BendingElement.WATER, passive = true, canBeUsedWithTools = true) 18 | public class FastSwimming extends BendingPassiveAbility { 19 | public final static String NAME = "Dolphin"; 20 | 21 | @ConfigurationParameter("Speed-Factor") 22 | private static double FACTOR = 0.7; 23 | 24 | public FastSwimming(RegisteredAbility register, Player player) { 25 | super(register, player); 26 | } 27 | 28 | @Override 29 | public boolean start() { 30 | setState(BendingAbilityState.PROGRESSING); 31 | return true; 32 | } 33 | 34 | 35 | @Override 36 | public boolean canTick() { 37 | if(!super.canTick()) { 38 | return false; 39 | } 40 | 41 | if (!(EntityTools.canBendPassive(player, BendingElement.WATER) && player.isSneaking())) { 42 | return false; 43 | } 44 | String ability = EntityTools.getBendingAbility(player); 45 | RegisteredAbility register = AbilityManager.getManager().getRegisteredAbility(ability); 46 | if ((ability != null) && register.isShift() && !ability.equals(WaterSpout.NAME)) { 47 | return false; 48 | } 49 | 50 | if (WaterSpout.isBending(player)) { 51 | return false; 52 | } 53 | 54 | return true; 55 | } 56 | 57 | @Override 58 | public void progress() { 59 | if (player.getLocation().getBlock().getType() == Material.WATER && !TempBlock.isTempBlock(player.getLocation().getBlock())) { 60 | swimFast(); 61 | } 62 | } 63 | 64 | private void swimFast() { 65 | Vector dir = player.getEyeLocation().getDirection().clone(); 66 | player.setVelocity(dir.normalize().multiply(FACTOR)); 67 | } 68 | 69 | @Override 70 | public Object getIdentifier() { 71 | return this.player; 72 | } 73 | 74 | @Override 75 | public void stop() { 76 | 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /migration/create_db.sql: -------------------------------------------------------------------------------- 1 | 2 | CREATE TABLE IF NOT EXISTS `players` ( 3 | `uuid` CHAR(36) NOT NULL, 4 | `name` VARCHAR(16) NOT NULL, 5 | PRIMARY KEY (`uuid`)) 6 | ENGINE = InnoDB; 7 | 8 | CREATE TABLE IF NOT EXISTS `elements` ( 9 | `player_uuid` CHAR(36) NOT NULL, 10 | `element` VARCHAR(32) NOT NULL, 11 | PRIMARY KEY (`player_uuid`, `element`), 12 | CONSTRAINT `fk_element_player` 13 | FOREIGN KEY (`player_uuid`) 14 | REFERENCES `players` (`uuid`)) 15 | ENGINE = InnoDB; 16 | 17 | CREATE TABLE IF NOT EXISTS `affinities` ( 18 | `player_uuid` CHAR(36) NOT NULL, 19 | `affinity` VARCHAR(64) NOT NULL, 20 | PRIMARY KEY (`player_uuid`, `affinity`), 21 | CONSTRAINT `fk_affinity_player` 22 | FOREIGN KEY (`player_uuid`) 23 | REFERENCES `players` (`uuid`)) 24 | ENGINE = InnoDB; 25 | 26 | CREATE TABLE IF NOT EXISTS `credentials` ( 27 | `player_uuid` CHAR(36) NOT NULL, 28 | `username` VARCHAR(64) NOT NULL, 29 | `token` VARCHAR(16) NOT NULL, 30 | PRIMARY KEY (`player_uuid`), 31 | CONSTRAINT `fk_credentials_player` 32 | FOREIGN KEY (`player_uuid`) 33 | REFERENCES `players` (`uuid`)) 34 | ENGINE = InnoDB; 35 | 36 | CREATE TABLE IF NOT EXISTS `decks` ( 37 | `uuid` CHAR(36) NOT NULL, 38 | `owner_uuid` CHAR(36) NOT NULL, 39 | `name` VARCHAR(64) NOT NULL DEFAULT 'default', 40 | `current` TINYINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '1 True\n0 False', 41 | PRIMARY KEY (`uuid`), 42 | UNIQUE INDEX `uq_deck_per_player` (`owner_uuid` ASC, `name` ASC), 43 | INDEX `ix_player_decks` (`owner_uuid` ASC), 44 | CONSTRAINT `fk_deck_owner` 45 | FOREIGN KEY (`owner_uuid`) 46 | REFERENCES `players` (`uuid`)) 47 | ENGINE = InnoDB; 48 | 49 | CREATE TABLE IF NOT EXISTS `deck_entries` ( 50 | `deck_uuid` CHAR(36) NOT NULL, 51 | `slot` SMALLINT NOT NULL, 52 | `ability` VARCHAR(64) NOT NULL, 53 | PRIMARY KEY (`deck_uuid`, `slot`), 54 | UNIQUE INDEX `uq_deck_slot` (`deck_uuid` ASC, `slot` ASC), 55 | CONSTRAINT `fk_entry_deck` 56 | FOREIGN KEY (`deck_uuid`) 57 | REFERENCES `decks` (`uuid`)) 58 | ENGINE = InnoDB; 59 | 60 | CREATE TABLE IF NOT EXISTS `abilities` ( 61 | `player_uuid` CHAR(36) NOT NULL, 62 | `ability` VARCHAR(64) NOT NULL, 63 | PRIMARY KEY (`player_uuid`, `ability`), 64 | CONSTRAINT `fk_ability_player` 65 | FOREIGN KEY (`player_uuid`) 66 | REFERENCES `players` (`uuid`)) 67 | ENGINE = InnoDB; 68 | 69 | CREATE TABLE IF NOT EXISTS `perks` ( 70 | `player_uuid` CHAR(36) NOT NULL, 71 | `perk` VARCHAR(128) NOT NULL, 72 | PRIMARY KEY (`player_uuid`, `perk`), 73 | CONSTRAINT `fk_perk_player` 74 | FOREIGN KEY (`player_uuid`) 75 | REFERENCES `players` (`uuid`)) 76 | ENGINE = InnoDB; 77 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/RegisteredAbility.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities; 2 | 3 | import java.lang.reflect.Constructor; 4 | import java.util.Objects; 5 | 6 | 7 | public class RegisteredAbility { 8 | 9 | private final Class ability; 10 | private final String name; 11 | private final BendingElement element; 12 | private final BendingAffinity affinity; 13 | private final Constructor constructor; 14 | private final boolean shift; 15 | private final boolean passive; 16 | private final boolean useWithTools; 17 | 18 | public RegisteredAbility(String name, Class ability, BendingElement element, boolean shift, boolean passive, boolean tools, Constructor constructor) { 19 | this(name, ability, element, null, shift, passive, tools, constructor); 20 | } 21 | 22 | public RegisteredAbility(String name, Class ability, BendingElement element, BendingAffinity affinity, boolean shift, boolean passive, boolean tools, Constructor constructor) { 23 | this.name = name; 24 | this.ability = ability; 25 | this.element = element; 26 | this.affinity = affinity; 27 | this.constructor = constructor; 28 | this.shift = shift; 29 | this.passive = passive; 30 | this.useWithTools = tools; 31 | } 32 | 33 | public Class getAbility() { 34 | return this.ability; 35 | } 36 | 37 | public String getName() { 38 | return this.name; 39 | } 40 | 41 | public BendingElement getElement() { 42 | return this.element; 43 | } 44 | 45 | public BendingAffinity getAffinity() { 46 | return this.affinity; 47 | } 48 | 49 | public String getConfigPath() { 50 | return this.element.name().toLowerCase() + "." + this.name.toLowerCase().replaceAll(" ", "_"); 51 | } 52 | 53 | public Constructor getConstructor() { 54 | return constructor; 55 | } 56 | 57 | public boolean isShift() { 58 | return shift; 59 | } 60 | 61 | public boolean isPassive() { 62 | return passive; 63 | } 64 | 65 | public boolean canBeUsedWithTools() { 66 | return useWithTools; 67 | } 68 | 69 | @Override 70 | public boolean equals(Object o) { 71 | if (this == o) { return true; } 72 | if (o == null || getClass() != o.getClass()) { return false; } 73 | RegisteredAbility that = (RegisteredAbility) o; 74 | return ability.equals(that.ability) && name.equals(that.name) && element == that.element && affinity == that.affinity; 75 | } 76 | 77 | @Override 78 | public int hashCode() { 79 | return Objects.hash(ability); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /migration/v6_1_0_to_v7_1_0.py: -------------------------------------------------------------------------------- 1 | import json 2 | import MySQLdb 3 | import os 4 | import uuid 5 | 6 | 7 | 8 | def main(): 9 | db = MySQLdb.connect( 10 | host='localhost', 11 | user='changeme', 12 | passwd='changeme', 13 | db='changeme', 14 | ) 15 | cursor = db.cursor() 16 | known = [] 17 | for filename in os.listdir('benders'): 18 | print('Processing {}...'.format(filename)) 19 | 20 | with open('benders/{}'.format(filename), 'r') as f: 21 | data = json.load(f) 22 | known.append(data['player']) 23 | cursor.execute('INSERT INTO players(uuid,name) VALUES (%s,%s)', args=[data['player'], 'Unknown']) 24 | args = [] 25 | for element in data['bendings']: 26 | if not element: 27 | continue 28 | args.append([data['player'], element]) 29 | cursor.executemany('INSERT INTO elements(player_uuid, element) VALUES (%s,%s)', args=args) 30 | 31 | args = [] 32 | for affinity in data['affinities']: 33 | args.append([data['player'], affinity]) 34 | cursor.executemany('INSERT INTO affinities(player_uuid, affinity) VALUES (%s,%s)', args=args) 35 | 36 | args_deck = [] 37 | args_entry = [] 38 | for name, content in data['decks'].items(): 39 | deck_uuid = uuid.uuid4() 40 | current = 1 if name == data['currentDeck'] else 0 41 | args_deck.append([deck_uuid, data['player'], name, current]) 42 | for slot, ability in content.items(): 43 | args_entry.append([deck_uuid, slot, ability]) 44 | cursor.executemany('INSERT INTO decks(uuid, owner_uuid, name, current) VALUES (%s,%s,%s,%s)', args=args_deck) 45 | cursor.executemany('INSERT INTO deck_entries(deck_uuid, slot, ability) VALUES (%s,%s,%s)', args=args_entry) 46 | with open('permissions.json', 'r') as f: 47 | data = json.load(f) 48 | args = [] 49 | for player_uuid, permissions in data['permissions'].items(): 50 | if player_uuid not in known: 51 | continue 52 | done = [] 53 | for permission in permissions: 54 | permission = permission.split('.')[-1] 55 | if permission in done: 56 | continue 57 | done.append(permission) 58 | args.append([player_uuid, permission]) 59 | cursor.executemany('INSERT INTO abilities(player_uuid, ability) VALUES(%s,%s)', args=args) 60 | db.commit() 61 | db.close() 62 | 63 | 64 | if __name__ == '__main__': 65 | main() -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/commands/BendingCommand.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.commands; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | 6 | import org.bukkit.Bukkit; 7 | import org.bukkit.command.CommandSender; 8 | import org.bukkit.entity.Player; 9 | 10 | import net.bendercraft.spigot.bending.abilities.BendingElement; 11 | import net.bendercraft.spigot.bending.controller.Settings; 12 | 13 | public abstract class BendingCommand implements IBendingCommand { 14 | 15 | protected String command; 16 | protected List aliases; 17 | protected String basePermission; 18 | 19 | public BendingCommand() { 20 | this.aliases = new LinkedList(); 21 | } 22 | 23 | @Override 24 | public boolean isCommand(String cmd) { 25 | if (this.command.equalsIgnoreCase(cmd)) { 26 | return true; 27 | } 28 | 29 | for (String alias : this.aliases) { 30 | if (alias.equalsIgnoreCase(cmd)) { 31 | return true; 32 | } 33 | } 34 | 35 | return false; 36 | } 37 | 38 | protected Player getPlayer(String name) { 39 | for (Player player : Bukkit.getServer().getOnlinePlayers()) { 40 | if (player.getName().equalsIgnoreCase(name)) { 41 | return player; 42 | } 43 | } 44 | return null; 45 | } 46 | 47 | protected BendingElement getElement(String name) { 48 | 49 | for (String alias : Settings.AIR_ALIASES) { 50 | if (alias.equalsIgnoreCase(name)) { 51 | return BendingElement.AIR; 52 | } 53 | } 54 | 55 | for (String alias : Settings.MASTER_ALIASES) { 56 | if (alias.equalsIgnoreCase(name)) { 57 | return BendingElement.MASTER; 58 | } 59 | } 60 | 61 | for (String alias : Settings.EARTH_ALIASES) { 62 | if (alias.equalsIgnoreCase(name)) { 63 | return BendingElement.EARTH; 64 | } 65 | } 66 | 67 | for (String alias : Settings.FIRE_ALIASES) { 68 | if (alias.equalsIgnoreCase(name)) { 69 | return BendingElement.FIRE; 70 | } 71 | } 72 | 73 | for (String alias : Settings.WATER_ALIASES) { 74 | if (alias.equalsIgnoreCase(name)) { 75 | return BendingElement.WATER; 76 | } 77 | } 78 | 79 | return null; 80 | } 81 | 82 | @Override 83 | public void printUsage(CommandSender sender) { 84 | printUsage(sender, true); 85 | } 86 | 87 | @Override 88 | public String getCommand() { 89 | return this.command; 90 | } 91 | 92 | @Override 93 | public List autoComplete(CommandSender sender, List args) { 94 | return new LinkedList(); 95 | } 96 | 97 | @Override 98 | public final boolean hasBasePermission(CommandSender sender) { 99 | if (sender.hasPermission(this.basePermission)) { 100 | return true; 101 | } 102 | return false; 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/learning/MasterListener.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.learning; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import java.util.UUID; 6 | 7 | import org.bukkit.ChatColor; 8 | import org.bukkit.Location; 9 | import org.bukkit.entity.Player; 10 | import org.bukkit.event.EventHandler; 11 | import org.bukkit.event.Listener; 12 | import org.bukkit.event.player.PlayerToggleSprintEvent; 13 | 14 | import net.bendercraft.spigot.bending.abilities.BendingElement; 15 | import net.bendercraft.spigot.bending.abilities.BendingPlayer; 16 | import net.bendercraft.spigot.bending.abilities.arts.Dash; 17 | import net.bendercraft.spigot.bending.controller.Settings; 18 | import net.bendercraft.spigot.bending.utils.PluginTools; 19 | 20 | public class MasterListener implements Listener { 21 | private BendingLearning plugin; 22 | 23 | private Map sprintDistanceTraveledDash = new HashMap(); 24 | private Map sprintLastLocationDash = new HashMap(); 25 | private static final int distanceNeededDash = 1000; 26 | 27 | private static ChatColor color = PluginTools.getColor(Settings.getColor(BendingElement.MASTER)); 28 | 29 | public MasterListener(BendingLearning plugin) { 30 | this.plugin = plugin; 31 | 32 | } 33 | 34 | @EventHandler 35 | public void unlockDash(PlayerToggleSprintEvent event) { 36 | Player pl = event.getPlayer(); 37 | BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(pl); 38 | if (bPlayer != null) { 39 | if (bPlayer.isBender(BendingElement.MASTER)) { 40 | if (!pl.isSprinting()) { 41 | sprintLastLocationDash.put(pl.getUniqueId(), pl.getLocation().clone()); 42 | } else { 43 | if (sprintLastLocationDash.containsKey(pl.getUniqueId())) { 44 | Location last = sprintLastLocationDash.get(pl.getUniqueId()); 45 | Location current = pl.getLocation(); 46 | if (last.getWorld().getUID().equals(current.getWorld().getUID())) { 47 | double distance = last.distance(current); 48 | if (sprintDistanceTraveledDash.containsKey(pl.getUniqueId())) { 49 | distance = sprintDistanceTraveledDash.get(pl.getUniqueId()) + distance; 50 | } 51 | if (distance >= distanceNeededDash) { 52 | if (plugin.addPermission(pl, Dash.NAME)) { 53 | 54 | String message = "Wooo !"; 55 | pl.sendMessage(color + message); 56 | message = "Congratulations, you have unlocked " + Dash.NAME; 57 | pl.sendMessage(color + message); 58 | } 59 | sprintDistanceTraveledDash.remove(pl.getUniqueId()); 60 | } else { 61 | sprintDistanceTraveledDash.put(pl.getUniqueId(), distance); 62 | } 63 | } 64 | } 65 | } 66 | } 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/arts/Supply.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.arts; 2 | 3 | import org.bukkit.Material; 4 | import org.bukkit.NamespacedKey; 5 | import org.bukkit.enchantments.Enchantment; 6 | import org.bukkit.entity.Player; 7 | import org.bukkit.inventory.ItemStack; 8 | import org.bukkit.inventory.meta.ItemMeta; 9 | 10 | import net.bendercraft.spigot.bending.Bending; 11 | import net.bendercraft.spigot.bending.abilities.ABendingAbility; 12 | import net.bendercraft.spigot.bending.abilities.BendingActiveAbility; 13 | import net.bendercraft.spigot.bending.abilities.BendingAffinity; 14 | import net.bendercraft.spigot.bending.abilities.RegisteredAbility; 15 | import net.bendercraft.spigot.bending.controller.ConfigurationParameter; 16 | import net.bendercraft.spigot.bending.utils.EntityTools; 17 | import org.bukkit.persistence.PersistentDataType; 18 | 19 | @ABendingAbility(name = Supply.NAME, affinity = BendingAffinity.BOW) 20 | public class Supply extends BendingActiveAbility { 21 | public final static String NAME = "Supply"; 22 | 23 | private final static NamespacedKey BOW_KEY = new NamespacedKey(Bending.getInstance(), "Supply_bow"); 24 | private final static NamespacedKey ARROW_KEY = new NamespacedKey(Bending.getInstance(), "Supply_arrow"); 25 | 26 | @ConfigurationParameter("Cooldown") 27 | private static long COOLDOWN = 15000; 28 | 29 | @ConfigurationParameter("Range") 30 | private static int RANGE = 3; 31 | 32 | public Supply(RegisteredAbility register, Player player) { 33 | super(register, player); 34 | } 35 | 36 | @Override 37 | public boolean swing() { 38 | 39 | return false; 40 | } 41 | 42 | @Override 43 | public boolean sneak() { 44 | ItemStack bow = new ItemStack(Material.BOW, 1); 45 | bow.addEnchantment(Enchantment.ARROW_INFINITE, 1); 46 | bow.addEnchantment(Enchantment.ARROW_KNOCKBACK, 2); 47 | ItemMeta bowMeta = bow.getItemMeta(); 48 | bowMeta.getPersistentDataContainer().set(BOW_KEY, PersistentDataType.SHORT, (short)1); 49 | bow.setItemMeta(bowMeta); 50 | EntityTools.giveItemInMainHand(player, bow); 51 | 52 | ItemStack arrow = new ItemStack(Material.ARROW, 1); 53 | ItemMeta arrowMeta = arrow.getItemMeta(); 54 | arrowMeta.getPersistentDataContainer().set(ARROW_KEY, PersistentDataType.SHORT, (short)1); 55 | arrow.setItemMeta(arrowMeta); 56 | player.getInventory().addItem(arrow); 57 | 58 | bender.cooldown(this, COOLDOWN); 59 | return false; 60 | } 61 | 62 | @Override 63 | public void progress() { 64 | 65 | } 66 | 67 | public static boolean isBow(ItemStack item) { 68 | return item != null 69 | && item.getType() == Material.BOW 70 | && item.hasItemMeta() 71 | && item.getItemMeta().getPersistentDataContainer().has(BOW_KEY, PersistentDataType.SHORT); 72 | } 73 | 74 | public static boolean isArrow(ItemStack item) { 75 | return item != null 76 | && item.getType() == Material.ARROW 77 | && item.hasItemMeta() 78 | && item.getItemMeta().getPersistentDataContainer().has(ARROW_KEY, PersistentDataType.SHORT); 79 | } 80 | 81 | @Override 82 | public Object getIdentifier() { 83 | return this.player; 84 | } 85 | 86 | @Override 87 | public void stop() { 88 | 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/arts/Mark.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.arts; 2 | 3 | import org.bukkit.entity.Entity; 4 | import org.bukkit.entity.LivingEntity; 5 | import org.bukkit.entity.Player; 6 | import org.bukkit.potion.PotionEffectType; 7 | 8 | import net.bendercraft.spigot.bending.Bending; 9 | import net.bendercraft.spigot.bending.abilities.*; 10 | import net.bendercraft.spigot.bending.controller.ConfigurationParameter; 11 | import net.bendercraft.spigot.bending.event.BendingHitEvent; 12 | import net.bendercraft.spigot.bending.utils.EntityTools; 13 | 14 | import java.util.Map; 15 | 16 | /** 17 | * 18 | * This ability throws a poisonned dart to straight foward. If the dart hit an 19 | * entity, this entity gets poisonned. The type of poisonned can change if 20 | * specifics items are hold in hand. 21 | * 22 | */ 23 | 24 | @ABendingAbility(name = Mark.NAME, affinity = BendingAffinity.BOW) 25 | public class Mark extends BendingActiveAbility { 26 | public final static String NAME = "Mark"; 27 | 28 | @ConfigurationParameter("Range") 29 | private static int RANGE = 50; 30 | 31 | @ConfigurationParameter("Duration") 32 | private static int DURATION = 10000; 33 | 34 | @ConfigurationParameter("Amplifier") 35 | private static int AMPLIFIER = 1; 36 | 37 | private LivingEntity target; 38 | 39 | public Mark(RegisteredAbility register, Player player) { 40 | super(register, player); 41 | } 42 | 43 | @Override 44 | public boolean sneak() { 45 | target = EntityTools.getTargetedEntity(player, RANGE); 46 | if(target != null) { 47 | if(affect(target)) { 48 | bender.cooldown(this, DURATION); 49 | setState(BendingAbilityState.PROGRESSING); 50 | } 51 | } 52 | return false; 53 | } 54 | 55 | 56 | @Override 57 | public void progress() { 58 | 59 | } 60 | 61 | @Override 62 | public Object getIdentifier() { 63 | return this.player; 64 | } 65 | 66 | @Override 67 | public void stop() { 68 | if (target != null) { 69 | target.removePotionEffect(PotionEffectType.GLOWING); 70 | } 71 | } 72 | 73 | public LivingEntity getTarget() { 74 | return target; 75 | } 76 | 77 | @Override 78 | protected long getMaxMillis() { 79 | return DURATION; 80 | } 81 | 82 | private boolean affect(Entity entity) { 83 | BendingHitEvent event = new BendingHitEvent(this, entity); 84 | Bending.callEvent(event); 85 | if(event.isCancelled()) { 86 | return false; 87 | } 88 | target.addPotionEffect(PotionEffectType.GLOWING.createEffect(DURATION*20/1000, 1)); 89 | return true; 90 | } 91 | 92 | public static boolean isMarked(LivingEntity target) { 93 | return isMarked(target.getEntityId()); 94 | } 95 | 96 | public static boolean isMarked(int entityID) { 97 | Map marks = AbilityManager.getManager().getInstances(NAME); 98 | if (marks == null || marks.isEmpty()) { 99 | return false; 100 | } 101 | for(BendingAbility raw : marks.values()) { 102 | Mark ability = (Mark) raw; 103 | if(ability.getTarget() != null 104 | && ability.getTarget().getEntityId() == entityID) { 105 | return true; 106 | } 107 | } 108 | return false; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto init 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto init 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :init 68 | @rem Get command-line arguments, handling Windows variants 69 | 70 | if not "%OS%" == "Windows_NT" goto win9xME_args 71 | 72 | :win9xME_args 73 | @rem Slurp the command line arguments. 74 | set CMD_LINE_ARGS= 75 | set _SKIP=2 76 | 77 | :win9xME_args_slurp 78 | if "x%~1" == "x" goto execute 79 | 80 | set CMD_LINE_ARGS=%* 81 | 82 | :execute 83 | @rem Setup the command line 84 | 85 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 86 | 87 | @rem Execute Gradle 88 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 89 | 90 | :end 91 | @rem End local scope for the variables with windows NT shell 92 | if "%ERRORLEVEL%"=="0" goto mainEnd 93 | 94 | :fail 95 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 96 | rem the _cmd.exe /c_ return code! 97 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 98 | exit /b 1 99 | 100 | :mainEnd 101 | if "%OS%"=="Windows_NT" endlocal 102 | 103 | :omega 104 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/earth/MetalWire.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.earth; 2 | 3 | import java.util.HashMap; 4 | import java.util.LinkedList; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | import org.bukkit.Location; 9 | import org.bukkit.Material; 10 | import org.bukkit.block.Block; 11 | import org.bukkit.entity.FishHook; 12 | import org.bukkit.entity.Player; 13 | import org.bukkit.inventory.ItemStack; 14 | import org.bukkit.inventory.meta.Damageable; 15 | import org.bukkit.inventory.meta.ItemMeta; 16 | import org.bukkit.util.Vector; 17 | 18 | import com.google.common.collect.Sets; 19 | 20 | import net.bendercraft.spigot.bending.controller.ConfigurationParameter; 21 | import net.bendercraft.spigot.bending.utils.BlockTools; 22 | import net.bendercraft.spigot.bending.utils.Tools; 23 | 24 | public class MetalWire { 25 | 26 | private static Map instances = new HashMap(); 27 | private static Map noFall = new HashMap(); 28 | 29 | @ConfigurationParameter("Time-No-Fall") 30 | private static long TIME_NO_FALL = 2200; 31 | 32 | public static void pull(Player player, FishHook hook) { 33 | List toRemove = new LinkedList(); 34 | for (Player p : instances.keySet()) { 35 | if (instances.get(p).isDead() || !instances.get(p).isValid()) { 36 | toRemove.add(p); 37 | } 38 | } 39 | 40 | for (Player p : toRemove) { 41 | instances.remove(p); 42 | } 43 | 44 | if (instances.containsKey(player)) { 45 | if (hookHangsOn(hook)) { 46 | Location targetLoc = hook.getLocation().clone().add(0, 1.5, 0); 47 | Location playerLoc = player.getLocation(); 48 | 49 | Vector dir = Tools.getVectorForPoints(playerLoc, targetLoc); 50 | player.setVelocity(dir); 51 | noFall.put(player, System.currentTimeMillis()); 52 | int slot = player.getInventory().getHeldItemSlot(); 53 | ItemStack rod = player.getInventory().getItem(slot); 54 | if (rod != null && rod.getType() == Material.FISHING_ROD) { 55 | ItemMeta meta = rod.getItemMeta(); 56 | Damageable metaDamageable = (Damageable) meta; 57 | metaDamageable.setDamage(metaDamageable.getDamage() - 2); 58 | rod.setItemMeta(meta); 59 | player.getInventory().setItem(slot, rod); 60 | } 61 | } 62 | 63 | instances.remove(player); 64 | } else { 65 | // if the list doesn't contain the player, it means he just launched 66 | // the hook 67 | launchHook(player, hook); 68 | } 69 | } 70 | 71 | public static void launchHook(Player player, FishHook hook) { 72 | // Would prefer it more accurate 73 | instances.put(player, hook); 74 | Block b = player.getTargetBlock(BlockTools.getAirs(), 30); 75 | if (b != null) { 76 | hook.setVelocity(Tools.getVectorForPoints(hook.getLocation(), b.getLocation())); 77 | } 78 | } 79 | 80 | public static boolean hookHangsOn(FishHook hook) { 81 | for (Block block : BlockTools.getBlocksAroundPoint(hook.getLocation(), 1.5)) { 82 | if (!BlockTools.isFluid(block)) { 83 | return true; 84 | } 85 | } 86 | return false; 87 | } 88 | 89 | public static boolean hasNoFallDamage(Player pl) { 90 | boolean r = false; 91 | List toRemove = new LinkedList(); 92 | for (Player p : noFall.keySet()) { 93 | if (System.currentTimeMillis() > noFall.get(p) + TIME_NO_FALL) { 94 | toRemove.add(p); 95 | } else { 96 | if (p.equals(pl)) { 97 | r = true; 98 | } 99 | } 100 | } 101 | 102 | for (Player p : toRemove) { 103 | noFall.remove(p); 104 | } 105 | return r; 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/arts/Dash.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.arts; 2 | 3 | import java.util.Map; 4 | 5 | import org.bukkit.entity.Player; 6 | import org.bukkit.util.Vector; 7 | 8 | import net.bendercraft.spigot.bending.abilities.ABendingAbility; 9 | import net.bendercraft.spigot.bending.abilities.AbilityManager; 10 | import net.bendercraft.spigot.bending.abilities.BendingAbility; 11 | import net.bendercraft.spigot.bending.abilities.BendingAbilityState; 12 | import net.bendercraft.spigot.bending.abilities.BendingActiveAbility; 13 | import net.bendercraft.spigot.bending.abilities.BendingElement; 14 | import net.bendercraft.spigot.bending.abilities.BendingPerk; 15 | import net.bendercraft.spigot.bending.abilities.RegisteredAbility; 16 | import net.bendercraft.spigot.bending.controller.ConfigurationParameter; 17 | 18 | @ABendingAbility(name = Dash.NAME, element = BendingElement.MASTER, shift = false, canBeUsedWithTools = true) 19 | public class Dash extends BendingActiveAbility { 20 | public final static String NAME = "Dash"; 21 | 22 | @ConfigurationParameter("Length") 23 | private static double LENGTH = 1.95; 24 | 25 | @ConfigurationParameter("Height") 26 | private static double HEIGHT = 0.71; 27 | 28 | @ConfigurationParameter("Cooldown") 29 | private static long COOLDOWN = 4000; 30 | 31 | private Vector direction; 32 | 33 | private double length; 34 | 35 | private long cooldown; 36 | 37 | public Dash(RegisteredAbility register, Player player) { 38 | super(register, player); 39 | 40 | this.length = LENGTH; 41 | if(bender.hasPerk(BendingPerk.MASTER_DASH_RANGE)) { 42 | this.length *= 1.1; 43 | } 44 | 45 | this.cooldown = COOLDOWN; 46 | if(bender.hasPerk(BendingPerk.MASTER_DASH_CD)) { 47 | this.cooldown -= 500; 48 | } 49 | } 50 | 51 | @Override 52 | public boolean sneak() { 53 | if (getState() == BendingAbilityState.START) { 54 | setState(BendingAbilityState.PREPARING); 55 | } 56 | 57 | return false; 58 | } 59 | 60 | public static boolean isDashing(Player player) { 61 | Map instances = AbilityManager.getManager().getInstances(NAME); 62 | if ((instances == null) || instances.isEmpty()) { 63 | return false; 64 | } 65 | return instances.containsKey(player); 66 | } 67 | 68 | public static Dash getDash(Player pl) { 69 | Map instances = AbilityManager.getManager().getInstances(NAME); 70 | return (Dash) instances.get(pl); 71 | } 72 | 73 | @Override 74 | public void progress() { 75 | if (getState() == BendingAbilityState.PROGRESSING) { 76 | dash(); 77 | } 78 | } 79 | 80 | public void dash() { 81 | Vector dir = new Vector(this.direction.getX() * length, HEIGHT, this.direction.getZ() * length); 82 | this.player.setVelocity(dir); 83 | remove(); 84 | } 85 | 86 | // This should be called in OnMoveEvent to set the direction dash the same 87 | // as the player 88 | public void setDirection(Vector d) { 89 | if (getState() != BendingAbilityState.PREPARING) { 90 | return; 91 | } 92 | if (Double.isNaN(d.getX()) || Double.isNaN(d.getY()) || Double.isNaN(d.getZ()) || (((d.getX() < 0.005) && (d.getX() > -0.005)) && ((d.getZ() < 0.005) && (d.getZ() > -0.005)))) { 93 | this.direction = this.player.getLocation().getDirection().clone().normalize(); 94 | } else { 95 | this.direction = d.normalize(); 96 | } 97 | setState(BendingAbilityState.PROGRESSING); 98 | } 99 | 100 | @Override 101 | public void stop() { 102 | this.bender.cooldown(NAME, cooldown); 103 | } 104 | 105 | @Override 106 | public Object getIdentifier() { 107 | return this.player; 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/commands/subcommands/PerkExecution.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.commands.subcommands; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | 6 | import org.bukkit.ChatColor; 7 | import org.bukkit.command.CommandSender; 8 | import org.bukkit.entity.Player; 9 | 10 | import net.bendercraft.spigot.bending.Messages; 11 | import net.bendercraft.spigot.bending.abilities.BendingPerk; 12 | import net.bendercraft.spigot.bending.abilities.BendingPlayer; 13 | import net.bendercraft.spigot.bending.commands.BendingCommand; 14 | 15 | public class PerkExecution extends BendingCommand { 16 | 17 | public PerkExecution() { 18 | super(); 19 | this.command = "perk"; 20 | this.aliases.add("p"); 21 | this.basePermission = "bending.command.perk"; 22 | } 23 | 24 | @Override 25 | public boolean execute(CommandSender sender, List args) { 26 | if(args.size() == 0) { 27 | if(!(sender instanceof Player)) { 28 | sender.sendMessage(ChatColor.RED + Messages.NOT_CONSOLE_COMMAND); 29 | return true; 30 | } 31 | Player player = (Player) sender; 32 | BendingPlayer bender = BendingPlayer.getBendingPlayer(player); 33 | 34 | List perks = bender.getPerks(); 35 | StringBuilder sb = new StringBuilder(); 36 | 37 | perks.forEach(p -> sb.append(p.name+", ")); 38 | 39 | sender.sendMessage("Player "+player.getName()+" has perk :"); 40 | sender.sendMessage(sb.toString()); 41 | return true; 42 | } else if(args.size() == 1) { 43 | String arg = args.get(0); 44 | if(arg.equals("reset")) { 45 | if(!(sender instanceof Player)) { 46 | sender.sendMessage(ChatColor.RED + Messages.NOT_CONSOLE_COMMAND); 47 | return true; 48 | } 49 | //TODO check perm when debug is over 50 | Player player = (Player) sender; 51 | BendingPlayer bender = BendingPlayer.getBendingPlayer(player); 52 | bender.resetPerks(); 53 | sender.sendMessage("You have lost all your perks."); 54 | return true; 55 | } else { 56 | if (!sender.hasPermission("bending.admin")) { 57 | sender.sendMessage(ChatColor.RED + Messages.NO_PERMISSION); 58 | return true; 59 | } 60 | Player player = getPlayer(arg); 61 | BendingPlayer bender = BendingPlayer.getBendingPlayer(player); 62 | List perks = bender.getPerks(); 63 | StringBuilder sb = new StringBuilder(); 64 | 65 | perks.forEach(p -> sb.append(p.name+", ")); 66 | 67 | sender.sendMessage("Player "+player.getName()+" has perk :"); 68 | sender.sendMessage(sb.toString()); 69 | return true; 70 | } 71 | } else if(args.size() == 2) { 72 | if (!sender.hasPermission("bending.admin")) { 73 | sender.sendMessage(ChatColor.RED + Messages.NO_PERMISSION); 74 | return true; 75 | } 76 | 77 | String arg = args.get(0); 78 | if(arg.equals("reset")) { 79 | Player player = getPlayer(args.get(1)); 80 | BendingPlayer bender = BendingPlayer.getBendingPlayer(player); 81 | bender.resetPerks(); 82 | sender.sendMessage("Player "+player.getName()+" losts all its perks."); 83 | return true; 84 | } 85 | } 86 | 87 | printUsage(sender); 88 | return true; 89 | } 90 | 91 | @Override 92 | public void printUsage(CommandSender sender, boolean permission) { 93 | if (sender.hasPermission("bending.command.perk")) { 94 | sender.sendMessage("/bending perk"); 95 | } else if (permission) { 96 | sender.sendMessage(ChatColor.RED + Messages.NO_PERMISSION); 97 | } 98 | } 99 | 100 | @Override 101 | public List autoComplete(CommandSender sender, List args) { 102 | return new LinkedList(); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/arts/DirectHit.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.arts; 2 | 3 | import org.bukkit.entity.Entity; 4 | import org.bukkit.entity.LivingEntity; 5 | import org.bukkit.entity.Player; 6 | import org.bukkit.util.Vector; 7 | 8 | import net.bendercraft.spigot.bending.Bending; 9 | import net.bendercraft.spigot.bending.abilities.ABendingAbility; 10 | import net.bendercraft.spigot.bending.abilities.BendingActiveAbility; 11 | import net.bendercraft.spigot.bending.abilities.BendingElement; 12 | import net.bendercraft.spigot.bending.abilities.BendingPerk; 13 | import net.bendercraft.spigot.bending.abilities.RegisteredAbility; 14 | import net.bendercraft.spigot.bending.controller.ConfigurationParameter; 15 | import net.bendercraft.spigot.bending.event.BendingHitEvent; 16 | import net.bendercraft.spigot.bending.utils.DamageTools; 17 | import net.bendercraft.spigot.bending.utils.EntityTools; 18 | 19 | /** 20 | * 21 | * This ability hit the first entity in front of you powerfully driving to a 22 | * knockback You must be sneaking when clicking to activate this technique. 23 | * 24 | */ 25 | @ABendingAbility(name = DirectHit.NAME, element = BendingElement.MASTER, shift=false) 26 | public class DirectHit extends BendingActiveAbility { 27 | public final static String NAME = "DirectHit"; 28 | 29 | @ConfigurationParameter("Damage") 30 | public static long DAMAGE = 5; 31 | 32 | @ConfigurationParameter("Knockback") 33 | public static long KNOCKBACK = 2; 34 | 35 | @ConfigurationParameter("Range") 36 | public static long RANGE = 4; 37 | 38 | @ConfigurationParameter("Cooldown") 39 | public static long COOLDOWN = 1500; 40 | 41 | private long knockback; 42 | private long cooldown; 43 | 44 | public DirectHit(RegisteredAbility register, Player player) { 45 | super(register, player); 46 | 47 | this.knockback = KNOCKBACK; 48 | if(bender.hasPerk(BendingPerk.MASTER_DIRECTHIT_PUSH)) { 49 | this.knockback += 1; 50 | } 51 | this.cooldown = COOLDOWN; 52 | if(bender.hasPerk(BendingPerk.MASTER_DIRECTHIT_COOLDOWN)) { 53 | this.cooldown -= 500; 54 | } 55 | } 56 | 57 | @Override 58 | public boolean swing() { 59 | LivingEntity target = EntityTools.getTargetedEntity(this.player, RANGE); 60 | if(target == null) { 61 | remove(); 62 | return false; 63 | } 64 | if(this.player.isSneaking()) { 65 | if(affect(target)) { 66 | this.bender.cooldown(this, cooldown); 67 | } 68 | } 69 | return false; 70 | } 71 | 72 | @Override 73 | public void progress() { 74 | 75 | } 76 | 77 | @Override 78 | protected long getMaxMillis() { 79 | return 1; 80 | } 81 | 82 | @Override 83 | public Object getIdentifier() { 84 | return this.player; 85 | } 86 | 87 | @Override 88 | public boolean canBeInitialized() { 89 | if (!super.canBeInitialized()) { 90 | return false; 91 | } 92 | 93 | if (EntityTools.holdsTool(player)) { 94 | return false; 95 | } 96 | 97 | return true; 98 | } 99 | 100 | @Override 101 | public void stop() { 102 | 103 | } 104 | 105 | private boolean affect(Entity entity) { 106 | BendingHitEvent event = new BendingHitEvent(this, entity); 107 | Bending.callEvent(event); 108 | if(event.isCancelled()) { 109 | return false; 110 | } 111 | DamageTools.damageEntity(bender, entity, this, DAMAGE, false, DamageTools.DEFAULT_NODAMAGETICKS, 0.0f, true); 112 | Vector direction = entity.getLocation().toVector().subtract(player.getLocation().toVector()).normalize(); 113 | entity.setVelocity(direction.multiply(knockback)); 114 | 115 | return true; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/commands/subcommands/AddExecution.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.commands.subcommands; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | 6 | import org.bukkit.Bukkit; 7 | import org.bukkit.ChatColor; 8 | import org.bukkit.command.CommandSender; 9 | import org.bukkit.entity.Player; 10 | 11 | import net.bendercraft.spigot.bending.Messages; 12 | import net.bendercraft.spigot.bending.abilities.BendingElement; 13 | import net.bendercraft.spigot.bending.abilities.BendingPlayer; 14 | import net.bendercraft.spigot.bending.commands.BendingCommand; 15 | 16 | public class AddExecution extends BendingCommand { 17 | 18 | public AddExecution() { 19 | super(); 20 | this.command = "add"; 21 | this.basePermission = "bending.command.add"; 22 | } 23 | 24 | @Override 25 | public boolean execute(CommandSender sender, List args) { 26 | 27 | if ((args.size() != 1) && (args.size() != 2)) { 28 | printUsage(sender); 29 | return true; 30 | } 31 | 32 | if (!(sender instanceof Player) && args.size() != 2) { 33 | sender.sendMessage(Messages.CONSOLE_SPECIFY_PLAYER); 34 | return true; 35 | } 36 | 37 | Player player; 38 | 39 | if (args.size() == 2) { 40 | if (!sender.hasPermission("bending.command.add.other")) { 41 | sender.sendMessage(ChatColor.RED + Messages.NO_PERMISSION); 42 | return true; 43 | } 44 | player = getPlayer(args.remove(0)); 45 | } else { 46 | player = (Player) sender; 47 | } 48 | 49 | if (player == null) { 50 | sender.sendMessage(ChatColor.RED + Messages.INVALID_PLAYER); 51 | return true; 52 | } 53 | 54 | final String choice = args.remove(0); 55 | BendingElement element = getElement(choice); 56 | if (element == null) { 57 | sender.sendMessage(ChatColor.RED + Messages.INVALID_ELEMENT); 58 | return true; 59 | } 60 | 61 | if (!player.hasPermission("bending." + element.name().toLowerCase())) { 62 | sender.sendMessage(ChatColor.RED + Messages.NOT_ELEMENT_ABLE); 63 | return true; 64 | } 65 | 66 | BendingPlayer bender = BendingPlayer.getBendingPlayer(player); 67 | if (bender.isBender(element)) { 68 | sender.sendMessage(ChatColor.RED + Messages.ALREADY_ELEMENT); 69 | return true; 70 | } 71 | 72 | bender.addBender(element); 73 | String msg = Messages.YOU_ADDED; 74 | msg = msg.replaceAll("\\{0\\}", element.name()); 75 | msg = msg.replaceAll("\\{1\\}", player.getName()); 76 | sender.sendMessage(msg); 77 | msg = Messages.YOU_WERE_ADDED; 78 | msg = msg.replaceAll("\\{0\\}", element.name()); 79 | player.sendMessage(msg); 80 | 81 | return true; 82 | } 83 | 84 | @Override 85 | public void printUsage(CommandSender sender, boolean permission) { 86 | if (sender.hasPermission("bending.command.add")) { 87 | sender.sendMessage("/bending add [player] "); 88 | } 89 | else if (permission) { 90 | sender.sendMessage(ChatColor.RED + Messages.NO_PERMISSION); 91 | } 92 | } 93 | 94 | @Override 95 | public List autoComplete(CommandSender sender, List args) { 96 | List values = new LinkedList(); 97 | if (!sender.hasPermission("bending.command.add")) { 98 | return values; 99 | } 100 | 101 | for (BendingElement el : BendingElement.values()) { 102 | values.add(el.name()); 103 | } 104 | 105 | if (args.size() == 2 || !sender.hasPermission("bending.command.add.other")) { 106 | return values; 107 | } 108 | 109 | for (Player online : Bukkit.getServer().getOnlinePlayers()) { 110 | values.add(online.getName()); 111 | } 112 | 113 | return values; 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/fire/Illumination.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.fire; 2 | 3 | import java.util.Map; 4 | 5 | import org.bukkit.Material; 6 | import org.bukkit.block.Block; 7 | import org.bukkit.block.BlockFace; 8 | import org.bukkit.entity.Player; 9 | import net.bendercraft.spigot.bending.abilities.ABendingAbility; 10 | import net.bendercraft.spigot.bending.abilities.AbilityManager; 11 | import net.bendercraft.spigot.bending.abilities.BendingAbility; 12 | import net.bendercraft.spigot.bending.abilities.BendingAbilityState; 13 | import net.bendercraft.spigot.bending.abilities.BendingActiveAbility; 14 | import net.bendercraft.spigot.bending.abilities.BendingElement; 15 | import net.bendercraft.spigot.bending.abilities.RegisteredAbility; 16 | import net.bendercraft.spigot.bending.controller.ConfigurationParameter; 17 | import net.bendercraft.spigot.bending.utils.BlockTools; 18 | import net.bendercraft.spigot.bending.utils.TempBlock; 19 | 20 | @ABendingAbility(name = Illumination.NAME, element = BendingElement.FIRE, shift=false) 21 | public class Illumination extends BendingActiveAbility { 22 | public final static String NAME = "Illumination"; 23 | 24 | @ConfigurationParameter("Range") 25 | private static int RANGE = 5; 26 | 27 | private TempBlock block; 28 | 29 | public Illumination(RegisteredAbility register, Player player) { 30 | super(register, player); 31 | } 32 | 33 | @Override 34 | public boolean sneak() { 35 | if(isState(BendingAbilityState.START)) { 36 | setState(BendingAbilityState.PROGRESSING); 37 | } else if(isState(BendingAbilityState.PROGRESSING)) { 38 | remove(); 39 | } 40 | return false; 41 | } 42 | 43 | private void set() { 44 | Block standingblock = player.getLocation().getBlock(); 45 | Block standblock = standingblock.getRelative(BlockFace.DOWN); 46 | 47 | if (FireStream.isIgnitable(player, standingblock) 48 | && !BlockTools.isLeaf(standblock) 49 | && block == null && !isIlluminated(standblock)) { 50 | block = TempBlock.makeTemporary(this, standingblock, Material.TORCH, false); 51 | } else if (FireStream.isIgnitable(this.player, standingblock) 52 | && (standblock.getType() == Material.DIRT 53 | || standblock.getType() == Material.STONE 54 | || standblock.getType() == Material.GRASS 55 | || standblock.getType() == Material.COBBLESTONE 56 | || standblock.getType() == Material.CLAY 57 | || standblock.getType() == Material.SANDSTONE 58 | || standblock.getType() == Material.RED_SANDSTONE) 59 | && !block.equals(standblock) 60 | && !isIlluminated(standblock)) { 61 | if(block != null) { 62 | block.revertBlock(); 63 | } 64 | block = TempBlock.makeTemporary(this, standingblock, Material.TORCH, false); 65 | } 66 | } 67 | 68 | @Override 69 | public void progress() { 70 | set(); 71 | } 72 | 73 | @Override 74 | public void stop() { 75 | if(block != null) { 76 | block.revertBlock(); 77 | } 78 | } 79 | 80 | @Override 81 | protected long getMaxMillis() { 82 | return 1000 * 60 * 15; 83 | } 84 | 85 | public static boolean isIlluminated(Block block) { 86 | Map instances = AbilityManager.getManager().getInstances(NAME); 87 | if (instances == null) { 88 | return false; 89 | } 90 | for (Object o : instances.keySet()) { 91 | Illumination ill = (Illumination) instances.get(o); 92 | if (ill.block != null && ill.block.equals(block)) { 93 | return true; 94 | } 95 | } 96 | return false; 97 | } 98 | 99 | @Override 100 | public Object getIdentifier() { 101 | return this.player; 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/air/AirBubble.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.air; 2 | 3 | import net.bendercraft.spigot.bending.utils.BlockTools; 4 | import net.bendercraft.spigot.bending.utils.ProtectionManager; 5 | import net.bendercraft.spigot.bending.utils.TempBlock; 6 | import org.bukkit.Location; 7 | import org.bukkit.Material; 8 | import org.bukkit.block.Block; 9 | import org.bukkit.block.data.BlockData; 10 | import org.bukkit.block.data.Waterlogged; 11 | import org.bukkit.entity.Player; 12 | 13 | import net.bendercraft.spigot.bending.abilities.ABendingAbility; 14 | import net.bendercraft.spigot.bending.abilities.BendingElement; 15 | import net.bendercraft.spigot.bending.abilities.BendingPerk; 16 | import net.bendercraft.spigot.bending.abilities.RegisteredAbility; 17 | import net.bendercraft.spigot.bending.controller.ConfigurationParameter; 18 | import net.bendercraft.spigot.bending.utils.abilities.Bubble; 19 | 20 | import java.util.List; 21 | 22 | 23 | @ABendingAbility(name = AirBubble.NAME, element = BendingElement.AIR, shift = false, canBeUsedWithTools = true) 24 | public class AirBubble extends Bubble { 25 | public final static String NAME = "AirBubble"; 26 | 27 | @ConfigurationParameter("Radius") 28 | private static double DEFAULT_RADIUS = 4; 29 | 30 | @ConfigurationParameter("Max-Duration") 31 | private static long MAX_DURATION = 600000; 32 | 33 | public AirBubble(RegisteredAbility register, Player player) { 34 | super(register, player); 35 | 36 | this.radius = DEFAULT_RADIUS; 37 | 38 | if(bender.hasPerk(BendingPerk.AIR_AIRBUBBLE_RADIUS)) { 39 | this.radius += 1; 40 | } 41 | } 42 | 43 | public boolean isBlockPushable(Block block) { 44 | if (this.origins.containsKey(block)) { 45 | return false; 46 | } 47 | 48 | if (ProtectionManager.isLocationProtectedFromBending(this.player, register, block.getLocation())) { 49 | return false; 50 | } 51 | 52 | Material type = block.getType(); 53 | 54 | if (Material.DIRT == type 55 | || Material.STONE == type 56 | || Material.GRAVEL == type 57 | || Material.GRASS == type) { 58 | return false; 59 | } 60 | return true; 61 | } 62 | 63 | @Override 64 | protected void pushNewBlocks() { 65 | final Location center = player.getLocation(); 66 | List affectedBlocks = BlockTools.getFilteredBlocksAroundPoint(center, this.radius, this::isBlockPushable); 67 | 68 | for (Block block : affectedBlocks) { 69 | TempBlock tempBlock = TempBlock.get(block); 70 | if (tempBlock == null || tempBlock.isBendAllowed()) { 71 | Material type = block.getType(); 72 | if (Material.WATER == type || Material.BUBBLE_COLUMN == type) { 73 | this.origins.put(block, TempBlock.makeTemporary(this, block, Material.AIR,true)); 74 | } 75 | else if (Material.KELP == type || Material.KELP_PLANT == type) { 76 | this.origins.put(block, TempBlock.makeTemporary(this, block, Material.JUNGLE_SAPLING,true)); 77 | } 78 | else if (Material.SEAGRASS == type) { 79 | this.origins.put(block, TempBlock.makeTemporary(this, block, Material.GRASS, true)); 80 | } 81 | else if (Material.TALL_SEAGRASS == type) { 82 | this.origins.put(block, TempBlock.makeTemporary(this, block, Material.TALL_GRASS, true)); 83 | } 84 | else { 85 | BlockData blockData = block.getBlockData(); 86 | if (blockData instanceof Waterlogged) { 87 | Waterlogged data = (Waterlogged) blockData; 88 | if (data.isWaterlogged()) { 89 | data.setWaterlogged(false); 90 | this.origins.put(block, TempBlock.makeTemporary(this, block, type, data, true)); 91 | } 92 | } 93 | } 94 | } 95 | } 96 | } 97 | 98 | @Override 99 | protected long getMaxMillis() { 100 | return MAX_DURATION; 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/commands/subcommands/DisplayExecution.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.commands.subcommands; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | import java.util.Map; 6 | import java.util.Map.Entry; 7 | 8 | import org.bukkit.Bukkit; 9 | import org.bukkit.ChatColor; 10 | import org.bukkit.command.CommandSender; 11 | import org.bukkit.entity.Player; 12 | 13 | import net.bendercraft.spigot.bending.Messages; 14 | import net.bendercraft.spigot.bending.abilities.AbilityManager; 15 | import net.bendercraft.spigot.bending.abilities.BendingAffinity; 16 | import net.bendercraft.spigot.bending.abilities.BendingElement; 17 | import net.bendercraft.spigot.bending.abilities.BendingPlayer; 18 | import net.bendercraft.spigot.bending.abilities.RegisteredAbility; 19 | import net.bendercraft.spigot.bending.commands.BendingCommand; 20 | import net.bendercraft.spigot.bending.controller.Settings; 21 | import net.bendercraft.spigot.bending.utils.PluginTools; 22 | 23 | public class DisplayExecution extends BendingCommand { 24 | 25 | public DisplayExecution() { 26 | super(); 27 | this.command = "display"; 28 | this.aliases.add("d"); 29 | this.basePermission = "bending.command.display"; 30 | } 31 | 32 | @Override 33 | public boolean execute(CommandSender sender, List args) { 34 | Player player = null; 35 | 36 | if (!args.isEmpty() && sender.hasPermission("bending.admin")) { 37 | player = Bukkit.getPlayer(args.get(0)); 38 | } else if(sender instanceof Player) { 39 | player = (Player) sender; 40 | } 41 | 42 | if(player == null) { 43 | sender.sendMessage(ChatColor.RED + Messages.INVALID_PLAYER); 44 | return true; 45 | } 46 | 47 | BendingPlayer bender = BendingPlayer.getBendingPlayer(player); 48 | sender.sendMessage("Player: "+ChatColor.GOLD+player.getName()); 49 | sender.sendMessage("Elements:"); 50 | for(BendingElement element : bender.getBendingTypes()) { 51 | StringBuilder sb = new StringBuilder(); 52 | for(BendingAffinity affinity : bender.getAffinities()) { 53 | if(affinity.getElement() == element) { 54 | sb.append(affinity.name()+", "); 55 | } 56 | } 57 | sender.sendMessage(" - "+PluginTools.getColor(Settings.getColor(element))+element.name()+" with affinities ["+(sb.length()==0 ? "NONE" : sb.substring(0, sb.lastIndexOf(", ")))+"]"); 58 | } 59 | Map abilities = bender.getAbilities(); 60 | sender.sendMessage("Active deck : " + bender.getCurrentDeck()); 61 | StringBuilder sb = new StringBuilder(); 62 | bender.getDecks().keySet().forEach(d -> sb.append(d+", ")); 63 | sender.sendMessage("Decks : " + sb.substring(0, sb.lastIndexOf(", "))); 64 | if (abilities != null && !abilities.isEmpty()) { 65 | sender.sendMessage("Slots:"); 66 | for (Entry slot : abilities.entrySet()) { 67 | RegisteredAbility ab = AbilityManager.getManager().getRegisteredAbility(slot.getValue()); 68 | if (ab != null) { 69 | ChatColor color = PluginTools.getColor(Settings.getColor(ab.getElement())); 70 | sender.sendMessage(" - " + color + (slot.getKey() + 1) + ChatColor.WHITE + " : " + color + ab.getName()); 71 | } 72 | } 73 | } else { 74 | sender.sendMessage("Slots: " + Messages.NOTHING_BOUND); 75 | } 76 | 77 | return true; 78 | } 79 | 80 | @Override 81 | public void printUsage(CommandSender sender, boolean permission) { 82 | if (sender.hasPermission("bending.command.display")) { 83 | sender.sendMessage("/bending display"); 84 | } 85 | else if (permission) { 86 | sender.sendMessage(ChatColor.RED + Messages.NO_PERMISSION); 87 | } 88 | } 89 | 90 | @Override 91 | public List autoComplete(CommandSender sender, List args) { 92 | return new LinkedList(); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/arts/NebularChain.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.arts; 2 | 3 | import org.bukkit.Location; 4 | import org.bukkit.Particle; 5 | import org.bukkit.Sound; 6 | import org.bukkit.entity.LivingEntity; 7 | import org.bukkit.entity.Player; 8 | import org.bukkit.util.Vector; 9 | 10 | import net.bendercraft.spigot.bending.Bending; 11 | import net.bendercraft.spigot.bending.abilities.ABendingAbility; 12 | import net.bendercraft.spigot.bending.abilities.BendingActiveAbility; 13 | import net.bendercraft.spigot.bending.abilities.BendingAffinity; 14 | import net.bendercraft.spigot.bending.abilities.BendingPerk; 15 | import net.bendercraft.spigot.bending.abilities.RegisteredAbility; 16 | import net.bendercraft.spigot.bending.controller.ConfigurationParameter; 17 | import net.bendercraft.spigot.bending.event.BendingHitEvent; 18 | import net.bendercraft.spigot.bending.utils.EntityTools; 19 | 20 | @ABendingAbility(name = NebularChain.NAME, affinity = BendingAffinity.SWORD) 21 | public class NebularChain extends BendingActiveAbility { 22 | public final static String NAME = "NebularChain"; 23 | 24 | @ConfigurationParameter("Cooldown") 25 | private static long COOLDOWN = 8000; 26 | 27 | @ConfigurationParameter("Range") 28 | public static double RANGE = 17; 29 | 30 | @ConfigurationParameter("Push") 31 | public static double PUSH = 3.0; 32 | 33 | private double range; 34 | 35 | private long cooldown; 36 | 37 | public NebularChain(RegisteredAbility register, Player player) { 38 | super(register, player); 39 | 40 | this.range = RANGE; 41 | if(bender.hasPerk(BendingPerk.MASTER_BLANKPOINTPUSH_POISONNEDARTRANGE_NEBULARCHAINRANGE)) { 42 | this.range += 1; 43 | } 44 | if(bender.hasPerk(BendingPerk.MASTER_BLANKPOINTDAMAGE_PARASTICKCD_NEBULARRANGE)) { 45 | this.range += 1; 46 | } 47 | this.cooldown = COOLDOWN; 48 | if(bender.hasPerk(BendingPerk.MASTER_STRAIGHTSHOTCD_C4RADIUS_NEBULARCD)) { 49 | this.cooldown -= 500; 50 | } 51 | if(bender.hasPerk(BendingPerk.MASTER_EXPLOSIVESHOTRADIUSDAMAGE_SMOKEBOMBPARASTICKDAMAGE_NEBULARCD)) { 52 | this.cooldown -= 500; 53 | } 54 | } 55 | 56 | @Override 57 | public boolean swing() { 58 | LivingEntity target = EntityTools.getTargetedEntity(player, range); 59 | if(target != null && affect(target)) { 60 | player.getWorld().playSound(player.getLocation(), Sound.BLOCK_ANVIL_HIT, 5, 1); 61 | bender.cooldown(this, cooldown); 62 | } 63 | return false; 64 | } 65 | 66 | @Override 67 | public boolean sneak() { 68 | 69 | return false; 70 | } 71 | 72 | @Override 73 | public void progress() { 74 | 75 | } 76 | 77 | @Override 78 | public Object getIdentifier() { 79 | return this.player; 80 | } 81 | 82 | @Override 83 | public void stop() { 84 | 85 | } 86 | 87 | private boolean affect(LivingEntity entity) { 88 | BendingHitEvent event = new BendingHitEvent(this, entity); 89 | Bending.callEvent(event); 90 | if(event.isCancelled()) { 91 | return false; 92 | } 93 | Vector direction = entity.getEyeLocation().subtract(player.getEyeLocation()).toVector(); 94 | double distance = direction.length(); 95 | for(double i=0; i < distance ; i = i + 0.01) { 96 | Location location = player.getEyeLocation().clone().add(direction.clone().normalize().multiply(i)); 97 | location.getWorld().spawnParticle(Particle.SPELL_WITCH, location, 1, 0, 0, 0, 0); 98 | } 99 | 100 | Location location = player.getEyeLocation().add(player.getEyeLocation().getDirection()); 101 | location.setPitch(entity.getEyeLocation().getPitch()); 102 | location.setYaw(entity.getEyeLocation().getYaw()); 103 | entity.teleport(location); 104 | return true; 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /migration/v6_0_0_to_v6_1_0.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | 4 | def replace_list(x, old, wanted=None): 5 | try: 6 | x.remove(old) 7 | if wanted is not None: 8 | x.append(wanted) 9 | except ValueError: 10 | pass 11 | 12 | def main(): 13 | print "Start converting..." 14 | 15 | print "... benders ..." 16 | try: 17 | os.mkdir("benders_new") 18 | 19 | for filename in os.listdir("benders"): 20 | print "Processing {}...".format(filename) 21 | with open("benders/{}".format(filename), "r") as original_file: 22 | data_json = json.load(original_file) 23 | 24 | # Enumeration are now uppercase 25 | data_json["bendings"] = [x.upper() for x in data_json["bendings"]] 26 | data_json["affinities"] = [x.upper() for x in data_json["affinities"]] 27 | data_json["paths"] = [x.upper() for x in data_json["paths"]] 28 | 29 | # Some affinities have just be renamed 30 | replace_list(data_json["affinities"], "BLOODBEND", "BLOOD") 31 | replace_list(data_json["affinities"], "DRAINBEND", "DRAIN") 32 | replace_list(data_json["affinities"], "METALBEND", "METAL") 33 | replace_list(data_json["affinities"], "LAVABEND", "LAVA") 34 | 35 | # Element "chi" has been replaced with "master", and "chi" is now an affinity 36 | try: 37 | data_json["bendings"].remove("CHIBLOCKER") 38 | except ValueError: 39 | pass 40 | else: 41 | data_json["bendings"].append("MASTER") 42 | data_json["affinities"].append("CHI") 43 | 44 | # No more elementary affinity 45 | for x in ["CHIAIR", "CHIWATER", "CHIFIRE", "CHIEARTH", "INVENTOR"]: 46 | try: 47 | data_json["affinities"].remove(x) 48 | except ValueError: 49 | pass 50 | 51 | # Paths "seeker", "equality", "restless" are no more 52 | for x in ["SEEKER", "EQUALITY", "RESTLESS"]: 53 | try: 54 | data_json["paths"].remove(x) 55 | except ValueError: 56 | pass 57 | 58 | # Some abilities changed their name, faster to reset decks and bindings than changing them :o 59 | data_json["currentDeck"] = "default" 60 | data_json["decks"] = {"default":{}} 61 | 62 | with open("benders_new/{}".format(filename), "w") as migrated_file: 63 | json.dump(data_json, migrated_file) 64 | except Exception as e: 65 | print "Benders failed because of {}".format(e) 66 | 67 | print "... learning ..." 68 | 69 | try: 70 | with open("permissions.json", "r") as original_file: 71 | data_json = json.load(original_file) 72 | for player in data_json["permissions"]: 73 | # Old cleanup 74 | replace_list(data_json["permissions"][player], "bending.chiblocker.rapidpunch") 75 | replace_list(data_json["permissions"][player], "bending.chiblocker.paralize") 76 | 77 | # Actual changes 78 | replace_list(data_json["permissions"][player], "bending.water.bloodbending", "bending.water.bloodbend") 79 | with open("permissions.json.new", "w") as migrated_file: 80 | json.dump(data_json, migrated_file) 81 | 82 | except Exception as e: 83 | print "Permissions failed because of {}".format(e) 84 | 85 | print "... finished !" 86 | 87 | if __name__ == "__main__": 88 | main() 89 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/energy/AvatarState.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.energy; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import org.bukkit.entity.Player; 8 | import org.bukkit.potion.PotionEffect; 9 | import org.bukkit.potion.PotionEffectType; 10 | 11 | import net.bendercraft.spigot.bending.abilities.ABendingAbility; 12 | import net.bendercraft.spigot.bending.abilities.AbilityManager; 13 | import net.bendercraft.spigot.bending.abilities.BendingAbility; 14 | import net.bendercraft.spigot.bending.abilities.BendingAbilityState; 15 | import net.bendercraft.spigot.bending.abilities.BendingActiveAbility; 16 | import net.bendercraft.spigot.bending.abilities.BendingElement; 17 | import net.bendercraft.spigot.bending.abilities.RegisteredAbility; 18 | import net.bendercraft.spigot.bending.controller.ConfigurationParameter; 19 | 20 | @ABendingAbility(name = AvatarState.NAME, element = BendingElement.ENERGY) 21 | public class AvatarState extends BendingActiveAbility { 22 | public final static String NAME = "AvatarState"; 23 | 24 | @ConfigurationParameter("Factor") 25 | public static double FACTOR = 4.5; 26 | 27 | @ConfigurationParameter("Max-Duration") 28 | private static long MAX_DURATION = 300000; 29 | 30 | @ConfigurationParameter("Cooldown-Factor") 31 | private static int COOLDOWN_FACTOR = 4; 32 | 33 | private long realDuration; 34 | 35 | public AvatarState(RegisteredAbility register, Player player) { 36 | super(register, player); 37 | } 38 | 39 | @Override 40 | public boolean swing() { 41 | if (getState() == BendingAbilityState.PROGRESSING) { 42 | remove(); 43 | return false; 44 | } 45 | 46 | if (getState() == BendingAbilityState.START) { 47 | setState(BendingAbilityState.PROGRESSING); 48 | } 49 | 50 | return false; 51 | } 52 | 53 | @Override 54 | public void progress() { 55 | if (getState() == BendingAbilityState.PROGRESSING) { 56 | addPotionEffects(); 57 | return; 58 | } 59 | 60 | remove(); 61 | } 62 | 63 | private void addPotionEffects() { 64 | int duration = 70; 65 | this.player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, duration, 2)); 66 | this.player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, duration, 2)); 67 | this.player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, duration, 2)); 68 | this.player.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, duration, 0)); 69 | } 70 | 71 | public static boolean isAvatarState(Player player) { 72 | Map instances = AbilityManager.getManager().getInstances(NAME); 73 | 74 | if ((instances == null) || instances.isEmpty()) { 75 | return false; 76 | } 77 | 78 | if (instances.containsKey(player)) { 79 | return true; 80 | } 81 | return false; 82 | } 83 | 84 | public static double getValue(double value) { 85 | return FACTOR * value; 86 | } 87 | 88 | public static int getValue(int value) { 89 | return (int) FACTOR * value; 90 | } 91 | 92 | public static List getPlayers() { 93 | Map instances = AbilityManager.getManager().getInstances(NAME); 94 | LinkedList players = new LinkedList(); 95 | if ((instances == null) || instances.isEmpty()) { 96 | return players; 97 | } 98 | 99 | for (Object obj : instances.keySet()) { 100 | players.add((Player) obj); 101 | } 102 | return players; 103 | } 104 | 105 | @Override 106 | public void stop() { 107 | long now = System.currentTimeMillis(); 108 | this.realDuration = now - this.startedTime; 109 | this.bender.cooldown(NAME, this.realDuration * COOLDOWN_FACTOR); 110 | } 111 | 112 | @Override 113 | protected long getMaxMillis() { 114 | return MAX_DURATION; 115 | } 116 | 117 | @Override 118 | public Object getIdentifier() { 119 | return this.player; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/utils/ProtectionManager.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.utils; 2 | 3 | import org.bukkit.Bukkit; 4 | import org.bukkit.Location; 5 | import org.bukkit.entity.Entity; 6 | import org.bukkit.entity.Player; 7 | import org.bukkit.plugin.Plugin; 8 | 9 | import net.bendercraft.spigot.bending.Bending; 10 | import net.bendercraft.spigot.bending.abilities.AbilityManager; 11 | import net.bendercraft.spigot.bending.abilities.RegisteredAbility; 12 | import net.bendercraft.spigot.bending.controller.Settings; 13 | import net.bendercraft.spigot.bending.integrations.worldguard.WorldGuardProtection; 14 | import net.citizensnpcs.api.CitizensAPI; 15 | import net.citizensnpcs.api.trait.Trait; 16 | 17 | public class ProtectionManager { 18 | 19 | private static WorldGuardProtection worldguard = null; 20 | private static boolean useCitizens = false; 21 | 22 | public static void init(Bending plugin) { 23 | try { 24 | worldguard = new WorldGuardProtection(plugin); 25 | } catch (NoClassDefFoundError e) { 26 | Bukkit.getLogger().warning("WorldGuard classes not found."); 27 | worldguard = null; 28 | } 29 | 30 | 31 | Plugin citizens = Bukkit.getPluginManager().getPlugin("Citizens"); 32 | if (citizens != null) { 33 | plugin.getLogger().info("Recognized Citizens..."); 34 | if (Settings.RESPECT_CITIZENS) { 35 | useCitizens = true; 36 | plugin.getLogger().info("Bending is set to respect Citizens traits."); 37 | } else { 38 | plugin.getLogger().info("But Bending is set to ignore Citizens traits."); 39 | } 40 | } 41 | } 42 | 43 | public static boolean isEntityProtected(Entity entity) { 44 | if (useCitizens) { 45 | if (CitizensAPI.getNPCRegistry().isNPC(entity)) { 46 | for (Trait trait : CitizensAPI.getNPCRegistry().getNPC(entity).getTraits()) { 47 | if (trait.getName().equals("bendable")) { 48 | return false; 49 | } 50 | } 51 | return true; 52 | } 53 | } 54 | return entity.hasPermission("bending.immune"); 55 | } 56 | 57 | public static boolean isLocationProtectedFromExplosion(Player player, String ability, Location loc) { 58 | if (Settings.RESPECT_WORLDGUARD && worldguard != null) { 59 | RegisteredAbility register = AbilityManager.getManager().getRegisteredAbility(ability); 60 | return worldguard.isRegionProtectedFromExplosion(player, register, loc); 61 | } 62 | return false; 63 | } 64 | 65 | public static boolean isLocationProtectedFromPerks(Player player, Location loc) { 66 | if (player == null) { 67 | return false; 68 | } 69 | 70 | if (player.hasPermission("bending.protection.bypass")) { 71 | return false; 72 | } 73 | 74 | if (Settings.RESPECT_WORLDGUARD && worldguard != null) { 75 | return worldguard.isRegionProtectedFromPerks(player, loc); 76 | } 77 | 78 | return false; 79 | } 80 | 81 | public static boolean isLocationProtectedFromBending(Player player, RegisteredAbility ability, Location loc) { 82 | if (ability == null || player == null) { 83 | return false; 84 | } 85 | 86 | if (player.hasPermission("bending.protection.bypass")) { 87 | return false; 88 | } 89 | 90 | if (Settings.RESPECT_WORLDGUARD && worldguard != null) { 91 | return worldguard.isRegionProtectedFromBending(player, ability, loc); 92 | } 93 | 94 | return false; 95 | } 96 | 97 | public static boolean isRegionProtectedFromBendingPassives(Player player, Location loc) { 98 | if (player == null) { 99 | return false; 100 | } 101 | if (player.hasPermission("bending.protection.bypass")) { 102 | return false; 103 | } 104 | if (Settings.RESPECT_WORLDGUARD && worldguard != null) { 105 | return worldguard.isRegionProtectedFromBendingPassives(player, loc); 106 | } 107 | return false; 108 | } 109 | 110 | public static void disable() { 111 | 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/earth/EarthTunnel.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.earth; 2 | 3 | import org.bukkit.Location; 4 | import org.bukkit.block.Block; 5 | import org.bukkit.entity.Player; 6 | import org.bukkit.util.Vector; 7 | 8 | import net.bendercraft.spigot.bending.abilities.ABendingAbility; 9 | import net.bendercraft.spigot.bending.abilities.BendingAbilityState; 10 | import net.bendercraft.spigot.bending.abilities.BendingActiveAbility; 11 | import net.bendercraft.spigot.bending.abilities.BendingElement; 12 | import net.bendercraft.spigot.bending.abilities.RegisteredAbility; 13 | import net.bendercraft.spigot.bending.controller.ConfigurationParameter; 14 | import net.bendercraft.spigot.bending.utils.BlockTools; 15 | import net.bendercraft.spigot.bending.utils.EntityTools; 16 | import net.bendercraft.spigot.bending.utils.Tools; 17 | 18 | @ABendingAbility(name = EarthTunnel.NAME, element = BendingElement.EARTH, canBeUsedWithTools = true) 19 | public class EarthTunnel extends BendingActiveAbility { 20 | public final static String NAME = "EarthTunnel"; 21 | 22 | @ConfigurationParameter("Max-Radius") 23 | private static double RADIUS = 1.0; 24 | 25 | @ConfigurationParameter("Range") 26 | private static double range = 9.0; 27 | 28 | @ConfigurationParameter("Radius") 29 | private static double radiusinc = 0.25; 30 | 31 | @ConfigurationParameter("Revert") 32 | private static boolean REVERT = true; 33 | 34 | @ConfigurationParameter("Interval") 35 | private static long INTERVAL = 30; 36 | 37 | private Block block; 38 | private Location origin, location; 39 | private Vector direction; 40 | private double depth, radius, angle; 41 | private long time; 42 | 43 | public EarthTunnel(RegisteredAbility register, Player player) { 44 | super(register, player); 45 | } 46 | 47 | @Override 48 | public boolean sneak() { 49 | if (getState() != BendingAbilityState.START) { 50 | return false; 51 | } 52 | location = player.getEyeLocation().clone(); 53 | origin = EntityTools.getTargetBlock(player, range).getLocation(); 54 | block = origin.getBlock(); 55 | direction = location.getDirection().clone().normalize(); 56 | depth = origin.distance(location) - 1; 57 | if (depth < 0) 58 | depth = 0; 59 | angle = 0; 60 | radius = radiusinc; 61 | time = System.currentTimeMillis(); 62 | 63 | setState(BendingAbilityState.PROGRESSING); 64 | return false; 65 | } 66 | 67 | public void progress() { 68 | if (System.currentTimeMillis() - time >= INTERVAL) { 69 | time = System.currentTimeMillis(); 70 | // Tools.verbose("progressing"); 71 | if (Math.abs(Math.toDegrees(player.getEyeLocation().getDirection().angle(direction))) > 20 || !player.isSneaking()) { 72 | remove(); 73 | return; 74 | } else { 75 | while (!BlockTools.isEarthbendable(player, block)) { 76 | // Tools.verbose("going"); 77 | if (!BlockTools.isTransparentToEarthbending(player, block)) { 78 | remove(); 79 | return; 80 | } 81 | if (angle >= 360) { 82 | angle = 0; 83 | if (radius >= RADIUS) { 84 | radius = radiusinc; 85 | if (depth >= range) { 86 | remove(); 87 | return; 88 | } else { 89 | depth += .5; 90 | } 91 | } else { 92 | radius += radiusinc; 93 | } 94 | } else { 95 | angle += 20; 96 | } 97 | // block.setType(Material.GLASS); 98 | Vector vec = Tools.getOrthogonalVector(direction, angle, radius); 99 | block = location.clone().add(direction.clone().normalize().multiply(depth)).add(vec).getBlock(); 100 | } 101 | 102 | if (REVERT) { 103 | BlockTools.addTempAirBlock(block); 104 | } else { 105 | block.breakNaturally(); 106 | } 107 | } 108 | } 109 | } 110 | 111 | @Override 112 | public Object getIdentifier() { 113 | return player; 114 | } 115 | 116 | @Override 117 | public void stop() { 118 | 119 | } 120 | 121 | } 122 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/water/WaterBubble.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.water; 2 | 3 | import net.bendercraft.spigot.bending.utils.BlockTools; 4 | import net.bendercraft.spigot.bending.utils.ProtectionManager; 5 | import net.bendercraft.spigot.bending.utils.TempBlock; 6 | import org.bukkit.Location; 7 | import org.bukkit.Material; 8 | import org.bukkit.block.Block; 9 | import org.bukkit.block.data.BlockData; 10 | import org.bukkit.block.data.Waterlogged; 11 | import org.bukkit.entity.Player; 12 | 13 | import net.bendercraft.spigot.bending.abilities.ABendingAbility; 14 | import net.bendercraft.spigot.bending.abilities.BendingElement; 15 | import net.bendercraft.spigot.bending.abilities.BendingPerk; 16 | import net.bendercraft.spigot.bending.abilities.RegisteredAbility; 17 | import net.bendercraft.spigot.bending.abilities.energy.AvatarState; 18 | import net.bendercraft.spigot.bending.controller.ConfigurationParameter; 19 | import net.bendercraft.spigot.bending.utils.abilities.Bubble; 20 | 21 | import java.util.List; 22 | 23 | 24 | @ABendingAbility(name = WaterBubble.NAME, element = BendingElement.WATER, shift=false, canBeUsedWithTools = true) 25 | public class WaterBubble extends Bubble { 26 | public final static String NAME = "WaterBubble"; 27 | 28 | @ConfigurationParameter("Radius") 29 | public static double DEFAULT_RADIUS = 4; 30 | 31 | @ConfigurationParameter("Max-Duration") 32 | private static long MAX_DURATION = 600000; 33 | 34 | public WaterBubble(RegisteredAbility register, Player player) { 35 | super(register, player); 36 | 37 | this.radius = DEFAULT_RADIUS; 38 | if(bender.hasPerk(BendingPerk.WATER_WATERBUBBLE_RADIUS)) { 39 | this.radius += 1; 40 | } 41 | 42 | if (AvatarState.isAvatarState(player)) { 43 | this.radius = AvatarState.getValue(this.radius); 44 | } 45 | } 46 | 47 | public boolean isBlockPushable(Block block) { 48 | if (this.origins.containsKey(block)) { 49 | return false; 50 | } 51 | 52 | if (ProtectionManager.isLocationProtectedFromBending(this.player, register, block.getLocation())) { 53 | return false; 54 | } 55 | 56 | Material type = block.getType(); 57 | 58 | if (Material.DIRT == type 59 | || Material.STONE == type 60 | || Material.GRAVEL == type 61 | || Material.GRASS == type) { 62 | return false; 63 | } 64 | return true; 65 | } 66 | 67 | @Override 68 | protected void pushNewBlocks() { 69 | final Location center = player.getLocation(); 70 | List affectedBlocks = BlockTools.getFilteredBlocksAroundPoint(center, this.radius, this::isBlockPushable); 71 | 72 | for (Block block : affectedBlocks) { 73 | TempBlock tempBlock = TempBlock.get(block); 74 | if (tempBlock == null || tempBlock.isBendAllowed()) { 75 | Material type = block.getType(); 76 | if (Material.WATER == type || Material.BUBBLE_COLUMN == type) { 77 | this.origins.put(block, TempBlock.makeTemporary(this, block, Material.AIR,true)); 78 | } 79 | else if (Material.KELP == type || Material.KELP_PLANT == type) { 80 | this.origins.put(block, TempBlock.makeTemporary(this, block, Material.JUNGLE_SAPLING,true)); 81 | } 82 | else if (Material.SEAGRASS == type) { 83 | this.origins.put(block, TempBlock.makeTemporary(this, block, Material.GRASS, true)); 84 | } 85 | else if (Material.TALL_SEAGRASS == type) { 86 | this.origins.put(block, TempBlock.makeTemporary(this, block, Material.TALL_GRASS, true)); 87 | } 88 | else { 89 | BlockData blockData = block.getBlockData(); 90 | if (blockData instanceof Waterlogged) { 91 | Waterlogged data = (Waterlogged) blockData; 92 | if (data.isWaterlogged()) { 93 | data.setWaterlogged(false); 94 | this.origins.put(block, TempBlock.makeTemporary(this, block, type, data, true)); 95 | } 96 | } 97 | } 98 | } 99 | } 100 | } 101 | 102 | @Override 103 | public long getMaxMillis() { 104 | return MAX_DURATION; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/utils/PluginTools.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.utils; 2 | 3 | import java.util.Collections; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import org.bukkit.ChatColor; 8 | import org.bukkit.Location; 9 | import org.bukkit.entity.Player; 10 | 11 | import net.bendercraft.spigot.bending.abilities.air.AirSpout; 12 | import net.bendercraft.spigot.bending.abilities.fire.FireStream; 13 | import net.bendercraft.spigot.bending.abilities.water.WaterSpout; 14 | 15 | public class PluginTools { 16 | 17 | private static final Map colors; 18 | static { 19 | Map tmpMap = new HashMap(); 20 | tmpMap.put("black", ChatColor.BLACK); 21 | tmpMap.put("0", ChatColor.BLACK); 22 | 23 | tmpMap.put("dark blue", ChatColor.DARK_BLUE); 24 | tmpMap.put("dark_blue", ChatColor.DARK_BLUE); 25 | tmpMap.put("1", ChatColor.DARK_BLUE); 26 | 27 | tmpMap.put("dark green", ChatColor.DARK_GREEN); 28 | tmpMap.put("dark_green", ChatColor.DARK_GREEN); 29 | tmpMap.put("2", ChatColor.DARK_GREEN); 30 | 31 | tmpMap.put("dark aqua", ChatColor.DARK_AQUA); 32 | tmpMap.put("dark_aqua", ChatColor.DARK_AQUA); 33 | tmpMap.put("teal", ChatColor.DARK_AQUA); 34 | tmpMap.put("3", ChatColor.DARK_AQUA); 35 | 36 | tmpMap.put("dark red", ChatColor.DARK_RED); 37 | tmpMap.put("dark_red", ChatColor.DARK_RED); 38 | tmpMap.put("4", ChatColor.DARK_RED); 39 | 40 | tmpMap.put("dark purple", ChatColor.DARK_PURPLE); 41 | tmpMap.put("dark_purple", ChatColor.DARK_PURPLE); 42 | tmpMap.put("purple", ChatColor.DARK_PURPLE); 43 | tmpMap.put("5", ChatColor.DARK_PURPLE); 44 | 45 | tmpMap.put("gold", ChatColor.GOLD); 46 | tmpMap.put("orange", ChatColor.GOLD); 47 | tmpMap.put("6", ChatColor.GOLD); 48 | 49 | tmpMap.put("gray", ChatColor.GRAY); 50 | tmpMap.put("grey", ChatColor.GRAY); 51 | tmpMap.put("7", ChatColor.GRAY); 52 | 53 | tmpMap.put("dark gray", ChatColor.DARK_GRAY); 54 | tmpMap.put("dark_gray", ChatColor.DARK_GRAY); 55 | tmpMap.put("dark grey", ChatColor.DARK_GRAY); 56 | tmpMap.put("dark_grey", ChatColor.DARK_GRAY); 57 | tmpMap.put("8", ChatColor.DARK_GRAY); 58 | 59 | tmpMap.put("blue", ChatColor.BLUE); 60 | tmpMap.put("9", ChatColor.BLUE); 61 | 62 | tmpMap.put("bright green", ChatColor.GREEN); 63 | tmpMap.put("bright_green", ChatColor.GREEN); 64 | tmpMap.put("green", ChatColor.GREEN); 65 | tmpMap.put("a", ChatColor.GREEN); 66 | 67 | tmpMap.put("aqua", ChatColor.AQUA); 68 | tmpMap.put("b", ChatColor.AQUA); 69 | 70 | tmpMap.put("red", ChatColor.RED); 71 | tmpMap.put("c", ChatColor.RED); 72 | 73 | tmpMap.put("light purple", ChatColor.LIGHT_PURPLE); 74 | tmpMap.put("light_purple", ChatColor.LIGHT_PURPLE); 75 | tmpMap.put("pink", ChatColor.LIGHT_PURPLE); 76 | tmpMap.put("d", ChatColor.LIGHT_PURPLE); 77 | 78 | tmpMap.put("yellow", ChatColor.YELLOW); 79 | tmpMap.put("e", ChatColor.YELLOW); 80 | 81 | tmpMap.put("white", ChatColor.WHITE); 82 | tmpMap.put("f", ChatColor.WHITE); 83 | 84 | tmpMap.put("random", ChatColor.MAGIC); 85 | tmpMap.put("magic", ChatColor.MAGIC); 86 | tmpMap.put("k", ChatColor.MAGIC); 87 | 88 | colors = Collections.unmodifiableMap(tmpMap); 89 | } 90 | 91 | public static void stopAllBending() { 92 | FireStream.removeAll(); 93 | TempBlock.removeAll(); 94 | } 95 | 96 | public static void removeSpouts(Location location, double radius, Player sourceplayer) { 97 | WaterSpout.removeSpouts(location, radius, sourceplayer); 98 | AirSpout.removeSpouts(location, radius, sourceplayer); 99 | } 100 | 101 | public static void removeSpouts(Location location, Player sourceplayer) { 102 | removeSpouts(location, 1.5, sourceplayer); 103 | } 104 | 105 | public static ChatColor getColor(String input) { 106 | return colors.get(input.toLowerCase().replace("&", "")); 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/commands/subcommands/AvailableExecution.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.commands.subcommands; 2 | 3 | import java.util.HashMap; 4 | import java.util.LinkedList; 5 | import java.util.List; 6 | import java.util.Map; 7 | import java.util.Map.Entry; 8 | 9 | import org.bukkit.Bukkit; 10 | import org.bukkit.ChatColor; 11 | import org.bukkit.command.CommandSender; 12 | import org.bukkit.entity.Player; 13 | 14 | import net.bendercraft.spigot.bending.Messages; 15 | import net.bendercraft.spigot.bending.abilities.AbilityManager; 16 | import net.bendercraft.spigot.bending.abilities.BendingAffinity; 17 | import net.bendercraft.spigot.bending.abilities.BendingElement; 18 | import net.bendercraft.spigot.bending.abilities.BendingPlayer; 19 | import net.bendercraft.spigot.bending.abilities.RegisteredAbility; 20 | import net.bendercraft.spigot.bending.commands.BendingCommand; 21 | import net.bendercraft.spigot.bending.controller.Settings; 22 | import net.bendercraft.spigot.bending.utils.PluginTools; 23 | 24 | public class AvailableExecution extends BendingCommand { 25 | 26 | public AvailableExecution() { 27 | super(); 28 | this.command = "available"; 29 | this.aliases.add("availables"); 30 | this.aliases.add("avail"); 31 | this.aliases.add("a"); 32 | this.basePermission = "bending.command.available"; 33 | } 34 | 35 | @Override 36 | public boolean execute(CommandSender sender, List args) { 37 | Player player = null; 38 | 39 | if (!args.isEmpty() && sender.hasPermission("bending.admin")) { 40 | player = Bukkit.getPlayer(args.get(0)); 41 | } else if(sender instanceof Player) { 42 | player = (Player) sender; 43 | } 44 | 45 | if(player == null) { 46 | sender.sendMessage(ChatColor.RED + Messages.INVALID_PLAYER); 47 | return true; 48 | } 49 | 50 | BendingPlayer bender = BendingPlayer.getBendingPlayer(player); 51 | 52 | Map> elements = new HashMap>(); 53 | Map> affinities = new HashMap>(); 54 | 55 | 56 | for (RegisteredAbility ability : AbilityManager.getManager().getRegisteredAbilities()) { 57 | if (bender.hasAbility(ability) && bender.isBender(ability.getElement()) 58 | && (ability.getAffinity() == BendingAffinity.NONE || bender.hasAffinity(ability.getAffinity()))) { 59 | if(ability.getAffinity() == null || ability.getAffinity() == BendingAffinity.NONE) { 60 | if(!elements.containsKey(ability.getElement())) { 61 | elements.put(ability.getElement(), new LinkedList()); 62 | } 63 | elements.get(ability.getElement()).add(ability); 64 | } else { 65 | if(!affinities.containsKey(ability.getAffinity())) { 66 | affinities.put(ability.getAffinity(), new LinkedList()); 67 | } 68 | affinities.get(ability.getAffinity()).add(ability); 69 | } 70 | } 71 | } 72 | sender.sendMessage("Player: "+ChatColor.GOLD+player.getName()); 73 | sender.sendMessage("Available abilities : "); 74 | for(Entry> entry : elements.entrySet()) { 75 | ChatColor color = PluginTools.getColor(Settings.getColor(entry.getKey())); 76 | sender.sendMessage(" - "+color+entry.getKey()); 77 | for(RegisteredAbility ability : entry.getValue()) { 78 | sender.sendMessage(" - "+color+ability.getName()); 79 | } 80 | } 81 | for(Entry> entry : affinities.entrySet()) { 82 | ChatColor color = PluginTools.getColor(Settings.getColor(entry.getKey().getElement())); 83 | sender.sendMessage(" - "+color+entry.getKey()); 84 | for(RegisteredAbility ability : entry.getValue()) { 85 | sender.sendMessage(" - "+color+ability.getName()); 86 | } 87 | } 88 | 89 | 90 | return true; 91 | } 92 | 93 | @Override 94 | public void printUsage(CommandSender sender, boolean permission) { 95 | sender.sendMessage("/bending available"); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/utils/abilities/Bubble.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.utils.abilities; 2 | 3 | import java.util.HashMap; 4 | import java.util.Iterator; 5 | import java.util.Map; 6 | import java.util.Map.Entry; 7 | 8 | import org.bukkit.Location; 9 | import org.bukkit.block.Block; 10 | import org.bukkit.entity.Player; 11 | 12 | import net.bendercraft.spigot.bending.abilities.AbilityManager; 13 | import net.bendercraft.spigot.bending.abilities.BendingAbility; 14 | import net.bendercraft.spigot.bending.abilities.BendingAbilityState; 15 | import net.bendercraft.spigot.bending.abilities.BendingActiveAbility; 16 | import net.bendercraft.spigot.bending.abilities.RegisteredAbility; 17 | import net.bendercraft.spigot.bending.abilities.air.AirBubble; 18 | import net.bendercraft.spigot.bending.abilities.water.WaterBubble; 19 | import net.bendercraft.spigot.bending.utils.BlockTools; 20 | import net.bendercraft.spigot.bending.utils.EntityTools; 21 | import net.bendercraft.spigot.bending.utils.TempBlock; 22 | 23 | public abstract class Bubble extends BendingActiveAbility { 24 | 25 | protected double radius; 26 | protected Location lastLocation; 27 | 28 | protected Map origins; 29 | 30 | public Bubble(RegisteredAbility register, Player player) { 31 | super(register, player); 32 | this.lastLocation = player.getLocation(); 33 | this.origins = new HashMap<>(); 34 | } 35 | 36 | @Override 37 | public void progress() { 38 | if (getName().equals(EntityTools.getBendingAbility(player))) { 39 | pushLiquids(); 40 | } 41 | else { 42 | remove(); 43 | } 44 | } 45 | 46 | @Override 47 | public boolean swing() { 48 | if (getState().equals(BendingAbilityState.START)) { 49 | setState(BendingAbilityState.PROGRESSING); 50 | return false; 51 | } 52 | 53 | if (!getState().equals(BendingAbilityState.PROGRESSING)) { 54 | return false; 55 | } 56 | 57 | return false; 58 | } 59 | 60 | public boolean blockInBubble(Block block) { 61 | if (block.getWorld() != this.player.getWorld()) { 62 | return false; 63 | } 64 | if (block.getLocation().distance(this.player.getLocation()) <= this.radius) { 65 | return true; 66 | } 67 | return false; 68 | } 69 | 70 | private void pushLiquids() { 71 | Location location = this.player.getLocation(); 72 | 73 | // Do not bother entering this loop if player location has not been 74 | // modified 75 | if (!BlockTools.locationEquals(this.lastLocation, location)) { 76 | 77 | resetOldBlocks(); 78 | 79 | pushNewBlocks(); 80 | 81 | this.lastLocation = this.player.getLocation(); 82 | } 83 | } 84 | 85 | protected abstract void pushNewBlocks(); 86 | 87 | private void resetOldBlocks() { 88 | Iterator> originsIterator = this.origins.entrySet().iterator(); 89 | while (originsIterator.hasNext()) { 90 | Entry entry = originsIterator.next(); 91 | if (!blockInBubble(entry.getKey())) { 92 | entry.getValue().revertBlock(); 93 | originsIterator.remove(); 94 | } 95 | } 96 | } 97 | 98 | public static boolean canFlowTo(Block block) { 99 | Map instances = AbilityManager.getManager().getInstances(AirBubble.NAME); 100 | if (instances == null) { 101 | instances = new HashMap<>(); 102 | } 103 | Map insts = AbilityManager.getManager().getInstances(WaterBubble.NAME); 104 | 105 | if (insts != null) { 106 | instances.putAll(insts); 107 | } 108 | 109 | if (instances.isEmpty()) { 110 | return true; 111 | } 112 | 113 | for (Object o : instances.keySet()) { 114 | Bubble bubble = (Bubble) instances.get(o); 115 | if (bubble.blockInBubble(block)) { 116 | return false; 117 | } 118 | } 119 | return true; 120 | } 121 | 122 | @Override 123 | public void stop() { 124 | for (Entry entry : this.origins.entrySet()) { 125 | entry.getValue().revertBlock(); 126 | } 127 | } 128 | 129 | @Override 130 | public Object getIdentifier() { 131 | return this.player; 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/arts/BlankPoint.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.arts; 2 | 3 | import org.bukkit.entity.Entity; 4 | import org.bukkit.entity.LivingEntity; 5 | import org.bukkit.entity.Player; 6 | import org.bukkit.util.Vector; 7 | 8 | import net.bendercraft.spigot.bending.Bending; 9 | import net.bendercraft.spigot.bending.abilities.ABendingAbility; 10 | import net.bendercraft.spigot.bending.abilities.BendingActiveAbility; 11 | import net.bendercraft.spigot.bending.abilities.BendingAffinity; 12 | import net.bendercraft.spigot.bending.abilities.BendingPerk; 13 | import net.bendercraft.spigot.bending.abilities.RegisteredAbility; 14 | import net.bendercraft.spigot.bending.controller.ConfigurationParameter; 15 | import net.bendercraft.spigot.bending.event.BendingHitEvent; 16 | import net.bendercraft.spigot.bending.utils.DamageTools; 17 | import net.bendercraft.spigot.bending.utils.EntityTools; 18 | 19 | /** 20 | * 21 | * This ability hit the first entity in front of you powerfully driving to a 22 | * knockback You must be sneaking when clicking to activate this technique. 23 | * 24 | */ 25 | @ABendingAbility(name = BlankPoint.NAME, affinity=BendingAffinity.BOW) 26 | public class BlankPoint extends BendingActiveAbility { 27 | public final static String NAME = "BlankPoint"; 28 | 29 | @ConfigurationParameter("Damage") 30 | public static long DAMAGE = 5; 31 | 32 | @ConfigurationParameter("Knockback") 33 | public static double KNOCKBACK = 4; 34 | 35 | @ConfigurationParameter("Range") 36 | public static long RANGE = 4; 37 | 38 | @ConfigurationParameter("Cooldown") 39 | public static long COOLDOWN = 1500; 40 | 41 | private double knockback; 42 | private long cooldown; 43 | private long damage; 44 | 45 | public BlankPoint(RegisteredAbility register, Player player) { 46 | super(register, player); 47 | 48 | this.knockback = KNOCKBACK; 49 | if(bender.hasPerk(BendingPerk.MASTER_BLANKPOINTPUSH_POISONNEDARTRANGE_NEBULARCHAINRANGE)) { 50 | this.knockback += 0.5; 51 | } 52 | 53 | this.cooldown = COOLDOWN; 54 | if(bender.hasPerk(BendingPerk.MASTER_BLANKPOINTCD_SMOKEBOMBCD_DASHSTUN)) { 55 | this.cooldown -= 500; 56 | } 57 | 58 | this.damage = DAMAGE; 59 | if(bender.hasPerk(BendingPerk.MASTER_BLANKPOINTDAMAGE_PARASTICKCD_NEBULARRANGE)) { 60 | this.damage += 1; 61 | } 62 | } 63 | 64 | @Override 65 | public boolean swing() { 66 | LivingEntity target = EntityTools.getTargetedEntity(this.player, RANGE); 67 | if(target == null) { 68 | remove(); 69 | return false; 70 | } 71 | affect(target); 72 | if(bender.hasPerk(BendingPerk.MASTER_DISENGAGE_PARAPARASTICK_CONSTITUTION)) { 73 | Vector push = player.getEyeLocation().getDirection().multiply(-1).normalize(); 74 | push.setY(0.2); 75 | push = push.normalize().multiply(knockback); 76 | 77 | player.setVelocity(push); 78 | } 79 | this.bender.cooldown(this, cooldown); 80 | return false; 81 | } 82 | 83 | @Override 84 | public void progress() { 85 | 86 | } 87 | 88 | @Override 89 | protected long getMaxMillis() { 90 | return 1; 91 | } 92 | 93 | @Override 94 | public Object getIdentifier() { 95 | return this.player; 96 | } 97 | 98 | @Override 99 | public boolean canBeInitialized() { 100 | if (!super.canBeInitialized()) { 101 | return false; 102 | } 103 | 104 | if (EntityTools.holdsTool(player)) { 105 | return false; 106 | } 107 | 108 | return true; 109 | } 110 | 111 | @Override 112 | public void stop() { 113 | 114 | } 115 | 116 | private void affect(Entity entity) { 117 | BendingHitEvent event = new BendingHitEvent(this, entity); 118 | Bending.callEvent(event); 119 | if(event.isCancelled()) { 120 | return; 121 | } 122 | DamageTools.damageEntity(bender, entity, this, damage); 123 | Vector push = player.getEyeLocation().getDirection().normalize(); 124 | push.setY(0.2); 125 | push = push.normalize().multiply(knockback); 126 | 127 | entity.setVelocity(push); 128 | } 129 | 130 | } 131 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/commands/subcommands/BindExecution.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.commands.subcommands; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | 6 | import org.bukkit.ChatColor; 7 | import org.bukkit.command.CommandSender; 8 | import org.bukkit.entity.Player; 9 | 10 | import net.bendercraft.spigot.bending.Messages; 11 | import net.bendercraft.spigot.bending.abilities.AbilityManager; 12 | import net.bendercraft.spigot.bending.abilities.BendingPassiveAbility; 13 | import net.bendercraft.spigot.bending.abilities.BendingPlayer; 14 | import net.bendercraft.spigot.bending.abilities.RegisteredAbility; 15 | import net.bendercraft.spigot.bending.commands.BendingCommand; 16 | import net.bendercraft.spigot.bending.controller.Settings; 17 | import net.bendercraft.spigot.bending.utils.EntityTools; 18 | import net.bendercraft.spigot.bending.utils.PluginTools; 19 | 20 | public class BindExecution extends BendingCommand { 21 | 22 | public BindExecution() { 23 | super(); 24 | this.command = "bind"; 25 | this.aliases.add("b"); 26 | this.basePermission = "bending.command.bind"; 27 | } 28 | 29 | @Override 30 | public boolean execute(CommandSender sender, List args) { 31 | if (!(sender instanceof Player)) { 32 | sender.sendMessage(ChatColor.RED + Messages.NOT_CONSOLE_COMMAND); 33 | return true; 34 | } 35 | 36 | if ((args.size() != 1) && (args.size() != 2)) { 37 | printUsage(sender); 38 | return true; 39 | } 40 | 41 | final String a = args.get(0); 42 | RegisteredAbility ability = AbilityManager.getManager().getRegisteredAbility(a); 43 | if ((ability == null) || BendingPassiveAbility.isPassive(ability)) { 44 | sender.sendMessage(ChatColor.RED + Messages.INVALID_ABILITY); 45 | return true; 46 | } 47 | 48 | Player player = (Player) sender; 49 | 50 | if (!EntityTools.hasPermission(player, ability)) { 51 | player.sendMessage(ChatColor.RED + Messages.NO_BIND_PERMISSION); 52 | return true; 53 | } 54 | 55 | int slot; 56 | if (args.size() == 2) { 57 | try { 58 | slot = Integer.parseInt(args.get(1)); 59 | slot--; 60 | } catch (final NumberFormatException e) { 61 | printUsage(player); 62 | return true; 63 | } 64 | } else { 65 | slot = player.getInventory().getHeldItemSlot(); 66 | } 67 | if ((slot < 0) || (slot > 8)) { 68 | printUsage(player); 69 | return true; 70 | } 71 | ChatColor color = ChatColor.WHITE; 72 | color = PluginTools.getColor(Settings.getColor(ability.getElement())); 73 | BendingPlayer bender = BendingPlayer.getBendingPlayer(player); 74 | if (!bender.isBender(ability.getElement())) { 75 | player.sendMessage(color + Messages.NOT_HAVE_ELEMENT + ability.getElement().name()); 76 | return true; 77 | } 78 | bender.bind(slot, ability.getName()); 79 | String boundMessage = Messages.ABILITY_BOUND; 80 | boundMessage = boundMessage.replaceAll("\\{0\\}", ability.getName()); 81 | boundMessage = boundMessage.replaceAll("\\{1\\}", "" + (slot + 1)); 82 | player.sendMessage(color + boundMessage); 83 | return true; 84 | } 85 | 86 | @Override 87 | public void printUsage(CommandSender sender, boolean permission) { 88 | if (sender.hasPermission("bending.command.bind")) { 89 | sender.sendMessage("/bending bind [slot]"); 90 | } 91 | else if (permission) { 92 | sender.sendMessage(ChatColor.RED + Messages.NO_PERMISSION); 93 | } 94 | } 95 | 96 | @Override 97 | public List autoComplete(CommandSender sender, List args) { 98 | List values = new LinkedList(); 99 | if (args.size() != 1) { 100 | return values; 101 | } 102 | 103 | if (!(sender instanceof Player)) { 104 | return values; 105 | } 106 | 107 | Player player = (Player) sender; 108 | 109 | BendingPlayer bender = BendingPlayer.getBendingPlayer(player); 110 | 111 | if (bender == null || !bender.isBender()) { 112 | return values; 113 | } 114 | 115 | for(RegisteredAbility ability : AbilityManager.getManager().getRegisteredAbilities()) { 116 | if (bender.hasAbility(ability)) { 117 | values.add(ability.getName()); 118 | } 119 | } 120 | 121 | return values; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/arts/Concussion.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.arts; 2 | 3 | import org.bukkit.Material; 4 | import org.bukkit.Particle; 5 | import org.bukkit.entity.Entity; 6 | import org.bukkit.entity.LivingEntity; 7 | import org.bukkit.entity.Player; 8 | import org.bukkit.util.Vector; 9 | 10 | import net.bendercraft.spigot.bending.Bending; 11 | import net.bendercraft.spigot.bending.abilities.ABendingAbility; 12 | import net.bendercraft.spigot.bending.abilities.AbilityManager; 13 | import net.bendercraft.spigot.bending.abilities.BendingAbility; 14 | import net.bendercraft.spigot.bending.abilities.BendingAbilityState; 15 | import net.bendercraft.spigot.bending.abilities.BendingActiveAbility; 16 | import net.bendercraft.spigot.bending.abilities.BendingAffinity; 17 | import net.bendercraft.spigot.bending.abilities.BendingPerk; 18 | import net.bendercraft.spigot.bending.abilities.RegisteredAbility; 19 | import net.bendercraft.spigot.bending.controller.ConfigurationParameter; 20 | import net.bendercraft.spigot.bending.event.BendingHitEvent; 21 | import net.bendercraft.spigot.bending.utils.EntityTools; 22 | 23 | @ABendingAbility(name = Concussion.NAME, affinity = BendingAffinity.SWORD) 24 | public class Concussion extends BendingActiveAbility { 25 | public final static String NAME = "Concussion"; 26 | 27 | @ConfigurationParameter("Cooldown") 28 | private static long COOLDOWN = 10000; 29 | 30 | @ConfigurationParameter("Range") 31 | public static long RANGE = 3; 32 | 33 | @ConfigurationParameter("Duration") 34 | public static long DURATION = 2000; 35 | 36 | private LivingEntity target; 37 | 38 | private long cooldown; 39 | 40 | private long range; 41 | 42 | private long duration; 43 | 44 | public Concussion(RegisteredAbility register, Player player) { 45 | super(register, player); 46 | 47 | this.cooldown = COOLDOWN; 48 | if(bender.hasPerk(BendingPerk.MASTER_AIMCHARGETIME_PARASTICKCD_CONCUSSIONCD)) { 49 | this.cooldown -= 500; 50 | } 51 | 52 | this.range = RANGE; 53 | if(bender.hasPerk(BendingPerk.MASTER_BLANKPOINTCD_SMOKEBOMBCD_DASHSTUN)) { 54 | this.range += 1; 55 | } 56 | 57 | this.duration = DURATION; 58 | if(bender.hasPerk(BendingPerk.MASTER_EXPLOSIVESHOTFIRE_POISONNEDDARTDAMAGE_CONCUSSIONDURATION)) { 59 | this.duration += 1000; 60 | } 61 | } 62 | 63 | @Override 64 | public boolean canBeInitialized() { 65 | if (!super.canBeInitialized()) { 66 | return false; 67 | } 68 | 69 | if(player.getInventory().getItemInOffHand() == null || player.getInventory().getItemInOffHand().getType() != Material.SHIELD) { 70 | return false; 71 | } 72 | return true; 73 | } 74 | 75 | @Override 76 | public boolean sneak() { 77 | target = EntityTools.getTargetedEntity(player, range); 78 | if(target != null) { 79 | setState(BendingAbilityState.PROGRESSING); 80 | bender.cooldown(this, cooldown); 81 | } 82 | return false; 83 | } 84 | 85 | @Override 86 | public void progress() { 87 | if(target != null) { 88 | if(startedTime + duration < System.currentTimeMillis()) { 89 | remove(); 90 | return; 91 | } 92 | affect(target); 93 | } 94 | } 95 | 96 | @Override 97 | public Object getIdentifier() { 98 | return this.player; 99 | } 100 | 101 | @Override 102 | public void stop() { 103 | 104 | } 105 | 106 | private void affect(Entity entity) { 107 | BendingHitEvent event = new BendingHitEvent(this, entity); 108 | Bending.callEvent(event); 109 | if(event.isCancelled()) { 110 | return; 111 | } 112 | 113 | target.setVelocity(new Vector(0, 0, 0)); 114 | target.getWorld().spawnParticle(Particle.CLOUD, target.getEyeLocation().add(target.getEyeLocation().getDirection().multiply(0.5)), 1, 0, 0, 0, 0); 115 | } 116 | 117 | public static Concussion getTarget(LivingEntity entity) { 118 | for(BendingAbility ability : AbilityManager.getManager().getInstances(NAME).values()) { 119 | Concussion concussion = (Concussion) ability; 120 | if(concussion.target == entity) { 121 | return concussion; 122 | } 123 | } 124 | return null; 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/commands/subcommands/ChooseExecution.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.commands.subcommands; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | 6 | import org.bukkit.Bukkit; 7 | import org.bukkit.ChatColor; 8 | import org.bukkit.command.CommandSender; 9 | import org.bukkit.entity.Player; 10 | 11 | import net.bendercraft.spigot.bending.Messages; 12 | import net.bendercraft.spigot.bending.abilities.BendingElement; 13 | import net.bendercraft.spigot.bending.abilities.BendingPlayer; 14 | import net.bendercraft.spigot.bending.commands.BendingCommand; 15 | import net.bendercraft.spigot.bending.controller.Settings; 16 | import net.bendercraft.spigot.bending.utils.PluginTools; 17 | 18 | public class ChooseExecution extends BendingCommand { 19 | 20 | public ChooseExecution() { 21 | super(); 22 | this.command = "choose"; 23 | this.aliases.add("ch"); 24 | this.basePermission = "bending.command.choose"; 25 | } 26 | 27 | @Override 28 | public boolean execute(CommandSender sender, List args) { 29 | 30 | if ((args.size() != 1) && (args.size() != 2)) { 31 | printUsage(sender); 32 | return true; 33 | } 34 | Player target; 35 | boolean other = false; 36 | if (args.size() == 1) { 37 | if (!(sender instanceof Player)) { 38 | sender.sendMessage(Messages.CONSOLE_SPECIFY_PLAYER); 39 | return true; 40 | } 41 | target = (Player) sender; 42 | } else { 43 | if (!sender.hasPermission("bending.command.choose.other")) { 44 | sender.sendMessage(ChatColor.RED + Messages.ERROR_CHOOSE_OTHER); 45 | return true; 46 | } 47 | target = getPlayer(args.remove(0)); 48 | other = true; 49 | } 50 | 51 | if (target == null) { 52 | sender.sendMessage(ChatColor.RED + Messages.INVALID_PLAYER); 53 | return true; 54 | } 55 | 56 | BendingPlayer bender = BendingPlayer.getBendingPlayer(target); 57 | if (bender == null) { 58 | return false; 59 | } 60 | if (bender.isBender()) { 61 | if (!other) { 62 | if (!sender.hasPermission("bending.command.rechoose")) { 63 | sender.sendMessage(ChatColor.RED + Messages.ERROR_CHANGE_ELEMENT); 64 | return true; 65 | } 66 | } 67 | } 68 | 69 | String choice = args.remove(0); 70 | BendingElement element = getElement(choice); 71 | 72 | if (element == null) { 73 | sender.sendMessage(ChatColor.RED + Messages.INVALID_ELEMENT); 74 | return true; 75 | } 76 | 77 | bender.setBender(element); 78 | 79 | ChatColor color = PluginTools.getColor(Settings.getColor(element)); 80 | if (other) { 81 | String msg = Messages.YOU_CHANGE_OTHER; 82 | msg = msg.replaceAll("\\{0\\}", target.getName()); 83 | msg = msg.replaceAll("\\{1\\}", element.name()); 84 | sender.sendMessage(color + msg); 85 | msg = Messages.OTHER_CHANGE_YOU; 86 | msg = msg.replaceAll("\\{0\\}", element.name()); 87 | target.sendMessage(color + msg); 88 | } else { 89 | String msg = Messages.SET_ELEMENT; 90 | msg = msg.replaceAll("\\{0\\}", element.name()); 91 | target.sendMessage(color + msg); 92 | } 93 | 94 | return true; 95 | } 96 | 97 | @Override 98 | public void printUsage(CommandSender sender, boolean permission) { 99 | if (sender.hasPermission("bending.admin.choose") || sender.hasPermission("bending.admin.rechoose")) { 100 | sender.sendMessage("/bending choose [player] "); 101 | } 102 | else if (sender.hasPermission("bending.command.choose")) { 103 | sender.sendMessage("/bending choose "); 104 | } 105 | else if (permission) { 106 | sender.sendMessage(ChatColor.RED + Messages.NO_PERMISSION); 107 | } 108 | } 109 | 110 | @Override 111 | public List autoComplete(CommandSender sender, List args) { 112 | List values = new LinkedList(); 113 | if (!sender.hasPermission("bending.command.choose")) { 114 | return values; 115 | } 116 | 117 | for (BendingElement el : BendingElement.values()) { 118 | values.add(el.name()); 119 | } 120 | 121 | if (args.size() == 2 || !sender.hasPermission("bending.command.choose.other")) { 122 | return values; 123 | } 124 | 125 | for (Player online : Bukkit.getServer().getOnlinePlayers()) { 126 | values.add(online.getName()); 127 | } 128 | 129 | return values; 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/utils/Tools.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.utils; 2 | 3 | import org.bukkit.Location; 4 | import org.bukkit.block.BlockFace; 5 | import org.bukkit.util.Vector; 6 | 7 | import net.bendercraft.spigot.bending.controller.Settings; 8 | 9 | public class Tools { 10 | public static final long timeinterval = Settings.GLOBAL_COOLDOWN; 11 | 12 | public static double getDistanceFromLine(Vector line, Location pointonline, Location point) { 13 | Vector AP = new Vector(); 14 | double Ax, Ay, Az; 15 | Ax = pointonline.getX(); 16 | Ay = pointonline.getY(); 17 | Az = pointonline.getZ(); 18 | 19 | double Px, Py, Pz; 20 | Px = point.getX(); 21 | Py = point.getY(); 22 | Pz = point.getZ(); 23 | 24 | AP.setX(Px - Ax); 25 | AP.setY(Py - Ay); 26 | AP.setZ(Pz - Az); 27 | 28 | return (AP.crossProduct(line).length()) / (line.length()); 29 | } 30 | 31 | public static Vector rotateVectorAroundVector(Vector axis, Vector rotator, double degrees) { 32 | double angle = Math.toRadians(degrees); 33 | Vector rotation = axis.clone(); 34 | Vector rotate = rotator.clone(); 35 | rotation = rotation.normalize(); 36 | 37 | Vector thirdaxis = rotation.crossProduct(rotate).normalize().multiply(rotate.length()); 38 | 39 | return rotate.multiply(Math.cos(angle)).add(thirdaxis.multiply(Math.sin(angle))); 40 | } 41 | 42 | public static Vector getOrthogonalVector(Vector axis, double degrees, double length) { 43 | 44 | Vector ortho = new Vector(axis.getY(), -axis.getX(), 0); 45 | ortho = ortho.normalize(); 46 | ortho = ortho.multiply(length); 47 | 48 | return rotateVectorAroundVector(axis, ortho, degrees); 49 | } 50 | 51 | public static Location getPointOnLine(Location origin, Location target, double distance) { 52 | return origin.clone().add(getDirection(origin, target).normalize().multiply(distance)); 53 | 54 | } 55 | 56 | public static Vector getDirection(Location location, Location destination) { 57 | double x1, y1, z1; 58 | double x0, y0, z0; 59 | 60 | x1 = destination.getX(); 61 | y1 = destination.getY(); 62 | z1 = destination.getZ(); 63 | 64 | x0 = location.getX(); 65 | y0 = location.getY(); 66 | z0 = location.getZ(); 67 | 68 | return new Vector(x1 - x0, y1 - y0, z1 - z0); 69 | } 70 | 71 | public static Vector getVectorForPoints(Location origin, Location target) { 72 | double g = -0.08; 73 | double d = target.distance(origin); 74 | double t = d; 75 | double vX = (1.0 + 0.07 * t) * (target.getX() - origin.getX()) / t; 76 | double vY = (1.0 + 0.03 * t) * (target.getY() - origin.getY()) / t - 0.5 * g * t; 77 | double vZ = (1.0 + 0.07 * t) * (target.getZ() - origin.getZ()) / t; 78 | return new Vector(vX, vY, vZ); 79 | } 80 | 81 | public static BlockFace getCardinalDirection(Vector vector) { 82 | BlockFace[] faces = { BlockFace.NORTH, BlockFace.NORTH_EAST, BlockFace.EAST, BlockFace.SOUTH_EAST, BlockFace.SOUTH, BlockFace.SOUTH_WEST, BlockFace.WEST, BlockFace.NORTH_WEST }; 83 | Vector n, ne, e, se, s, sw, w, nw; 84 | w = new Vector(-1, 0, 0); 85 | n = new Vector(0, 0, -1); 86 | s = n.clone().multiply(-1); 87 | e = w.clone().multiply(-1); 88 | ne = n.clone().add(e.clone()).normalize(); 89 | se = s.clone().add(e.clone()).normalize(); 90 | nw = n.clone().add(w.clone()).normalize(); 91 | sw = s.clone().add(w.clone()).normalize(); 92 | 93 | Vector[] vectors = { n, ne, e, se, s, sw, w, nw }; 94 | 95 | double comp = 0; 96 | int besti = 0; 97 | for (int i = 0; i < vectors.length; i++) { 98 | double dot = vector.dot(vectors[i]); 99 | if (dot > comp) { 100 | comp = dot; 101 | besti = i; 102 | } 103 | } 104 | return faces[besti]; 105 | } 106 | 107 | public static int getIntCardinalDirection(Vector vector) { 108 | BlockFace face = getCardinalDirection(vector); 109 | switch (face) { 110 | case SOUTH: 111 | return 7; 112 | case SOUTH_WEST: 113 | return 6; 114 | case WEST: 115 | return 3; 116 | case NORTH_WEST: 117 | return 0; 118 | case NORTH: 119 | return 1; 120 | case NORTH_EAST: 121 | return 2; 122 | case EAST: 123 | return 5; 124 | case SOUTH_EAST: 125 | return 8; 126 | default: 127 | break; 128 | } 129 | return 4; 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/fire/Enflamed.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.fire; 2 | 3 | import java.util.HashMap; 4 | import java.util.LinkedList; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | import org.bukkit.entity.Entity; 9 | import org.bukkit.entity.Player; 10 | 11 | import net.bendercraft.spigot.bending.Bending; 12 | import net.bendercraft.spigot.bending.abilities.BendingAbility; 13 | import net.bendercraft.spigot.bending.abilities.BendingElement; 14 | import net.bendercraft.spigot.bending.abilities.BendingPerk; 15 | import net.bendercraft.spigot.bending.abilities.BendingPlayer; 16 | import net.bendercraft.spigot.bending.event.BendingHitEvent; 17 | import net.bendercraft.spigot.bending.utils.DamageTools; 18 | import net.bendercraft.spigot.bending.utils.EntityTools; 19 | 20 | public class Enflamed { 21 | private static Map instances = new HashMap(); 22 | 23 | private static final double DAMAGE = 1; 24 | 25 | private int secondsLeft; 26 | private Entity target; 27 | 28 | private long time; 29 | private BendingPlayer bender; 30 | private double damage; 31 | private BendingAbility ability; 32 | 33 | public static void enflame(Player source, Entity target, int seconds, BendingAbility ability) { 34 | if (target == source) { 35 | return; 36 | } 37 | 38 | BendingPlayer bender = BendingPlayer.getBendingPlayer(source); 39 | double damage = DAMAGE; 40 | if (instances.containsKey(target)) { 41 | if(bender.hasPerk(BendingPerk.FIRE_SCORCH)) { 42 | damage = DAMAGE * 1.4; 43 | if(bender.hasPerk(BendingPerk.FIRE_SCORCH_ENHANCE_1)) { 44 | damage = DAMAGE * 1.6; 45 | } 46 | if(bender.hasPerk(BendingPerk.FIRE_SCORCH_ENHANCE_2)) { 47 | damage = DAMAGE * 1.8; 48 | } 49 | } 50 | } 51 | instances.put(target, new Enflamed(bender, target, damage, seconds, ability)); 52 | } 53 | 54 | private Enflamed(BendingPlayer bender, Entity target, double damage, int seconds, BendingAbility ability) { 55 | this.ability = ability; 56 | this.target = target; 57 | this.time = System.currentTimeMillis(); 58 | this.secondsLeft = seconds; 59 | this.damage = damage; 60 | this.bender = bender; 61 | target.setFireTicks(secondsLeft*20); 62 | } 63 | 64 | public void addSeconds(int amount) { 65 | this.secondsLeft += amount; 66 | } 67 | 68 | public boolean progress() { 69 | long now = System.currentTimeMillis(); 70 | if(target.isDead()) { 71 | return false; 72 | } 73 | if ((now - this.time) < 1000) { 74 | return true; 75 | } 76 | time = now; 77 | 78 | if(secondsLeft <= 0) { 79 | return false; 80 | } 81 | if (target.getFireTicks() == 0 && !bender.hasPerk(BendingPerk.FIRE_INNERFIRE)) { 82 | return false; 83 | } 84 | 85 | if (target instanceof Player && !canBurn((Player) target)) { 86 | return false; 87 | } 88 | 89 | affect(target); 90 | secondsLeft -= 1; 91 | 92 | 93 | return true; 94 | } 95 | 96 | public void affect(Entity entity) { 97 | BendingHitEvent event = new BendingHitEvent(ability, entity); 98 | Bending.callEvent(event); 99 | if(event.isCancelled()) { 100 | return; 101 | } 102 | target.setFireTicks(this.secondsLeft * 20); 103 | DamageTools.damageEntity(bender, target, ability, damage, true, 0, 0.0F, true); 104 | } 105 | 106 | public static boolean isEnflamed(Entity entity) { 107 | return instances.containsKey(entity); 108 | } 109 | 110 | public static boolean canBurn(Player player) { 111 | if (HeatControl.NAME.equals(EntityTools.getBendingAbility(player)) || FireJet.checkTemporaryImmunity(player)) { 112 | player.setFireTicks(0); 113 | return false; 114 | } 115 | 116 | if ((player.getFireTicks() > 80) && EntityTools.canBendPassive(player, BendingElement.FIRE)) { 117 | player.setFireTicks(80); 118 | } 119 | 120 | return true; 121 | } 122 | 123 | public static void progressAll() { 124 | List toRemove = new LinkedList(); 125 | for (Enflamed flame : instances.values()) { 126 | if (!flame.progress()) { 127 | toRemove.add(flame); 128 | } 129 | } 130 | 131 | for (Enflamed flame : toRemove) { 132 | flame.remove(); 133 | } 134 | } 135 | 136 | public boolean remove() { 137 | instances.remove(this.target); 138 | return true; 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/water/Frozen.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.water; 2 | 3 | import java.util.Collections; 4 | import java.util.HashMap; 5 | import java.util.Iterator; 6 | import java.util.LinkedList; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | import org.bukkit.Location; 11 | import org.bukkit.Material; 12 | import org.bukkit.Sound; 13 | import org.bukkit.block.Block; 14 | import org.bukkit.entity.Player; 15 | 16 | import net.bendercraft.spigot.bending.utils.BlockTools; 17 | import net.bendercraft.spigot.bending.utils.ProtectionManager; 18 | import net.bendercraft.spigot.bending.utils.TempBlock; 19 | 20 | public class Frozen { 21 | private static List instances = new LinkedList<>(); 22 | 23 | public static int DURATION = 60000; 24 | public static int STEP = 20; 25 | public static int DEPTH = 8; 26 | 27 | private Player player; 28 | private Map> expands = new HashMap<>(); 29 | private int iteration = 0; 30 | private long time; 31 | private long interval = (long) (1000. / 8); 32 | private double range; 33 | private Location location; 34 | 35 | private Frozen(Player player, Location location, double range) { 36 | this.player = player; 37 | this.location = location; 38 | this.range = range; 39 | } 40 | 41 | private boolean prepareBlocks() { 42 | for(Block block : BlockTools.getBlocksAroundPoint(location, range)) { 43 | if(block.getLocation().getBlockY() < location.getBlockY() - DEPTH) { 44 | continue; 45 | } 46 | if(ProtectionManager.isRegionProtectedFromBendingPassives(player, block.getLocation())) { 47 | continue; 48 | } 49 | // List of authorized blocks to be changed 50 | if(block.getType() != Material.DIRT 51 | && block.getType() != Material.GRASS 52 | && block.getType() != Material.STONE 53 | && block.getType() != Material.COBBLESTONE 54 | && block.getType() != Material.GRAVEL 55 | && block.getType() != Material.SAND 56 | && block.getType() != Material.SANDSTONE 57 | && block.getType() != Material.BRICK 58 | && BlockTools.isLeaf(block)) { 59 | continue; 60 | } 61 | int distance = (int) location.distance(block.getLocation()); 62 | if(!expands.containsKey(distance)) { 63 | expands.put(distance, new LinkedList<>()); 64 | } 65 | expands.get(distance).add(block); 66 | } 67 | for(List blocks : expands.values()) { 68 | Collections.shuffle(blocks); 69 | } 70 | time = System.currentTimeMillis(); 71 | return false; 72 | } 73 | 74 | private boolean progress() { 75 | if (System.currentTimeMillis() - time >= interval) { 76 | time = System.currentTimeMillis(); 77 | if(expands.isEmpty()) { 78 | return false; 79 | } 80 | if(expands.containsKey(iteration)) { 81 | int done = 0; 82 | Iterator it = expands.get(iteration).iterator(); 83 | while(it.hasNext()) { 84 | Block block = it.next(); 85 | if(BlockTools.isLeaf(block)) { 86 | double rand = Math.random(); 87 | Material mat = Material.BLUE_STAINED_GLASS; 88 | if(rand < 0.75) { 89 | mat = Material.LIGHT_BLUE_STAINED_GLASS; 90 | } else if(rand < 0.5) { 91 | mat = Material.BLUE_STAINED_GLASS_PANE; 92 | } else if(rand < 0.5) { 93 | mat = Material.LIGHT_BLUE_STAINED_GLASS_PANE; 94 | } 95 | TempBlock.makeGlobal(DURATION, block, mat, true); 96 | block.getWorld().playSound(block.getLocation(), Sound.BLOCK_SNOW_PLACE, 1.0f, 1.0f); 97 | } else { 98 | TempBlock.makeGlobal(DURATION, block, Material.ICE, true); 99 | block.getWorld().playSound(block.getLocation(), Sound.BLOCK_SNOW_PLACE, 1.0f, 1.0f); 100 | } 101 | it.remove(); 102 | done++; 103 | if(done > STEP) { 104 | break; 105 | } 106 | } 107 | if(expands.get(iteration).isEmpty()) { 108 | expands.remove(iteration); 109 | iteration++; 110 | } 111 | } else { 112 | iteration++; 113 | } 114 | } 115 | return true; 116 | } 117 | 118 | public static void freeze(Player player, Location location, double range) { 119 | Frozen frozen = new Frozen(player, location, range); 120 | frozen.prepareBlocks(); 121 | instances.add(frozen); 122 | } 123 | 124 | public static void handle() { 125 | Iterator it = instances.iterator(); 126 | while(it.hasNext()) { 127 | Frozen frozen = it.next(); 128 | if(!frozen.progress()) { 129 | it.remove(); 130 | } 131 | } 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/commands/subcommands/DeckExecution.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.commands.subcommands; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | import java.util.Map; 6 | import java.util.TreeMap; 7 | 8 | import org.bukkit.ChatColor; 9 | import org.bukkit.command.CommandSender; 10 | import org.bukkit.entity.Player; 11 | 12 | import net.bendercraft.spigot.bending.Messages; 13 | import net.bendercraft.spigot.bending.abilities.BendingPlayer; 14 | import net.bendercraft.spigot.bending.commands.BendingCommand; 15 | import net.bendercraft.spigot.bending.controller.Settings; 16 | 17 | public class DeckExecution extends BendingCommand { 18 | 19 | public DeckExecution() { 20 | super(); 21 | this.command = "deck"; 22 | this.aliases.add("dk"); 23 | this.basePermission = "bending.command.deck"; 24 | } 25 | 26 | @Override 27 | public boolean execute(CommandSender sender, List args) { 28 | if (!(sender instanceof Player)) { 29 | sender.sendMessage(Messages.NOT_CONSOLE_COMMAND); 30 | return true; 31 | } 32 | 33 | if (args.size() == 1) { 34 | if (args.get(0).equalsIgnoreCase("list")) { 35 | listDecks(sender); 36 | } 37 | else { 38 | changeDeck(sender, args); 39 | } 40 | } 41 | else if (args.size() == 3) { 42 | renameDeck(sender, args); 43 | } 44 | else { 45 | printUsage(sender); 46 | } 47 | 48 | return true; 49 | } 50 | 51 | private void listDecks(CommandSender sender) { 52 | Player player = (Player) sender; 53 | BendingPlayer bender = BendingPlayer.getBendingPlayer(player); 54 | sender.sendMessage("Decks : "); 55 | for (String deck : bender.getDecksNames()) { 56 | sender.sendMessage("----" + deck); 57 | } 58 | } 59 | 60 | private void renameDeck(CommandSender sender, List args) { 61 | Player player = (Player) sender; 62 | BendingPlayer bender = BendingPlayer.getBendingPlayer(player); 63 | String deckName = args.get(1).toLowerCase(); 64 | String newName = args.get(2).toLowerCase(); 65 | if (bender.getDecks().containsKey(deckName)) { 66 | if (bender.getDecks().containsKey(newName)) { 67 | sender.sendMessage(ChatColor.RED + Messages.ALREADY_DECK_NAME); 68 | } 69 | else { 70 | Map deck = bender.getDecks().remove(deckName); 71 | bender.getDecks().put(newName, deck); 72 | sender.sendMessage(ChatColor.GREEN + Messages.DECK_RENAMED + newName); 73 | } 74 | } 75 | else { 76 | sender.sendMessage(ChatColor.RED + Messages.INVALID_DECK); 77 | } 78 | } 79 | 80 | private void changeDeck(CommandSender sender, List args) { 81 | Player player = (Player) sender; 82 | BendingPlayer bender = BendingPlayer.getBendingPlayer(player); 83 | String deckName = args.get(0).toLowerCase(); 84 | if (bender.getDecks().containsKey(deckName)) { 85 | bender.setCurrentDeck(deckName); 86 | String msg = Messages.DECK_SET; 87 | msg = msg.replaceAll("\\{0\\}", deckName); 88 | sender.sendMessage(ChatColor.GREEN + msg); 89 | } 90 | else { 91 | if (bender.getDecks().size() >= Settings.MAX_DECKS_AMOUNT) { 92 | sender.sendMessage(ChatColor.RED + Messages.MAX_DECKS_REACHED); 93 | } 94 | else { 95 | Map deck = new TreeMap(); 96 | bender.getDecks().put(deckName, deck); 97 | bender.setCurrentDeck(deckName); 98 | String msg = Messages.DECK_SET; 99 | msg = msg.replaceAll("\\{0\\}", deckName); 100 | sender.sendMessage(ChatColor.GREEN + msg); 101 | } 102 | } 103 | } 104 | 105 | 106 | @Override 107 | public void printUsage(CommandSender sender, boolean permission) { 108 | if (sender.hasPermission("bending.command.deck")) { 109 | sender.sendMessage("/bending deck list"); 110 | sender.sendMessage("/bending deck "); 111 | sender.sendMessage("/bending deck rename "); 112 | } 113 | else if (permission) { 114 | sender.sendMessage(ChatColor.RED + Messages.NO_PERMISSION); 115 | } 116 | } 117 | 118 | @Override 119 | public List autoComplete(CommandSender sender, List args) { 120 | List values = new LinkedList(); 121 | if (!(sender instanceof Player)) { 122 | return values; 123 | } 124 | 125 | if (args.size() == 1 || args.size() == 2) { 126 | Player player = (Player) sender; 127 | BendingPlayer bender = BendingPlayer.getBendingPlayer(player); 128 | for (String value : bender.getDecksNames()) { 129 | values.add(value); 130 | } 131 | } 132 | 133 | return values; 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/controller/FlyingPlayer.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.controller; 2 | 3 | import java.util.*; 4 | 5 | import org.bukkit.entity.Player; 6 | 7 | import net.bendercraft.spigot.bending.abilities.BendingAbility; 8 | import net.bendercraft.spigot.bending.abilities.BendingAbilityState; 9 | 10 | public class FlyingPlayer { 11 | /* When dealing with flying players in Minecraft, there is two important booleans : 12 | 1. allowFlight : allows the player to fly by double-jumping like in creative mode. 13 | Whatever the ability, we want to set this boolean to true as the server will not try to kick players for cheating. 14 | We prevent the players from actually using double-jumping in BendingPlayerListener. 15 | 2. flying : Make the player fly, giving him the ability to go up and down with space and sneak respectively. 16 | 17 | Some abilities (like FireJet) do not set flying to true, while others (like AirSpout) do. 18 | It is important for us to keep track of which ability sets this flag to true in order to revoke the fly 19 | whenever it is not allowed anymore, even if other abilities still make the player considered as a FlyingPlayer. 20 | */ 21 | private static Map flyingPlayers = new HashMap(); 22 | 23 | private Player player; 24 | private List causes; 25 | 26 | private class FlyingCause { 27 | BendingAbility ability; 28 | Long endTime; 29 | boolean setFlying; //If this FlyingCause actually sets player.setFlying(true) 30 | 31 | FlyingCause(BendingAbility ability, Long endTime, boolean setFlying) { 32 | this.ability = ability; 33 | this.endTime = endTime; 34 | this.setFlying = setFlying; 35 | } 36 | } 37 | 38 | private FlyingPlayer(Player player) { 39 | this.player = player; 40 | this.causes = new LinkedList<>(); 41 | } 42 | 43 | private void updatePermission() { 44 | this.player.setAllowFlight(true); 45 | this.player.setFlying(hasOneSetFlyingCause()); 46 | } 47 | 48 | private void resetState() { 49 | this.player.setAllowFlight(false); 50 | this.player.setFlying(false); 51 | } 52 | 53 | private void addCause(BendingAbility cause, Long endTime, boolean setFlying) { 54 | this.causes.add(new FlyingCause(cause, endTime, setFlying)); 55 | this.updatePermission(); 56 | } 57 | 58 | private boolean hasCauses() { 59 | return !this.causes.isEmpty(); 60 | } 61 | 62 | private boolean hasOneSetFlyingCause() { 63 | for (FlyingCause cause : this.causes) { 64 | if (cause.setFlying) { 65 | return true; 66 | } 67 | } 68 | return false; 69 | } 70 | 71 | private void removeCause(BendingAbility abilityCause) { 72 | this.causes.removeIf(cause -> cause.ability.equals(abilityCause)); 73 | this.updatePermission(); 74 | } 75 | 76 | public static FlyingPlayer addFlyingPlayer(Player player, BendingAbility cause, Long maxDuration, boolean setFlying) { 77 | if ((player == null) || (cause == null)) { 78 | return null; 79 | } 80 | 81 | FlyingPlayer fp; 82 | if (flyingPlayers.containsKey(player.getUniqueId())) { 83 | fp = flyingPlayers.get(player.getUniqueId()); 84 | } else { 85 | fp = new FlyingPlayer(player); 86 | } 87 | 88 | fp.addCause(cause, System.currentTimeMillis() + maxDuration, setFlying); 89 | flyingPlayers.put(player.getUniqueId(), fp); 90 | return fp; 91 | } 92 | 93 | public static void removeFlyingPlayer(Player player, BendingAbility cause) { 94 | if (!flyingPlayers.containsKey(player.getUniqueId())) { 95 | return; 96 | } 97 | 98 | FlyingPlayer fp = flyingPlayers.get(player.getUniqueId()); 99 | if (fp == null) { 100 | flyingPlayers.remove(player.getUniqueId()); 101 | return; 102 | } 103 | 104 | fp.removeCause(cause); 105 | if (!fp.hasCauses()) { 106 | fp.resetState(); 107 | flyingPlayers.remove(player.getUniqueId()); 108 | } 109 | } 110 | 111 | private void handle() { 112 | long now = System.currentTimeMillis(); 113 | 114 | causes.removeIf(cause -> now > cause.endTime || cause.ability.getState() == BendingAbilityState.ENDED); 115 | updatePermission(); 116 | } 117 | 118 | public static void handleAll() { 119 | Iterator it = flyingPlayers.keySet().iterator(); 120 | while (it.hasNext()) { 121 | FlyingPlayer fp = flyingPlayers.get(it.next()); 122 | fp.handle(); 123 | if (!fp.hasCauses()) { 124 | fp.resetState(); 125 | it.remove(); 126 | } 127 | } 128 | } 129 | 130 | public static boolean isFlying(Player p) { 131 | return flyingPlayers.containsKey(p.getUniqueId()); 132 | } 133 | 134 | } 135 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/learning/BendingLearning.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.learning; 2 | 3 | import org.bukkit.entity.Player; 4 | import net.bendercraft.spigot.bending.Bending; 5 | import net.bendercraft.spigot.bending.abilities.AbilityManager; 6 | import net.bendercraft.spigot.bending.abilities.BendingPlayer; 7 | import net.bendercraft.spigot.bending.abilities.RegisteredAbility; 8 | import net.bendercraft.spigot.bending.abilities.air.AirBlast; 9 | import net.bendercraft.spigot.bending.abilities.air.AirSlice; 10 | import net.bendercraft.spigot.bending.abilities.air.AirSpout; 11 | import net.bendercraft.spigot.bending.abilities.air.AirSwipe; 12 | import net.bendercraft.spigot.bending.abilities.arts.Dash; 13 | import net.bendercraft.spigot.bending.abilities.arts.DirectHit; 14 | import net.bendercraft.spigot.bending.abilities.arts.HighJump; 15 | import net.bendercraft.spigot.bending.abilities.earth.Collapse; 16 | import net.bendercraft.spigot.bending.abilities.earth.EarthBlast; 17 | import net.bendercraft.spigot.bending.abilities.earth.EarthLariat; 18 | import net.bendercraft.spigot.bending.abilities.earth.EarthWall; 19 | import net.bendercraft.spigot.bending.abilities.fire.Blaze; 20 | import net.bendercraft.spigot.bending.abilities.fire.FireBlast; 21 | import net.bendercraft.spigot.bending.abilities.fire.FireFerret; 22 | import net.bendercraft.spigot.bending.abilities.fire.HeatControl; 23 | import net.bendercraft.spigot.bending.abilities.water.HealingWaters; 24 | import net.bendercraft.spigot.bending.abilities.water.WaterManipulation; 25 | import net.bendercraft.spigot.bending.abilities.water.WaterSpout; 26 | 27 | public class BendingLearning { 28 | 29 | public void onEnable() { 30 | PermissionListener permListener = new PermissionListener(this); 31 | AirListener airListener = new AirListener(this); 32 | EarthListener earthListener = new EarthListener(this); 33 | WaterListener waterListener = new WaterListener(this); 34 | FireListener fireListener = new FireListener(this); 35 | MasterListener chiListener = new MasterListener(this); 36 | 37 | // Register listeners 38 | Bending.getInstance().getServer().getPluginManager().registerEvents(permListener, Bending.getInstance()); 39 | Bending.getInstance().getServer().getPluginManager().registerEvents(airListener, Bending.getInstance()); 40 | Bending.getInstance().getServer().getPluginManager().registerEvents(earthListener, Bending.getInstance()); 41 | Bending.getInstance().getServer().getPluginManager().registerEvents(waterListener, Bending.getInstance()); 42 | Bending.getInstance().getServer().getPluginManager().registerEvents(fireListener, Bending.getInstance()); 43 | Bending.getInstance().getServer().getPluginManager().registerEvents(chiListener, Bending.getInstance()); 44 | } 45 | 46 | public boolean addPermission(Player player, String ability) { 47 | return addPermission(player, AbilityManager.getManager().getRegisteredAbility(ability)); 48 | } 49 | 50 | public boolean addPermission(Player player, RegisteredAbility ability) { 51 | BendingPlayer bender = BendingPlayer.getBendingPlayer(player); 52 | if (bender != null && !bender.hasAbility(ability)) { 53 | bender.addAbility(ability); 54 | return true; 55 | } 56 | return false; 57 | } 58 | 59 | public boolean removePermission(Player player, String ability) { 60 | return removePermission(player, AbilityManager.getManager().getRegisteredAbility(ability)); 61 | } 62 | 63 | public boolean removePermission(Player player, RegisteredAbility ability) { 64 | BendingPlayer bender = BendingPlayer.getBendingPlayer(player); 65 | if (bender != null && bender.hasAbility(ability)) { 66 | bender.removeAbility(ability); 67 | return true; 68 | } 69 | return false; 70 | } 71 | 72 | public boolean isBasicBendingAbility(String ability) { 73 | if(ability.equals(AirBlast.NAME) 74 | || ability.equals(AirSpout.NAME) 75 | || ability.equals(AirSwipe.NAME) 76 | || ability.equals(AirSlice.NAME) 77 | 78 | || ability.equals(FireBlast.NAME) 79 | || ability.equals(Blaze.NAME) 80 | || ability.equals(HeatControl.NAME) 81 | || ability.equals(FireFerret.NAME) 82 | 83 | || ability.equals(EarthBlast.NAME) 84 | || ability.equals(Collapse.NAME) 85 | || ability.equals(EarthWall.NAME) 86 | || ability.equals(EarthLariat.NAME) 87 | 88 | || ability.equals(WaterManipulation.NAME) 89 | || ability.equals(HealingWaters.NAME) 90 | || ability.equals(WaterSpout.NAME) 91 | 92 | || ability.equals(Dash.NAME) 93 | || ability.equals(DirectHit.NAME) 94 | || ability.equals(HighJump.NAME)) { 95 | return true; 96 | } 97 | return false; 98 | } 99 | } -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/earth/EarthPassive.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.earth; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | import java.util.Map; 6 | import java.util.UUID; 7 | 8 | import org.bukkit.Material; 9 | import org.bukkit.block.Block; 10 | import org.bukkit.block.BlockFace; 11 | import org.bukkit.entity.Player; 12 | 13 | import net.bendercraft.spigot.bending.abilities.ABendingAbility; 14 | import net.bendercraft.spigot.bending.abilities.AbilityManager; 15 | import net.bendercraft.spigot.bending.abilities.BendingAbility; 16 | import net.bendercraft.spigot.bending.abilities.BendingAbilityState; 17 | import net.bendercraft.spigot.bending.abilities.BendingElement; 18 | import net.bendercraft.spigot.bending.abilities.BendingPassiveAbility; 19 | import net.bendercraft.spigot.bending.abilities.RegisteredAbility; 20 | import net.bendercraft.spigot.bending.controller.ConfigurationParameter; 21 | import net.bendercraft.spigot.bending.utils.BlockTools; 22 | import net.bendercraft.spigot.bending.utils.EntityTools; 23 | import net.bendercraft.spigot.bending.utils.TempBlock; 24 | 25 | @ABendingAbility(name = EarthPassive.NAME, element = BendingElement.EARTH, passive = true) 26 | public class EarthPassive extends BendingPassiveAbility { 27 | public final static String NAME = "EarthPassive"; 28 | 29 | @ConfigurationParameter("Time-Before-Reverse") 30 | private static long DURATION = 2500; 31 | 32 | private List blocks = new LinkedList(); 33 | 34 | public EarthPassive(RegisteredAbility register, Player player) { 35 | super(register, player); 36 | } 37 | 38 | @Override 39 | public boolean start() { 40 | Block block = player.getLocation().getBlock().getRelative(BlockFace.DOWN); 41 | 42 | if (BlockTools.isEarthbendable(player, register, block) || BlockTools.isTransparentToEarthbending(player, register, block)) { 43 | 44 | if (!BlockTools.isTransparentToEarthbending(player, block)) { 45 | if (BlockTools.isSolid(block.getRelative(BlockFace.DOWN))) { 46 | if (!isPassiveSand(block)) { 47 | //blocks.add(new TempBlock(block, Material.SAND, (byte) 0x0)); 48 | blocks.add(TempBlock.makeTemporary(this, block, Material.SAND, false)); 49 | } 50 | } 51 | } 52 | 53 | for (Block affectedBlock : BlockTools.getBlocksAroundPoint(block.getLocation(), 2)) { 54 | if (BlockTools.isEarthbendable(player, affectedBlock) && !BlockTools.isIronBendable(player, affectedBlock.getType())) { 55 | if (BlockTools.isSolid(affectedBlock.getRelative(BlockFace.DOWN))) { 56 | if (!isPassiveSand(affectedBlock) && !block.getLocation().equals(affectedBlock.getLocation())) { 57 | //blocks.add(new TempBlock(affectedBlock, Material.SAND, (byte) 0x0)); 58 | blocks.add(TempBlock.makeTemporary(this, affectedBlock, Material.SAND, false)); 59 | } 60 | } 61 | } 62 | } 63 | 64 | setState(BendingAbilityState.PROGRESSING); 65 | return true; 66 | } 67 | 68 | return false; 69 | } 70 | 71 | @Override 72 | protected long getMaxMillis() { 73 | return DURATION; 74 | } 75 | 76 | @Override 77 | public void stop() { 78 | for (TempBlock state : blocks) { 79 | state.revertBlock(); 80 | } 81 | blocks.clear(); 82 | } 83 | 84 | public static boolean isPassiveSand(Block block) { 85 | Map instances = AbilityManager.getManager().getInstances(NAME); 86 | if (instances == null || instances.isEmpty()) { 87 | return false; 88 | } 89 | if(!TempBlock.isTempBlock(block)) { 90 | return false; 91 | } 92 | for (BendingAbility passive : instances.values()) { 93 | if (((EarthPassive) passive).blocks.contains(TempBlock.get(block))) { 94 | return true; 95 | } 96 | } 97 | return false; 98 | } 99 | 100 | public static void revertSand(Block block) { 101 | if(isPassiveSand(block)) { 102 | TempBlock.get(block).revertBlock(); 103 | } 104 | } 105 | 106 | @Override 107 | public boolean canBeInitialized() { 108 | if (!super.canBeInitialized()) { 109 | return false; 110 | } 111 | 112 | if (!bender.isBender(BendingElement.EARTH)) { 113 | return false; 114 | } 115 | 116 | if (!EntityTools.canBendPassive(player, BendingElement.EARTH)) { 117 | return false; 118 | } 119 | 120 | Map instances = AbilityManager.getManager().getInstances(NAME); 121 | if (instances == null) { 122 | return true; 123 | } 124 | 125 | return !instances.containsKey(player); 126 | } 127 | 128 | @Override 129 | public Object getIdentifier() { 130 | return UUID.randomUUID(); 131 | } 132 | 133 | @Override 134 | public void progress() { 135 | 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/earth/Collapse.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.earth; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.LinkedList; 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | import org.bukkit.Location; 10 | import org.bukkit.block.Block; 11 | import org.bukkit.block.BlockFace; 12 | import org.bukkit.entity.Player; 13 | 14 | import net.bendercraft.spigot.bending.abilities.ABendingAbility; 15 | import net.bendercraft.spigot.bending.abilities.BendingAbilityState; 16 | import net.bendercraft.spigot.bending.abilities.BendingActiveAbility; 17 | import net.bendercraft.spigot.bending.abilities.BendingElement; 18 | import net.bendercraft.spigot.bending.abilities.RegisteredAbility; 19 | import net.bendercraft.spigot.bending.controller.ConfigurationParameter; 20 | import net.bendercraft.spigot.bending.utils.BlockTools; 21 | import net.bendercraft.spigot.bending.utils.EntityTools; 22 | 23 | @ABendingAbility(name = Collapse.NAME, element = BendingElement.EARTH) 24 | public class Collapse extends BendingActiveAbility { 25 | public final static String NAME = "Collapse"; 26 | 27 | @ConfigurationParameter("Range") 28 | public static int RANGE = 20; 29 | 30 | @ConfigurationParameter("Radius") 31 | private static double RADIUS = 7; 32 | 33 | @ConfigurationParameter("Depth") 34 | public static int DEPTH = 6; 35 | 36 | @ConfigurationParameter("Cooldown") 37 | public static long COOLDOWN = 250; 38 | 39 | @ConfigurationParameter("Speed") 40 | public static double SPEED = 8; 41 | 42 | private Map blocks = new HashMap(); 43 | private Map baseblocks = new HashMap(); 44 | private double radius = RADIUS; 45 | 46 | private List columns = new LinkedList(); 47 | 48 | public Collapse(RegisteredAbility ability, Player player) { 49 | super(ability, player); 50 | } 51 | 52 | @Override 53 | public boolean swing() { 54 | if (getState() != BendingAbilityState.START) { 55 | return false; 56 | } 57 | this.bender.cooldown(NAME, COOLDOWN); 58 | this.columns.add(new CompactColumn(this.player)); 59 | setState(BendingAbilityState.PROGRESSING); 60 | 61 | return false; 62 | } 63 | 64 | @Override 65 | public boolean sneak() { 66 | if (getState() != BendingAbilityState.START) { 67 | return false; 68 | } 69 | 70 | Block sblock = BlockTools.getEarthSourceBlock(this.player, register, RANGE); 71 | Location location; 72 | if (sblock == null) { 73 | location = EntityTools.getTargetBlock(this.player, RANGE, BlockTools.getTransparentEarthbending()).getLocation(); 74 | } else { 75 | location = sblock.getLocation(); 76 | } 77 | for (Block block : BlockTools.getBlocksAroundPoint(location, this.radius)) { 78 | if (BlockTools.isEarthbendable(this.player, register, block) && !this.blocks.containsKey(block) && block.getY() >= location.getBlockY()) { 79 | getAffectedBlocks(block); 80 | } 81 | } 82 | 83 | if (!this.baseblocks.isEmpty()) { 84 | this.bender.cooldown(NAME, COOLDOWN); 85 | } 86 | 87 | for (Block block : this.baseblocks.keySet()) { 88 | this.columns.add(new CompactColumn(this.player, block.getLocation())); 89 | } 90 | setState(BendingAbilityState.PROGRESSING); 91 | return false; 92 | } 93 | 94 | @Override 95 | public boolean canTick() { 96 | if(!super.canTick()) { 97 | return false; 98 | } 99 | if (getState() == BendingAbilityState.PROGRESSING && this.columns.isEmpty()) { 100 | return false; 101 | } 102 | return true; 103 | } 104 | 105 | @Override 106 | public void progress() { 107 | LinkedList test = new LinkedList(this.columns); 108 | for (CompactColumn column : test) { 109 | if (!column.progress()) { 110 | this.columns.remove(column); 111 | } 112 | } 113 | } 114 | 115 | @Override 116 | public void stop() { 117 | for (CompactColumn column : this.columns) { 118 | column.remove(); 119 | } 120 | } 121 | 122 | private void getAffectedBlocks(Block block) { 123 | Block baseblock = block; 124 | int tall = 0; 125 | List bendableblocks = new ArrayList(); 126 | bendableblocks.add(block); 127 | for (int i = 1; i <= DEPTH; i++) { 128 | Block blocki = block.getRelative(BlockFace.DOWN, i); 129 | if (BlockTools.isEarthbendable(this.player, register, blocki)) { 130 | baseblock = blocki; 131 | bendableblocks.add(blocki); 132 | tall++; 133 | } else { 134 | break; 135 | } 136 | } 137 | this.baseblocks.put(baseblock, tall); 138 | for (Block blocki : bendableblocks) { 139 | this.blocks.put(blocki, baseblock); 140 | } 141 | 142 | } 143 | 144 | @Override 145 | public Object getIdentifier() { 146 | return this.player; 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/air/AirSink.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.air; 2 | 3 | import org.bukkit.Color; 4 | import org.bukkit.Location; 5 | import org.bukkit.Particle; 6 | import org.bukkit.World; 7 | import org.bukkit.entity.Entity; 8 | import org.bukkit.entity.LivingEntity; 9 | import org.bukkit.entity.Player; 10 | import org.bukkit.util.Vector; 11 | 12 | import net.bendercraft.spigot.bending.Bending; 13 | import net.bendercraft.spigot.bending.abilities.ABendingAbility; 14 | import net.bendercraft.spigot.bending.abilities.BendingAbilityState; 15 | import net.bendercraft.spigot.bending.abilities.BendingActiveAbility; 16 | import net.bendercraft.spigot.bending.abilities.BendingAffinity; 17 | import net.bendercraft.spigot.bending.abilities.RegisteredAbility; 18 | import net.bendercraft.spigot.bending.controller.ConfigurationParameter; 19 | import net.bendercraft.spigot.bending.event.BendingHitEvent; 20 | import net.bendercraft.spigot.bending.utils.EntityTools; 21 | import net.bendercraft.spigot.bending.utils.ProtectionManager; 22 | 23 | @ABendingAbility(name = AirSink.NAME, affinity = BendingAffinity.TORNADO, canBeUsedWithTools = true) 24 | public class AirSink extends BendingActiveAbility { 25 | public final static String NAME = "AirSink"; 26 | 27 | @ConfigurationParameter("Cooldown") 28 | public static long COOLDOWN = 10000; 29 | 30 | @ConfigurationParameter("Duration") 31 | public static long DURATION = 10000; 32 | 33 | @ConfigurationParameter("Radius") 34 | private static double RADIUS = 10; 35 | 36 | @ConfigurationParameter("Range") 37 | private static double RANGE = 25; 38 | 39 | @ConfigurationParameter("Push") 40 | private static double PUSH = 0.3; 41 | 42 | @ConfigurationParameter("Speed") 43 | private static double SPEED = 35; 44 | 45 | private Location origin; 46 | private long interval; 47 | private long time; 48 | 49 | private double particleDistance; 50 | 51 | private int noDisplayTick = 0; 52 | 53 | public AirSink(RegisteredAbility register, Player player) { 54 | super(register, player); 55 | this.interval = (long) (1000. / SPEED); 56 | } 57 | 58 | @Override 59 | public boolean sneak() { 60 | if(getState() == BendingAbilityState.START) { 61 | origin = EntityTools.getTargetBlock(player, RANGE).getLocation(); 62 | time = System.currentTimeMillis(); 63 | particleDistance = RADIUS; 64 | setState(BendingAbilityState.PROGRESSING); 65 | } 66 | return false; 67 | } 68 | 69 | @Override 70 | public void stop() { 71 | bender.cooldown(this, COOLDOWN); 72 | } 73 | 74 | @Override 75 | public boolean canTick() { 76 | if(!super.canTick()) { 77 | return false; 78 | } 79 | if (ProtectionManager.isLocationProtectedFromBending(player, register, origin)) { 80 | return false; 81 | } 82 | return true; 83 | } 84 | 85 | private static final Color AIRSINK_COLOR = Color.fromRGB(230, 250, 250); 86 | 87 | @Override 88 | public void progress() { 89 | if ((System.currentTimeMillis() - time) >= interval) { 90 | time = System.currentTimeMillis(); 91 | 92 | // Compute effect 93 | for (LivingEntity entity : EntityTools.getLivingEntitiesAroundPoint(origin, RADIUS)) { 94 | affect(entity); 95 | } 96 | 97 | if(noDisplayTick <= 0) { 98 | // Compute particles 99 | World world = origin.getWorld(); 100 | Particle.DustOptions display = new Particle.DustOptions(AIRSINK_COLOR, (float) (1.0f + (particleDistance / RADIUS)*3.0f)); 101 | for(double theta = 0 ; theta < 360 ; theta+=36) { 102 | for(double phi = 0 ; phi < 360 ; phi+=36) { 103 | double x = particleDistance * Math.cos(Math.toRadians(theta)) * Math.sin(Math.toRadians(phi)); 104 | double y = particleDistance * Math.sin(Math.toRadians(theta)) * Math.sin(Math.toRadians(phi)); 105 | double z = particleDistance * Math.cos(Math.toRadians(phi)); 106 | world.spawnParticle(Particle.REDSTONE, origin.clone().add(x, y, z), 1, 0.5, 0.5, 0.5, 0, display, true); 107 | } 108 | } 109 | particleDistance -= 1; 110 | if(particleDistance < 0) { 111 | particleDistance = RADIUS; 112 | } 113 | noDisplayTick = 4; 114 | } 115 | noDisplayTick--; 116 | } 117 | } 118 | 119 | @Override 120 | public Object getIdentifier() { 121 | return this.player; 122 | } 123 | 124 | @Override 125 | public long getMaxMillis() { 126 | return DURATION; 127 | } 128 | 129 | private void affect(Entity entity) { 130 | BendingHitEvent event = new BendingHitEvent(this, entity); 131 | Bending.callEvent(event); 132 | if(event.isCancelled()) { 133 | return; 134 | } 135 | if(entity == player) { 136 | return; 137 | } 138 | Vector direction = origin.clone().subtract(entity.getLocation()).toVector(); 139 | double distance = direction.length(); 140 | entity.setVelocity(entity.getVelocity().add(direction.normalize().multiply(PUSH*distance/RADIUS))); 141 | entity.setFallDistance(0); 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /src/main/java/net/bendercraft/spigot/bending/abilities/fire/FireBlade.java: -------------------------------------------------------------------------------- 1 | package net.bendercraft.spigot.bending.abilities.fire; 2 | 3 | import java.util.Arrays; 4 | import java.util.Map; 5 | 6 | import org.bukkit.Material; 7 | import org.bukkit.entity.Entity; 8 | import org.bukkit.entity.LivingEntity; 9 | import org.bukkit.entity.Player; 10 | import org.bukkit.inventory.ItemStack; 11 | import org.bukkit.inventory.meta.ItemMeta; 12 | 13 | import net.bendercraft.spigot.bending.Bending; 14 | import net.bendercraft.spigot.bending.abilities.ABendingAbility; 15 | import net.bendercraft.spigot.bending.abilities.AbilityManager; 16 | import net.bendercraft.spigot.bending.abilities.BendingAbility; 17 | import net.bendercraft.spigot.bending.abilities.BendingAbilityState; 18 | import net.bendercraft.spigot.bending.abilities.BendingActiveAbility; 19 | import net.bendercraft.spigot.bending.abilities.BendingElement; 20 | import net.bendercraft.spigot.bending.abilities.RegisteredAbility; 21 | import net.bendercraft.spigot.bending.controller.ConfigurationParameter; 22 | import net.bendercraft.spigot.bending.event.BendingHitEvent; 23 | import net.bendercraft.spigot.bending.listeners.BendingDenyItem; 24 | import net.bendercraft.spigot.bending.listeners.BendingPlayerListener; 25 | import net.bendercraft.spigot.bending.utils.DamageTools; 26 | import net.bendercraft.spigot.bending.utils.EntityTools; 27 | 28 | 29 | /** 30 | * FireBlade works by giving player a GOLDEN_SWORD, that is allowed by bending {@link BendingDenyItem}. 31 | * This sword does no damage @link {@link BendingPlayerListener} but calls {@link #affect(LivingEntity)} 32 | * 33 | */ 34 | @ABendingAbility(name = FireBlade.NAME, element = BendingElement.FIRE, shift=false) 35 | public class FireBlade extends BendingActiveAbility { 36 | public final static String NAME = "FireBlade"; 37 | 38 | private static String LORE_NAME = "FireBlade"; 39 | 40 | @ConfigurationParameter("Duration") 41 | private static int DURATION = 40000; 42 | 43 | @ConfigurationParameter("Damage") 44 | private static int DAMAGE = 5; 45 | 46 | private ItemStack blade; 47 | 48 | public FireBlade(RegisteredAbility register, Player player) { 49 | super(register, player); 50 | } 51 | 52 | @Override 53 | public boolean swing() { 54 | if(getState() == BendingAbilityState.START) { 55 | blade = new ItemStack(Material.GOLDEN_SWORD); 56 | ItemMeta meta = blade.getItemMeta(); 57 | meta.setLore(Arrays.asList(LORE_NAME)); 58 | blade.setItemMeta(meta); 59 | EntityTools.giveItemInMainHand(player, blade); 60 | 61 | setState(BendingAbilityState.PROGRESSING); 62 | } 63 | return false; 64 | } 65 | 66 | @Override 67 | public boolean canTick() { 68 | if(!super.canTick()) { 69 | return false; 70 | } 71 | if (blade == null 72 | || !isFireBlade(player.getInventory().getItemInMainHand()) 73 | || !NAME.equals(EntityTools.getBendingAbility(player))) { 74 | return false; 75 | } 76 | return true; 77 | } 78 | 79 | @Override 80 | public void progress() { 81 | 82 | } 83 | 84 | @Override 85 | public void stop() { 86 | ItemStack toRemove = null; 87 | for (ItemStack is : player.getInventory().getContents()) { 88 | if ((is != null) && isFireBlade(is)) { 89 | toRemove = is; 90 | break; 91 | } 92 | } 93 | if (toRemove != null) { 94 | player.getInventory().remove(toRemove); 95 | } 96 | } 97 | 98 | public ItemStack getBlade() { 99 | return this.blade; 100 | } 101 | 102 | public static boolean isFireBlade(ItemStack is) { 103 | if (is == null) { 104 | return false; 105 | } 106 | if ((is.getItemMeta() != null) && (is.getItemMeta().getLore() != null) && is.getItemMeta().getLore().contains(LORE_NAME)) { 107 | return true; 108 | } 109 | return false; 110 | } 111 | 112 | public static boolean isFireBlading(Player p) { 113 | Map instances = AbilityManager.getManager().getInstances(NAME); 114 | if (instances == null) { 115 | return false; 116 | } 117 | return instances.containsKey(p); 118 | } 119 | 120 | public static FireBlade getFireBlading(Player p) { 121 | Map instances = AbilityManager.getManager().getInstances(NAME); 122 | if (instances == null) { 123 | return null; 124 | } 125 | if (!instances.containsKey(p)) { 126 | return null; 127 | } 128 | return (FireBlade) instances.get(p); 129 | } 130 | 131 | public void affect(Entity entity) { 132 | BendingHitEvent event = new BendingHitEvent(this, entity); 133 | Bending.callEvent(event); 134 | if(event.isCancelled()) { 135 | return; 136 | } 137 | DamageTools.damageEntity(bender, entity, this, DAMAGE); 138 | Enflamed.enflame(player, entity, 4, this); 139 | } 140 | 141 | @Override 142 | public Object getIdentifier() { 143 | return this.player; 144 | } 145 | } 146 | --------------------------------------------------------------------------------