1.7.10 Boolean problem

Discussion in 'Spigot Plugin Development' started by Wezord, Feb 17, 2020.

  1. So i'm trying to do a game where you need to find buttons and i have problem with a boolean.


    Event :
    Code (Text):
    public class BEvent implements Listener{
       
        @EventHandler
        public void onRightClick(PlayerInteractEvent e){
           
            Action act = e.getAction();
            Block bloc = e.getClickedBlock();
            Player p = e.getPlayer();
           
            game g = new game();
            boolean game = g.getState();
           
           
            if(act == Action.RIGHT_CLICK_BLOCK) {
                if(bloc.getType() == Material.WOOD_BUTTON) {
               
                    if(game == true) {
                       
                        p.sendMessage("Un bouton trouvé ! + 1 point");
                        bloc.breakNaturally();
                       
                    }
                    else {
                        p.sendMessage("Problème");
                    }
                   
                }
            }
           
        }

    }
    Command :
    Code (Text):
    public class BCommand implements CommandExecutor{
       
       
        game g = new game();
       
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
           
            Player p = (Player)sender;
           
            if(label.equalsIgnoreCase("ra")) {
                if(label.length() > 1) {
                    if(args[0].equalsIgnoreCase("bouton")) {
                        if(args[1].equalsIgnoreCase("start")) {
                           
                            boolean games = true;
                            g.setState(games);
                            p.sendMessage("Début du jeu Bouton" + games);
                           
                        }
                        else if(args[1].equalsIgnoreCase("end")) {
                           
                            boolean games = false;
                            g.setState(games);
                            p.sendMessage("Fin du jeu Bouton" + games);
                        }
                        else if(args[1].equalsIgnoreCase("state")) {
                           
                            p.sendMessage(" " + g.getState());
                        }
                       
                    }
                }
            }
            p.sendMessage(" " + g.getState());
            return g.getState();
        }

    }
    Getter/Setter :
    Code (Text):
    public class game {
       
        public boolean game;
       
        public void setState(boolean state) {
            this.game = state;
        }
       
        public boolean getState() {
            return game;
           
        }

    }
    I start the game, my boolean is true but when I click on a button, it doesn't work but the boolean is still true. And it seems that the boolean goes wrong when it is called in the event. So how can i fix this ?
     
  2. SteelPhoenix

    Moderator

    • Agree Agree x 4
  3. I don't understand how I'm supposed to fix it
     
  4. SteelPhoenix

    Moderator

    Which is why I provided that handy-dandy tutorial
     
  5. You should have a basic understanding of OOP before developing plugins
     
    • Agree Agree x 1