Solved Can't find the problem.. (Blockiterator)

Discussion in 'Plugin Development' started by GreatMinerZ, Feb 21, 2014.

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

    GreatMinerZ

    Hey,

    i need help with this plugin i'm making. This is my first time using a blockiterator and i don't understand what could be wrong. Help would be much appreciated!

    Code:

    Main class:

    Code:java
    1. public class Main extends JavaPlugin implements Listener {
    2. public static Main plugin;
    3.  
    4. public void onEnable() {
    5. this.getServer().getLogger().info("DLWand started!");
    6. PluginManager pm = this.getServer().getPluginManager();
    7.  
    8. pm.registerEvents(this, this);
    9. pm.registerEvents(new WandUse(this), this);
    10. }
    11.  
    12. public void onDisable() {
    13. this.getServer().getLogger().info("DLWand stopped!");
    14. }
    15.  
    16. public boolean onCommand(CommandSender sender, Command cmd, String commandlabel, String[] args) {
    17. Player p = (Player) sender;
    18. PlayerInventory pi = p.getInventory();
    19.  
    20. //wands
    21. String Wand = ChatColor.DARK_RED + "[" + ChatColor.GOLD + "" + ChatColor.BOLD + "Toverstaf" + ChatColor.DARK_RED + "]";
    22.  
    23. //ItemStack
    24. ItemStack iWand = new ItemStack(Material.BLAZE_ROD, 1);
    25. //ItemMeta
    26. ItemMeta WandMeta = iWand.getItemMeta();
    27. //Name
    28. WandMeta.setDisplayName(Wand);
    29. //Meta
    30. iWand.setItemMeta(WandMeta);
    31. //
    32.  
    33. if(commandlabel.equals("wand")) {
    34. p.sendMessage("Done");
    35. pi.addItem(iWand);
    36. }
    37.  
    38.  
    39. return false;
    40.  
    41. }
    42. }


    And WandUse class:

    Code:java
    1. public class WandUse extends JavaPlugin implements Listener {
    2. static Main plugin;
    3.  
    4. public WandUse(Main instance) {
    5. plugin = instance;
    6. }
    7.  
    8. @EventHandler
    9. public void onWandShot(PlayerInteractEvent e) {
    10. Player p = e.getPlayer();
    11.  
    12. //wand
    13. String Wandname = ChatColor.DARK_RED + "[" + ChatColor.GOLD + "" + ChatColor.BOLD + "Toverstaf" + ChatColor.DARK_RED + "]";
    14.  
    15.  
    16. //spell effect
    17. if(p.getItemInHand().getType().equals(Material.BLAZE_ROD)){
    18. if(p.getItemInHand().getItemMeta().getDisplayName() == null){
    19. e.setCancelled(true);
    20. }
    21.  
    22. if(p.getItemInHand().getItemMeta().getDisplayName() != null){
    23. if(p.getItemInHand().getItemMeta().getDisplayName().contains(Wandname)){
    24.  
    25. if(e.getAction() == org.bukkit.event.block.Action.LEFT_CLICK_AIR ||
    26. e.getAction() == org.bukkit.event.block.Action.LEFT_CLICK_BLOCK){
    27.  
    28. p.sendMessage("test");
    29. Location eloc = p.getEyeLocation(); //Get player's eye location
    30. BlockIterator blocksToAdd = new BlockIterator(eloc, 0D, 25); //intialize the blockiterator
    31. Location blockToAdd; //intialize a location called blockToAdd
    32.  
    33. while(blocksToAdd.hasNext()) {
    34. blockToAdd = blocksToAdd.next().getLocation(); //set blocktoadd
    35. if (blockToAdd.getBlock().getType() != Material.AIR) {
    36. break;
    37. }
    38. p.getWorld().playEffect(blockToAdd, Effect.SMOKE, 1); //play effect
    39. }
    40. }
    41. }
    42. }
    43. }
    44. }
    45. }


    Thanks!
     
  2. Offline

    xTrollxDudex

    GreatMinerZ
    What doesn't work? I would personally use the LivingEntity, int constructor.
     
  3. Offline

    GreatMinerZ

    xTrollxDudex When rightclicking the item, nothing happens unfortunately.
     
  4. Offline

    xTrollxDudex

    GreatMinerZ
    Don't make your WandUse extend JavaPlugin.

    I would think that your if statements are returnig false somewhere, debug that.
     
  5. Offline

    GreatMinerZ

    xTrollxDudex Checked everything but i can't find the problem, spawning the item works fine though.
     
  6. Offline

    xTrollxDudex

    GreatMinerZ likes this.
  7. Offline

    GreatMinerZ

Thread Status:
Not open for further replies.

Share This Page