And My Plugin Doesn't work {}_{}

Discussion in 'Plugin Development' started by MineMeetsRoblox, Aug 30, 2015.

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

    MineMeetsRoblox

    Ok so I have been trying to get my Plugin working for the past few days, with the help of @au2001 but It is broke again -_-
    So I am needing a few people to proof read this to check and see what i messed up on.

    Please Help!!!!

    Main:
    Code:
    package me.MineMeetsRoblox;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin {
       
        @Override
        public void onEnable(){
            new PlayerListener(this);
        }
       
        @Override
        public void onDisable(){
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String args){
           
            Player player = (Player) sender;
           
            if(cmd.getName().equalsIgnoreCase("BOOTS"));
           
            ItemStack BOOTS = new ItemStack(Material.GOLD_BOOTS, 1);
            BOOTS.getItemMeta().setLore(ChatColor.BOLD + "May God Speed Be With You");
            return false;
           
           
        }
    }
    
    Player Listener
    Code:
    package me.MineMeetsRoblox;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerInventoryEvent;
    import org.bukkit.event.player.PlayerItemBreakEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    @SuppressWarnings("deprecation")
    public class PlayerListener implements Listener {
       
        public PlayerListener(Main main) {
            main.getServer().getPluginManager().registerEvents(this, main);
        }
       
        @EventHandler
        public void SpeedBoots(PlayerEvent event) {
            Player p = event.getEntity();
                for (ItemStack item : p.getInventory()) {
                    if (item.getType() == Material.GOLD_BOOTS && item.hasItemMeta()) {
                        ItemMeta meta = item.getItemMeta();
                        if (meta.getLore().equals("May God Speed Be With You")) {
                           
                            p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 2, false), true);
                           
                        }
                    }
                }
    
           
        }
       
        @EventHandler
        public void onDeath(PlayerItemBreakEvent event) {
            Player p = event.getEntity();
                for (ItemStack item : p.getInventory()) {
                    if (item.getType() == Material.GOLD_BOOTS && item.hasItemMeta()) {
                        ItemMeta meta = item.getItemMeta();
                        if (meta.getLore().equals(ChatColor.BOLD + "May God Speed Be With You")) {
                           
                            p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 0, 0));
                           
                        }
                    }
                }
    
           
        }
    
    }
    
    plugin.yml
    Code:
    name: Special Boots
    main: me.MineMeetsRoblox.Main
    version: 0.1B
    commands:
       boots:
          description: DEV ONLY | WILL BE REMOVED | Gives Boots of Speed
          usage: /boots
    
    Also! Craftbukkit.jar is the latest version from Buildtools.... So I have no clue what is wrong with this.
    When i type in /boots the chat says:

    /boots
    And doesnt give me boots....

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Aug 30, 2015
  2. Offline

    Zombie_Striker

    1. JavaNamingConventions: don't use Main as a class name.
    2. Make sure package names are different between plugins
    3. JavaNamingConvention, package names should all be lower case.
    4. Keep an instance of PlayerListener in the main class. And register it in the main class.
    5. the ; is messing you up.
    6. You can't set the lore of an item that does not exist. If the commandlabel is not BOOTS, the there will not be a Boots field and thus you could never get it's item meta.\
    7. WHY DID YOU NOT CHECK IF THE SENDER IS A PLAYER! WHAT IF THE sender IS THE CONSOLE!
    8. You forgot to add .additem . you're creating an item but never doing anything with it.
     
  3. Offline

    Oxyorum

    @MineMeetsRoblox

    Your if statement in the onCommand method is doing nothing right now. I assume you want the rest of the code in that method to go inside it, so you'd want to replace the semicolon after the statement with curly braces, so your code looks like this:

    Code:
    if(condition){
    //do things
    }
    
    Also, you are never actually putting the boots into the player's inventory. You just make the item and do nothing with it.

    @Zombie_Striker pretty much explained everything.
     
  4. @Zombie_Striker 10. He returned false which sends the sender the usage of the command.
    11. List<String> will never be equal to a String.
     
  5. Offline

    MineMeetsRoblox

    Code:
    
            Player player = (Player) sender;
         
            if(cmd.getName().equalsIgnoreCase("BOOTS")  && instanceof Player);
         
            ItemStack BOOTS = new ItemStack(Material.GOLD_BOOTS, 1);
            BOOTS.getItemMeta().setLore(ChatColor.BOLD + "May God Speed Be With You");
            return false;
    
    I tried to fix that but it just send an error message and I can't even read it...
    The reason why I didn't add it in the first place was the command was gonna be removed after I finished developement of the boots... that was litteraly just to make sure the plugin worked...

    EDIT:I am working on the other stuff... I am still kinda new at java so It takes me a minute to understand the stuff your saying.

    EDIT: the changes I made just created an error and wasnt needed. So I just removed the instanceof player. as I am not gonna be running the command in the consle and the command will be removed after development.

    10. Removed return false;

    Where is List<String> located in the files... I couldn't find what your saying.

    Changed Main to start

    1. I dont understand what you are saying. that is used as /boots not as a label...... This is kinda confusing me... ?

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Aug 30, 2015
  6. Offline

    NickenatorDev

    Try this for your "onCommand" boolean (Another thing as well, if this does not work, try removing "usage: /boots" from your plugin.yml. When I was a beginner in coding I had a few problems with this):

    Code:
        public boolean onCommand(CommandSender sender, Command command, String label, String[] arguments) {
    
            //Checking if the sender of the command is a player
            if (!(sender instanceof Player)) {
    
                //If the sender of the command is not a player, the sender will receive the following message
                sender.sendMessage(Formatter.getColorRed() + "That Command Can Only Be Executed In-Game!");
            } else {
    
                //Checking if the command specified is "boots"
                if (command.getName().equalsIgnoreCase("boots")) {
    
                    //Casting the sender of the command to a player
                    Player player = (Player) sender;
               
                    //Checking the length of the command (Integers in java always start with "0" instead of "1")
                    if (arguments.length > 0) {
                        player.sendMessage(ChatColor.RED + "Usage:\n/boots");
                    } else if (arguments.length == 0) {
    
                        //Getting the player's inventory
                        Inventory playerInventory = player.getInventory();
    
                        //Creating an item stack instance of gold boots
                        ItemStack boots = new ItemStack(Material.GOLD_BOOTS);
                   
                        //Getting the boots item meta
                        ItemMeta bootsMeta = boots.getItemMeta();
                   
                        //Creating a list containing strings for the boots lore (Always use list's for item stack lore's)
                        List<String> bootsLore = new ArrayList<String>();
                   
                        //Adding the the lore to the list
                        bootsLore.add(ChatColor.BOLD + "May God Speed Be With You.");
                   
                        //Setting the boots lore to the list
                        bootsMeta.setLore(bootsLore);
                   
                        //Setting the boots meta to "bootsMeta" because of what we named it above
                        boots.setItemMeta(bootsMeta);
                   
                        //Using the "playerInventory" instance created above and adding the item to the player's inventory
                        playerInventory.addItem(boots);
                    }
                }
            }
       
            return false;
        }
     
    Last edited: Aug 30, 2015
  7. Offline

    sionzee

    Which Java u using?
    Why u using PlayerEvent? :confused:
    Above onCommand u miss @Override

    WHATS DO
    'if(cmd.getName().equalsIgnoreCase("BOOTS"));'
     
  8. Offline

    NickenatorDev

    1.Removing "@Override" from your command boolean does to the equivalent of nothing. To be fair, I would actually recommend removing it.

    2. I do however agree that an event like the PlayerMoveEvent should be used instead of the PlayerEvent. To do this, get the player's inventory, and check if the player is wearing gold boots by using the "getBoots()" method. Example:
    Code:
    if (event.getPlayer().getInventory().getBoots() == new ItemStack(Material.GOLD_BOOTS)) {
        //Code
    }
     
    Last edited: Aug 30, 2015
  9. Offline

    MineMeetsRoblox

    Java Version 8 Update 51

    I am using PlayerEvent because I was trying to figure out which Player(interact, inventoryevent, event) is the correct one.

    Fixxed @Override onCommand

    Please use correct grammer, I have no clue what you mean by WHATS DO
    If you are asking What does this do? it gets the command so if a player does /boots it will give boots.

    @sionzee The @Override you say to use above onCommand was unnecessary.... @Override is for things like onEnable and onDisable

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Aug 30, 2015
  10. Offline

    teej107

    @Override is for any inherited method you are overriding. That includes the onEnable and onDisable methods as well as the onCommand method. It's optional, but I wouldn't recommend neglecting it.
     
    Last edited: Aug 30, 2015
  11. Offline

    sionzee

    ** Updated
    Let's implement it CommandExecutor.

    No, it's not true. This is correct...
    Code:
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String args){
        if(cmd.getName().equalsIgnoreCase("boots")) {
            if(sender instanceof Player) {
                Player player = (Player) sender;
                ItemStack bootsIs = new ItemStack(Material.GOLD_BOOTS, 1);
                ItemMeta meta = bootsIs.getItemMeta();
                meta.setLore(Arrays.asList(new String[]{ChatColor.BOLD + "May God Speed Be With You"}));
                bootsIs.setItemMeta(meta);
            }
        }
        return false;
    }
     
  12. It still isn't correct.
    Correct would be:
    ItemMeta:
    Code:
    ItemMeta meta = item.getItemMeta();
    meta.setLore(Arrays.asList(ChatColor.BOLD+"May god's speed be with you"));
    item.setItemMeta(meta);
    And send a message to the player and give him the item so he knows that it worked.
    And return true.
    And args is an array. :p
     
  13. Offline

    sionzee

    Yup, I updated it... I know about it
    We returing true if command isn't successfull...
    Return true show usage message.

    @teej107
    JavaPlugin has:
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args);

    You can @Override it...

    Woops, I read it wrong, sorry man :) U're right
     
    Last edited: Aug 30, 2015
  14. Offline

    MineMeetsRoblox

    Alright. So you guys done messed up my plugin.... It doesnt even load anymore. :/
     
  15. Offline

    CrystallFTW

  16. Offline

    rbrick

  17. Offline

    meguy26

    @MineMeetsRoblox
    Question: How could they mess up your plugin if;
    1. It wasnt working to begin with
    2. Very few of them gave you code
    3. You (clearly) need to learn more Java before attempting to make a Bukkit plugin
     
  18. Offline

    MineMeetsRoblox

    Fixed the Problem with the not loading forgot what it was... but It sort of worked before... And IT WAS A JOKE!
    start.java
    Code:
    package me.MineMeetsRoblox;
    
    import java.util.Arrays;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class start extends JavaPlugin {
       
        @Override
        public void onEnable(){
            new playerlistener(this);
        }
       
        @Override
        public void onDisable(){
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String args){
           if(cmd.getName().equalsIgnoreCase("boots")) {
               if(sender instanceof Player) {
                   Player player = (Player) sender;
                   ItemStack bootsIs = new ItemStack(Material.GOLD_BOOTS, 1);
                   ItemMeta meta = item.getItemMeta();
                   meta.setLore(Arrays.asList(ChatColor.BOLD+"May god's speed be with you"));
                   item.setItemMeta(meta);
                   sender.sendMessage(ChatColor.GREEN + "PickleServers" + ChatColor.BOLD + ": " + ChatColor.BLUE + "Item done GOT");
               }
           }
           return false;}}
       
    playerlistener.java
    Code:
    package me.MineMeetsRoblox;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerInventoryEvent;
    import org.bukkit.event.player.PlayerItemBreakEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    @SuppressWarnings("deprecation")
    public class playerlistener implements Listener {
       
        public playerlistener(start main) {
            main.getServer().getPluginManager().registerEvents(this, main);
        }
       
        @EventHandler
        public void SpeedBoots(PlayerEvent event) {
            Player p = event.getEntity();
                for (ItemStack item : p.getInventory()) {
                    if (item.getType() == Material.GOLD_BOOTS && item.hasItemMeta()) {
                        ItemMeta meta = item.getItemMeta();
                        if (meta.getLore().equals("May God Speed Be With You")) {
                           
                            p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 2, false), true);
                           
                        }
                    }
                }
    
           
        }
       
        @EventHandler
        public void onDeath(PlayerItemBreakEvent event) {
            Player p = event.getEntity();
                for (ItemStack item : p.getInventory()) {
                    if (item.getType() == Material.GOLD_BOOTS && item.hasItemMeta()) {
                        ItemMeta meta = item.getItemMeta();
                        if (meta.getLore().equals(ChatColor.BOLD + "May God Speed Be With You")) {
                           
                            p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 0, 0));
                           
                        }
                    }
                }
    
           
        }
    
    }
    
    plugin.yml
    Code:
    name: Special Boots
    main: me.MineMeetsRoblox.start
    version: 0.1B
    commands:
       boots:
          description: DEV ONLY | WILL BE REMOVED | Gives Boots of Speed
          usage: /boots
    
    I was joking.
    1. It sort of worked before.
    2. It was just a joke.
    3. Yes I realize i need to learn java.... But this is how i am learning. FROM MY MISTAKES! by experience.

    Refere to 3 on my post above
    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Aug 30, 2015
  19. Offline

    xMrPoi

    The point of this community is to help people with the Bukkit API. Not to teach people basic Java knowledge.
     
  20. Offline

    CrystallFTW

    @MineMeetsRoblox 1. What is "item" from your main class?
    2. You never gave the itemstack to the sender.
    3. If you already checked if the sender is instance of player, you could use "player" instead of "sender" .
     
  21. Offline

    caderape

    @MineMeetsRoblox
    - it's not recommanded to use start as a class name. A capital letter would be nice.
    - If you return false in your command, you will get the usage everytime.
    - don't forget to add the itemstack to the inventory. You didn't.
    - You should use player move event i guess.
    - You should not loops the inventory. Juste use #getInventory().getBoots() and check if the boots are your BOOTS. Then add the potion effect
     
  22. A scheduler would be better I guess.
     
  23. Offline

    caderape

    @FisheyLP I don't even know why i said to use the playerMoveEvent.
     
  24. Offline

    MineMeetsRoblox

    I am just getting corrections on my work not learning.
    1. Golden_boots
    2. Ill fix that when I get Home
    3. Ill change it.
    Will Do.
     
  25. Offline

    CrystallFTW

    @MineMeetsRoblox I meant that the actual GOLDEN_BOOTS is defined as "bootsIs" not "item" so you are not getting it's itemmeta.
     
  26. Offline

    MineMeetsRoblox

  27. Offline

    mrCookieSlime

    Locked on request.

    @MineMeetsRoblox
    Please use the report button next time.
     
Thread Status:
Not open for further replies.

Share This Page