Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Better Online Command

Junior Spellweaver
Joined
Oct 31, 2009
Messages
112
Reaction score
9
PHP:
            String online;
            for (int i = 1; i <= ChannelServer.getAllInstances().size(); i++) {
                online = "[CHANNEL " + i + "] ";
                for (MapleCharacter chr : ChannelServer.getInstance(i).getPlayerStorage().getAllCharacters())
                    online += MapleCharacter.makeMapleReadable(chr.getName()) + ", ";
                player.message(online);
            }
 
Newbie Spellweaver
Joined
Apr 10, 2009
Messages
91
Reaction score
195
Probably should switch to StringBuilders if your server has a lot of people and this command is made available to normal players.
 
Junior Spellweaver
Joined
Oct 5, 2008
Messages
105
Reaction score
16
Where's the stringbuilder? It's costly to continually concatenate an immutable string compared to a mutable one.
 
Newbie Spellweaver
Joined
Dec 29, 2009
Messages
9
Reaction score
0
Here's my improved version of the Online Command.
Code:
if (sp[0].equals("online")) {
    if (sp.length < 2) {
        int connected = 0;

        for (ChannelServer chs : ChannelServer.getAllInstances()) {
            int clients = chs.getPlayerStorage().getAllCharacters().size();
            connected += clients;
            mc.dropMessage(6, "Channel " + chs.getChannel() + " : " + clients);
        }

        mc.dropMessage(6, "Connected clients : " + connected);
    } else {
        int cId = Integer.parseInt(sp[1]);
        ChannelServer chs = ChannelServer.getInstance(cId);

        if (chs != null) {
            Collection<MapleCharacter> ch = new LinkedHashSet<MapleCharacter>(chs.getPlayerStorage().getAllCharacters());
            StringBuilder characters = new StringBuilder();

            for (MapleCharacter cha : ch)
                characters.append(MapleCharacter.makeMapleReadable(cha.getName()) + ", ");

            mc.dropMessage(6, "Channel " + cId + " : " + ch.size());
            mc.dropMessage(6, characters.substring(0, characters.length() - 2));
        } else {
            mc.dropMessage(5, "Channel " + cId + " is offline.");
        }
    }
}
 
Last edited:
Back
Top