Advertisement
phanaticd

Untitled

Jul 16th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.78 KB | None | 0 0
  1. package com.phanaticmc.whip;
  2.  
  3. import com.projectkorra.projectkorra.command.Commands;
  4. import org.bukkit.block.*;
  5. import org.bukkit.util.*;
  6. import com.projectkorra.projectkorra.configuration.*;
  7. import com.projectkorra.projectkorra.waterbending.util.*;
  8. import com.projectkorra.projectkorra.ability.*;
  9. import org.bukkit.*;
  10. import org.bukkit.entity.*;
  11. import com.projectkorra.projectkorra.util.*;
  12. import org.bukkit.potion.*;
  13. import com.projectkorra.projectkorra.*;
  14.  
  15. import static com.projectkorra.projectkorra.GeneralMethods.getWaterData;
  16.  
  17. public class Whip extends WaterAbility implements AddonAbility
  18. {
  19. private long cooldown;
  20. private double range;
  21. private double damage;
  22. private double speed;
  23. private TempBlock tempBlock;
  24. private Location location;
  25. private Block sourceBlock;
  26. private Block above;
  27. private Vector direction;
  28.  
  29. public Whip(final Player player) {
  30. super(player);
  31. if (bPlayer.isOnCooldown(this)) {
  32. return;
  33. }
  34. if (!player.isSneaking()) {
  35. return;
  36. }
  37. setFields();
  38. if (!WaterReturn.hasWaterBottle(player)) {
  39. sourceBlock = BlockSource.getWaterSourceBlock(player, 8.0, ClickType.SHIFT_DOWN, true, true, true, true, false);
  40. //sourceBlock = BlockSource.getWaterSourceBlock(player,5,true,true,true);
  41. } else {
  42. sourceBlock = player.getEyeLocation().clone().getBlock();
  43. WaterReturn.emptyWaterBottle(player);
  44. }
  45. if (sourceBlock == null) {
  46. return;
  47. }
  48. start();
  49. bPlayer.addCooldown(this);
  50. }
  51.  
  52. public void setFields() {
  53. cooldown = ConfigManager.getConfig().getLong("ExtraAbilities.NickC1211.Whip.Cooldown");
  54. range = ConfigManager.getConfig().getDouble("ExtraAbilities.NickC1211.Whip.Range");
  55. damage = ConfigManager.getConfig().getDouble("ExtraAbilities.NickC1211.Whip.Damage");
  56. speed = ConfigManager.getConfig().getDouble("ExtraAbilities.NickC1211.Whip.Speed");
  57. location = player.getEyeLocation();
  58. direction = player.getEyeLocation().getDirection();
  59. location.add(direction.multiply(1));
  60.  
  61. /*
  62. if (!WaterReturn.hasWaterBottle(player) && sourceBlock != BlockSource.getWaterSourceBlock(player, 8.0, ClickType.SHIFT_DOWN, true, true, true, true, true) && sourceBlock != player.getEyeLocation().clone().getBlock()) {
  63. sourceBlock = null;
  64. }
  65. if (!WaterReturn.hasWaterBottle(player) && sourceBlock != null) {
  66. location = sourceBlock.getLocation().clone();
  67. above = sourceBlock.getLocation().add(0.0, 1.0, 0.0).getBlock();
  68. }
  69. if (WaterReturn.hasWaterBottle(player) && sourceBlock != null) {
  70. location = sourceBlock.getLocation().clone();
  71. }*/
  72.  
  73.  
  74. /*if ((!WaterReturn.hasWaterBottle(player) && sourceBlock.getType() == Material.TALL_GRASS) ||
  75. sourceBlock.getType() == Material.TALL_GRASS ||
  76. sourceBlock.getType() == Material.POPPY ||
  77. sourceBlock.getType() == Material.DANDELION ||
  78. sourceBlock.getType() == Material.JUNGLE_SAPLING ||
  79. sourceBlock.getType() == Material.DARK_OAK_SAPLING ||
  80. sourceBlock.getType() == Material.BIRCH_SAPLING ||
  81. sourceBlock.getType() == Material.ACACIA_SAPLING ||
  82. sourceBlock.getType() == Material.SPRUCE_SAPLING ||
  83. sourceBlock.getType() == Material.OAK_SAPLING ||
  84. sourceBlock.getType() == Material.RED_MUSHROOM ||
  85. sourceBlock.getType() == Material.BROWN_MUSHROOM) {
  86. location = above.getLocation().clone();
  87. }
  88. if ((!WaterReturn.hasWaterBottle(player) && sourceBlock.getType() == Material.WATER) ||
  89. sourceBlock.getType() == Material.WATER ||
  90. sourceBlock.getType() == Material.ICE ||
  91. sourceBlock.getType() == Material.PACKED_ICE ||
  92. sourceBlock.getType() == Material.SNOW_BLOCK) {
  93. location = above.getLocation().clone();
  94. }*/
  95. }
  96.  
  97. public void progress() {
  98. if (!bPlayer.canBendIgnoreCooldowns(this)) {
  99. remove();
  100. return;
  101. }
  102. if (player.getLocation().distance(location) > range) {
  103. remove();
  104. return;
  105. }
  106. if (!player.isSneaking()) {
  107. remove();
  108. return;
  109. }
  110.  
  111. direction = player.getEyeLocation().getDirection();
  112. location.add(direction.multiply(speed));
  113. if (!getTransparentMaterialSet().contains(location.getBlock().getType()) && location.getBlock().getType() != Material.WATER){
  114. remove();
  115. return;
  116. }
  117. tempBlock = new TempBlock(location.getBlock(), Material.WATER, getWaterData(2));
  118. ParticleEffect.WATER_DROP.display(location, 5, 0.5f, 0.5f, 0.5f, 0.0f);
  119. playWaterbendingSound(location);
  120. tempBlock.setRevertTime(800L);
  121. /*if (WaterReturn.hasWaterBottle(player)) {
  122. tempBlock = new TempBlock(currentLoc.getBlock(), Material.WATER, getWaterData(2));
  123. ParticleEffect.WATER_DROP.display(location, 5, 0.5f, 0.5f, 0.5f, 0.0f);
  124. playWaterbendingSound(location);
  125. tempBlock.setRevertTime(1200L);
  126. }
  127. if (!WaterReturn.hasWaterBottle(player) && WaterReturn.isWater(sourceBlock)) {
  128. tempBlock = new TempBlock(currentLoc.getBlock(), Material.WATER, getWaterData(8));
  129. ParticleEffect.WATER_DROP.display(location, 5,0.5f, 0.5f, 0.5f, 0.0f);
  130. playWaterbendingSound(location);
  131. tempBlock.setRevertTime(1200L);
  132. }
  133. if (!WaterReturn.hasWaterBottle(player) && WaterReturn.isSnow(sourceBlock)) {
  134. tempBlock = new TempBlock(currentLoc.getBlock(), Material.SNOW_BLOCK);
  135. location.getWorld().playSound(location, Sound.BLOCK_SNOW_BREAK, 1.0f, 1.0f);
  136. tempBlock.setRevertTime(1200L);
  137. }
  138. if (!WaterReturn.hasWaterBottle(player) && bPlayer.canUseSubElement(Element.SubElement.PLANT) && WaterReturn.isLeaves(sourceBlock)) {
  139. tempBlock = new TempBlock(currentLoc.getBlock(), Material.OAK_LEAVES);
  140. location.getWorld().playSound(location, Sound.BLOCK_GRASS_BREAK, 1.0f, 1.0f);
  141. tempBlock.setRevertTime(1200L);
  142. }
  143. if (!WaterReturn.hasWaterBottle(player) && bPlayer.canUseSubElement(Element.SubElement.PLANT) && sourceBlock.getType() == Material.CACTUS) {
  144. tempBlock = new TempBlock(currentLoc.getBlock(), Material.OAK_LEAVES);
  145. location.getWorld().playSound(location, Sound.BLOCK_GRASS_BREAK, 1.0f, 1.0f);
  146. tempBlock.setRevertTime(1200L);
  147. }
  148. if ((!WaterReturn.hasWaterBottle(player) && bPlayer.canUseSubElement(Element.SubElement.PLANT)) && sourceBlock.getType() == Material.TALL_GRASS) {
  149. tempBlock = new TempBlock(currentLoc.getBlock(), Material.TALL_GRASS);
  150. location.getWorld().playSound(location, Sound.BLOCK_GRASS_BREAK, 1.0f, 1.0f);
  151. tempBlock.setRevertTime(1200L);
  152. }
  153. if ((!WaterReturn.hasWaterBottle(player) && bPlayer.canUseSubElement(Element.SubElement.PLANT)) && (sourceBlock.getType() == Material.POPPY || sourceBlock.getType() == Material.DANDELION)) {
  154. tempBlock = new TempBlock(currentLoc.getBlock(), Material.WATER, getWaterData(2));
  155. ParticleEffect.WATER_DROP.display(location, 5, 0.5f, 0.5f, 0.5f, 0.0f);
  156. playWaterbendingSound(location);
  157. tempBlock.setRevertTime(1200L);
  158. }
  159. if ((!WaterReturn.hasWaterBottle(player) && bPlayer.canUseSubElement(Element.SubElement.PLANT)) && (sourceBlock.getType() == Material.RED_MUSHROOM || sourceBlock.getType() == Material.BROWN_MUSHROOM)) {
  160. tempBlock = new TempBlock(currentLoc.getBlock(), Material.WATER, getWaterData(2));
  161. ParticleEffect.WATER_DROP.display(location, 5, 0.5f, 0.5f, 0.5f, 0.0f);
  162. playWaterbendingSound(location);
  163. tempBlock.setRevertTime(1200L);
  164. }
  165. if ((!WaterReturn.hasWaterBottle(player) && bPlayer.canUseSubElement(Element.SubElement.PLANT)) && (sourceBlock.getType() == Material.PUMPKIN || sourceBlock.getType() == Material.MELON)) {
  166. tempBlock = new TempBlock(currentLoc.getBlock(), Material.WATER, getWaterData(8));
  167. ParticleEffect.WATER_DROP.display(location, 5,0.5f, 0.5f, 0.5f, 0.0f);
  168. playWaterbendingSound(location);
  169. tempBlock.setRevertTime(1200L);
  170. }
  171. if ((!WaterReturn.hasWaterBottle(player) && bPlayer.canUseSubElement(Element.SubElement.PLANT)) && (sourceBlock.getType() == Material.OAK_SAPLING || sourceBlock.getType() == Material.SPRUCE_SAPLING || sourceBlock.getType() == Material.ACACIA_SAPLING || sourceBlock.getType() == Material.BIRCH_SAPLING || sourceBlock.getType() == Material.DARK_OAK_SAPLING || sourceBlock.getType() == Material.JUNGLE_SAPLING) || sourceBlock.getType() == Material.PUMPKIN_STEM || sourceBlock.getType() == Material.MELON_STEM) {
  172. tempBlock = new TempBlock(currentLoc.getBlock(), Material.WATER, getWaterData(2));
  173. ParticleEffect.WATER_DROP.display(location, 5, 0.5f, 0.5f, 0.5f, 0.0f);
  174. playWaterbendingSound(location);
  175. tempBlock.setRevertTime(1200L);
  176. }
  177. if ((!WaterReturn.hasWaterBottle(player) && bPlayer.canUseSubElement(Element.SubElement.PLANT)) && (sourceBlock.getType() == Material.VINE || sourceBlock.getType() == Material.LILY_PAD || sourceBlock.getType() == Material.WHEAT || sourceBlock.getType() == Material.POTATOES || sourceBlock.getType() == Material.CARROTS || sourceBlock.getType() == Material.BEETROOTS)) {
  178. tempBlock = new TempBlock(currentLoc.getBlock(), Material.WATER, getWaterData(2));
  179. ParticleEffect.WATER_DROP.display(location, 5, 0.5f, 0.5f, 0.5f, 0.0f);
  180. playWaterbendingSound(location);
  181. tempBlock.setRevertTime(1200L);
  182. }
  183. if (!WaterReturn.hasWaterBottle(player) && bPlayer.canUseSubElement(Element.SubElement.PLANT) && sourceBlock.getType() == Material.SUGAR_CANE) {
  184. tempBlock = new TempBlock(currentLoc.getBlock(), Material.SUGAR_CANE);
  185. location.getWorld().playSound(location, Sound.BLOCK_GRASS_BREAK, 1.0f, 1.0f);
  186. tempBlock.setRevertTime(1200L);
  187. }
  188. if ((!WaterReturn.hasWaterBottle(player) && bPlayer.canUseSubElement(Element.SubElement.PLANT)) && (sourceBlock.getType() == Material.MUSHROOM_STEM || sourceBlock.getType() == Material.BROWN_MUSHROOM_BLOCK || sourceBlock.getType() == Material.RED_MUSHROOM_BLOCK)) {
  189. tempBlock = new TempBlock(currentLoc.getBlock(), Material.WATER, getWaterData(8));
  190. ParticleEffect.WATER_DROP.display(location, 5, 0.5f, 0.5f, 0.5f, 0.0f);
  191. playWaterbendingSound(location);
  192. tempBlock.setRevertTime(1200L);
  193. }
  194. if (!WaterReturn.hasWaterBottle(player) && (sourceBlock.getType() == Material.ACACIA_LOG || sourceBlock.getType() == Material.BIRCH_LOG || sourceBlock.getType() == Material.DARK_OAK_LOG || sourceBlock.getType() == Material.JUNGLE_LOG || sourceBlock.getType() == Material.OAK_LOG || sourceBlock.getType() == Material.SPRUCE_LOG)) {
  195. tempBlock = new TempBlock(currentLoc.getBlock(), Material.WATER, getWaterData(8));
  196. ParticleEffect.WATER_DROP.display(location, 5,0.5f, 0.5f, 0.5f, 0.0f);
  197. playWaterbendingSound(location);
  198. tempBlock.setRevertTime(1200L);
  199. }
  200. if (!WaterReturn.hasWaterBottle(player) && bPlayer.canUseSubElement(Element.SubElement.ICE) && sourceBlock.getType() == Material.ICE) {
  201. tempBlock = new TempBlock(currentLoc.getBlock(), Material.ICE);
  202. playIcebendingSound(location);
  203. tempBlock.setRevertTime(1200L);
  204. }
  205. if (!WaterReturn.hasWaterBottle(player) && bPlayer.canUseSubElement(Element.SubElement.ICE) && sourceBlock.getType() == Material.PACKED_ICE) {
  206. tempBlock = new TempBlock(currentLoc.getBlock(), Material.PACKED_ICE);
  207. playIcebendingSound(location);
  208. tempBlock.setRevertTime(1200L);
  209. }
  210. if (!WaterReturn.hasWaterBottle(player) && WaterReturn.isNight(player.getWorld())) {
  211. damage = 5.0;
  212. range = 22.0;
  213. }
  214. if (!WaterReturn.hasWaterBottle(player) && WaterReturn.isFullMoon(player.getWorld())) {
  215. damage = 6.0;
  216. range = 24.0;
  217. }
  218. */
  219.  
  220. for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(location, 1.0)) {
  221. if (entity instanceof LivingEntity && entity.getEntityId() != player.getEntityId()) {
  222. if (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation()) || ((entity instanceof Player) && Commands.invincible.contains(((Player) entity).getName()))){
  223. continue;
  224. }
  225. final Location location = player.getEyeLocation();
  226. final Vector vector = location.getDirection();
  227. entity.setVelocity(vector.normalize().multiply(0.8f));
  228.  
  229. DamageHandler.damageEntity(entity, damage, this);
  230.  
  231. if (!WaterReturn.hasWaterBottle(player) && WaterReturn.isIce(sourceBlock)) {
  232. ((LivingEntity)entity).addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 60, 3));
  233. }
  234. if (!WaterReturn.hasWaterBottle(player) && WaterReturn.isPlant(sourceBlock)) {
  235. ((LivingEntity)entity).addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 60, 3));
  236. }
  237. if (WaterReturn.hasWaterBottle(player) || !WaterReturn.isSnow(sourceBlock)) {
  238. continue;
  239. }
  240. ((LivingEntity)entity).addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60, 3));
  241.  
  242. remove();
  243. return;
  244. }
  245. }
  246. }
  247.  
  248. public long getCooldown() {
  249. return cooldown;
  250. }
  251.  
  252. public Location getLocation() {
  253. return location;
  254. }
  255.  
  256. public String getName() {
  257. return "Whip";
  258. }
  259.  
  260. public String getDescription() {
  261. return "Send a whip of water, plant, ice, or snow at your opponent.";
  262. }
  263.  
  264. public String getInstructions() {
  265. return "Hold Shift and Left Click to shoot.";
  266. }
  267.  
  268. public boolean isHarmlessAbility() {
  269. return false;
  270. }
  271. public void remove(){
  272. new WaterReturn(player, location.getBlock());
  273. super.remove();
  274. }
  275.  
  276. public boolean isSneakAbility() {
  277. return ConfigManager.getConfig().getBoolean("ExtraAbilities.NickC1211.Whip.Swim.Disabled");
  278. }
  279.  
  280. public String getAuthor() {
  281. return "NickC1211";
  282. }
  283.  
  284. public String getVersion() {
  285. return "v5.0";
  286. }
  287.  
  288. public void load() {
  289. ProjectKorra.plugin.getServer().getPluginManager().registerEvents(new WhipListener(), ProjectKorra.plugin);
  290. ProjectKorra.log.info(getName() + " " + getVersion() + " by " + getAuthor() + " loaded!");
  291. ConfigManager.getConfig().addDefault("ExtraAbilities.NickC1211.Whip.Cooldown", 2000);
  292. ConfigManager.getConfig().addDefault("ExtraAbilities.NickC1211.Whip.Range", 20);
  293. ConfigManager.getConfig().addDefault("ExtraAbilities.NickC1211.Whip.Damage", 4);
  294. ConfigManager.getConfig().addDefault("ExtraAbilities.NickC1211.Whip.Speed", 1);
  295. ConfigManager.getConfig().addDefault("ExtraAbilities.NickC1211.Whip.Swim.Disabled", true);
  296. ConfigManager.defaultConfig.save();
  297.  
  298. ProjectKorra.getCollisionInitializer().addSmallAbility(this);
  299. }
  300.  
  301. public void stop() {
  302. ProjectKorra.log.info(getName() + " " + getVersion() + " by " + getAuthor() + " disabled!");
  303. }
  304. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement