Solved [Help] Player inventories.

Discussion in 'Spigot Plugin Development' started by SwagiWagi, Jun 9, 2016.

Thread Status:
Not open for further replies.
  1. Hey guys!

    Why is this code not working?
    Code (Text):
    package me.rom.com;

    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;

    public class Commands implements Listener {

        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] arg3) {
            if((label.equalsIgnoreCase("Hello"))) {
                if (!(sender instanceof Player)){
                    sender.sendMessage("Hey! You must be a player to use this command!");
                    return false;
                }
                }
            Player player = (Player) sender;
            PlayerInventory inv = player.getInventory();
           
            inv.clear();
           
            ItemStack ds = new ItemStack(Material.DIAMOND_SWORD);
           
            ds.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 1000000000);
           
            inv.addItem(ds);
            sender.sendMessage(ChatColor.GREEN + "There ya' go!");
            return true;
        }
    }
     
    When I type /hello it's writing me back /hello .
    What is wrong?
     
    • Optimistic Optimistic x 1
  2. Don't use label, use cmd,getName() instead
    if sender is not a player why are you still running the code? Use return true;
    You can't add enchantment level 1000000000

    Also your ( and ) are out of place on some points. I suggest to go back to java and learn that instead of doing Spigot/Bukkit plugins.
     
    • Agree Agree x 1
    • Useful Useful x 1
  3. you don't have to check if he is not the player mobs can't do your command :'(
     
    • Funny Funny x 1
    • Optimistic Optimistic x 1
  4. You have to,, CommandBlocks, Console etc can execute it and than boom ERRORS everywhere
     
    • Agree Agree x 1
Thread Status:
Not open for further replies.