Skip to content

Commit

Permalink
fix: crash if no player is it and no players are online
Browse files Browse the repository at this point in the history
testing if the it player is null before trying to use it
  • Loading branch information
SeriousGuy888 committed Mar 12, 2022
1 parent 7786a13 commit 21c4ac2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ private void loadState() {
}

public void saveState() {
gameDataStorage.set("it", getIt().getUniqueId().toString());
OfflinePlayer it = getIt();
if(it == null) {
Bukkit.getLogger().warning("Current It was not saved as no player is It.");
return;
}
gameDataStorage.set("it", it.getUniqueId().toString());

try {
gameDataStorage.save(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public void onJoin(PlayerJoinEvent event) {
plugin.game.loadTagStats(player);

OfflinePlayer it = plugin.game.getIt();
player.sendMessage(ChatColor.GRAY + it.getName() + " is currently It.");
if(it != null)
player.sendMessage(ChatColor.GRAY + it.getName() + " is currently It.");
}

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public ChooseRandomIt(CheezSurvTagGame plugin) {
@Override
public void run() {
OfflinePlayer currentIt = plugin.game.getIt();
if(currentIt.isOnline())
if(currentIt != null && currentIt.isOnline())
return;

Player newIt = plugin.game.pickRandomIt();
Expand Down

0 comments on commit 21c4ac2

Please sign in to comment.