Solved Shop System

Discussion in 'Plugin Development' started by mrkirby153, Nov 3, 2013.

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

    mrkirby153

    I have the basics for a GUI shop system set up but I want an easy way for me to add items to the shop like set the inventory contents to
    Code:java
    1. new ShopItem(<NAME>, <MATERIAL>, <DESCRIPTION>,<COST>, <EXECUTOR>)
    and run the "buy(Player player)" method in the <EXECUTOR> class.

    The ShopItem has to somehow become an ItemStack with the name set to NAME, material set to MATERIAL, description be: "DESCRIPTION" and on a new line "Cost: COST coins". I have no idea how to do that and hope that some people can give me some examples or pointers:)
     
  2. Offline

    bigbeno37

    Hm...just wondering, would it be easier to have to create a new ShopItem object for each item, or have a method such as ShopItem.addItem() that does it?
     
  3. Offline

    beastman3226

    I would do a Shop that has shop items and buy and sell shop items. Also why do you need a Executor for every shop item? Why not make a static variable and set it on start?
     
  4. Offline

    bigbeno37

    As for the prices and descriptions and all of that for the items, HashMaps are a way to go. Have several hashmaps that have <Item, String> or <Item, double>, and stuff like that. When you need information, call these HashMaps all at once, and present that information to the player.
     
  5. Offline

    beastman3226

    bigbeno37
    This is inefficient and a bad practice. Wrappers are the way to go.
     
  6. Offline

    bigbeno37

    What exactly are 'wrappers'?
     
  7. Offline

    beastman3226

    bigbeno37
    Wrappers are objects that contain references to other objects. A player wrapper allows you to reference a player and add functionality without implementing a new type of player. Wrappers are very useful. A wrapper in this instance would be a Shop and contain ItemStacks. Prices and names would be contained in a separate object that makes these values constant or otherwise. This is a much more efficient and OO way to program.
     
Thread Status:
Not open for further replies.

Share This Page