Change:
To:Code:String[] args = playerCommand.split(" ");
Code:String[] args = playerCommand.split(" ", 2);
|
|
how would i get this command ::xnpcother to work on players with spaces in their names?
Code:if (playerCommand.startsWith("xnpcother")) { try { String[] args = playerCommand.split(" "); String otherplayer = args[1]; int newNPC = Integer.parseInt(args[2]); for(int i = 0; i < Config.MAX_PLAYERS; i++) { if(Server.playerHandler.players[i] != null) { if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(otherplayer)) { Client c2 = (Client)Server.playerHandler.players[i]; c2.npcId2 = newNPC; c2.isNpc = true; c2.updateRequired = true; c2.setAppearanceUpdateRequired(true); c2.sendMessage("You have been turned into an NPC by: " + c.playerName); break; } } } } catch(Exception e) { c.sendMessage("Player Must Be Offline."); } }
Change:
To:Code:String[] args = playerCommand.split(" ");
Code:String[] args = playerCommand.split(" ", 2);
A cheap hax would be to replace the seperation between command sections with something other than spaces.
Example:
::xnpcother_Player Name_NpcId
An even easier way would be to just load the player name from the end of the command. IE, after the second space so the code would be:
::xnpcother NpcId Player Name
String[] args = playerCommand.split(" ");
if (args.length == 3) {
Your method here.
}
Try this?
or this
if (playerCommand.startsWith("xnpcother")) {
String name = playerCommand.substring(9);
for(int i = 0; i < Config.MAX_PLAYERS; i++) {
if(Server.playerHandler.players[i] != null) {
if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(otherplayer)) {
Client c2 = (Client)Server.playerHandler.players[i];
c2.npcId2 = newNPC;
c2.isNpc = true;
c2.updateRequired = true;
c2.setAppearanceUpdateRequired(true);
c2.sendMessage("You have been turned into an NPC by: " + c.playerName);
break;
}
}
}
} catch(Exception e) {
c.sendMessage("Player Must Be Offline.");
}
| « Clipped Following Problem | Wtf? » |
| Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |