Config in EventHandler

Discussion in 'Plugin Development' started by creppii, Feb 11, 2014.

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

    creppii

    Heyoo :)

    First of all:
    I have 2 Classes. One class i have a killsystem...for every kill you got 2 coins and this coins are now saved in the config. this works fine. now the second class is a eventHandler only!!! Its a shop system!
    How can i get the Coins out of the config to check in the EventHandler class if the player has enough coins? Ehm i saved it to the config like this:
    Code:java
    1. int Coins = getConfig().getInt("Spieler." + killer.getName() + ".Punkte");



    here the code of my EventHandler class:
    Code:java
    1. if(e.getInventory().getName().equalsIgnoreCase("§b§lShop - Goldene Äpfel")) {
    2. if(e.getSlot() == 0) {
    3. if(/*WHAT INSERT HERE TO CHECK IF THE PLAYER HAS ENOUGH COINS?*/ < 80) {
    4. p.sendMessage("§bZu wenig Coins!");
    5. p.sendMessage("§bDeine Coins: §6" + Coins + " Coins");
    6. p.sendMessage("§bPreis des Items: §b680 Coins");
    7. } else {
    8. p.sendMessage("Du hast 4 verzauberte Goldene Äpfel für 80 Coins gekauft");
    9. p.getInventory().addItem(new ItemStack(Material.GOLDEN_APPLE, 4, (short)1));
    10. Coins = Coins - 80;
    11. }
    12. e.getView().close();
    13. }
    14. else if(e.getCurrentItem().getType() == Material.GOLDEN_APPLE) {
    15. p.sendMessage("Du hast einen goldenen Apfel gekauft");
    16. p.getInventory().addItem(new ItemStack(Material.GOLDEN_APPLE, 30));
    17. e.getView().close();
    18. }
    19. }
    20. }
     
  2. Offline

    ztowne13

    In your main class put:

    Code:
     
    public static Plugin plugin;
     
    public void onEnable()
    {
    plugin = this;
    }
    
    and then to get the config in your EventHandler class, use:

    Code:
    MainClassName.plugin.getConfig()
    
     
Thread Status:
Not open for further replies.

Share This Page