Item shop

Discussion in 'Plugin Development' started by djmaster329, Apr 20, 2013.

  1. Offline

    djmaster329

    Hello,

    For my new server I build an online webshop for players to buy items with iConomy money. The orders get saved into the MySQL database in the following format:
    [​IMG]
    So far so good. I am trying to make it possible for players to receive the items with a command (/getorder [id]). It works when you use item ids without damage value. The image above shows a working order. But when I try to deliver 'Spruce Wood Planks' with item id '5:1' it resolved the item name to 'null'.

    This is the code I use to deliver the orders:
    Code (Text):
    1. try{
    2.                         for(int i = 0; i <= 9; i++){
    3.                             if(item[i] == null || item[i] == ""){
    4.                        
    5.                             }else{
    6.                                 String [] split = item[i].split("x");
    7.                                 String itemid = split[0];
    8.                                 int itemamount = Integer.parseInt(split[1]);
    9.                                 Material itemname = Material.matchMaterial(itemid);
    10.                                 player.getInventory().addItem(new ItemStack(itemname, itemamount));
    11.                             }
    12.                         }
    13.                         MysqlHandler.finishOrder(id);                
    14.                     }catch(Exception e){
    15.                         System.out.println(e);
    16.                             sender.sendMessage(ChatColor.YELLOW + "[Shop] " + ChatColor.RED + "An error occured. Please contact server owner and note current date and time.");
    17.                        
    18.                     }
    Does anyone know a solution to this?

    Kind regards,
    Djmaster329
     
  2. Save the durability in a format something like this: "<id>:<durability>x<amount>" so for spruce wood planks it would be like this: "5:1x4", 4 being the amount.
     
  3. Offline

    djmaster329

    Yes, that is exactly the way I save the items:
    [​IMG]
     

Share This Page