} problem with listener

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

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

    KoolzSkillz

    the problem is i am trying to do 2 @EventHandlers in 1 class
    a destrey one and a place one
    do i need 2 class's
    or how do i do it
     
  2. Offline

    Konkz

    [​IMG]

    Do you mean
    Code:java
    1. @EventHandler
    2. public void onPlace(PlayerBlockPlaceEvent event) {
    3. //code
    4. }
    5.  
    6. @EventHandler
    7. pbulic void onBreak(PlayerBlockBreakEvent event) {
    8. //code
    9. }
     
    KoolzSkillz likes this.
  3. Offline

    Adriani6

    You can have 2 EventHandlers in one class if thats what youre asking.

    I am on my phone just now so I wont post any code examples. Just remember to register your events in omEnable.
     
    KoolzSkillz likes this.
  4. Offline

    KoolzSkillz

    Yes Konkz that's what I mean but I get an error redline under the } separating them
     
  5. Offline

    Code0

    That means you screwed up at the top.

    Please post the full code. KoolzSkillz
     
    KoolzSkillz likes this.
  6. Offline

    Konkz

    You most likely close the braces off wrong, just check through it and look
    what the error says.
     
    KoolzSkillz likes this.
  7. Offline

    KoolzSkillz

    Code0 only the BlockListener or the main one as we'll?

    Konkz how I post the code

    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
    {
      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 e) {
            {
              Player player = e.getPlayer();
              if (e.getBlock().getType() == Material.ENDER_CHEST) {
                if (!player.hasPermission("EnderChest.break"))
                {
                  player.sendMessage(ChatColor.RED + "You cannot Break Enderchests!");
                  e.setCancelled(true);
                }
              }else
              {
              if (e.getBlock().getType() == Material.ENDER_STONE) {
                if (!player.hasPermission("EndStone.break")) {
                  player.sendMessage(ChatColor.RED + "You cannot Break Enderstone Only Vip+ can");
                  e.setCancelled(true);}
              }else
              {
              if (e.getBlock().getType() == Material.ENDER_PORTAL_FRAME) {
                if (!player.hasPermission("EndPortalFrame.break")) {
                  player.sendMessage(ChatColor.RED + "You cannot place an End Portal Frame");
                  e.setCancelled(true);}
              }else
              {
              if (e.getBlock().getType() == Material.NETHER_BRICK) {
                if (!player.hasPermission("NetherBrick.break")) {
                  player.sendMessage(ChatColor.RED + "You cannot break an End Stone");
                  e.setCancelled(true);}
               
           
          }
          }
          }
              }
            }
      }
    }
     
     
     
       
     
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  8. Offline

    Code0

    click the little {}# icon on your toolbar (above where you type your stuff)

    click it, paste the code in the blank area and select java
     
    KoolzSkillz likes this.
  9. Offline

    KoolzSkillz

  10. Offline

    Code0

    You don't do
    Code:java
    1. else
    2. {
    3. if
    4. }
    5.  


    You do else if(){
     
    KoolzSkillz likes this.
  11. Offline

    KoolzSkillz

    K

    Thx

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

    L33m4n123

    you are missing at least 2 closing brackets at your first EventHandler. If theres more wrong I dunno did not looked further
     
    KoolzSkillz likes this.
  13. Offline

    KoolzSkillz

    Sorry bout this it's my first plugin
     
  14. Offline

    Konkz

    Still, learning Java syntax helps and should be taught first. (Y)
     
    KoolzSkillz likes this.
  15. Offline

    KoolzSkillz

  16. KoolzSkillz He'll probably just say the same as me :p
     
  17. Offline

    KoolzSkillz

  18. Offline

    FerusGrim




    Mm. This isn't true. First of all:
    Code:java
    1. }else{
    2. if(){
    3. }

    is perfectly valid code, even necessary in some situations. You would only use
    Code:java
    1. }else if(){
    in situations where there's no other information being passed that is reliant on the if() statement.
     
Thread Status:
Not open for further replies.

Share This Page