How would I translate an int to a string?

Discussion in 'Plugin Development' started by TaiSmoove, Jun 27, 2013.

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

    TaiSmoove

    Okay, do I'm making a plugin for my server and I came across a problem... I need to know how to translate ID into a string: e.g: /ime stone instead of /ime 1?

    Here is my code:
    Code:java
    1. if(cmd.getName().equalsIgnoreCase("ime") || cmd.getName().equalsIgnoreCase("item")){
    2. if(se.hasPermission(new Permissions().ime)){
    3. if(se instanceof Player){
    4. if(args.length == 0){
    5. se.sendMessage(cPrefix + " " + ChatColor.BLUE + "Usage: /ime <ID>");
    6. }else if(args.length == 1){
    7. ID = Integer.parseInt(args[0]);
    8. Amount = Integer.parseInt(args[0]);
    9. ItemStack IDP = new ItemStack(ID, Amount);
    10. PlayerInventory pi = pl.getInventory();
    11. pi.addItem(IDP);
    12. se.sendMessage(cPrefix + " " + ChatColor.BLUE + "Here is your: " + ChatColor.RED + ID);
    13. }else if(args.length == 2){
    14. Player target = pl.getServer().getPlayer(args[1]);
    15. ID = Integer.parseInt(args[1]);
    16. Amount = Integer.parseInt(args[1]);
    17. PlayerInventory ti = target.getInventory();
    18. ItemStack IDT = new ItemStack(ID, Amount);
    19. ti.addItem(IDT);
    20. target.sendMessage(cPrefix + " " + ChatColor.BLUE + "Here is your: " + ChatColor.RED + ID);
    21. }
    22. }else{
    23. PluginDescriptionFile p = plugin.getDescription();
    24. l.info("[" + p.getName() + "]" + " " + "You must be a player to perform this command!");
    25. }
    26. }else{
    27. se.sendMessage(noPerms);
    28. }
    29. }
     
  2. Offline

    dillyg10

    Ah, do something along the lines of

    Material.valueOf(args[0].toUpperCase());
     
  3. Offline

    TaiSmoove

    dillyg10
    Thanks

    dillyg10
    BTW how do you get that AWESOME Sig?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
  4. Offline

    RealDope

    You can use Material.matchMaterial(String) and it's more forgiving about input
     
  5. Offline

    dillyg10

    Photoshop hun :).
     
  6. Offline

    Minnymin3

  7. Offline

    RealDope

  8. Offline

    Minnymin3

    RealDope
    Google
    You know... that company that is going to rule the world
     
  9. Offline

    RealDope

    Minnymin3
    Yeah so? We already answered that what are you saying?
     
  10. Offline

    Minnymin3

    RealDope
    Im saying try google first next time
     
  11. Offline

    RealDope

    Minnymin3
    Dude I didn't post this thread I don't understand what you're saying
     
  12. Offline

    Minnymin3

    RealDope
    XD Sorry tagged the wrong person...
     
Thread Status:
Not open for further replies.

Share This Page