Can't Get Two Things To Work Together

Discussion in 'Plugin Development' started by Reptar_, Mar 16, 2013.

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

    Reptar_

    So I've made my on join random firework plugin, but now I want to make it so you can also use a command to shoot a firework. But the thing is, the command works now and the on join firework doesn't. I don't understand why.

    Here's my main class:
    http://pastebin.com/xwTbpZpc

    Here's my listener class:
    http://pastebin.com/9k8fNAfD

    I could really use some advice on how to make them both work together. Thanks!

    EDIT
    By adding the below code into the join event:
    Code:
    if(player instanceof Player){}
    
    what I want to happen works. The problem is, if I join it will work once then never again unless I turn the server off and boot it back up. How can I get it to always work on every join?
     
  2. Offline

    chasechocolate

    Casting Player to sender before doing an instanceof check?
     
  3. Offline

    Reptar_

    I added if(player instanceof Player){} into the listener class and it worked. I don't know if that's the correct way to do it, but if it's not, can someone show me the correct way?

    Updated the OP.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  4. Offline

    LudicrousYoshi

    Im not seeing why the instanceof is needed for the command or the event...? Best advice I have is to see what data is being modified when the fireworks shoot on login and for the command. Something has to be changing a field value inside the shootFireworks method that is preventing it from firing off again

    One thing I did notice though, is that you have two exact copies of shootFireworks and getColor when you really don't need to. To save space you could take the main class as a parameter of the listener and call the method through the main class rather than duplicating a substantial amount of code to have on both classes.

    Code:
    public class MyPlayerListener
    {
        ...
        xFireworks main;
     
        public MyPlayerListener(xFireworks xFW)
        {
            main = xFW;
        }
        ...
        main.getColor(3);
        ...
    }
    public class xFireworks
    {
        ...
        public final MyPlayerListener pl = new MyPlayerListener(this);
        ...
    }
    
     
  5. Offline

    Reptar_

    LudicrousYoshi

    I only did that because I have no clue on how to make it work any other way. I'm still a beginner at Java, so I don't understand most things.

    Also, I don't understand what you're talking about for this:

    Code:
    public class MyPlayerListener
    {
        ...
        xFireworks main;
     
        public MyPlayerListener(xFireworks xFW)
        {
            main = xFW;
        }
        ...
        main.getColor(3);
        ...
    }
    public class xFireworks
    {
        ...
        public final MyPlayerListener pl = new MyPlayerListener(this);
        ...
    }
    
    Just updated my Minecraft and server to 1.5. Now it works perfectly. . .

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  6. Offline

    LudicrousYoshi

    I was just showing you how you could clean up your code a bit. I added a field and a constructor to your listener that sets a variable as your main class, xFireworks, and provided an example of how you would call getColor with the new format. I also showed how you would initialize the new version of the listener in your main class at the bottom. the "..." was just all the other code that goes in your classes that I left out for the sake of showing you exactly what i was suggesting.
     
Thread Status:
Not open for further replies.

Share This Page