Solved I don't understand. lolwat ez happenin

Discussion in 'Plugin Development' started by shagzow, Feb 1, 2016.

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

    shagzow

    I am learning Java. Thats for some smart guys, who will tell me to learn Java. I do.
    ok
    now im not gonna be this serious xddd
    so, i have this code
    oh
    and
    Hello!
    so, this code:
    Code:
        ItemStack item = new ItemStack(Material.STICK, 1);
        ItemMeta meta = item.getItemMeta().setDisplayName("hi");
    So, my lovely Idea says that ("hi") is void. dafuq.
    pls help would appreciate it
     
    Last edited: Feb 2, 2016
  2. Offline

    fatpigsarefat

    I don't understand your error. What is wrong with your plugin?
     
  3. Offline

    teej107

    @shagzow This is exactly the reason why you should learn Java. You can't write Bukkit plugins without knowing Java.
    The setDisplayName method does in fact return nothing so don't try to assign the return value (or lack of) to a variable.
     
    [ HashMap ] likes this.
  4. Offline

    shagzow

    ikr
    i am learning it atm (watching courses on udemy).
    So how can i do it then?

    setDisplayName("Wand") method says, that it finds void in brackets .-.
     
    Last edited by a moderator: Feb 1, 2016
  5. Offline

    teej107

    I told you.
     
  6. Offline

    shagzow

    Can you make a example pls?
    im dumb, okeay?
     
  7. Offline

    JoaoBM

    @shagzow Basically you can't set the Name in the variable. Get the item meta and then set it (not in the variable)
     
  8. Offline

    shagzow

    Indeed, I got it. But it doesnt work.
    It says undentified token.
    Here's the code:
    Code:
        ItemStack item = new ItemStack(Material.STICK);
        ItemMeta meta = item.getItemMeta();
        meta.setDisplayName("help");
     
  9. Offline

    JoaoBM

    @shagzow Because there you are just specifying the ItemMeta and not setting it. Here https://jd.bukkit.org/
    Left Side Bar > ItemStack > Search the Methods
    JavaDocs has everything you need for Bukkit Plugins
     
  10. Offline

    shagzow

    I think im too dumb for that atm.
    Can u show me pls?
    I promise I will go learn java more after that xdd
     
  11. Offline

    JoaoBM

  12. Offline

    fatpigsarefat

    @shagzow Here is an example from a project I am working on:

    Code:
    ItemStack ruggedboots = new ItemStack(Material.LEATHER_BOOTS);
                                ItemMeta ruggedbootsm = ruggedboots.getItemMeta();
                                ruggedbootsm.setDisplayName(ChatColor.BLUE + "Running Boots");
                                List ruggedbootsl = new ArrayList();
                                ruggedbootsl.add("A pair of old rugged boots");
                                ruggedbootsl.add(ChatColor.RED + "");
                                ruggedbootsl.add(ChatColor.GRAY + "Speed IV");
                                ruggedbootsm.setLore(ruggedbootsl);
                                ruggedboots.setItemMeta(ruggedbootsm);
     
  13. Offline

    shagzow

    I do the same. It just doesnt work.
     
  14. Offline

    fatpigsarefat

    @shagzow you missed one bit out heres what you put:
    Code:
        ItemStack item = new ItemStack(Material.STICK);
        ItemMeta meta = item.getItemMeta();
        meta.setDisplayName("help");
    You missed out 'item.setItemMeta(meta);'

    New code:
    Code:
        ItemStack item = new ItemStack(Material.STICK);
        ItemMeta meta = item.getItemMeta();
        meta.setDisplayName("help");
        item.setItemMeta(meta);
     
  15. Offline

    shagzow

    As I said.
    It doesnt work.
     
  16. Offline

    Xerox262

    @shagzow Post what you have, he was trying to say you were missing item.setMeta(meta); we can't really help if you don't show us, we can't just guess why it's not working. And if you have any errors in your logs post those too along with annotations a comment on the line the error is pointing.
     
  17. Offline

    shagzow

    @Xerox262

    Here is my class:
    Code:
    public class Commands implements CommandExecutor {
        private MainClass plugin;
        public static Player player;
        public static final HashMap<Player, Player> hmap = new HashMap<Player, Player>();
        public Commands(MainClass plugin) {
            this.plugin = plugin;
        }
        ItemStack item = new ItemStack(Material.STICK);
        ItemMeta meta = item.getItemMeta();
        meta.setDisplayName("help");
        item.setItemMeta(meta);
    
        ////////ZEUS////////
        public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
            Player p = (Player) commandSender;
            this.player = p;
            if (command.getName().equalsIgnoreCase("zeus")) {
                if (commandSender instanceof Player) {
                        if (p.hasPermission("gods.use")) {
                            if (hmap.containsKey(p)) {
                                hmap.remove(p);
                                p.sendMessage(Info.zeus + ChatColor.DARK_RED + " You are just a mortal now!");
                            } else {
                                hmap.put(p, p);
                                p.getInventory().addItem(item);
                                p.sendMessage(Info.zeus + ChatColor.GOLD + " I will share my power with you, mortal!");
                            }
                        } else {
                            p.sendMessage(Info.zeus + ChatColor.DARK_RED + " You don't have permission to use my power, mortal!");
                        }
                    } else {
                        p.sendMessage("You cant use this command, console!");
                    }
                }
            return true;
            }
        }
        ///////ZEUS////////
    I just need to give the stick to the player after he uses command.

    Elcipse says:
    Multiple markers at this line
    - Syntax error on token ".", @ expected after this token
    - Syntax error, insert ")" to complete MethodDeclaration
    - Syntax error, insert "Identifier (" to complete MethodHeaderName
    - Syntax error, insert "SimpleName" to complete QualifiedName
    to meta.setDisplayName("name here");
    Idea just cant resolve symbol on meta.setDisplayName("s");
    btw
    item.setItemMeta(); doesnt work too.
    I dont understand what is wrong .-.
     
  18. Offline

    boomboompower

  19. Offline

    shagzow

    Anyway I've already fixed it.
    ty
     
  20. Offline

    boomboompower

    @shagzow
    Please mark this thread as solved then :p
     
Thread Status:
Not open for further replies.

Share This Page