May I ask what it is for?
|
I have been messing around and trying to get a if is logged in code to work and I am not the best at coding so I haven't been able to achieve success, so I would like to ask the community for help at this point.
All help is appreciated.Code:} if(!playerName.equalsIgnoreCase("Admin").isLoggedIn()) { //Do Something } else { //Do Something }
When a player logs in it will shout it in the server. I know how to do that, I am just trying to get the login part to work.
Edit; sorry you probably knew all of thisso nvm sorryI know how to do that
Well to be honest, all the codes that needs to see if a player just logged in\ is logged in uses this :
Like this in public void initialize, client class :Code:for (int j = 0; j < PlayerHandler.players.length; j++) { if (PlayerHandler.players[j] != null) { Client c2 = (Client)PlayerHandler.players[j];
To create the "isLoggedIn" , You would have to define it, so you'd probably have to create like a void of somekind with that code , with statements etc if you don't want to have it everytime, like to keep it only in the line " loggedIn" but i've never personally seen it. It's repeated everywhere in my source, commands.java and in initialize for every single rank\ command that checks if people are onlineCode:if (playerRights == 2) { for (int j = 0; j < PlayerHandler.players.length; j++) { if (PlayerHandler.players[j] != null) { Client c2 = (Client)PlayerHandler.players[j]; c2.sendMessage("<col=16759296><shad=16759296>[Administrator]<img=2> "+ Misc.optimizeText(playerName) +" has just logged in."); } } }
add this to player.java
then to check if it is logged in i believe u can doCode:public static Player getPlayerForName(String playerName) { for(Player p : PlayerHandler.players) { if(p.playerName == playerName) return p; } return null; }
if(Player.getPlayerForName("playerName") != null)
or if you have a loggedIn boolean use it like this Player.getPlayerForName("playerName").isLoggedIn
also in case you need this:
Code:public static boolean isOffline(String playerName) { for(Player p : PlayerHandler.players) { if(p.playerName == playerName) return false; } return true; }
Olinice,
Thank you for the assistance, but I want it to just say it for the admin, I dont really care if other logs in, just if the main one comes online, that's the one I want to show.
tringanmistake,
I believe that's for a different type of source.
No it's not, this works for PI, but since you were checking for username i thought u wanted to know if the player was online using its username if its not that its also easy.
just use something like this:
Code:public static boolean isAdminOnline() { for(Player p : PlayerHandler.players) { if(p.playerRights == 3) return true; } return false; }
Adding this to public void initialize in client.java will make it send a message when an admins log in . ( Player rights 2?)
Code:if (playerRights == 2) { for (int j = 0; j < PlayerHandler.players.length; j++) { if (PlayerHandler.players[j] != null) { Client c2 = (Client)PlayerHandler.players[j]; c2.sendMessage("<col=16759296><shad=16759296>[Administrator]<img=2> "+ Misc.optimizeText(playerName) +" has just logged in."); } } }
Olinice is correct. Allow me to explain what which part does.
The red part is the condition which must be met in order for the "logged in" code to be executed. Yours would be if the playerName equals a certain value, here it is broadened to a rank.Code:if (playerRights == 2) { for (int j = 0; j < PlayerHandler.players.length; j++) { if (PlayerHandler.players[j] != null) { Client c2 = (Client)PlayerHandler.players[j]; c2.sendMessage("<col=16759296><shad=16759296>[Administrator]<img=2> "+ Misc.optimizeText(playerName) +" has just logged in."); } } }
The green part loops through all the players who're online. If the playerObject grabbed is legit (not null) the violet part is executed.
The violet part is the code that gets executed for EVERY player online. Notice the first line casts the player to the Client object, this is the target player.
Here the target player receives a message.
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |