Cycling code twice, or looping once.

Discussion in 'Plugin Development' started by Matthewenderle, May 10, 2012.

Thread Status:
Not open for further replies.
  1. So I am adding a feature to my IceBox plugin that will allow users to harvest ice from lakes if they have the permission "icebox.harvest". I commented the permissions part out so I don't have to keep adding and removing the permission from my user, and I'm getting nowhere. When the user goes in the game and breaks the ice with or without Op it brakes and reverts the ice to stationary water and does not give an ice block (this is how I want this part). However if they use a defined tool like a wooden hoe it gives two ice blocks and makes water and I only want one block of ice and air.
    Here is the listener code. And this is all that matters to make it work.

    Code:
            public void icebox(BlockBreakEvent event)
            {
                Player player = event.getPlayer();
                //if(!checkPermission(player, "icebox.harvest"))
                //{
                    if(player.getItemInHand().getType().equals(Material.STICK) && event.getBlock().getType().equals(Material.ICE))
                        {
                            event.getPlayer().getWorld().dropItemNaturally(event.getBlock().getLocation(), new ItemStack(Material.ICE));
                            String message = plugin.getConfig().getString("no-permission");
                            player.sendMessage(ChatColor.AQUA + message);
                        }
    //                else
    //                    {
    //                        if(event.getBlock().getType() == Material.ICE)
    //                            {
    //                                event.getBlock().setType(Material.STATIONARY_WATER);
    //
    //                            }
    //                    }
     
    //            }
    //                else
    //                    {
    //                        if(event.getBlock().getType() == Material.ICE)
    //                            {
    //                                event.getBlock().setType(Material.STATIONARY_WATER);
    //
    //                            }
                        }
            }
    
    Oh I got it now! I guess telling it to set it to air after it is called would set it to air... who would have known... :p

    Code:
    if(player.getItemInHand().getType().equals(Material.STICK) && event.getBlock().getType().equals(Material.ICE))
                        {
                            event.getPlayer().getWorld().dropItemNaturally(event.getBlock().getLocation(), new ItemStack(Material.ICE));
                            String message = plugin.getConfig().getString("no-permission");
                            player.sendMessage(ChatColor.AQUA + message);
                          event.getBlock().setType(Material.AIR);
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
Thread Status:
Not open for further replies.

Share This Page