Solved Plugin booleans maybe source of problem??

Discussion in 'Plugin Development' started by spankynutbean, Jan 27, 2013.

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

    spankynutbean

    My plugin so far:
    Code:
    public final class TownCraft extends JavaPlugin {
       
        boolean create;
        @Override
        public void onEnable() {
            create = false;
            PluginDescriptionFile pdfFile = this.getDescription();
            getLogger().info( pdfFile.getName() + " version " + pdfFile.getVersion() + "enabled!");
            }
       
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            if(cmd.getName().equalsIgnoreCase("TownCraft")){ // If the player typed /TownCraft then do the following...
                if (sender instanceof Player) { // checks if the command was by a player
                    Player player = (Player)sender;
                    player.getInventory().addItem(itemstack);
                    player.sendMessage("Place down the enderchest to create a settlement!");
                    create = true;
                    return true;
                }else{
                    sender.sendMessage("You must be a player!");
                   
            }
            return false;
           
            }
            return false;
        }
       
        public void onBlockPlace(BlockPlaceEvent event) {
            if(create = true) {
                Player player = event.getPlayer();
                player.sendMessage("Settlement Created!");
            }
        }
           
           
           
        ItemStack itemstack = new ItemStack(Material.ENDER_CHEST, 1); // Itemstack is 1 enderchest
       
       
       
       
        @Override
        public void onDisable() {
            getLogger().info("TownCraft Disabled!");
            create = false;
        }
    }
    
    This plugin has no errors, shows no errors on the server, and seems to work fine, BUT!
    When the enderchest is placed, the plugin doesn't say the message: "Settlement created!"
    Is there something wrong with the booleans??
    Please help!
     
  2. Offline

    pzxc

    You need an @EventHandler before any function that is a listener (like your onBlockPlace function)

    You also have to register your events in your onEnable function
     
  3. Offline

    spankynutbean

    Does the onCommand need an @EventHandler?
     
  4. Offline

    RealDope

  5. Offline

    danthonywalker

    Is your commands setup in the plugin.yml?
     
  6. Offline

    spankynutbean

    Yes i have danth, and how do you register your event for the onEnable? I'm quite new:confused:
     
  7. Offline

    danthonywalker

    Commands don't need an EventHandler.

    I also found your problem. You're using an assignment operator for your if statement. = is an assignment, you want an compare operator. Instead of if(create = true) do if(create == true)
     
  8. Offline

    Th3Controller

    Insert this in your onEnable
    Code:
    getServer().getPluginManager().registerEvents(new NAMEOFLISTENERCLASS(), this);


    If you want a constructor just insert "this" inside NAMEOFLISTENERCLASS(). Without the quotes :p

    Oops on your onEnable just type this
    Code:
    getServer().getPluginManager().registerEvents(this, this);
    And place "@EventHandler" on top of your event class.
     
  9. Offline

    danthonywalker

    Actually Th3Controller you should never create a new instance of the main java class when using Bukkit it'll cause errors. just use getServer().getPluginManager().registerEvents(this, this);
     
  10. Offline

    Th3Controller

    Lol I just copypasta this here. Didn't pay attention to detail.
     
  11. Offline

    spankynutbean

    it all works now guys thanks!
     
Thread Status:
Not open for further replies.

Share This Page