Signs are Null blocks?

Discussion in 'Plugin Development' started by vsams14, Aug 27, 2012.

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

    vsams14

    Using the following code:
    PHP:
        public void enchant(PlayerInteractEvent event) {
            if (
    event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
                
    Block b event.getClickedBlock();
                if ((
    b.getType() == Material.WALL_SIGN) || (b.getType() == Material.ENCHANTMENT_TABLE)) {
    If I were to right click on a sign, the event would not register. Turns out that right clicking signs is now considered "Action.RIGHT_CLICK_AIR", so I changed the code accordingly. Now, I get a NullPointerException at line "if ((b.getType() == Material.WALL_SIGN) || (b.getType() == Material.ENCHANTMENT_TABLE))" when I right click a sign.

    Weirdly, if I right click the sign while holding a block, this issue happens. However, right clicking with nothing in hand or with an item in hand (like diamonds), will register as a "Action.RIGHT_CLICK_BLOCK" and will return a valid block for Block b...

    Any ideas on why this would happen? Worked just fine in 1.2.5 R5, then I switched to 1.3.1 R2, and this started happening...

    Thanks!
    vsams14

    I realize that. I'm not trying to get an instance of the sign to edit or anything. I just want to check if the block is of Material type "WALL_SIGN". Even if I remove this, and just check if it is a block such as, say, STONE, I still get a NullPointerException upon trying to access the Material type for Block b... That should not make a slightest difference in if the block is a sign, stone, or anything else...

    Source: It worked EXACTLY like this in 1.2.5


    EDIT:
    This was in reply to someone telling me that Signs were BlockStates, but they deleted their comment. -.-

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  2. Offline

    skore87

    Try event.getAction() == Action.RIGHT_CLICK_BLOCK
     
  3. Offline

    vsams14

    I had that earlier. Did the same thing. Changed it to .equals in hopes that it might fix something, but NOPE!
     
  4. Offline

    skore87

    Are you registering it? The event system is different than it was in 1.2.5.

    getServer().getPluginManager().registerEvents(Listener);

    Implement Listener into the class holding the events, or create an anonymous class.

    Add @EventHandler or @EventHandler(priority = EventPriority.YourPriority) to the line above the event method.
     
  5. Offline

    vsams14

    Really? I have "new Events(this);" in my main class, and
    Code:
    public Events(Main main) {
      main.getServer().getPluginManager().registerEvents(this, main);
      this.main = main;
    }
    as the constructor for the event class.

    The event itself has a @EventHandler above it.

    What has changed since 1.2.5? That's probably why stuff isn't working... Although, the event IS being reached...
     
  6. Offline

    skore87

    I had to ask since there is nothing wrong with that snippet of code you posted. =\
     
  7. Offline

    vsams14

    I suppose I could go without right clicking signs...
    As a note, if the block right-clicked is a enchantment table, as is required by the snipet, the code runs perfectly fine, regardless of what is being held...

    Another interesting note:
    Using Action.LEFT_CLICK_BLOCK and punching the sign returns a valid block for the sign. Also creates particle effect for the sign being broken before I cancel the event, so I'll stick to that... Still very odd that right_click_block is stupid like that...

    A completely unrelated question:
    How do I link my BukkitDev account to show up under my username like yours does?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  8. Offline

    skore87

  9. Offline

    vsams14

    Thanks!
     
  10. Offline

    desht

    Strange. My ScrollingMenuSign plugin is behaving just the same in 1.3.1 as it did in 1.2.5 - right-clicking a sign (which by default scrolls the sign's menu view) is still working, and debug log shows that the event is definitely is still a RIGHT_CLICK_BLOCK:
    Code:
    08:30:25 [FINE] [ScrollingMenuSign] player interact event @ Location{world=CraftWorld{name=world},x=-481.0,y=68.0,z=108.0,pitch=0.0,yaw=0.0}, desht did RIGHT_CLICK_BLOCK, menu=xx
    
    I'm not doing anything special here, just listening for the PlayerInteractEvent as normal.
     
  11. Offline

    skore87

  12. Hmm, I belive there's an issue with the priority or ignoreCancelled on PlayerInteractEvent, I remember the event not triggering for written books when I set it to priority MONITOR and ignoreCancelled true.
    So if you have arguments in your @EventHandler, try without them.

    EDIT:
    I've done some tests... right-clicking sign works just fine regardless of @EventHandler options or item.
    debug msg if you don't belive me (open)
    Code:
    2012-08-28 14:45:38 [INFO] PlayerInteractEvent | ignoreCancelled
    2012-08-28 14:45:38 [INFO]         isCancelled = false
    2012-08-28 14:45:38 [INFO]         isAsynchronous = false
    2012-08-28 14:45:38 [INFO]         priority = false
    2012-08-28 14:45:38 [INFO]         getAction = RIGHT_CLICK_BLOCK
    2012-08-28 14:45:38 [INFO]         getItem = null
    2012-08-28 14:45:38 [INFO]         getClickedblock = CraftBlock{chunk=CraftChunk{x=-15z=8},x=-233,y=72,z=142,type=WALL_SIGN,data=5}
    2012-08-28 14:45:38 [INFO]         getPlayer = CraftPlayer{name=Digi}


    The event is by default cancelled if player didn't do anything, so the event is set as cancelled when:
    - empty hand left-click air (doesn't trigger when right-click air with empty hand)
    - right-click with any item that doesn't do anything... even book&quill/written book because it's client side.

    So placing blocks, using items (food, bow, sword, etc) while not aiming at a block triggers the PlayerInteractEvent as cancelled... I'm unsure if this is intended.
     
  13. Offline

    vsams14

  14. Well, you've done something terribly wrong there because I downloaded your entire source, added in Events class:
    Code:
    public void enchant(PlayerInteractEvent event) {
    		System.out.print("PlayerInteractEvent | " + event.getAction()); // <<------ added
    		if (event.getAction()==Action.RIGHT_CLICK_BLOCK) { //  <<----- changed this
    			Block b = event.getClickedBlock();
    			System.out.print("PlayerInteractEvent | " + b); // <<---- added
    And the output:
    Code:
    16:30:30 [INFO] PlayerInteractEvent | RIGHT_CLICK_BLOCK
    16:30:30 [INFO] PlayerInteractEvent | CraftBlock{chunk=CraftChunk{x=-15z=9},x=-235,y=73,z=152,type=WALL_SIGN,data=5}
    So the event works just fine.
    Tested and compiled with CraftBukkit 1.3.1-R2.0
    Also, I did not compile it Bukkit jar because I don't have that updated and I got lazy xD compiled with CraftBukkit as said, but I doubt that's the issue.
     
  15. Offline

    vsams14

    I can definitely try that. You just took the public CB 1.3.1R2.0 and added it as an external jar, right?

    Nope, no change. I also found out that I am able to right click on the sides of signs (left and right faces) and have it function correctly. However, right clicking the front face still returns null.

    vsams14

    I think that maybe my bukkit is broken. I can't seem to use spawn eggs either... Maybe it's a plugin conflict,but that's doubtful. If you guys figure anything out, let me know!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  16. Offline

    desht

    What other plugins are you using right now? Have you tried with only your plugin installed?
     
  17. Offline

    vsams14

    I will when I get back home from school. I appreciate all the time you guys have spent on this!

    Turned off all mods except EC. Walk up to condenser. Right click with hand:
    Code:
    19:45:59 [INFO] PlayerInteractEvent | RIGHT_CLICK_BLOCK
    19:45:59 [INFO] PlayerInteractEvent | CraftBlock{chunk=CraftChunk{x=-2z=14},x=-19,y=119,z=230,type=WALL_SIGN,data=2}
    Switch item in hand to a Diamond Block:
    Code:
    19:46:16 [INFO] PlayerInteractEvent | RIGHT_CLICK_AIR
    Allowing the Right_Click_Air event returns the following:
    Code:
    19:52:22 [INFO] PlayerInteractEvent | RIGHT_CLICK_AIR
    19:52:22 [INFO] PlayerInteractEvent | null
    Which basically means it's not seeing the sign at all...

    I am running CB build #02340 according to the download page.
    I know that this is a silly error, but I want to know why it happens!

    Thanks for all your help!
    vsams14

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  18. Offline

    chaseoes

    Uhh..
     
  19. Offline

    vsams14

    What's the issue with that? As I said, I right clicked with my hand, aka: not holding any blocks/items, while the issue has been stated to appear only when right-clicking while holding a block...
     
  20. Yeah, the PlayerInteractEvent needs to be reviewed on the self-cancelled part, it's really confusing and annoying.

    I've tested myself with the diamond block, it only happens if you can't place the diamond block (event is cancelled), if you get out of the way and the diamond block is placed in front of the sign then it detects RIGHT_CLICK_BLOCK just fine... I know, kinda stupid.

    For now you could use ignoreCancelled=true to avoid complications.
     
  21. Offline

    vsams14

    Sorry, could you explain how to add that to the handler? I'm a noob...

    Got it, nvm. Now to test if it helps!
     
  22. You have your @EventHandler, then you add () to it, then while "aiming" between them, use Ctrl+Space to list all available settings and their accepted values... currently only priority and ignoreCancelled. You can asign them as any variable and separate them with a comma:
    Code:
    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    EDIT: It doesn't help, it only ignores when it can't detect properly... so if you click on a sign while holding a block it won't work.
     
  23. Offline

    vsams14

    I see it working if I step out of the way and allow block placement, but adding the ignoreCancelled did not do anything... Either I wrote it wrong, or it's broken...
    I'm probably going to stick with left click because that seems to be reliable, but I still want to get this to work in case I will need something similar in the future...

    WHY DID THIS WORK IN 1.2.5???!!!!
    -I'm not mad at you guys, you've been of great help!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  24. Offline

    vsams14

    Fixed it, though maybe not the most satisfactory way:
    PHP:
        @EventHandler
        
    public void enchant(PlayerInteractEvent event) {
            if (
    event.getAction()==Action.RIGHT_CLICK_BLOCK) {
                
    Block b event.getClickedBlock();
                if ((
    b.getType() == Material.WALL_SIGN) || (b.getType() == Material.ENCHANTMENT_TABLE)) {
                    
    Player p event.getPlayer();
                    
    Condenser c;
                    if ((
    main.util.getCondenser(b)) != null) {
                        
    ItemStack i p.getItemInHand();
                        if (
    main.conf.getEMC(i) > 0) {
                            
    ItemStack x = new ItemStack(i.getType(), 1i.getDurability());
                            
    c.makesign();
                            
    c.getChests();
                            
    c.out.getBlockInventory().addItem(x);
                            
    p.getInventory().removeItem(x);
                            
    p.updateInventory();
                            
    c.setTarget(i.clone());
                            
    c.updateSign();
                        }else if (
    i.getAmount() <= 0) {
                            if (
    c.pause) {
                                
    c.pause false;
                            }else{
                                
    c.pause true;
                            }
                            
    c.updateSign();
                        }
     
                        
    event.setCancelled(true);
                    }
                }
            
    //This next bit solves the issue
            
    }else if(event.getAction() == Action.RIGHT_CLICK_AIR){
                List<
    Blocklosb event.getPlayer().getLineOfSight(null10);
                for(
    Block b losb){
                    if(
    b.getType()==Material.WALL_SIGN){
                        
    Player p event.getPlayer();
                        
    Condenser c;
                        if ((
    main.util.getCondenser(b)) != null) {
                            
    ItemStack i p.getItemInHand();
                            if (
    main.conf.getEMC(i) > 0) {
                                
    ItemStack x = new ItemStack(i.getType(), 1i.getDurability());
                                
    c.makesign();
                                
    c.getChests();
                                
    c.out.getBlockInventory().addItem(x);
                                
    p.getInventory().removeItem(x);
                                
    p.updateInventory();
                                
    c.setTarget(i.clone());
                                
    c.updateSign();
                            }else if (
    i.getAmount() <= 0) {
                                if (
    c.pause) {
                                    
    c.pause false;
                                }else{
                                    
    c.pause true;
                                }
                                
    c.updateSign();
                            }
     
                            
    event.setCancelled(true);
                        }
                    }
                }
            }
        }
    Thanks goes to all who stuck through it and helped out! skore87, desht, and Digi, you guys are amazing!
    vsams14

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  25. Offline

    skore87

    You might want to break that for loop after you find that it is the block you're looking for just so that it doesn't have to loop more than necessary.
     
  26. Offline

    vsams14

    Ah, of course! Did not notice that...
     
Thread Status:
Not open for further replies.

Share This Page