JavaPlugin in all my classes which has config

Discussion in 'Spigot Plugin Development' started by Fazzer84, May 29, 2018.

  1. Is there a way to get a configuration without having to add JavaPlugin all the time.
     
  2. Why do you extend every class from JavaPlugin, only one Class must extend JavePlugin.
    Create a static instance of the Class and use them in other Classes
     
  3. But when I created an instance, I could not completely put p.sendMessage
     
  4. Can you post some code of what you tried?
     
  5. DavidDevelops

    Supporter

    Do you know what you are doing? That shouldnt effect you sending a message to the player show the code and ill help <3
     
  6. Why not? I show you what I mean:

    1. Create a simple instance of the Mainclass
    Code (Text):
    public class Main extends JavaPlugin {
     
      public static Main instance;

      @Override
      public void onEnable() {
        instance = this;
      }
    }
    2. Go in your class where do you want to use the Config and write:
    Code (Text):
    private Main main = Main.instance;

    public void execute() {
      main.getConfig()....
      //Do something
    }
     
  7. The problem is that when I add: instance.getServer (). GetPlayer (instance.getConfig (). GetString ("Gamemode-Survival"). Replace ("&", "§")); I wanted to send a message to the player. Where is "GETPLAYER" was to get "sendMessage"
     
  8. Learn Java.
     
    • Optimistic Optimistic x 1
  9. What you have said is literally getting the value from Gamemode-Survival from your config and trying to cast whatever it is to a value.
    Where are you getting the player from? An event? or are you locating an online player?
     

  10. Uhh what are you even trying to send to the player? I would rather want you to paste screenshots of your code than copying-and-pasting.