Help this is not working as expected

Discussion in 'Plugin Development' started by iWareWolf, Aug 16, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    iWareWolf

    Code:java
    1. node.set("radius", 2);
    2. node.set("base-damage", 5);
    3. node.set("damage-per-stacks", 10);
    4. node.set("max-stack-cost", 3);

    Code:java
    1. if (player.hasMetadata("Scorch")) {
    2. int stacks = player.getMetadata("Scorch").get(0).asInt();
    3. if (stacks > this.getDefaultConfig().getInt("max-stack-cost")) {
    4. stacks = this.getDefaultConfig().getInt("max-stack-cost");
    5. }
    6. stacks = player.getMetadata("Scorch").get(0).asInt() - stacks;
    7. if (stacks != 0) {
    8. player.setMetadata("Scorch", new FixedMetadataValue(plugin, stacks));
    9. } else {
    10. player.removeMetadata("Scorch", plugin);
    11. }
    12. Arrow arrow = (Arrow) player.shootArrow();
    13. arrow.setMetadata("Eruption", new FixedMetadataValue(plugin, this.getDefaultConfig().getInt("base-damage")
    14. + (stacks * this.getDefaultConfig().getInt("damage-per-stack"))));
    15. arrow.setMetadata("Radius", new FixedMetadataValue(plugin, this.getDefaultConfig().getInt("radius")));
    16. arrow.setVelocity(player.getLocation().getDirection().multiply(3));
    17. player.sendMessage("Damage " + arrow.getMetadata("Eruption").get(0).asInt());
    18. } else {
    19. Arrow arrow = (Arrow) player.shootArrow();
    20. arrow.setMetadata("Eruption", new FixedMetadataValue(plugin, this.getDefaultConfig().getInt("base-damage")));
    21. arrow.setMetadata("Radius", new FixedMetadataValue(plugin, this.getDefaultConfig().getInt("radius")));
    22. arrow.setVelocity(player.getLocation().getDirection().multiply(3));
    23. }


    I send the player how much damage he has but it always comes out to 5 even tho I know the scorch stacks are 10
     
  2. Offline

    mine-care

    Can we have full class?
     
  3. Offline

    iWareWolf


    Code:java
    1. package com.crucifiedrealms.skills;
    2.  
    3. import com.herocraftonline.heroes.Heroes;
    4. import com.herocraftonline.heroes.api.SkillResult;
    5. import com.herocraftonline.heroes.characters.Hero;
    6. import com.herocraftonline.heroes.characters.skill.ActiveSkill;
    7. import com.herocraftonline.heroes.characters.skill.SkillType;
    8. import java.util.Random;
    9. import org.bukkit.Bukkit;
    10. import org.bukkit.Material;
    11. import org.bukkit.configuration.ConfigurationSection;
    12. import org.bukkit.entity.Arrow;
    13. import org.bukkit.entity.Entity;
    14. import org.bukkit.entity.FallingBlock;
    15. import org.bukkit.entity.LivingEntity;
    16. import org.bukkit.entity.Player;
    17. import org.bukkit.event.EventHandler;
    18. import org.bukkit.event.Listener;
    19. import org.bukkit.event.entity.EntityChangeBlockEvent;
    20. import org.bukkit.event.entity.ProjectileHitEvent;
    21. import org.bukkit.metadata.FixedMetadataValue;
    22. import org.bukkit.scheduler.BukkitRunnable;
    23. import org.bukkit.util.Vector;
    24.  
    25. public class SkillEruption
    26. extends ActiveSkill {
    27.  
    28. public SkillEruption(Heroes plugin) {
    29. super(plugin, "Eruption");
    30. setDescription("Create a small volcanic eruption dealing " + getDefaultConfig().getInt("base-damage") + " damage and an"
    31. + " additional " + getDefaultConfig().getInt("damage-per-stacks") + " damage for each scorch stack (max. 3)");
    32. setUsage("/skill eruption");
    33. setArgumentRange(0, 0);
    34. setIdentifiers(new String[]{"skill eruption"});
    35. setTypes(new SkillType[]{SkillType.BUFF, SkillType.FIRE});
    36. plugin.getServer().getPluginManager().registerEvents(new PvPListener(plugin), plugin);
    37. }
    38.  
    39. @Override
    40. public ConfigurationSection getDefaultConfig() {
    41. ConfigurationSection node = super.getDefaultConfig();
    42. node.set("radius", 2);
    43. node.set("base-damage", 5);
    44. node.set("damage-per-stacks", 10);
    45. node.set("max-stack-cost", 3);
    46. return node;
    47. }
    48.  
    49. @Override
    50. public SkillResult use(Hero hero, String[] args) {
    51. broadcastExecuteText(hero);
    52. Player player = hero.getPlayer();
    53.  
    54. if (player.hasMetadata("Scorch")) {
    55. int stacks = player.getMetadata("Scorch").get(0).asInt();
    56. if (stacks > this.getDefaultConfig().getInt("max-stack-cost")) {
    57. stacks = this.getDefaultConfig().getInt("max-stack-cost");
    58. }
    59. stacks = player.getMetadata("Scorch").get(0).asInt() - stacks;
    60. if (stacks != 0) {
    61. player.setMetadata("Scorch", new FixedMetadataValue(plugin, stacks));
    62. } else {
    63. player.removeMetadata("Scorch", plugin);
    64. }
    65. Arrow arrow = (Arrow) player.shootArrow();
    66. arrow.setMetadata("Eruption", new FixedMetadataValue(plugin, this.getDefaultConfig().getInt("base-damage")
    67. + (stacks * this.getDefaultConfig().getInt("damage-per-stack"))));
    68. arrow.setMetadata("Radius", new FixedMetadataValue(plugin, this.getDefaultConfig().getInt("radius")));
    69. arrow.setVelocity(player.getLocation().getDirection().multiply(3));
    70. player.sendMessage("Damage " + arrow.getMetadata("Eruption").get(0).asInt());
    71. } else {
    72. Arrow arrow = (Arrow) player.shootArrow();
    73. arrow.setMetadata("Eruption", new FixedMetadataValue(plugin, this.getDefaultConfig().getInt("base-damage")));
    74. arrow.setMetadata("Radius", new FixedMetadataValue(plugin, this.getDefaultConfig().getInt("radius")));
    75. arrow.setVelocity(player.getLocation().getDirection().multiply(3));
    76. }
    77.  
    78. return SkillResult.NORMAL;
    79. }
    80.  
    81. @Override
    82. public String getDescription(Hero hero) {
    83. return getDescription();
    84. }
    85. }
    86.  
    87. class PvPListener implements Listener {
    88.  
    89. Heroes plugin;
    90.  
    91. public PvPListener(Heroes plugin) {
    92. this.plugin = plugin;
    93. }
    94.  
    95. @EventHandler
    96. public void onHit(ProjectileHitEvent event) {
    97. if (event.getEntity() instanceof Arrow) {
    98. final Arrow arrow = (Arrow) event.getEntity();
    99. if (arrow.getShooter() instanceof Player) {
    100. Player player = (Player) arrow.getShooter();
    101. if (player != null) {
    102. if (arrow.hasMetadata("Eruption")) {
    103. int damage = arrow.getMetadata("Eruption").get(0).asInt();
    104. int radius = arrow.getMetadata("Radius").get(0).asInt();
    105. for (Entity ent : arrow.getWorld().getEntities()) {
    106. if (ent instanceof LivingEntity) {
    107. LivingEntity liv = (LivingEntity) ent;
    108. if (ent.getLocation().distance(arrow.getLocation()) < radius) {
    109. liv.damage(damage, player);
    110.  
    111. liv.setFireTicks(40);
    112. liv.setVelocity(liv.getVelocity().add(new Vector(0, .75, 0)));
    113. }
    114. }
    115. }
    116. FallingBlock block = arrow.getWorld().spawnFallingBlock(arrow.getLocation().add(0, .25, 0), Material.LAVA, (byte) 0);
    117. arrow.getWorld().createExplosion(arrow.getLocation(), 0, false);
    118. block.setVelocity(block.getVelocity().add(new Vector(0, .75, 0)));
    119. block.setDropItem(false);
    120. Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new BukkitRunnable() {
    121.  
    122. int i = 0;
    123.  
    124. @Override
    125. public void run() {
    126. if (i < 5) {
    127. FallingBlock lava = arrow.getWorld().spawnFallingBlock(arrow.getLocation().add(0, .25, 0), Material.LAVA, (byte) 0);
    128. lava.setVelocity(lava.getVelocity().add(new Vector(0, .5, 0)));
    129. lava.setDropItem(false);
    130. if (new Random().nextInt(3) == 1) {
    131. FallingBlock stone = arrow.getWorld().spawnFallingBlock(arrow.getLocation().add(0, .25, 0), Material.OBSIDIAN, (byte) 0);
    132. stone.setVelocity(stone.getVelocity().add(new Vector(0, .5, 0)));
    133. stone.setDropItem(false);
    134. }
    135. }
    136. if (i != 8) {
    137. arrow.getWorld().createExplosion(arrow.getLocation(), 0, false);
    138. i += 1;
    139. } else {
    140. try {
    141. this.cancel();
    142. } catch (IllegalStateException e) {
    143. }
    144. }
    145. }
    146.  
    147. }, 0, 5);
    148. arrow.remove();
    149. }
    150. }
    151. }
    152. }
    153. }
    154.  
    155. @EventHandler
    156. public void onChange(EntityChangeBlockEvent event) {
    157. if (event.getEntity() instanceof FallingBlock) {
    158. FallingBlock block = (FallingBlock) event.getEntity();
    159. if (block.getMaterial().equals(Material.LAVA) || block.getMaterial().equals(Material.OBSIDIAN)) {
    160. block.remove();
    161. event.setCancelled(true);
    162. }
    163. }
    164. }
    165. }
    166.  
     
  4. Offline

    mine-care

    Wadi if I understand right, you want to tell them their health left? Or the arrow damage they got?
     
Thread Status:
Not open for further replies.

Share This Page