Purpose: Places a prefix (a title) before the player's name when using yell
Difficulty: 1
Classes Modified: client class
Procedure
Step 1: Replace your current yell command with this:
Step 2: Declare these fields:Code:if (command.startsWith("yell")) {
try {
if (playerRights >= 1)
PlayerHandler.messageToAll = playerTitle[--playerRights] + playerName + ": " + command.substring(5);
else if (personalTitle != null)
PlayerHandler.messageToAll = personalTitle + playerName + ": " + command.substring(5);
else
PlayerHandler.messageToAll = playerName + ": " + command.substring(5);
} catch(Exception e) {
sendMessage("Wrong syntax. Use ::yell <message>");
}
}
Step 3: Add these methods if you like. They're optional, but they'll allow you to access fields declared in step 2 from outside of the client class:Code:private final String[] playerTitles = {"[Moderator]", "[Administrator]", "[Owner]"};
private String personalTitle = null;
Anyway, that's how you turn a messy tutorial like this: [Only registered and activated users can see links. Click Here To Register...] into something nice. :)Code://Use these methods to get titles when in other classes
public String getPersonalTitle() {
return personalTitle;
}
public String[] getPlayerTitles() {
return playerTitles;
}
public String getTitleForRights(int pRights) {
return playerTitles[--pRights];
}
//Use this method to set the personal title when in other classes
public void setPersonalTitle(String personalTitle) {
this.personalTitle = personalTitle;
}
Oh, and you'll have to make your own command to set personal titles for other players.
Credits: Lothy
