Shaun
July 4th, 2010, 11:09
Why do people use integers for ranks that they need to explicitly check later? I don't get it. This is far simpler and more intuitive, in my opinion.
/**
* Contain/handle possible player ranks
*
* @author Shaun
*
*/
public enum Rank
{
GUEST(0),
MEMBER(0),
MODERATOR(1),
ADMINISTRATOR(2),
DEVELOPER(2),
OWNER(2);
private final int CROWN_LEVEL; // crown level of the rank (0-2, normal being the lowest, admin crown the highest)
/**
* Initiate rank
*
* @param crownLevel
* crown level of the rank (0-2, normal being the lowest, admin
* crown the highest)
*/
Rank(int crownLevel)
{
this.CROWN_LEVEL = crownLevel;
}
/**
* @return staff/crown level of the rank
*/
public int getCrownLevel()
{
return CROWN_LEVEL;
}
}
Note that they are ordered by importance, least to greatest.
Oh, you might want to add
Rank playerRank; to Player.java and in the constructor set to
playerRank = Rank.GUEST;
Oh yeah, we need to fix the crowns now.
In Client, find
handler.players[i2].sendpm(Misc.playerNameToInt64(playerName) in packet 126 (PMs) and replace that line with
handler.players[i2].sendpm(Misc.playerNameToInt64(playerName), playerRank.getCrownLevel(), pmchatText, pmchatTextSize);
then in void run where you write the playerLevel, replace that with
out.write(playerRank.getCrownLevel());
Z0MG how do I SAIVE AND LOED NAOOO???
Simple.
characterfile.write("character-rank = ", 0, 17);
characterfile.write(c.playerRank.toString(), 0, c.playerRank.toString().length());
characterfile.newLine();
else if (token.equals("character-rank"))
{
c.playerRank = Rank.valueOf(token2);
}
So now, lets pretend we want to print someone's rank(admin, mod, etc). Instead of checking playerLevel == 1, mod, we just print out the playerRank.toString()
Need something to be mod up?
if (playerRank.getCrownLevel() >= 1)
What about owner of dev only?
if (playerRank == Rank.OWNER)
if (playerRank == Rank.DEVELOPER)
YAY!
/**
* Contain/handle possible player ranks
*
* @author Shaun
*
*/
public enum Rank
{
GUEST(0),
MEMBER(0),
MODERATOR(1),
ADMINISTRATOR(2),
DEVELOPER(2),
OWNER(2);
private final int CROWN_LEVEL; // crown level of the rank (0-2, normal being the lowest, admin crown the highest)
/**
* Initiate rank
*
* @param crownLevel
* crown level of the rank (0-2, normal being the lowest, admin
* crown the highest)
*/
Rank(int crownLevel)
{
this.CROWN_LEVEL = crownLevel;
}
/**
* @return staff/crown level of the rank
*/
public int getCrownLevel()
{
return CROWN_LEVEL;
}
}
Note that they are ordered by importance, least to greatest.
Oh, you might want to add
Rank playerRank; to Player.java and in the constructor set to
playerRank = Rank.GUEST;
Oh yeah, we need to fix the crowns now.
In Client, find
handler.players[i2].sendpm(Misc.playerNameToInt64(playerName) in packet 126 (PMs) and replace that line with
handler.players[i2].sendpm(Misc.playerNameToInt64(playerName), playerRank.getCrownLevel(), pmchatText, pmchatTextSize);
then in void run where you write the playerLevel, replace that with
out.write(playerRank.getCrownLevel());
Z0MG how do I SAIVE AND LOED NAOOO???
Simple.
characterfile.write("character-rank = ", 0, 17);
characterfile.write(c.playerRank.toString(), 0, c.playerRank.toString().length());
characterfile.newLine();
else if (token.equals("character-rank"))
{
c.playerRank = Rank.valueOf(token2);
}
So now, lets pretend we want to print someone's rank(admin, mod, etc). Instead of checking playerLevel == 1, mod, we just print out the playerRank.toString()
Need something to be mod up?
if (playerRank.getCrownLevel() >= 1)
What about owner of dev only?
if (playerRank == Rank.OWNER)
if (playerRank == Rank.DEVELOPER)
YAY!