Buffing Chain Armour

Discussion in 'Plugin Development' started by Slash9211, Apr 6, 2014.

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

    Slash9211

    I'm new to coding and to some this might seem like a stupid problem to try to sovle but it keeps saying I'm missing a class or an invert at the end... What should I put then?
    Code:java
    1. private final List<Material> chainSet = Lists.newArrayList(
    2. Material.CHAINMAIL_HELMET, Material.CHAINMAIL_CHESTPLATE,
    3. Material.CHAINMAIL_LEGGINGS, Material.CHAINMAIL_BOOTS
    4. );
    5.  
    6. @EventHandler
    7. public void onEntityDamage(EntityDamageEvent event) {
    8. Entity entity = event.getEntity();
    9.  
    10. if (entity instanceof Player) {
    11. PlayerInventory inventory = ((Player) entity).getInventory();
    12. double modifier = 1;
    13.  
    14. // Damage reduction is 1 - 0.57 ^ (number of equipped pieces)
    15. for (ItemStack armorPiece : inventory.getArmorContents()) {
    16. if (armorPiece != null && chainSet.contains(armorPiece.getType())) {
    17. modifier *= 0.57D;
    18. armorPiece.setDurability((short) 0);
    19. }
    20. }
    21.  
    22. if (modifier < 1) {
    23. int original = event.getDamage();
    24. event.setDamage((int) Math.round(event.getDamage() * modifier));
    25.  
    26. System.out.println("Damage reduced from " + original + " to " + event.getDamage());
    27. }
    28. }
    29. }
    30. }
    31. }
     
  2. Offline

    Slash9211

    Help would be appreciated...

    Anyone?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  3. Offline

    coasterman10

    You have extra brackets at the end.
     
  4. Offline

    Plo124

    The } on line 30 should go away.
     
  5. Offline

    Slash9211

    That helped and then it revealed three more errors I solved two of them and now I'm stuck on the final one... on line 23 it says there needs to be something in the () for event.getDamage()... What should I put there?
     
  6. Offline

    JD_Guy17

    Slash9211 This might work:
    Code:java
    1. event.getDamage().getAmount();
     
  7. Offline

    Slash9211

    JD_Guy17

    I tried that and got this as an errer "Error:(53, 49) java: double cannot be dereferenced"
     
  8. Offline

    JBoss925

    Your modifier isn't a double. Try 1.0 as your modifier.
     
  9. Offline

    Slash9211

    JBoss925 still doesn't work...

    Anymore ideas on how to fix it?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  10. Offline

    JBoss925

    What is armor piece?
     
  11. Offline

    JD_Guy17

    Slash9211 Change:
    Code:java
    1. int original = event.getDamage().getAmount();
    2. //to
    3. double original = event.getDamage().getAmount();
    4. //or
    5. int original = (int) event.getDamage().getAmount();


    A double is a number like 1.0 (so it isn't always a whole number). int has to always be a whole number
     
  12. Offline

    Slash9211

    I tried both JD_Guy17 and its still putting a red underline under what I underlined in the quotation marks "event.getDamage() ; ) and its saying this http://imgur.com/XPGCB52
    What should I do this is whats been throwing me off lately...

    JBoss925 it's the armor the player is wearing...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  13. Offline

    JBoss925

    Let me see your method for it. Perhaps it's incorrect? Idk thinking of fixes.
     
  14. Offline

    Slash9211

    JBoss925 I'll just post all of my code...
    Code:java
    1. package com.Slash9211.GuardArmour.com;
    2.  
    3.  
    4. import com.google.common.collect.Lists;
    5. import org.bukkit.Material;
    6. import org.bukkit.entity.Entity;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.entity.EntityDamageEvent;
    10. import org.bukkit.inventory.ItemStack;
    11. import org.bukkit.inventory.PlayerInventory;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13. import java.util.List;
    14.  
    15. /**
    16. * Created by Slash9211 on 4/6/2014.
    17. */
    18. public class GuardArmour extends JavaPlugin {
    19.  
    20. @Override
    21. public void onEnable() {
    22. getLogger().info("Plugin Enabled And Is Working");
    23. }
    24.  
    25. @Override
    26. public void onDisable() {
    27. getLogger().info("Plugin Disabled And Is Not Longer Working");
    28. }
    29.  
    30. private final List<Material> chainSet = Lists.newArrayList(
    31. Material.CHAINMAIL_HELMET, Material.CHAINMAIL_CHESTPLATE,
    32. Material.CHAINMAIL_LEGGINGS, Material.CHAINMAIL_BOOTS
    33. );
    34.  
    35. @EventHandler
    36. public void onEntityDamage(EntityDamageEvent event) {
    37. Entity entity = event.getEntity();
    38.  
    39. if (entity instanceof Player) {
    40. PlayerInventory inventory = ((Player) entity).getInventory();
    41. double modifier = 1;
    42.  
    43. // Damage reduction is 1 - 0.57 ^ (number of equipped pieces)
    44. for (ItemStack armorPiece : inventory.getArmorContents()) {
    45. if (armorPiece != null && chainSet.contains(armorPiece.getType())) {
    46. modifier *= 0.57D;
    47. armorPiece.setDurability((short) 0);
    48. }
    49. }
    50.  
    51. if (modifier < 1) {
    52. int original = (int) event.getDamage().getAmount();
    53. event.setDamage((int) Math.round(original * modifier));
    54.  
    55.  
    56. }
    57. }
    58. }
    59. }
    That's all I have and http://imgur.com/XPGCB52 is the problem at the end where it says event.getDamage() the () is underlined red...
     
Thread Status:
Not open for further replies.

Share This Page