Public void onBlockDestroy(BlockDestroyEvent e) { error

Discussion in 'Plugin Development' started by KoolzSkillz, Apr 23, 2014.

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

    KoolzSkillz

    Ok so my code has

    Public void onBlockDestroy(BlockDestroyEvent e) {

    That's the line that has an error
     
  2. KoolzSkillz likes this.
  3. Offline

    KoolzSkillz

  4. KoolzSkillz No it's not. Java keywords are case-sensitive. I really don't mean this offensively, but please learn before plugins, because you'll be posting here all the time otherwise.
     
    KoolzSkillz likes this.
  5. Offline

    KoolzSkillz

    It is lower case that wasn't a copy and paste

    I'll type it case sensitive for you then

    public void onBlockDestroy(BlockBreakEvent e) {


    AdamQpzm
     
  6. KoolzSkillz Well I just assumed that since you'd put a capital in (twice), it has a capital in the original thing. ;) What's the error, and please show the full code.
     
    KoolzSkillz likes this.
  7. Offline

    FerusGrim

    Agreed with above: Post the full code, please.
     
    KoolzSkillz likes this.
  8. Offline

    KoolzSkillz

    AdamQpzm FerusGrim
    Code:
    package me.REMOVENAME.youtube;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.BlockPlaceEvent;
     
    public class BlockListener
      implements Listener
    {
      public BlockListener(Youtube plugin)
      {
        plugin.getServer().getPluginManager().registerEvents(this, plugin);
      }
     
      @EventHandler
      public void onBlockPlace(BlockPlaceEvent e)
      {
        Player player = e.getPlayer();
        if (e.getBlock().getType() == Material.BEDROCK) {
          if (!player.hasPermission("Bedrock.place"))
          {
            player.sendMessage(ChatColor.RED + "You cannot place Bedrock!");
            e.setCancelled(true);
          }
        }else
          {
          if (e.getBlock().getType() == Material.TNT) {
            if (!player.hasPermission("TNT.place")) {
              player.sendMessage(ChatColor.RED + "You cannot place Tnt!");
              e.setCancelled(true);
            }
          }else if (e.getBlock().getType() == Material.ENDER_CHEST) {
            if (!player.hasPermission("EC.place")) {
              player.sendMessage(ChatColor.RED + "You cannot place an Enderchest");
              e.setCancelled(true);}
           
     
           
        @EventHandler
        public void onBlockDestroy(BlockBreakEvent e1) {
              Player player1 = e1.getPlayer();{
              if (e1.getBlock().getType() == Material.ENDER_CHEST) {
                if (!player1.hasPermission("EnderChest.break"))
                {
                  player1.sendMessage(ChatColor.RED + "You cannot Break Enderchests!");
                  e1.setCancelled(true);
                }
              }else if (e1.getBlock().getType() == Material.ENDER_STONE) {
                if (!player1.hasPermission("EndStone.break")) {
                  player1.sendMessage(ChatColor.RED + "You cannot Break Enderstone Only Vip+ can");
                  e1.setCancelled(true);}
              }else if (e1.getBlock().getType() == Material.ENDER_PORTAL_FRAME) {
                if (!player1.hasPermission("EndPortalFrame.break")) {
                  player1.sendMessage(ChatColor.RED + "You cannot place an End Portal Frame");
                  e1.setCancelled(true);}
              }else if (e1.getBlock().getType() == Material.NETHER_BRICK) {
                if (!player1.hasPermission("NetherBrick.break")) {
                  player1.sendMessage(ChatColor.RED + "You cannot break an End Stone");
                  e1.setCancelled(true);}
             
         
          }
          }
          }
              }
            }
      }
    }
     
     
     
     
    
     
  9. Offline

    FerusGrim

    First of all, you're missing a constructor. You need a value above
    Code:java
    1. public BlockListener(Youtube plugin)


    It should look something like:
    Code:java
    1. public class BlockListener implements Listener {
    2. private Youtube plugin;
    3.  
    4. public BlockListener(Youtube plugin) {
    5. this.plugin = plugin;
    6. }


    Secondly, you need to register the listener in your main class (not in the listener class), via:
    Code:java
    1. public void onEnable() {
    2. PluginManager pm = getServer().getPluginManager();
    3. pm.registerEvents(new BlockListener(this), this);
    4. }


    Make sure to double-check any of the above, as I didn't use an IDE to write it. But, it should be correct, as this is basic, fundamental Java, and should already be known before attempting to write plugins.
     
    KoolzSkillz likes this.
  10. FerusGrim Technically it could be fine doing it like that, if in the onEnable he just does something like new BlockListener(this)

    KoolzSkillz It's the same problem you were having in the other thread - the braces are closing in the wrong places.
     
    KoolzSkillz likes this.
  11. Offline

    SuppaTim

    Code:java
    1. @EventHandler
    2. public void onBlockPlace(BlockPlaceEvent e) {
    3. Player player = e.getPlayer();
    4. // Do your stuff, ex:
    5. if(e.getBlock().getType().equals(Material.TNT)) {
    6. if(!player.hasPermission("i.can.place.tnt.yay") {
    7. e.setCancelled(true);
    8. }
    9. }
    10. }
    11.  



    That should do it. Add your own stuff in it, you had your curly bracket thingies wrong. To prevent things like this start with the basics and build it up.

    Code:java
    1. @EventHandler
    2. public void onBlockPlace(BlockPlaceEvent e) {
    3. //Add all the variables
    4. //Add the first checks, and add things
    5. }
    6.  

    As said below you need to see the logic in methods and what the { } things do.
     
    KoolzSkillz likes this.
  12. Offline

    FerusGrim


    Yes. If you were proficient and could create a proper constructor, you could do this. But there's really no reason to, and this guy should stick to convention as much as possible, considering his relative skill with Java. My post was to lead him in the right direction, not get technical about what could or couldn't be done.
     
    KoolzSkillz likes this.
  13. Offline

    KoolzSkillz

    FerusGrim

    I had all that but the last one line 3
    I fixed it but I'm still getting the error
     
  14. FerusGrim While I agree it's good to get into convention, I have to say that I disagree with making statements like "missing constructor" when they have one, and telling them they have to do it one way, when a different way technically works even if it goes against convention. Better, I think, to explain that it shouldn't be done (and why not), rather than it can't be done.

    SuppaTim Please tell me you're not going to just give him the fixed version without telling him what he's doing wrong?

    KoolzSkillz You need to learn what the { and } do, and then move them to the correct places. Fixing the indentation would also be good, because it will make it clearer what's going wrong.
     
    KoolzSkillz likes this.
  15. Offline

    KoolzSkillz

    SuppaTim
    I did that and it gave me a error in the one above it

    the end bit of it

    e.setCanceleed(true):}
     
  16. Offline

    SuppaTim

    AdamQpzm Of course not. He shouldn't make the same mistake again ;)
     
    KoolzSkillz likes this.
  17. Offline

    SuppaTim

    No you didn't the same, you misplaced the { } characters. But as said in that post, check if all the { } chars are in the right place, you can do that by building it up step by step.
    Agreed with Adam: Repost new code =)
     
  18. Offline

    KoolzSkillz

    AdamQpzm
    Code:
    package me.kyle.youtube;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.BlockPlaceEvent;
     
    public class BlockListener implements Listener {
    private Youtube plugin;
     
    public BlockListener(Youtube plugin) {
    this.plugin = plugin;
     
      {
        plugin.getServer().getPluginManager().registerEvents(this, plugin); }
      }
     
      @EventHandler
      public void onBlockPlace(BlockPlaceEvent e)
      {
        Player player = e.getPlayer();
        if (e.getBlock().getType() == Material.BEDROCK) {
          if (!player.hasPermission("Bedrock.place"))
          {
            player.sendMessage(ChatColor.RED + "You cannot place Bedrock!");
            e.setCancelled(true);
          }
        }else
          {
          if (e.getBlock().getType() == Material.TNT) {
            if (!player.hasPermission("TNT.place")) {
              player.sendMessage(ChatColor.RED + "You cannot place Tnt!");
              e.setCancelled(true);
            }
          }else if (e.getBlock().getType() == Material.ENDER_CHEST) {
            if (!player.hasPermission("EC.place")) {
              player.sendMessage(ChatColor.RED + "You cannot place an Enderchest");
              e.setCancelled(true); }
           
     
           
        @EventHandler
        public void onBlockDestroy(BlockBreakEvent e1) {
              Player player1 = e1.getPlayer();
              if (e1.getBlock().getType() == Material.ENDER_CHEST) {
                if (!player1.hasPermission("EnderChest.break")) {
                  player1.sendMessage(ChatColor.RED + "You cannot Break Enderchests!");
                  e1.setCancelled(true); }
              }else if (e1.getBlock().getType() == Material.ENDER_STONE) {
                if (!player1.hasPermission("EndStone.break")) {
                  player1.sendMessage(ChatColor.RED + "You cannot Break Enderstone Only Vip+ can");
                  e1.setCancelled(true);}
              }else if (e1.getBlock().getType() == Material.ENDER_PORTAL_FRAME) {
                if (!player1.hasPermission("EndPortalFrame.break")) {
                  player1.sendMessage(ChatColor.RED + "You cannot break an End Portal Frame");
                  e1.setCancelled(true);}
              }else if (e1.getBlock().getType() == Material.NETHERRACK) {
                if (!player1.hasPermission("Netherrack.break")) {
                  player1.sendMessage(ChatColor.RED + "You cannot break an netherrack only vips can");
                  e1.setCancelled(true);}
             
         
          }
          }
          }
          }
       
      }
     
    }
     
     
    
     
  19. Offline

    KoolzSkillz

    KoolzSkillz @AdminQpzm @SuppTin
    Code:
    package me.kyle.youtube;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.BlockPlaceEvent;
     
    public class BlockListener implements Listener {
    private Youtube plugin;
     
    public BlockListener(Youtube plugin) {
    this.plugin = plugin;
     
      {
        plugin.getServer().getPluginManager().registerEvents(this, plugin); }
      }
     
    @EventHandler
    public void onBlockPlace(BlockPlaceEvent e) {
      Player player = e.getPlayer();
      if (e.getBlock().getType() == Material.BEDROCK) {
        if (!player.hasPermission("Bedrock.place")) {
          player.sendMessage(ChatColor.RED + "You cannot place Bedrock!");
          e.setCancelled(true);
      }else if (e.getBlock().getType() == Material.TNT) {
          if (!player.hasPermission("TNT.place")) {
            player.sendMessage(ChatColor.RED + "You cannot place Tnt!");
            e.setCancelled(true);
        }else if (e.getBlock().getType() == Material.ENDER_CHEST) {
          if (!player.hasPermission("EC.place")) {
            player.sendMessage(ChatColor.RED + "You cannot place an Enderchest");
            e.setCancelled(true);
          }
      }
    }
     
           
        @EventHandler
        public void onBlockDestroy(BlockBreakEvent e) {
              Player player1 = e.getPlayer();
              if (e.getBlock().getType() == Material.ENDER_CHEST) {
                if (!player1.hasPermission("EnderChest.break")) {
                  player1.sendMessage(ChatColor.RED + "You cannot Break Enderchests!");
                  e.setCancelled(true); }
              }else if (e.getBlock().getType() == Material.ENDER_STONE) {
                if (!player1.hasPermission("EndStone.break")) {
                  player1.sendMessage(ChatColor.RED + "You cannot Break Enderstone Only Vip+ can");
                  e.setCancelled(true);}
              }else if (e.getBlock().getType() == Material.ENDER_PORTAL_FRAME) {
                if (!player1.hasPermission("EndPortalFrame.break")) {
                  player1.sendMessage(ChatColor.RED + "You cannot break an End Portal Frame");
                  e.setCancelled(true);}
              }else if (e.getBlock().getType() == Material.NETHERRACK) {
                if (!player1.hasPermission("Netherrack.break")) {
                  player1.sendMessage(ChatColor.RED + "You cannot break an netherrack only vips can");
                  e.setCancelled(true);}
             
              }
        }
    }
     
     
    
     
  20. Offline

    SuppaTim

    Still wrong, first create all the material checks and then add the permission checks.
     
  21. Offline

    KoolzSkillz

    Ok

    SuppaTim I can't get them 3 } right in the middle

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

    SuppaTim

    What do you mean?
     
  23. Offline

    Konkz

    I said it in your previous question about this exact question
    [​IMG]

    You need to learn how to use braces, how Java syntax works etc. Then learn to use an API.
     
  24. Offline

    KoolzSkillz

    SuppaTim is that correct?
    Code:
    package me.kyle.youtube;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.BlockPlaceEvent;
     
    public class BlockListener implements Listener {
    private Youtube plugin;
     
    public BlockListener(Youtube plugin) {
    this.plugin = plugin;
     
      {
        plugin.getServer().getPluginManager().registerEvents(this, plugin); }
      }
     
    @EventHandler
    public void onBlockPlace(BlockPlaceEvent e) {
      Player player = e.getPlayer();
      if (e.getBlock().getType() == Material.BEDROCK) {
          player.sendMessage(ChatColor.RED + "You cannot place Bedrock!");
          e.setCancelled(true);
         
      }
    }
    }
     
           
        @EventHandler
        public void onBlockDestroy(BlockBreakEvent e) {
              Player player1 = e.getPlayer();
              if (e.getBlock().getType() == Material.ENDER_CHEST) {
                  player1.sendMessage(ChatColor.RED + "You cannot Break Enderchests!");
                  e.setCancelled(true);
                 
              }
        }
        }
     
       
     
    
     
  25. Offline

    Wizehh

    Yes, but make sure you initialize the plugin field from your main class, so as to avoid any null exceptions.
     
  26. Wizehh That's not right? :S
     
  27. Offline

    Wizehh

    What's not right?
    oh. I see. the constructor
     
Thread Status:
Not open for further replies.

Share This Page