1. Welcome to LilyPad. Download the project, explore the forums, and create your own LilyPad network.


    If you use the software and enjoy it or have a question, or would like to contribute to the future of the software directly or through resources, please sign up and join our little community.

Solved Bukkit schedule and Lilypad

Discussion in 'Support' started by TakeMeNL, Nov 7, 2013.

  1. TakeMeNL

    TakeMeNL Member Resource Contributor

    So i have a issue/question about how lilypad handles a MessageRequest.

    I have a minigames server and a hub server. To give you the idea same concept as The HiveMC but then with my own plugins and minigames.

    The signs in the HUB needs to be updated, and they do if someone is on the server of a minigame.
    But when the server is empty, the schedule on that server is still running. But the HUB server is not recieving any information. Only when someone joins the server again it get the information.

    Why is it that when a server is empty no messagerequest from that server are being send?
  2. The_Zip

    The_Zip Active Member Resource Contributor

  3. Coelho

    Coelho Software Engineer Staff Member Administrator Maintainer

    This is probably an issue with your code rather than LilyPad.
  4. TakeMeNL

    TakeMeNL Member Resource Contributor

    When there is nobody on the minigames server the scheduleSyncRepeatingTask will run.
    Only it doesn't send any information to the HUB server. When there IS someone online it will send it to the HUB server.

    Some code snippets:

    So on the minigame server i have this:
    Plugin.java
    Code (text):

    public Pinger ping;
    ping = new lilypadPinger(this);
    getServer().getScheduler().scheduleSyncRepeatingTask(this, new PingTimer(ping), 20L, LilypadSettings.pingInterval);
     
    PingTimer.java
    Code (text):

    public class PingTimer implements Runnable {
        private Pinger    pinger;
        public PingTimer(Pinger ping) {
            this.pinger = ping;
        }
        @Override
        public void run() {
            try {
                pinger.sendServerData();
                System.out.print("Run task");
            }
            catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
     
    lilypadPinger.java
    Code (text):

       @Override
        public void sendServerData() throws IOException {
            if (plugin.getServer().getOnlinePlayers().length > 0) {
                MessageRequest request = null;
                ByteArrayOutputStream b = new ByteArrayOutputStream();
                DataOutputStream out = new DataOutputStream(b);
                ByteArrayOutputStream msgbytes = new ByteArrayOutputStream();
                DataOutputStream msgout = new DataOutputStream(msgbytes);

                msgout.writeUTF(LilypadSettings.lilypadName); // server name
                msgout.writeUTF(LilypadSettings.lilypadNiceName); // server nice name
                if (ServerManager.forceMaxPlayers) {
                    msgout.writeInt(ServerManager.forceMaxPlayersSize); // max players
                }
                else {
                    msgout.writeInt(plugin.getServer().getMaxPlayers()); // max players
                }
                msgout.writeInt(plugin.getServer().getOnlinePlayers().length); // online players
                msgout.writeBoolean(GameManager.gameStatus); // Game true / false
                msgout.writeUTF(GameManager.currentGameState.name()); // DISABLED, LOADING, INACTIVE, WAITING, STARTING, INGAME, FINISHING, RESETING, ERROR
                msgout.writeUTF(GameManager.currentGameArena.getArenaName()); // Arena Name
                msgout.writeInt(GameManager.timeleft); // Time Left
                msgout.writeInt(GameManager.seekers.size()); // seekers
                msgout.writeInt(GameManager.hiders.size()); // hiders
                msgout.writeInt(GameManager.spectators.size()); // spectators

                out.writeShort(msgbytes.toByteArray().length);
                out.write(msgbytes.toByteArray());

                try {
                    request = new MessageRequest(LilypadSettings.hubname, "HideNSeek", b.toByteArray());
                    plugin.getBukkitConnect().request(request);
                }
                catch (RequestException e) {
                    e.printStackTrace();
                }
            }
        }
     


    HUB Plugins that receives:
    Plugin.java
    Code (text):
    private LilypadPinger lilypadpinger;
    lilypadpinger = new LilypadPinger(this);
    getBukkitConnect().registerEvents(lilypadpinger);
     
    LilypadPinger.java
    Code (text):

        @EventListener
        public void onMessage(MessageEvent me) {
            if (!me.getChannel().equals("HideNSeek")) {
                return;
            }
            try {
                DataInputStream in = new DataInputStream(new ByteArrayInputStream(me.getMessage()));
                short len = in.readShort();
                byte[] msgbytes = new byte[len];
                in.readFully(msgbytes);
               DataInputStream msgin = new DataInputStream(new ByteArrayInputStream(msgbytes));
                String server = msgin.readUTF(); // server name
                String serverNice = msgin.readUTF(); // server nice name
                int maxPlayers = msgin.readInt(); // max players
                int curPlayers = msgin.readInt(); // online players
                boolean status = msgin.readBoolean(); // Game true  / false
                GameState mode = GameState.valueOf(msgin.readUTF()); // DISABLED, LOADING, INACTIVE, WAITING, STARTING, INGAME, FINISHING, RESETING, ERROR
                String arena = msgin.readUTF(); // Arena Name
                int time = msgin.readInt(); // Time Left
                int seekers = msgin.readInt(); // seekers
                int hiders = msgin.readInt(); // hiders
                int spectators = msgin.readInt(); // spectators              

                LilypadServer bs = servers.get(server);
                bs.niceName = serverNice;
                bs.maxPlayers = maxPlayers;
                bs.playersOnline = curPlayers;
                bs.gameStatus = status;
                bs.gameState = mode;
                bs.arena = arena;
                bs.timeLeft = time;
                bs.seekers = seekers;
                bs.hiders = hiders;
                bs.spectators = spectators;
             
                System.out.print(bs.niceName + " | " + bs.maxPlayers + " | " +  bs.playersOnline + " | " +  bs.gameStatus + " | " +  bs.gameState + " | " +  bs.arena + " | " +  bs.timeLeft + " | " +  bs.seekers + " | " +  bs.hiders + " | " +  bs.spectators);
            }
            catch (IOException e) {
                e.printStackTrace();
            }      
        }
    }
     
  5. TakeMeNL

    TakeMeNL Member Resource Contributor

    Nvm.. solved it. Maybe i haven't slept enough...
    >> if (plugin.getServer().getOnlinePlayers().length > 0)

    Sorry
    Last edited: Jan 5, 2014
    • Funny Funny x 1

Share This Page