Solved PlayerInteractEvent returning Errors

Discussion in 'Plugin Development' started by Prothean_IGS, Feb 17, 2014.

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

    Prothean_IGS

    Hey guys so my PlayerInterractEvent is returning a bunch of errors whenever a player interacts with something that is not a block, like clicking the air. I would rather these errors not be there of coarse so I was wondering how I can fix them. My guess is just to check if the event.getClickedBlock is null or not but idk if that would actually work.

    Here's my code for the event:
    Code:
    @EventHandler
        public boolean onPlayerInteract(PlayerInteractEvent event) {
            Player player = event.getPlayer();
            Block block = event.getClickedBlock();
            if (block.getState() instanceof Sign) {
                Sign sign = (Sign) block.getState();
                if (sign.getLine(0).equalsIgnoreCase("[control point]")) {
                    String Arena = sign.getLine(1);
                    int pc = plugin.cpm.GetPlayers(Arena);
                    if (plugin.cpm.TryJoinArena(player, Arena) == true) {
                        pc++;
                        sign.setLine(2, pc + "/10");
                    }
                }
            }
            else {
                return false;
            }
            return false;
        }
    If you need to see more of my code, just let me know, but since the event does what it's supposed to, just returns a few errors, I didn't think you would need to see any other code.

    Here's the error message saying that it could not be passed to the event.
    HTML:
    9:14:19 PM CONSOLE: ERROR]: Could not pass event PlayerInteractEvent to ControlPoint v0.1
    9:14:20 PM CONSOLE: Method) ~[?:1.7.0]
    9:14:20 PM CONSOLE: Source) ~[?:1.7.0]
    9:14:20 PM CONSOLE: Source) ~[?:1.7.0]
    9:14:20 PM CONSOLE: Source) ~[?:1.7.0]
    Please note this error does not happen when the player places a block or actually clicks the sign like they are supposed to.

    Nevermind I solved it, it was exactly what I thought it was :p

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

    Garris0n

    1. event.getClickedBlock() returns null if they're not actually clicking on a block.
    2. Don't use state instanceof Sign. Instead check for Material.SIGN_POST or Material.WALL_SIGN.
    3. A few of your variable and method names don't follow the proper naming conventions. Fix that.
     
Thread Status:
Not open for further replies.

Share This Page