Fix NullPointerException when rank doesn't exist. Renamed some methods to be more descriptive.

This commit is contained in:
Beny 2019-05-15 21:36:11 +01:00
parent ea5811800d
commit 8254e7de61
4 changed files with 11 additions and 5 deletions

View File

@ -41,7 +41,7 @@ public class GiveRankCommand extends Command
} }
else else
{ {
rank = Emulator.getGameEnvironment().getPermissionsManager().getRank(params[2]); rank = Emulator.getGameEnvironment().getPermissionsManager().getRankByName(params[2]);
} }
if (rank != null) if (rank != null)

View File

@ -108,7 +108,7 @@ public class PermissionsManager
} }
public Rank getRank(String rankName) public Rank getRankByName(String rankName)
{ {
for (Rank rank : this.ranks.valueCollection()) for (Rank rank : this.ranks.valueCollection())
{ {
@ -161,8 +161,12 @@ public class PermissionsManager
return this.badges.keySet(); return this.badges.keySet();
} }
public List<Rank> getRanks(String code) public List<Rank> getRanksByBadgeCode(String code)
{ {
return this.badges.get(code); return this.badges.get(code);
} }
public List<Rank> getAllRanks() {
return new ArrayList<>(this.ranks.valueCollection());
}
} }

View File

@ -80,6 +80,8 @@ public class HabboInfo implements Runnable
if (this.rank == null) if (this.rank == null)
{ {
Emulator.getLogging().logErrorLine("No existing rank found with id " + set.getInt("rank") + ". Make sure an entry in the permissions table exists."); Emulator.getLogging().logErrorLine("No existing rank found with id " + set.getInt("rank") + ". Make sure an entry in the permissions table exists.");
Emulator.getLogging().logUserLine(this.username + " has an invalid rank with id " + set.getInt("rank") + ". Make sure an entry in the permissions table exists.");
this.rank = Emulator.getGameEnvironment().getPermissionsManager().getRank(1);
} }
this.accountCreated = set.getInt("account_created"); this.accountCreated = set.getInt("account_created");
@ -514,7 +516,7 @@ public class HabboInfo implements Runnable
statement.setInt(6, Emulator.getIntUnixTimestamp()); statement.setInt(6, Emulator.getIntUnixTimestamp());
statement.setInt(8, this.homeRoom); statement.setInt(8, this.homeRoom);
statement.setString(9, this.ipLogin); statement.setString(9, this.ipLogin);
statement.setInt(10, this.rank.getId()); statement.setInt(10, this.rank != null ? this.rank.getId() : 1);
statement.setString(11, this.machineID); statement.setString(11, this.machineID);
statement.setString(12, this.username); statement.setString(12, this.username);
statement.setInt(13, this.id); statement.setInt(13, this.id);

View File

@ -41,7 +41,7 @@ public class BadgesComponent
{ {
boolean delete = true; boolean delete = true;
for (Rank rank : Emulator.getGameEnvironment().getPermissionsManager().getRanks(badge.getCode())) for (Rank rank : Emulator.getGameEnvironment().getPermissionsManager().getRanksByBadgeCode(badge.getCode()))
{ {
if (rank.getId() == habbo.getHabboInfo().getRank().getId()) if (rank.getId() == habbo.getHabboInfo().getRank().getId())
{ {