@commands || Coded for All Repacks!
alright guys this is my first post and im still learning java so plz dont be too hard on me
alright, so uhh i handled my loading in commands files, but u can handle in worldserver.run/main if u want... but here is commands i think u should know wat file each 1 goes in... but first u need to add this in Server.java if u on new moople or channelserver.java if u on any other repack:
PHP Code:
public static Map<String, List<String>> commands = new LinkedHashMap<String, List<String>>();
or use diamond operator if java 7 so it removes gay warning sign!!
kk, now u go to each command file and paste this command:
PHP Code:
if (sub[0].equals("admincommands")) {
player.message(" == Admin Commands == ");
if (!Server.commands.containsKey("AdminCommands")) {
Server.commands.put("AdminCommands", CommandListMaker.generateList("AdminCommands"));
player.dropMessage(" List updated. Try using the command again. ");
} else {
for (String tosend : Server.commands.get("AdminCommands")) {
player.message(tosend);
}
}
but in like the other classes u just change the "admincommands" to "<classfilename>" so like gmcommands would be <gmcommands> get it??
so now u have to add the commandlistgenerator class but don't worry it's easy1!1 just make a new class in the tools folder and call it "CommandListGenerator.java" and then paste this code inside:
PHP Code:
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 ~ 2010 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation. You may not use, modify
or distribute this program under any other version of the
GNU Affero General Public License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package tools;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
public class CommandListMaker {
public static List<String> generateList(String commandtype) {
BufferedReader br;
try {
br = new BufferedReader(new FileReader("src\\client\\command\\" + commandtype + ".java"));
} catch (FileNotFoundException fnfe) {
System.out.println(commandtype+".java in location: src\\client\\command can not be located. ");
return null;
}
List<String> alreadyAdded = new LinkedList<>();
try {
String s;
while ((s = br.readLine()) != null) {
if (s.contains("if (sub[0].equals(\"") || s.contains("if (sub[0].equalsIgnoreCase(\"")) {
if (s.contains("||")) {
int count = StringUtil.countMatches(s, "(\"");
for (int i = 0; i < count; i++) {
String toAdd = s.substring(s.indexOf("(\"") + 2, s.indexOf("\")"));
if (!alreadyAdded.contains(toAdd)) {
alreadyAdded.add(getCommandCharacter(commandtype) + toAdd);
s = s.substring(s.indexOf("||") + 2);
}
}
} else {
String toAdd = s.substring(s.indexOf("(\"") + 2, s.indexOf("\")"));
if (!alreadyAdded.contains(toAdd)) {
alreadyAdded.add(getCommandCharacter(commandtype) + toAdd);
}
}
}
}
} catch (IOException io) {
} finally {
try {
br.close();
} catch (IOException ex) {
}
}
return alreadyAdded;
}
public static String getCommandCharacter(String commandtype) {
switch (commandtype) {
case "PlayerCommands":
return "@";
case "DonatorCommands":
return "$";
case "GMCommands":
return "!";
case "AdminCommands":
return "#";
default:
return "[Null]";
}
}
}
just remember to edit the getcommandcharacter method 2 match ur repack!!!
now u just go ingame and type like !admincommands and it should work!!! credits 2 me
Re: @commands || Coded for All Repacks!
Nice release, however I do have a couple of suggestions:
1. How about just keeping a list of commands? It's inefficient to open the file every time, and I'm not sure if that would even work for more than two people at a time.
2. For the getCommandCharacter method, how about using an enum? For example:
PHP Code:
public enum CommandType
{
PLAYERCOMMANDS ("@"),
DONATORCOMMANDS ("$"),
GMCOMMANDS ("!"),
ADMINCOMMANDS ("#"),
NULL ("[Null]");
private String val;
CommandType(String value)
{
val = value;
}
@Override
public String toString()
{
return val;
}
}
And then just do CommandType.[whatever].toString();.
Just some suggestions. Have fun!
Re: @commands || Coded for All Repacks!
Quote:
Originally Posted by
shakar96
Nice release, however I do have a couple of suggestions:
1. How about just keeping a list of commands? It's inefficient to open the file every time, and I'm not sure if that would even work for more than two people at a time.
2. For the getCommandCharacter method, how about using an enum? For example:
PHP Code:
public enum CommandType
{
PLAYERCOMMANDS ("@"),
DONATORCOMMANDS ("$"),
GMCOMMANDS ("!"),
ADMINCOMMANDS ("#"),
NULL ("[Null]");
private String val;
CommandType(String value)
{
val = value;
}
@Override
public String toString()
{
return val;
}
}
And then just do CommandType.[whatever].toString();.
Just some suggestions. Have fun!
What do you mean? He keeps a list in the commands Map. Also, why use a enum if the way he did it was shorter?
Re: @commands || Coded for All Repacks!
Quote:
Originally Posted by
Veda
What do you mean? He keeps a list in the commands Map. Also, why use a enum if the way he did it was shorter?
I mean, instead of a method, how about just having a set array or a list, much easier and more efficient. It's also easier to change in the future. For example, add this in Commands.java:
PHP Code:
public static String[] playerCommands = {"dispose", "rape", "etc."}; //put all the commands
/////////////////////////
if (sub[0].equals(playerCommands[0])) {
} else if (sub[0].equals(playerCommands[1])) {
} //etc. etc.
//Or for you List<E> lovers:
public static List<String> playerCommands = Arrays.asList(new String[] {"dispose", "rape", "etc."});
if (sub[0].equals(playerCommands.get(0))) {
} else if (sub[0].equals(playerCommands.get(1))) {
} //etc. etc.
And an enum is much easier and, again, easier to make changes in the future.
Re: @commands || Coded for All Repacks!
Oh, I see. Wouldn't that get rid of the purpose of what he's trying to do? It seems like he's trying to make it dynamic, and so no matter how many commands you have the list will be that exact amount. o.o
Re: @commands || Coded for All Repacks!
Quote:
Originally Posted by
shakar96
I mean, instead of a method, how about just having a set array or a list, much easier and more efficient. It's also easier to change in the future. For example, add this in Commands.java:
PHP Code:
public static String[] playerCommands = {"dispose", "rape", "etc."}; //put all the commands
/////////////////////////
if (sub[0].equals(playerCommands[0])) {
} else if (sub[0].equals(playerCommands[1])) {
} //etc. etc.
//Or for you List<E> lovers:
public static List<String> playerCommands = Arrays.asList(new String[] {"dispose", "rape", "etc."});
if (sub[0].equals(playerCommands.get(0))) {
} else if (sub[0].equals(playerCommands.get(1))) {
} //etc. etc.
And an enum is much easier and, again, easier to make changes in the future.
This is stupid. your way is static and you need to add the new commands everytime. His is dynamic and will automatically add the new commands to the Map.
Btw, why do i feel like this guy is a smart troll
Re: @commands || Coded for All Repacks!
Quote:
Originally Posted by
oxysoft
This is stupid. your way is static and you need to add the new commands everytime. His is dynamic and will automatically add the new commands to the Map.
Btw, why do i feel like this guy is a smart troll
>hurr it won't compiel for me in netbenaz so it must be stuipd or a troll what a fag lol xD
Re: @commands || Coded for All Repacks!
Quote:
Originally Posted by
DualityMS
Thanks
Kind of a useless post.
Re: @commands || Coded for All Repacks!
Quote:
Originally Posted by
Soulfist
You're stupid too. Regardless of how obvious it is... You don't even understand statics (not even mentioning maps, or any form of collections). Stop looking up words and pretending you know everything they represent (pertaining to programming)
And if this release makes you think he's smart, lol. It's not like its bad or anything, but "smart", not exactly.
Posted via Mobile Device
@ts
Why are you obsessed with linked collections? It's unnecessary (especially the map).
@shakar
That is a bad idea though, don't get me wrong.
Posted via Mobile Device
@ts
Probably better to use Collections.emptyList() instead of returning null. Won't bother to explain why.
Posted via Mobile Device
@shakar
The enum may be better, but not using it like that.
Posted via Mobile Device
you are a true faggot. by static i meant that it doesn't change and update by itself and you need to add them yourself.
Re: @commands || Coded for All Repacks!
Quote:
Originally Posted by
shakar96
LOL, what?
Anyway, I see that the list is dynamic but what if two people use it at the same time? And besides, I don't see anything bad with just keeping a list or a map of the commands in Commands.java, opening the file every time and reading the information seems so inefficient.
I'm sure on the real gMS source code they keep a list of commands or other stuff like that, just seems better.
Posted via Mobile Device
What if 2 people uses it at the same time?
Re: @commands || Coded for All Repacks!
Quote:
Originally Posted by
shakar96
LOL, what?
Posted via Mobile Device
adding the new commands in an array after you've coded them