Event help

Discussion in 'Plugin Development' started by frogman6102, Dec 29, 2014.

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

    frogman6102

    Hello!
    I am creating a mini game plugin for a server and I need help, despretly.

    This is my code:
    Code:
    @EventHandler
        public void clickSign(PlayerInteractEvent e){
            Player p = e.getPlayer();
          
        //working ^^
          
            if(e.getAction() == Action.RIGHT_CLICK_BLOCK){
              
              
                if(e.getClickedBlock().getType() == Material.SIGN_POST){
                  
                    if(Game.isFull()){
                        p.sendMessage(ChatColor.RED + "[Pirate Ship Battle] " + ChatColor.RED + "Game is currently full.");
                    }else{
                        p.sendMessage(ChatColor.RED + "[Pirate Ship Battle] " + ChatColor.GREEN + "Game is open, adding you too game!");
                    Game.plist.add(p);
                  
                    if(Game.plist.size() >= 2){
                        Game.startGame();
                    }
                    }
                  
                  
                  
                }
            }
        }
        //not working
        @EventHandler
        public void diamond(BlockBreakEvent e){
          
            if(e.getBlock().getType() == Material.DIAMOND_BLOCK){
              
                Game.endGame();
            }
        }
        
    No errors in console. :(
     
  2. Offline

    97WaterPolo

    @frogman6102
    To start you need to explain a bit more on what is suppose to happen. I would guess your Game.endGame() method doesn't outprint or do whatever you expect it to do. That is the correct code to check if the block broken was a diamond block. Mind putting your endGame() method?
     
  3. Offline

    frogman6102

    Oh yes, sorry about that.
    Code:
    public static void endGame(){
           
            plist.get(0).sendMessage(ChatColor.RED + "[Pirate Ship Battle] Game Over...");
    
            plist.get(1).sendMessage(ChatColor.RED + "[Pirate Ship Battle] Game Over...");
       
       
            plist.get(0).getServer().dispatchCommand(plist.get(0), "spawn");
            plist.get(1).getServer().dispatchCommand(plist.get(1), "spawn");
           
            plist.remove(0);
            plist.remove(1);
           
    
           
           
        }
    @97WaterPolo ^^
     
    Last edited by a moderator: Dec 29, 2014
  4. Offline

    WarmakerT

    If there are always only two players, you can use that.
    However, if there can be more/less, use this:
    Code:
    public static void endGame() {
       for(Player p : plist) {
           p.sendMessage(ChatColor.RED + "[Pirate Ship Battle] Game Over...");
           p.getServer().dispatchCommand(p, "spawn");
          plist.remove(p);
       }
    }
     
  5. Offline

    frogman6102

  6. Offline

    SuchSwegMuchWow

    @frogman6102 Just to clarify, breaking block does not work or something else?
     
    WarmakerT likes this.
  7. Offline

    trenton_jeffro

    Have you registered your events in the onEnable()?
     
Thread Status:
Not open for further replies.

Share This Page