Call a method from another class in a custom nms entity class

Discussion in 'Plugin Development' started by spiroulis, May 20, 2017.

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

    spiroulis

    what i want to do is override the custom entity's attributes and set them relative to the player's level. Problem is when i try to use a method from my stats class (that has main as an argument in the constructor) on my custom villager class i cant because i cant make a new main(). I kinda suck at explaining so heres the code:

    stats class:
    Code:
    public class stats{
        static main p;
    
       
        public stats(main instance){
            p = instance;
            System.out.println("stats rdy");
        }
       
        public int getlvl(String playername){
            System.out.println("okeokok mexri edw");
             FileConfiguration m =  p.getConfig();
            System.out.println("ok kai ws edw");
            int lv = m.getInt(playername + " lvl:");
            return lv;
    }
    }
    custom villager class:
    Code:
    public class villager extends EntityVillager{
        public villager(World world) {
           
            super(world);
              System.out.println("VGENEI O GAMIAS");
        }
       
        @Override
        protected void initAttributes() {
        super.initAttributes();
        stats ts = new stats(new main()); //where the problem lies
        this.getAttributeInstance(GenericAttributes.maxHealth).setValue(ts.getlvl("spiroulis") * 1.0);
        }
       
    
    
    }
    
     
  2. Offline

    Zombie_Striker

    @spiroulis
    Do not abuse static; There is almost no situation where a static objects are needed. Remove it.

    You can either pass the main instance of the class through the villagers constructor, or use Bukkit.getPluginManager().getPlugin("PLUGIN NAME") to get the plugin's instance.
     
    spiroulis likes this.
  3. Offline

    spiroulis

    @Zombie_Striker firsty oh god thank you so much i tried so many things xd. About the static thing thanks for pointing that out i just forgot to delete it after trying something. Also i tried pass the main instance of the class through the villagers constructor but i got errors, either because its nms or probably (and most likely) because i didnt do it correctly. Tho your last suggestion did the trick thank you very much :D
     
Thread Status:
Not open for further replies.

Share This Page