Getting a int and hashmap from a class listed in a config

Discussion in 'Plugin Development' started by mine2012craft, Jan 2, 2017.

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

    mine2012craft

    Hello,

    So, my current objective here to getting a global int and hashmap listed in a per-player-configuration file.

    I have (Or I'm pretty sure) that I've succeeded in grabbing the Class name successfully in a config. I just need to get the int and hashmap. The only problem is that I don't know a way to achieve this.

    So visually:

    I am getting a class listed in a per-player-config:

    Code:
    //Config:
    
    User:
         Active Class: MyActiveClass
    
    //Code:
    
    userConfig.set("User.ActiveClass", "MyActiveClass");
    
    Code:
    String activeclass = user.getUserFile().getString("User.Active Class");
            Type classtype = Type.getType(activeclass);
    Then getting the int and hashmap within the class. This is the part I am stuck on currently. If there is anyway to do this, please lend me a hand.

    EDIT:

    Variables

    Using a example class name to replace the real class name (Unless you need the real class name too)

    Code:
     
    public class ExampleClass implements Listener{
    
    
    private HashMap<String, Long> cooldowns = new HashMap<String, Long>();
         int cooldownTime = 19;
    More Clarification:

    Ok, so, do you see the "Spell Cooldown: 0" At the bottom of the Hotbar? That is where the cooldown will be.

    [​IMG]

    My objective is to show how much time is left on the cooldown. That part I have covered.

    Now, the problem is that I will have the option to switch out the players current spell with another spell, and each spell has a different cooldown. I will also need to show that spell's cooldown aswell.

    Now, my way of doing this is by getting the name of the class (FirstSpell) , putting it in a player's configuration file:

    Code:
    Username: PlayerName83
    
    Active Spell Class Name: FirstSpell
    getting that classes name from the config by using a method by using a Type:

    Code:
            String spellclass = user.getUserFile().getString("Active Spell Class Name";
            Type spellclasstype = Type.getType(spellclass);
    and grabing two variables, a hashmap, and a int from that class:

    Code:
    public class FirstSpell implements Listener {
        //private Core plugin; Exclude this
        public  HashMap<String, Long> cooldowns = new HashMap<String, Long>();
         int cooldownTime = 19;
    Now Like I have said, this is where I am stuck. I am having trouble grabbing those 2 variables, because I do not see a way how. Now unless there is a better method of doing this, which I am very sure there is, I need to find out how to accomplish this.

    IF there is anymore clarification needed, please let me know.​


    Thank you,
    WarlordWeaponry
     
    Last edited: Jan 2, 2017
  2. Offline

    kameronn

    what int are you talking about and what hashmap
     
  3. Offline

    ShaneCraftDev

    Your post is extremely vague. I have no clue what you are talking about. What integer? What hashmap?
     
  4. Offline

    mine2012craft

    @ShaneCraftDev @kameronn Oh, sorry. I forgot to put that in!

    These 2 variables:

    Using a example class name to replace the real class name (Unless you need the real class name too)

    Code:
       
    public class ExampleClass implements Listener{
    
    
    private HashMap<String, Long> cooldowns = new HashMap<String, Long>();
         int cooldownTime = 19;
    Is there any other info you need?
     
  5. Offline

    mythbusterma

    @mine2012craft

    Perhaps if you told us what you were trying to do, we might be able to help you.
     
  6. Offline

    mine2012craft

    @mythbusterma Like I said in the above post, and the title, I amtrying to pull a int and a hashmap from a class. The class is being mentioned by its name in a per-player-config.

    If you need to know why I need them, it is because so I can use them to send a ActionBar Message (A Message above the hot bar) listing them a number representing a timer on how long until they can use their given spell.

    If you need to know more info, please tell me.
     
  7. Offline

    mythbusterma

    @mine2012craft

    If it's out of another class, just create getter methods, and invoke them on an instance of that object. Although I get the feeling that's not what you meant.
     
  8. Offline

    mine2012craft

    @mythbusterma Hmm... Ok let's see if I can make what I am trying to accomplish a bit more better to understand.

    Ok, so, do you see the "Spell Cooldown: 0" At the bottom of the Hotbar? That is where the cooldown will be.

    [​IMG]

    My objective is to show how much time is left on the cooldown. That part I have covered.

    Now, the problem is that I will have the option to switch out the players current spell with another spell, and each spell has a different cooldown. I will also need to show that spell's cooldown aswell.

    Now, my way of doing this is by getting the name of the class (FirstSpell) , putting it in a player's configuration file:

    Code:
    Username: PlayerName83
    
    Active Spell Class Name: FirstSpell
    getting that classes name from the config by using a method by using a Type:

    Code:
            String spellclass = user.getUserFile().getString("Active Spell Class Name";
            Type spellclasstype = Type.getType(spellclass);
    and grabing two variables, a hashmap, and a int from that class:

    Code:
    public class FirstSpell implements Listener {
        //private Core plugin; Exclude this
        public  HashMap<String, Long> cooldowns = new HashMap<String, Long>();
         int cooldownTime = 19;
    Now Like I have said, this is where I am stuck. I am having trouble grabbing those 2 variables, because I do not see a way how. Now unless there is a better method of doing this, which I am very sure there is, I need to find out how to accomplish this.

    IF there is anymore clarification needed, please let me know.
     
Thread Status:
Not open for further replies.

Share This Page