Stats class and use stuff from there?

Discussion in 'Spigot Plugin Development' started by Creatos137, Apr 25, 2017.

  1. Hey,

    I made a class with stats to use for other classes. But how do I use it in other classes?

    Code (Text):
    package com.creatos;

    public class Stats {

        //Player Stats
        float mana;
        float maxMana;
        float stamina;
        float maxStamina;
        int maxhealth;
        public float getMana() {
            return mana;
        public void setMana(float mana) {
            this.mana = mana;
        public float getMaxMana() {
            return maxMana;
        public void setMaxMana(float maxMana) {
            this.maxMana = maxMana;
        public float getStamina() {
            return stamina;
        public void setStamina(float stamina) {
            this.stamina = stamina;
        public float getMaxStamina() {
            return maxStamina;
        public void setMaxStamina(float maxStamina) {
            this.maxStamina = maxStamina;
        public int getMaxhealth() {
            return maxhealth;
        public void setMaxhealth(int maxhealth) {
            this.maxhealth = maxhealth;
        //Item Stats

        String name;
        String type;
        float damage;
        float minLevel;
        String rarity;
        public String getName() {
            return name;
        public void setName(String name) {
   = name;
        public String getType() {
            return type;
        public void setType(String type) {
            this.type = type;
        public float getDamage() {
            return damage;
        public void setDamage(float damage) {
            this.damage = damage;
        public float getMinLevel() {
            return minLevel;
        public void setMinLevel(float minLevel) {
            this.minLevel = minLevel;
        public String getRarity() {
            return rarity;
        public void setRarity(String rarity) {
            this.rarity = rarity;
    Thank you for your time,

    - Creatos
  2. Just asking, have you done something like using classes in other classes already?
    Your class looks a bit empty, why do i say this? Simple, do you wanna save your fields private or should they be available for public ?
    You may need a class constructor ( have you ever used one? )

    I could tell you some more stuff but this should be it for the start
  3. No, I am really new to coding in java
  4. You may don't wanna hear that, because it has been here already for several posts, but you definitely have to learn some basic java first instead of creating a plugin.
    Why? Because you don't know that much and when we answer you something you may don't understand that.
  5. Well this is my wat of learning new stuff!
  6. Nevermind, I figured it out!!
  7. Ok well, i'll try to help you with that but this is definitely not the best way of learning java
    First of you have to access your class in another class, so how do you get the data, you may wanna use a constructor first so how do you build that constructor?

    Code (Text):

    public Stats(){
      //insert informations if required like default settings.
    So now how do you access the class, you could create a new class instance by using

    Code (Text):

    Stats stats = new Stats();
    Now you can modify your stats by using "stats.<method>" now its time to get some informations about your fields, you haven't modified the fields at the header so they can be edited. Do you wanna block that? then mark them as private.

    So now you can access all your data by just using the code construction above.
  8. Thanks man, but Is there a method to chante stats.<method> to just <method> because I have all the setters and getters but it will take long to import them all seperate by using String mana = stats.mana;

    Thank you
  9. just to give you the right information, how do you use now your stats class?
  10. What do you mean?
  11. Like how do receive the stats now, maybe a post of your classes could help, i thought about it because You mentioned something like Stats.mana.. Do you use that? Or do you use something like Stats stats = New Stats();
  12. I use stats.<Method>.
    Ex: stats.damage