what are your errors?
|
Hello rune-server, i have recently started with my passion towards learning java and some other software developing languages.
I'm still 16 and I want to study computer engineering in the university hopefully.
I'm buying a Java book soon for amateurs so i can start my way with java, but for now I'm just looking at video tuts so far.
alright back to topic.
TopicI have been taking a look at the commands.java and i wanted to make a ::notice command that a moderator+ ranked personnel would type like ::yell to inform people about something like "please do not forget to vote etc", so here is the ::yell command i found in the source i am using:
since i lack knowledge of how to create my own command and i don't know the classes yet, i thought i would tweak this command to refurbish it to ::notice, and this is what i came up with :Code:if(c.playerRights >= 0) { if (playerCommand.startsWith("yell")) { for (int j = 0; j < Server.playerHandler.players.length; j++) { if (Server.playerHandler.players[j] != null) { Client c2 = (Client)Server.playerHandler.players[j]; if (c.playerRights < 1 || c.playerRights > 3){ c2.sendMessage("@cr2@Player "+ Misc.optimizeText(c.playerName) +": " + (playerCommand.substring(5)) +""); }else if (c.playerRights == 1){ c2.sendMessage("@cr2@Moderator "+ Misc.optimizeText(c.playerName) +": " + (playerCommand.substring(5)) +""); }else if (c.playerRights == 2){ c2.sendMessage("@cr2@Administrator "+ Misc.optimizeText(c.playerName) +": " + (playerCommand.substring(5)) +""); }else if (c.playerRights == 3){ c2.sendMessage("Owner "+ Misc.optimizeText(c.playerName) +":" + (playerCommand.substring(5)) +""); }else if (c.playerRights == 0){ c2.sendMessage("@cr2@Player "+ Misc.optimizeText(c.playerName) +": " + (playerCommand.substring(5)) +""); }else if (c.playerRights == 10){ c2.sendMessage("@cr2@Player "+ Misc.optimizeText(c.playerName) +": " + (playerCommand.substring(5)) +""); } } } }
Code:if(c.playerRights >= 0) { if (playerCommand.startsWith("notice")) { for (int j = 0; j < Server.playerHandler.players.length; j++) { if (Server.playerHandler.players[j] != null) { Client c2 = (Client)Server.playerHandler.players[j]; }else if (c.playerRights == 1){ c2.sendMessage("Moderator @red@ NOTICE " + ": " + (playerCommand.substring(5)) +""); }else if (c.playerRights == 2){ c2.sendMessage("Administrator@red@ NOTICE " + ": " + (playerCommand.substring(5)) +""); }else if (c.playerRights == 3){ c2.sendMessage("Owner @red@ NOTICE " + ":" + (playerCommand.substring(5)) +""); } }
but i keep getting errors with this, what do you guys think i should add/delete to make this command work? and also if you have a better yell system that you could share that would help thanks.
UPDATE 1 : guys what does this error mean?
UPDATE 2: after adding the ::notice code icandoit provided me with, it worked flawlessly through the compiler, when i do it in game it it adds e before every thing i say, example ::notice hi, it says owner NOTICE: e hi. what's wrong with the code?
what are your errors?
Well first, I hope you have eclipse downloaded.
Second of all, you are missing a few brackets
Third,Doesn't let it work, because the first is a check to avoid nullpointer exceptoins, where the second is checking for playerRankCode:if (Server.playerHandler.players[j] != null) { Client c2 = (Client)Server.playerHandler.players[j]; }else if (c.playerRights == 1){
It will never pass to the first else statement if the first restriction is met, and if the the first restriction isn't met, it'll end up causing a nullpointer
Anyways, I'm guessing you just copied the if/elses from the first command, well the problem is, that you can't have an else without a if before it, e.g.
The first if statement should encompass the rest of the command, and the second one should just start with if, and then continue with if elsesCode:if (met) doThis() else doThis()
It can be done with a LOT less code, but it's better if you fix this first... goodluck
Eventually, it should look something like
If you want any information about what ANY of the lines does, and how you can properly modify them, feel free to PM meCode:if(c.playerRights >= 0) { if (playerCommand.startsWith("notice")) { for (int j = 0; j < Server.playerHandler.players.length; j++) { if (Server.playerHandler.players[j] != null) { Client c2 = (Client)Server.playerHandler.players[j]; if (c.playerRights == 1){ c2.sendMessage("Moderator @red@ NOTICE " + ": " + (playerCommand.substring(5)) +""); }else if (c.playerRights == 2){ c2.sendMessage("Administrator@red@ NOTICE " + ": " + (playerCommand.substring(5)) +""); }else if (c.playerRights == 3){ c2.sendMessage("Owner @red@ NOTICE " + ":" + (playerCommand.substring(5)) +""); } } } } }
It's really easy to do a lot of this when you know basic java, you can use video tutorials from thenewboston.com -> just like up to like 14 will help you a ton w/the basics, and then higher up will help you more.
Finally, a decent help thread. All you'd honestly have to do man is copy the entire yell command and paste it beneathe the closing bracket of the first one. Then change "yell" to "notice" and remove each if statement of the according rank of which you do not want to allow access to the command. Then add an else if statement to check if the player is not a high enough rank..
E.g.
If I was on my computer I would just do the whole thing real fast but since I'm only on my phone it's a bit hard.Code:} else if (c.playerRights < 1) { c.sendMessage("You do not have access to this command"); }
thanks guys, appreciate helping me out
yes i have eclipse downloaded, and btw if you can please would you tell me why eclipse is better than notepad++?
edit 1: your code has worked, i analyzed it and understood it thanks!
but when i notice in game, after everyword i type after ::notice, it adds automatically an e for some reason.
for example if i type ::notice hi, it outputs " owner NOTICE: e hi
I'm looking at the code atm too see why, but if you know why if you can help me out it would be great.
Multiple reasons, it tells you errors without having to compile manually, it has easy running, it spots memory leaks, does proper conventions (most of the time), lets you explore packages with ease (personal opinion, you can switch between heigharchy and just the normal display).
You can easily add libraries to your build path, refactoring is SO much easier, auto updates shit, and it's just generally better to use.
Use it properly for a week, and then try going back to notepad++, it'll be such a pain, believe me.
Show which code u are using now, btw ur coding is really messy and it's really hard to read it but maybe its just me cz im used in diff bracket style.
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |