Finally Some actually object orientated code
Somebody who makes something without sticking a bunch of methods into a class file!!!
Update i fixed up the names github will be updated shortly
A row of
if(message.contains("...")) {
event.getPlayer().doSomething();
} else if(message.contains("...")) {
event.getPlayer().doSomethingElse();
}
Is still not the right way to go about it.
@thomas15v had a nice, oo and modular solution to your problem. Just read it againā¦
EDIT: Also, this:
@SuppressWarnings("unused")
@Subscribe
public void onChatEvent(AsyncPlayerChatEvent event) {
String message = event.getMessage();
Player player = event.getPlayer();
...
if (message.equalsIgnoreCase("Hello")) {
event.getPlayer().sendMessage("Hey " + event.getPlayer() + " How may i assist you?");
} else if (message.contains("How do I get to the nether?")) {
event.getPlayer().sendMessage("...");
}
really makes me wonder. If you are already using a local variable to reference the player, then why would you use event.getPlayer()
in some places? As for surpressing unused, if you have that warning in a method, you are doing something wrong in 99.9% of all cases.
EDIT 2:
event.getPlayer().sendMessage("Hey " + event.getPlayer() + " How may i assist you?");
event.getPlayer().sendMessage("Need help with the nether? type \"how do i get to the nether\" in chat.");
event.getPlayer().sendMessage("About to die? type (heal) in chat ");
event.getPlayer().sendMessage("Want the server version? type (version) in chat");
event.getPlayer().sendMessage("type (Help me) to recieve kinda help");
event.getPlayer().sendMessage("Current Commands: ");
event.getPlayer().sendMessage("Current Commands: ");
event.getPlayer().sendMessage("Current Commands: ");
event.getPlayer().sendMessage("Current Commands: ");
event.getPlayer().sendMessage("Current Commands: ");
Seems a bit hardcodedā¦ You should probably store it in a List / and Array and then loop over it. Will make it easier to read from a config aswell.
EDIT 3:
public void Stopevent(ServerStoppingEvent event) {}
...
public void gameevent(PreInitializationEvent event) {}
Why are you using PascalCase for some methods instead of camelCase?
Try following these rules:
Classes, Interfaces and Enums in PascalCase
Methods, Fields, Parameters and local veriables in camelCase.
Example:
public void stopEvent(ServerStoppingEvent event) {}
...
//Although gameEvent is not a very descriptive name...Won't have a lot of events that aren't "gameEvents". Minecraft is a game afterall.
public void gameEvent(PreInitializationEvent event) {}
Donāt confuse him.
Trying my best.
I also would have made a local variable honestly . To limit lenght of the lines. As for the compiler it doesnāt really make a diffrence I think. I gues it would have changed it ā¦ not sure.
Its even simpler than that:
//harcoded
event.getPlayer().sendMessage("About to die? type (heal) in chat ", "Want the server version? type (version) in chat");
//nothardcoded (or at least less hardcoded xD)
String[] bunchoftext = {"About to die? type (heal) in chat ", "Want the server version? type (version) in chat"};
event.getPlayer().sendMessage( bunchoftext );
@Paulcarter : Half of being a good software developer is knowing how to think about your code, today, tomorrow, and just as importantly, a year from now.
May I humbly suggest watching this in its entirety: Rails Conf 2012 Keynote: Simplicity Matters by Rich Hickey - YouTube
Pardon the commercial-let at the beginning.
Good to know that works.
This makes me cry :ā(
Whichever one of you posted this to Redditā¦thatās not nice
ā¦ Thats not the updated github and WHO PUT THIS ON REDDIT
Excuse me for having a life, and not working on code every minute
Nono, itās the quality of the code.
Could be badder ā¦ . But apropos I think we should stop saying something about the code. I am sure the OP will learn a lot if he will make this plugin. And if we get to Servercore 3.0 recoded we may would talk differently. When I started coding I didnāt even know that if had an else ā¦ .
This was the first thing I made:
http://wololo.net/talk/viewtopic.php?p=119112
I remember it had ehm, more than 9000 lines of code in main.c. And no, it didnāt had an any else in itā¦ .
(Yeah I know the links are down, that dropbox account is probably canceled (I was a kid and shared illegal psp hacking stuff on that account )) Wait is that 3 years ago Ā°_Ā°ā¦ . Holy ā¦
Iām not sure whether you want to post that on the internet.
Andā¦ it really doesnāt look like you know how to code in Java, you should watch a tutorial, or even better, read a Java book.
Seems I was something like 15 when I started. I am 19 now. Akward I had the feeling,ā¦ . But yeah when I was 11 i didnāt even had a computer. And I got internet when I was 14 so yeah,ā¦ .
Well at least its good you started so young. If you continue to code, you will get to the elite definally. But hey definally respect. If I could change it now, I wished I had a computer at that age. But no I was still climbing treeās, playing card games and trading pokimon cards.
But to be honest the project that your trying to start may be a bit, euhm to mutch for a starter. I would recommend you to try something simpelers.
Ive had computers since i was 3 i was never a climb tree trade pokemon cards kind of kid
Well yeah, then I guess itās a good thing I submitted a PR to it? xD
Meh. Doubled vertical whitespaces. Meh meh meh.
But good job on the rest.
What you gonna do? eh? At least Iām not using tab characters for horizontal whitespaceā¦