Discussion in 'Spigot Plugin Development' started by TheBlackTeddy, Apr 17, 2017.

    #1 TheBlackTeddy, Apr 17, 2017
    Last edited: Jan 22, 2021
  2. Create a static method return the instance of your main class. Here's an example:

    Code (Text):

        private static Main i;
        public static Main get() { return i; }
        public void onEnable(){
            Main.i = this;
  3. A few more Java tutorials may be helpful for you.
    What exactly are you trying to achieve? I sense an X, Y problem here.
  4. If you had enough knowledge, would this thread exist? ;)

    There a few different ways to achieve this. What I'm asking is What exactly are you trying to do?
    An X, Y problem is when you're asking about X but are trying to do Y. We're solving X for you when Y is the actual problem we all could have been solving in the first place.
  5. You can use this but is more work but it looks more clean in your code and more good:
    Code (Text):
    //In first class
    String ex;
    public String GetEx(){
    return ex;
    //In second class
    FirstClass first = new FirstClass();
    String ex = first.GetEx();
    You decide what to use.
    • Agree Agree x 1
  6. It goes into your main class, into the onEnable() method.
  7. Yes, that's one solution to a problem. The question is; is it the problem of this thread? The Main class is usually static. Means it won't work.
    There's also static classes, Singletons, and the Service Locator pattern. I'm hesitant to recommend any at this point since I don't know what the problem actually is. It may be that none of those are even required for this particular issue.
  8. Ok you can to use :
    public FistClass fistclass;
    public secondclass(FistClass fc){
    fistclass = fc;
    • Useful Useful x 1
  9. That is indeed another solution to a problem. I wouldn't recommend that one in particular for this discussion, however, as it will end in spaghetti code.
  10. Ayy, look at that. An indicator of delicious pasghetti.
    Without code or an idea of what you're trying to achieve, it's hard to say much. The fact that you've given us the name of one class and nothing else doesn't help, either.

    Make sure you're setting warpString before you access it.
  11. Mas


    You're setting a String equal to an empty string.
    Then complaining when it's sending as an empty message.

    See the logic problem here?
  12. The part that's confusing me is the "console it debugs as non empty"
    Define "non empty". What's it supposed to read?
  13. Somewhere in your code that string is being set to empty. Find out where.
    I would also recommend the use of a design pattern to help eliminate some of your spaghetti code.
    • Agree Agree x 1
  14. Using dependency injection will generally not end up in spaghetti code :p

    @TheBlackTeddy don't depend on static as an access modifier, it's not designed to be one (Instead, it's a memory tool)
  15. You'd use constructors/setters to pass dependencies around