Help with my Kit plugin

Discussion in 'Plugin Development' started by GlacialCreeper, Jul 6, 2014.

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

    GlacialCreeper

    Hey, so I'm making a plugin for a server that's not public yet, and just so you know, here's the explanation of what I was doing (my last thread).
    Now, I got it to work the long way, storing each single location for the anvils, and they do fall, but its got some issues.

    Here's my KitDestroyer class:
    Code:java
    1. package me.camo.kits;
    2.  
    3. import java.util.Arrays;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.Location;
    7. import org.bukkit.Material;
    8. import org.bukkit.World;
    9. import org.bukkit.entity.FallingBlock;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.event.EventHandler;
    12. import org.bukkit.event.Listener;
    13. import org.bukkit.event.block.Action;
    14. import org.bukkit.event.player.PlayerInteractEvent;
    15. import org.bukkit.inventory.ItemStack;
    16. import org.bukkit.inventory.meta.ItemMeta;
    17. import org.bukkit.plugin.Plugin;
    18.  
    19. public class KitDestroyer implements Listener {
    20.  
    21. private ItemStack destroyerAnvil;
    22. private ItemMeta destroyerAnvilIM;
    23. private static Kit kitDestroyer;
    24.  
    25. public KitDestroyer(Plugin plugin, Player p){
    26.  
    27. kitDestroyer = new Kit();
    28. kitDestroyer.setTitle("Destroyer");
    29. kitDestroyer.setDescription("This kit will give you a Destroyer's anvil. When you right-click a"
    30. +" Destroyer's anvil, it will spawn a 5x5 square of anvils 3 blocks"
    31. +" above you. It causes 4 hearts of damage, and when used, it will"
    32. +" have a 10 second cooldown.");
    33.  
    34. kitDestroyer.setArmor(new ItemStack(Material.IRON_HELMET),
    35. new ItemStack(Material.IRON_CHESTPLATE),
    36. new ItemStack(Material.IRON_LEGGINGS),
    37. new ItemStack(Material.IRON_BOOTS));
    38.  
    39. destroyerAnvil = new ItemStack(Material.ANVIL, 1);
    40. destroyerAnvilIM = destroyerAnvil.getItemMeta();
    41.  
    42. destroyerAnvilIM.setDisplayName("§aDestroyer's Anvil");
    43. destroyerAnvilIM.setLore(Arrays.asList("When right clicked, a 5x5 square area ",
    44. "of anvils 3 blocks above you will spawn.", " Once this ability is used, you'll "
    45. , "have a ten second cooldown."));
    46. destroyerAnvil.setItemMeta(destroyerAnvilIM);
    47.  
    48. kitDestroyer.setItems(destroyerAnvil,
    49. new ItemStack(Material.IRON_SWORD, 1),
    50. new ItemStack(Material.BROWN_MUSHROOM, 64),
    51. new ItemStack(Material.RED_MUSHROOM, 64),
    52. new ItemStack(Material.BOWL, 64)
    53. );
    54.  
    55. kitDestroyer.applyKit(p);
    56.  
    57. KitInventory.addKit(kitDestroyer);
    58.  
    59. Bukkit.getServer().getPluginManager().registerEvents(this, plugin);
    60.  
    61. }
    62.  
    63. @SuppressWarnings("unused")
    64. @EventHandler
    65. public void onPlayerInteract(PlayerInteractEvent e)
    66. {
    67. Player player = e.getPlayer();
    68. World world = player.getWorld();
    69. String displayName = player.getItemInHand().getItemMeta().getDisplayName();
    70.  
    71. if ((e.getAction() == Action.RIGHT_CLICK_AIR) || (e.getAction() == Action.RIGHT_CLICK_BLOCK)){
    72. if ((displayName.equals("§aDestroyer's Anvil")) && (player.getItemInHand().getType() == Material.ANVIL)){
    73. double posCenter = player.getLocation().getY() + 3;
    74. double posX = player.getLocation().getX();
    75. double posZ = player.getLocation().getZ();
    76. double posXPlusOne = player.getLocation().getX() + 1;
    77. double posXPlusTwo = player.getLocation().getX() + 2;
    78. double posXMinusOne = player.getLocation().getX() - 1;
    79. double posXMinusTwo = player.getLocation().getX() - 2;
    80. double posZPlusOne = player.getLocation().getZ() + 1;
    81. double posZPlusTwo = player.getLocation().getZ() + 2;
    82. double posZMinusOne = player.getLocation().getZ() - 1;
    83. double posZMinusTwo = player.getLocation().getZ() - 2;
    84.  
    85. Location blockStoneOne = new Location(world, posXPlusOne, posCenter, posZ);
    86. Location blockStoneTwo = new Location(world, posXPlusTwo, posCenter, posZ);
    87. Location blockStoneThree = new Location(world, posX, posCenter, posZPlusOne);
    88. Location blockStoneFour = new Location(world, posX, posCenter, posZPlusTwo);
    89.  
    90. Location cbBlockYellowOne = new Location(world, posXMinusOne, posCenter, posZPlusOne);
    91. Location cbBlockYellowTwo = new Location(world, posXMinusOne, posCenter, posZMinusOne);
    92. Location cbBlockYellowThree = new Location(world, posXPlusOne, posCenter, posZMinusOne);
    93. Location cbBlockYellowFour = new Location(world, posXPlusOne, posCenter, posZPlusOne);
    94.  
    95. Location cbBlockRedOne = new Location(world, posXMinusOne, posCenter, posZPlusTwo);
    96. Location cbBlockRedTwo = new Location(world, posXMinusTwo, posCenter, posZPlusOne);
    97. Location cbBlockRedThree = new Location(world, posXMinusTwo, posCenter, posZMinusOne);
    98. Location cbBlockRedFour = new Location(world, posXMinusOne, posCenter, posZMinusTwo);
    99. Location cbBlockRedFive = new Location(world, posXPlusOne, posCenter, posZMinusTwo);
    100. Location cbBlockRedSix = new Location(world, posXPlusTwo, posCenter, posZMinusOne);
    101. Location cbBlockRedSeven = new Location(world, posXPlusTwo, posCenter, posZPlusOne);
    102. Location cbBlockRedEight = new Location(world, posXPlusOne, posCenter, posZPlusTwo);
    103.  
    104. Location cbBlockGreenOne = new Location(world, posXMinusTwo, posCenter, posZPlusTwo);
    105. Location cbBlockGreenTwo = new Location(world, posXMinusTwo, posCenter, posZMinusTwo);
    106. Location cbBlockGreenThree = new Location(world, posXPlusTwo, posCenter, posZMinusTwo);
    107. Location cbBlockGreenFour = new Location(world, posXPlusTwo, posCenter, posZPlusTwo);
    108.  
    109. System.out.println("Spawning anvils.");
    110. FallingBlock fbCenter = world.spawnFallingBlock(new Location(world, posX, posCenter, posZ), Material.ANVIL, (byte) 0);
    111. FallingBlock fb1 = world.spawnFallingBlock(blockStoneOne, Material.ANVIL, (byte) 0);
    112. FallingBlock fb2 = world.spawnFallingBlock(blockStoneTwo, Material.ANVIL, (byte) 0);
    113. FallingBlock fb3 = world.spawnFallingBlock(blockStoneThree, Material.ANVIL, (byte) 0);
    114. FallingBlock fb4 = world.spawnFallingBlock(blockStoneFour, Material.ANVIL, (byte) 0);
    115. FallingBlock fb5 = world.spawnFallingBlock(cbBlockYellowOne, Material.ANVIL, (byte) 0);
    116. FallingBlock fb6 = world.spawnFallingBlock(cbBlockYellowTwo, Material.ANVIL, (byte) 0);
    117. FallingBlock fb7 = world.spawnFallingBlock(cbBlockYellowThree, Material.ANVIL, (byte) 0);
    118. FallingBlock fb8 = world.spawnFallingBlock(cbBlockYellowFour, Material.ANVIL, (byte) 0);
    119. FallingBlock fb9 = world.spawnFallingBlock(cbBlockRedOne, Material.ANVIL, (byte) 0);
    120. FallingBlock fb10 = world.spawnFallingBlock(cbBlockRedTwo, Material.ANVIL, (byte) 0);
    121. FallingBlock fb11 = world.spawnFallingBlock(cbBlockRedThree, Material.ANVIL, (byte) 0);
    122. FallingBlock fb12 = world.spawnFallingBlock(cbBlockRedFour, Material.ANVIL, (byte) 0);
    123. FallingBlock fb13 = world.spawnFallingBlock(cbBlockRedFive, Material.ANVIL, (byte) 0);
    124. FallingBlock fb14 = world.spawnFallingBlock(cbBlockRedSix, Material.ANVIL, (byte) 0);
    125. FallingBlock fb15 = world.spawnFallingBlock(cbBlockRedSeven, Material.ANVIL, (byte) 0);
    126. FallingBlock fb16 = world.spawnFallingBlock(cbBlockRedEight, Material.ANVIL, (byte) 0);
    127. FallingBlock fb17 = world.spawnFallingBlock(cbBlockGreenOne, Material.ANVIL, (byte) 0);
    128. FallingBlock fb18 = world.spawnFallingBlock(cbBlockGreenTwo, Material.ANVIL, (byte) 0);
    129. FallingBlock fb19 = world.spawnFallingBlock(cbBlockGreenThree, Material.ANVIL, (byte) 0);
    130. FallingBlock fb20 = world.spawnFallingBlock(cbBlockGreenFour, Material.ANVIL, (byte) 0);
    131. System.out.println("Spawning finished!");
    132.  
    133. } else {
    134. return;
    135. }
    136. } else {
    137. return;
    138. }
    139.  
    140. }
    141.  
    142. }
    143.  


    Yes, I'm sorry, I know it looks hideous, but I wouldn't know how to make that huge chunk of code any smaller.
    Also here's the important code in the kit class:
    Code:java
    1. public class Kit {
    2. private ItemStack[] armor;
    3. private ArrayList<ItemStack> kitItems;
    4. .
    5. .
    6. .
    7. public void setArmor(ItemStack helmet, ItemStack chestplate, ItemStack leggings, ItemStack boots)
    8. {
    9. armor = new ItemStack[4];
    10. armor[0] = helmet;
    11. armor[1] = chestplate;
    12. armor[2] = leggings;
    13. armor[3] = boots;
    14. }
    15.  
    16. public void applyKit(Player player)
    17. {
    18. this.owner = player;
    19. for (int i = 0; i < 4; i++)
    20. {
    21. owner.getInventory().setHelmet(armor[0]);
    22. owner.getInventory().setChestplate(armor[1]);
    23. owner.getInventory().setLeggings(armor[2]);
    24. owner.getInventory().setBoots(armor[3]);
    25. }
    26. for (int i = 0; i < kitItems.size(); i++)
    27. {
    28. owner.getInventory().addItem(kitItems.get(i));
    29. }
    30. }
    31.  
    32. public void setItems(ItemStack...items)
    33. {
    34. kitItems = new ArrayList<ItemStack>();
    35. for (int i = 0; i < items.length; i++)
    36. {
    37. kitItems.add(items);
    38. }
    39.  
    40. }
    41. }


    So here's the issues:

    1) They end up looking like this.

    2) For some reason, they end up dropping way more than they should on his server; yet on mine, it drops usually 1 or 2. Looking at the JavaDocs, will a BlockDispenseEvent set cancelled cancel the drops? And how could I test if it was from the spawned anvils rather than normal ones?

    3) How would I make it so that the anvils still give damage when they hit the ground? It seems that they're falling sand entities (falling_block), and so they become a block when they hit the ground but won't cause any damage. I need it so that the players other than you are damaged by it and that the anvils die once on the ground.

    anyone?
    any help is appreciated :oops:

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page