Why is this code executing?

Discussion in 'Plugin Development' started by Creeper_668/xXGlitchedXx, Jul 23, 2015.

Thread Status:
Not open for further replies.
  1. I'm making a bukkit plugin called 'Jetpacks'. It is basically /fly, but a bit better. For some reason, this code is executing when the player isn't flying:

    Code:
    if (!thisPlayer.getInventory().contains(coal));
                    {
                    if (thisPlayer.isFlying());
                        {
                        thisPlayer.sendMessage(ChatColor.RED + "You've run out of fuel!");
                        thisPlayer.setAllowFlight(false);
                        }
                    }
    Here is the whole plugin just for more info:
    Code:
    package jetpacks;
    
    import java.util.Timer;
    import java.util.TimerTask;
    import java.util.logging.Logger;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.Server;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Jetpacks extends JavaPlugin
        {
        public static final Logger logger = Logger.getLogger("Minecraft");
        private Player CurrentPlayer;
       
       
       
        @Override
        public void onDisable()
            {
            PluginDescriptionFile thepdfFile = this.getDescription();
            //this.logger.info("Nothingness v1.0b has been ENABLED!");
           
            //this.logger.info(this.logger.info(thepdfFile.getName() + " has been DISABLED"));
            this.logger.info(thepdfFile.getName() + " has been DISABLED");
    
           
            }
    
        @Override
        public void onEnable()
            {
            PluginDescriptionFile thepdfFile = this.getDescription();
            //this.logger.info("Nothingness v1.0b has been ENABLED!");
           
            //this.logger.info(this.logger.info(thepdfFile.getName() + " has been DISABLED"));
            this.logger.info(thepdfFile.getName() + " Version " + thepdfFile.getVersion() + " has been ENABLED");
    
            }
       
       
       
        @Override
        public boolean onCommand(CommandSender theSender, Command cmd, String commandLabel, String args[]    )
            {
           
           
            Player thisPlayer = (Player) theSender;
           
           
            if (commandLabel.equalsIgnoreCase("jetpacks"))
                {
                    thisPlayer.sendMessage(ChatColor.GREEN + "Jetpacks Help:");
                    thisPlayer.sendMessage(ChatColor.BLUE + "Enable Jetpacks:"  + ChatColor.LIGHT_PURPLE + " /jpenable");
                    thisPlayer.sendMessage(ChatColor.BLUE + "Disable Jetpacks:" + ChatColor.LIGHT_PURPLE + " /jpdisable");
                    thisPlayer.sendMessage(ChatColor.BLUE + "How to use Jetpacks:" + ChatColor.LIGHT_PURPLE + " /jphowto");
                    thisPlayer.sendMessage(ChatColor.LIGHT_PURPLE + "Author: Creeper_668");
                   
                }
            if (commandLabel.equalsIgnoreCase("jp"))
                {
                    thisPlayer.sendMessage(ChatColor.GREEN + "Jetpacks Help:");
                    thisPlayer.sendMessage(ChatColor.BLUE + "Enable Jetpacks:"  + ChatColor.LIGHT_PURPLE + " /jpenable");
                    thisPlayer.sendMessage(ChatColor.BLUE + "Disable Jetpacks:" + ChatColor.LIGHT_PURPLE + " /jpdisable");
                    thisPlayer.sendMessage(ChatColor.BLUE + "How to use Jetpacks:" + ChatColor.LIGHT_PURPLE + " /jphowto");
                    thisPlayer.sendMessage(ChatColor.LIGHT_PURPLE + "Author: Creeper_668");
                    //*/
               
                }
               
            if (commandLabel.equalsIgnoreCase("jpenable"))
                {
                thisPlayer.sendMessage(ChatColor.GREEN + "Your Jetpack has been enabled!");
                thisPlayer.setAllowFlight(true);
               
                /*
               
                ItemStack[] availableItemsInTheInventory;
               
                availableItemsInTheInventory = thisPlayer.getInventory().getContents();
               
               
               
                for (int n = 0; n < availableItemsInTheInventory.length; n++)
                    {
                    ItemStack thisItem;
                   
                    thisItem = availableItemsInTheInventory[n];
                   
                    if (thisItem != null)
                        {
                        //thisPlayer.sendMessage(availableItemsInTheInventory[n].toString());
                        String itemText;
                       
                        itemText = thisItem.toString();
                       
                        if (itemText.toLowerCase().contains("coal"))
                            {
                            thisPlayer.sendMessage(thisItem.toString());
                            thisPlayer.sendMessage("details...");
                            thisPlayer.sendMessage(".......");
                            thisItem.getData().toString();
                            }
    
                       
                        }
                    }
                */
               
                ItemStack coal = new ItemStack(Material.COAL);
               
                if (thisPlayer.getInventory().contains(coal));
                    {
                    if (!thisPlayer.getAllowFlight());
                        {
                        thisPlayer.setAllowFlight(true);
                        }
                    }
               
                if (!thisPlayer.getInventory().contains(coal));
                    {
                    if (thisPlayer.isFlying());
                        {
                        thisPlayer.sendMessage(ChatColor.RED + "You've run out of fuel!");
                        thisPlayer.setAllowFlight(false);
                        }
                    }
               
               
                while(thisPlayer.getAllowFlight())
                    {
                    Timer aTimer = new Timer();
                   
                    aTimer.schedule(new TimerTask()
                        {
               
                        @Override
                        public void run()
                            {
                            //thisPlayer.getInventory().remove(coal);
    
                            }
                        }, 2000);
                    }
    
                }
               
               
            if (commandLabel.equalsIgnoreCase("jpdisable"))
                    {
                    thisPlayer.sendMessage(ChatColor.GREEN + "Your Jetpack has been disabled.");
                    thisPlayer.setAllowFlight(false);
                    }
            if (commandLabel.equalsIgnoreCase("jphowto"))
                {
                thisPlayer.sendMessage(ChatColor.GREEN + "What are Jetpacks?");
                thisPlayer.sendMessage(ChatColor.BLUE + "This plugin is simple. All it does is gives you fly mode, but in a special way. You will see clouds of smoke underneath you, and your jetpack will stop when you run out of fuel. To start your jetpack, do /jpenable. If you want to stop flying, do /jpdisable. For more help, do /jp or /jetpacks.");
                thisPlayer.sendMessage(ChatColor.LIGHT_PURPLE + "Author: Creeper_668");
    
                Server sv = thisPlayer.getServer();
    
                }
            return true;
               
            }
        }
     
  2. Offline

    DoggyCode™

    @Creeper_668/xXGlitchedXx I'd add the player to a ArrayList, then rather check if the ArrayList contains the player's name than checking of they're flying or not. Because let's say if the player is in gamemode, it still counts as the player is flying, so that would be a bit messed up. Then when you disable the jetpack or the fuil runs out you remove them from the ArrayList.
     
  3. Ok, I might try that, but that wouldn't help with my problem. ;P
     
  4. Offline

    LegacyGaming

    Maybe because of the semi-colons you have at the end of every if() line?
     
    finalblade1234 likes this.
  5. Will try this when I get time, can't do it rn tho.
     
  6. Offline

    DoggyCode™

    Yea.. why would he even have that?
     
  7. I don't know, I think it might appear by default...

    no nvm
     
  8. Offline

    LegacyGaming

    I don't get how you mean that, is that meant to be rhetorical? :p
     
  9. Offline

    DoggyCode™

  10. Ok, getting somewhere... I removed the semi-colons and now when I do /jpenable, it crashes my server, and also minecraft...
     
  11. Offline

    MCMatters

  12. At the top of the page. If you are too lazy then here...
    Code:
    package jetpacks;
    import java.util.Timer;
    import java.util.TimerTask;
    import java.util.logging.Logger;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.Server;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    public class Jetpacks extends JavaPlugin
        {
        public static final Logger logger = Logger.getLogger("Minecraft");
        private Player CurrentPlayer;
      
      
      
        @Override
        public void onDisable()
            {
            PluginDescriptionFile thepdfFile = this.getDescription();
            //this.logger.info("Nothingness v1.0b has been ENABLED!");
          
            //this.logger.info(this.logger.info(thepdfFile.getName() + " has been DISABLED"));
            this.logger.info(thepdfFile.getName() + " has been DISABLED");
          
            }
        @Override
        public void onEnable()
            {
            PluginDescriptionFile thepdfFile = this.getDescription();
            //this.logger.info("Nothingness v1.0b has been ENABLED!");
          
            //this.logger.info(this.logger.info(thepdfFile.getName() + " has been DISABLED"));
            this.logger.info(thepdfFile.getName() + " Version " + thepdfFile.getVersion() + " has been ENABLED");
            }
      
      
      
        @Override
        public boolean onCommand(CommandSender theSender, Command cmd, String commandLabel, String args[]    )
            {
          
          
            Player thisPlayer = (Player) theSender;
          
          
            if (commandLabel.equalsIgnoreCase("jetpacks"))
                {
                    thisPlayer.sendMessage(ChatColor.GREEN + "Jetpacks Help:");
                    thisPlayer.sendMessage(ChatColor.BLUE + "Enable Jetpacks:"  + ChatColor.LIGHT_PURPLE + " /jpenable");
                    thisPlayer.sendMessage(ChatColor.BLUE + "Disable Jetpacks:" + ChatColor.LIGHT_PURPLE + " /jpdisable");
                    thisPlayer.sendMessage(ChatColor.BLUE + "How to use Jetpacks:" + ChatColor.LIGHT_PURPLE + " /jphowto");
                    thisPlayer.sendMessage(ChatColor.LIGHT_PURPLE + "Author: Creeper_668");
                  
                }
            if (commandLabel.equalsIgnoreCase("jp"))
                {
                    thisPlayer.sendMessage(ChatColor.GREEN + "Jetpacks Help:");
                    thisPlayer.sendMessage(ChatColor.BLUE + "Enable Jetpacks:"  + ChatColor.LIGHT_PURPLE + " /jpenable");
                    thisPlayer.sendMessage(ChatColor.BLUE + "Disable Jetpacks:" + ChatColor.LIGHT_PURPLE + " /jpdisable");
                    thisPlayer.sendMessage(ChatColor.BLUE + "How to use Jetpacks:" + ChatColor.LIGHT_PURPLE + " /jphowto");
                    thisPlayer.sendMessage(ChatColor.LIGHT_PURPLE + "Author: Creeper_668");
                    //*/
              
                }
              
            if (commandLabel.equalsIgnoreCase("jpenable"))
                {
                thisPlayer.sendMessage(ChatColor.GREEN + "Your Jetpack has been enabled!");
                thisPlayer.setAllowFlight(true);
              
                /*
              
                ItemStack[] availableItemsInTheInventory;
              
                availableItemsInTheInventory = thisPlayer.getInventory().getContents();
              
              
              
                for (int n = 0; n < availableItemsInTheInventory.length; n++)
                    {
                    ItemStack thisItem;
                  
                    thisItem = availableItemsInTheInventory[n];
                  
                    if (thisItem != null)
                        {
                        //thisPlayer.sendMessage(availableItemsInTheInventory[n].toString());
                        String itemText;
                      
                        itemText = thisItem.toString();
                      
                        if (itemText.toLowerCase().contains("coal"))
                            {
                            thisPlayer.sendMessage(thisItem.toString());
                            thisPlayer.sendMessage("details...");
                            thisPlayer.sendMessage(".......");
                            thisItem.getData().toString();
                            }
                      
                        }
                    }
                */
              
                ItemStack coal = new ItemStack(Material.COAL);
              
                if (thisPlayer.getInventory().contains(coal));
                    {
                    if (!thisPlayer.getAllowFlight());
                        {
                        thisPlayer.setAllowFlight(true);
                        }
                    }
              
                if (!thisPlayer.getInventory().contains(coal));
                    {
                    if (thisPlayer.isFlying());
                        {
                        thisPlayer.sendMessage(ChatColor.RED + "You've run out of fuel!");
                        thisPlayer.setAllowFlight(false);
                        }
                    }
              
              
                while(thisPlayer.getAllowFlight())
                    {
                    Timer aTimer = new Timer();
                  
                    aTimer.schedule(new TimerTask()
                        {
              
                        @Override
                        public void run()
                            {
                            //thisPlayer.getInventory().remove(coal);
                            }
                        }, 2000);
                    }
                }
              
              
            if (commandLabel.equalsIgnoreCase("jpdisable"))
                    {
                    thisPlayer.sendMessage(ChatColor.GREEN + "Your Jetpack has been disabled.");
                    thisPlayer.setAllowFlight(false);
                    }
            if (commandLabel.equalsIgnoreCase("jphowto"))
                {
                thisPlayer.sendMessage(ChatColor.GREEN + "What are Jetpacks?");
                thisPlayer.sendMessage(ChatColor.BLUE + "This plugin is simple. All it does is gives you fly mode, but in a special way. You will see clouds of smoke underneath you, and your jetpack will stop when you run out of fuel. To start your jetpack, do /jpenable. If you want to stop flying, do /jpdisable. For more help, do /jp or /jetpacks.");
                thisPlayer.sendMessage(ChatColor.LIGHT_PURPLE + "Author: Creeper_668");
                Server sv = thisPlayer.getServer();
                }
            return true;
              
            }
        }
     
Thread Status:
Not open for further replies.

Share This Page