InventorySee Code

Discussion in 'Spigot Plugin Development' started by DJJujuVI, May 31, 2016.

  1. Hey guys trying to create a /invsee command. New to coding so please help me!
    What I have so far:
    Code (Text):
    if(cmd.equalsIgnoreCase("/inventorysee")){
                p.openInventory((Inventory) p);
     
  2. p.openInventory(target.getInventory())
     
  3. First you need define the plugin and commands in plugin.yml http://wiki.bukkit.org/Plugin_YAML and then

    Code (Java):
    if(command.getName().equalsIgnoreCase("myCommand")){
        //Check Arguments
        if(args.length==1){
            //Check if the player is valid
            if(getServer().getPlayer(args[0])){
                //Open inventory
                ((Player) sender).openInventory(getServer().getPlayer(args[0]));
            }
        }
    }
     
    • Agree Agree x 1
  4. No spoon feeding :)

    Just add to get that target's inventory in the bottom line there after you get the target player.
     
  5. I also need help with FlySpeed, I have..
    Code (Text):
    if(cmd.equalsIgnoreCase("/flyspeed 10")){
                p.setFlySpeed(10);
                p.sendMessage(ChatColor.GOLD.toString() + ChatColor.BOLD + "You have set your flying speed to" + ChatColor.BOLD.toString() + ChatColor.WHITE + "10" + ChatColor.GOLD.toString() + ChatColor.BOLD + "!");
    and Clearing Inventory..

    Code (Text):
    if(cmd.equalsIgnoreCase("/ci")){
                p.closeInventory();
                p.sendMessage(ChatColor.GOLD.toString() + ChatColor.BOLD + "Your inventory was cleared!");
     
  6. p.getInventory().clear();
    }

    And don't use "/mycommand arg1" use arguments
    https://bukkit.org/threads/tutorial-command-arguments.186497/
     
  7. Also this doesn't work, I had to change target.getInventory to p.getInventory because my p is a player.
     
  8. I also use that, its not very helpful towards me because I am a new DEV and need a little help.
     
  9. Well I assumed you wanted to see the inventory of another player; target was just a word I used to represent the player you wanted to see the inventory of. You have to replace with however you are getting the target player's inventory.
     
  10. If you are going to spoon feed at least give good practices... Dont cast a CommandSender to a Player before checking to see it is an instanceof a Player. If console types this in, you will see a bunch of errors which are easily fixed.
     
    • Agree Agree x 3
  11. Works but I cant see other players inventories.
    Can anyone help me with the setFlySpeed and Vanish? Vanish still doesn't work!
     
  12. Why are you recreating commands that are in essentials?
     
  13. Code (Java):
    /cmd args[0] args[1] args[...] // here's a format
    the only command for fly speed @JujuMot is only /flyspeed don't input the 10 as a command too,

    check args[0] of the player if its equals to integer if it is set the flyspeed to the args[0] of the command sender if you don't understand please learn basics java and read spigot api javadoc afterwards.
     
  14. you can use setAllowFlight on a player to give them creative flight in survival. Then just adjust the fly speed.
     
  15. I did that but it doesn't work. I think my FlySpeed code is wrong.

    Code (Text):
    if(cmd.equalsIgnoreCase("/flyspeed 8")){
                p.setFlySpeed(8);
                p.sendMessage(ChatColor.GOLD.toString() + ChatColor.BOLD + "You have set your flying speed to" + ChatColor.BOLD.toString() + ChatColor.WHITE + "8" + ChatColor.GOLD.toString() + ChatColor.BOLD + "!");
     
  16. yeah it was really wrong you command doesn't have space, so its only flyspeed.
     
  17. FlySpeed is a float, that means that it only handles a number between -1 and 1. 0.1 is the default value, and 1 is very fast ;)
    (You could do x100 and make it a percentage.)
     
  18. So then what will be the code? .1 - 1?
     
    #19 DJJujuVI, Jun 1, 2016
    Last edited: Jun 1, 2016
  19. If you are new to coding you can decompile a plugin like openinventory and see how it works then you can fix your plugin
     
    • Agree Agree x 1