mcMMO now checks in all places for a loaded profile before executing processing on said profile

This commit is contained in:
nossr50
2019-04-12 15:17:05 -07:00
parent 00cc5f0845
commit 33a68daa9c
62 changed files with 560 additions and 21 deletions

View File

@ -28,7 +28,7 @@ public class NotificationManager {
*/
public static void sendPlayerInformation(Player player, NotificationType notificationType, String key)
{
if(!UserManager.getPlayer(player).useChatNotifications())
if(UserManager.getPlayer(player) == null || !UserManager.getPlayer(player).useChatNotifications())
return;
ChatMessageType destination = AdvancedConfig.getInstance().doesNotificationUseActionBar(notificationType) ? ChatMessageType.ACTION_BAR : ChatMessageType.SYSTEM;
@ -39,6 +39,15 @@ public class NotificationManager {
sendNotification(player, customEvent);
}
public static boolean doesPlayerUseNotifications(Player player)
{
if(UserManager.getPlayer(player) == null)
return false;
else
return UserManager.getPlayer(player).useChatNotifications();
}
/**
* Sends players notifications from mcMMO
* This does this by sending out an event so other plugins can cancel it
@ -60,7 +69,7 @@ public class NotificationManager {
public static void sendPlayerInformation(Player player, NotificationType notificationType, String key, String... values)
{
if(!UserManager.getPlayer(player).useChatNotifications())
if(UserManager.getPlayer(player) == null || !UserManager.getPlayer(player).useChatNotifications())
return;
ChatMessageType destination = AdvancedConfig.getInstance().doesNotificationUseActionBar(notificationType) ? ChatMessageType.ACTION_BAR : ChatMessageType.SYSTEM;
@ -108,7 +117,7 @@ public class NotificationManager {
*/
public static void sendPlayerLevelUpNotification(McMMOPlayer mcMMOPlayer, PrimarySkillType skillName, int levelsGained, int newLevel)
{
if(!UserManager.getPlayer(mcMMOPlayer.getPlayer()).useChatNotifications())
if(!mcMMOPlayer.useChatNotifications())
return;
ChatMessageType destination = AdvancedConfig.getInstance().doesNotificationUseActionBar(NotificationType.LEVEL_UP_MESSAGE) ? ChatMessageType.ACTION_BAR : ChatMessageType.SYSTEM;
@ -129,7 +138,7 @@ public class NotificationManager {
public static void sendPlayerUnlockNotification(McMMOPlayer mcMMOPlayer, SubSkillType subSkillType)
{
if(!UserManager.getPlayer(mcMMOPlayer.getPlayer()).useChatNotifications())
if(!mcMMOPlayer.useChatNotifications())
return;
//CHAT MESSAGE

View File

@ -1,5 +1,6 @@
package com.gmail.nossr50.util.player;
import com.gmail.nossr50.api.exceptions.McMMOPlayerNotFoundException;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.mcMMO;
import com.google.common.collect.ImmutableList;
@ -95,12 +96,17 @@ public final class UserManager {
return retrieveMcMMOPlayer(playerName, true);
}
public static McMMOPlayer getPlayer(Player player) {
/**
* Gets the McMMOPlayer object for a player, this can be null if the player has not yet been loaded.
* @param player target player
* @return McMMOPlayer object for this player, null if Player has not been loaded
*/
public static McMMOPlayer getPlayer(Player player) throws McMMOPlayerNotFoundException {
//Avoid Array Index out of bounds
if(player.hasMetadata(mcMMO.playerDataKey))
return (McMMOPlayer) player.getMetadata(mcMMO.playerDataKey).get(0).value();
else
return null;
throw new McMMOPlayerNotFoundException(player);
}
private static McMMOPlayer retrieveMcMMOPlayer(String playerName, boolean offlineValid) {