|
So I am adding a simple premium method to my server..
The player save added fine without any errors
Now I am trying to add a command to give players premium status
Here is the command code
Here are the save methods:Code:if (playerCommand.startsWith("giveprem")) { try { String playerToVet = playerCommand.substring(8); for(int i = 0; i < Config.MAX_PLAYERS; i++) { if(Server.playerHandler.players[i] != null) { if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToPrem)) { Client c2 = (Client)Server.playerHandler.players[i]; c2.sendMessage("You have been given premium status by " + c.playerName); c2.isPremium = 1; c2.logout(); break; } } } } catch(Exception e) { c.sendMessage("Player Must Be Offline."); } }
Code:} else if (token.equals("isPremium")) { p.isPremium = Integer.parseInt(token2);Error:Code:characterfile.write("isPremium = ", 0, 12); characterfile.write(Integer.toString(p.isPremium), 0, Integer.toString(p.isPremium).length());
Edit
Fixed it myself.. It was this line:
String playerToVet = playerCommand.substring(8);
Nevermind..
The command is still not working..
No errors at all
Here is the command code:
Code:if (playerCommand.startsWith("giveprem")) { try { String playerToPre = playerCommand.substring(8); for(int i = 0; i < Config.MAX_PLAYERS; i++) { if(Server.playerHandler.players[i] != null) { if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToPre)) { Client c2 = (Client)Server.playerHandler.players[i]; c2.sendMessage("You have been given premium status by " + c.playerName); c2.isPremium = 1; c2.logout(); break; } } } } catch(Exception e) { c.sendMessage("Player Must Be Offline."); } }
It may be your substring, not certain though. Add a out print to make sure it works correctly... like...
System.out.println("Player Name: " + Server.playerHandler.players[i].playerName + ", Premium: " + c2.isPremium + ".");
That way you can check to make sure the name is correct and that it is changing the value correctly. Just add that right before the break;
Then the error lies with your substring. It isn't getting the right player name from the command. At least, that is the only thing that sounds logical to me. You would know if the name was correct if you added my check. My thinking is that when you type ::giveprem scotticus it is taking " scotticus". So therefore it isn't giving the premium to "scotticus", but to " scotticus". See what I mean?
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |