Eclipse errors

Discussion in 'Plugin Development' started by Anerdson, Mar 30, 2014.

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

    Anerdson

    Hello,

    First off, the code i am using:
    Code:java
    1. if(cmd.getName().equalsIgnoreCase("itemme")){
    2. if (s instanceof Player){
    3. Player player = (Player)s;
    4. PlayerInventory inv = player.getInventory();
    5. String i = args[0];
    6.  
    7. ItemStack item = new ItemStack(Material.i, 1);
    8.  
    9. }


    What i am trying to do i get the argument from a command, and then use that argument to create an itemstack which will then be given to the user. now on line 7, more specifically "Material.i" i am getting an error: "i cannot be resolved or is not a field." So, how could i make this work?

    Thanks,
    Anerdson
     
  2. Offline

    RawCode

    please learn java basics before coding bukkit.

    referencing enumtype by name done in different way.
     
  3. Offline

    Funergy

    Code:
    ItemStack item =new ItemStack(Material.args[0], 1);
    and one thing the player need to do it in caps /itemme IRON_SWORD
    to fix this you need to make a enum
     
  4. Offline

    TheLunarFrog

    RawCode Most people here are new to java, welcome to bukkit
    Funergy No.

    Try this:
    Code:java
    1. if(cmd.getName().equalsIgnoreCase("itemme")){
    2. if (s instanceof Player){
    3. Player player = (Player)s;
    4. PlayerInventory inv = player.getInventory();
    5. String i = args[0];
    6.  
    7. ItemStack item = new ItemStack(Material.matchMaterial(i), 1);


    Be careful however, and read the documentation on the Material#matchMaterial(String) method:
    http://jd.bukkit.org/rb/apidocs/org/bukkit/Material.html#matchMaterial(java.lang.String)

    Also consider reading the actual implementation of the method:
    http://jd.bukkit.org/rb/apidocs/src-html/org/bukkit/Material.html#line.595

    Finally, learn more about how enumeration types work here:
    http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html
     
  5. Offline

    Anerdson



    Thanks so much!
     
Thread Status:
Not open for further replies.

Share This Page