Token System

Discussion in 'Plugin Development' started by badboysteee98, May 8, 2014.

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

    badboysteee98

    Hello Bukkit,

    Before you ask this is NOT a request. :)

    I was wondering how hard would it be to make a system where I can give player's tokens and then they see how many tokens they have and have to do /shop to use them. In the /shop a GUI shows up and inside having custom gear that is enchanted and when they click the item they get that item there tokens get taken off them and then the item doesn't move outside the GUI?
    Would I have to like store all the Player's tokens to like a Config or something so they don't lose them on a reload/restart?

    I'm wondering because I was thinking about making my self one for my Server but don't know where to start
     
  2. Offline

    xMrPoi

    Yes, you would have to store them in a config so that they save over reloads.

    You could look at the InventoryClickEvent to see the methods you could use to see what they click.
     
  3. Offline

    badboysteee98

    xMrPoi Oh okay but would I have to say make my own little economy for tokens or not and just keep using this on the item

    if(tokens < 9) {
    player.sendMessage
    }

    Is that the best way going about it?
     
  4. Offline

    xMrPoi

    You could create an int which gets an int from the config.
    Code:java
    1. int tokens = getConfig().getInt("Tokens.{PlayerNameHere}");

    You'd also want to create a check seeing if that equals null.
     
  5. Offline

    badboysteee98

    xMrPoi Oh so the way I was going to do it was the long way xD
     
  6. Offline

    HungerCraftNL

    What should do in this case is making a custom .yml file and save the in that file like this:
    PHP:
    public void setMoney(Player pInteger tokens){
      
    getConfig().set("Players." p.getName() + ".Tokens"tokens);
    }
    Like this you've a list with players (List<String>), what you can get with a code like this:
    PHP:
    public List<StringgetPlayerNames(){
      return 
    getConfig().getStringList("Players");
    }
     
  7. Offline

    badboysteee98

    HungerCraftNL so there is no need to make my own little economy plugin?
     
  8. Offline

    HungerCraftNL

    This is a little economy system, but you can make it in your plugin you don't need another plugin for this.
     
  9. Offline

    badboysteee98

    HungerCraftNL I know that but I'm not to good with making my own Economy as I've never really looked into it xD
     
  10. Offline

    HungerCraftNL

    badboysteee98
    "In the /shop a GUI shows up and inside having custom gear that is enchanted and when they click the item they get that item there tokens get taken off them and then the item doesn't move outside the GUI?"
    Do you mean that they are not allowed to take a item out of an inventory?
     
  11. Offline

    badboysteee98

    HungerCraftNL Yes but still get given that item with the enchats

    EDIT: That is fairly simple though because on the InventoryClickEvent your set it to e.setCancelled(true)
    // Then give the Player the Item with the enchants
     
  12. Offline

    HungerCraftNL

    You can do both:

    PHP:
    public Inventory yourinv null;
    public 
    ItemStack youritem;
     
    @
    EventHandler
    public void onInteract(InventoryClickEvent e){
      
    Player p = (Playere.getWhoClicked();
      if(
    e.getInventory() == yourinv){
        if(
    p.getInventory().firstEmpty() == -1){
          
    p.getInventory().addItem(youritem);
          
    e.setCancelled(true);
     
        } else {
          
    p.sendMessage("Inventory is full!");
        }
        
    p.closeInventory();
      }
    }
    Editted: added inventory full and veriable on inventory
     
    badboysteee98 likes this.
  13. Offline

    badboysteee98

  14. Offline

    HungerCraftNL

    No problem bro
     
    badboysteee98 likes this.
Thread Status:
Not open for further replies.

Share This Page