Rewrite of McMMOPlayerNotificationEvent

This commit is contained in:
nossr50 2019-06-13 11:28:10 -07:00
parent bdd0335d0b
commit 8abccfc9cd
3 changed files with 97 additions and 31 deletions

View File

@ -153,6 +153,9 @@ Version 2.2.0
Config_Update_Overwrite, Tool_Mods_Enabled, Armor_Mods_Enabled, Block_Mods_Enabled, Entity_Mods_Enabled, ExperienceConversionMultiplier Config_Update_Overwrite, Tool_Mods_Enabled, Armor_Mods_Enabled, Block_Mods_Enabled, Entity_Mods_Enabled, ExperienceConversionMultiplier
API Changes API Changes
Restructured McMMOPlayerNotificationEvent to accommodate for new changes in NotificationManager
Now Notification events are no longer assumed to be sending to the action bar with an option to have a copy sent to chat
Notifications are now sent to either chat, actionbar, both or neither. The PlayerNotification type holds information on this. You can modify the event to change this how you wish if you hook into mcMMO.
Added PrimarySkillType::getCapitalizedName Added PrimarySkillType::getCapitalizedName
Config settings can now be found in the ConfigManager (getter for it in mcMMO.java) Config settings can now be found in the ConfigManager (getter for it in mcMMO.java)
Collection values from the config get converted into a runtime appropriate dataset, those can be found in DynamicSettingsManager (getter for it in mcMMO.java) Collection values from the config get converted into a runtime appropriate dataset, those can be found in DynamicSettingsManager (getter for it in mcMMO.java)

View File

@ -1,8 +1,10 @@
package com.gmail.nossr50.events.skills; package com.gmail.nossr50.events.skills;
import com.gmail.nossr50.config.hocon.notifications.PlayerNotification;
import com.gmail.nossr50.datatypes.interactions.NotificationType; import com.gmail.nossr50.datatypes.interactions.NotificationType;
import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.craftbukkit.libs.jline.internal.Nullable;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.Event; import org.bukkit.event.Event;
@ -10,26 +12,23 @@ import org.bukkit.event.HandlerList;
/** /**
* This event is sent for when mcMMO informs a player about various important information * This event is sent for when mcMMO informs a player about various important information
* Contains a TextComponent if the message contains complex features such as hover objects, clickables, etc
* TextComponent is not guaranteed to exist, but often it does
*/ */
public class McMMOPlayerNotificationEvent extends Event implements Cancellable { public class McMMOPlayerNotificationEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
protected final NotificationType notificationType; private PlayerNotification playerNotification;
protected ChatMessageType chatMessageType; private Player recipient;
protected TextComponent notificationTextComponent;
private boolean isCancelled; private boolean isCancelled;
/* private NotificationType notificationType;
* Messages can be sent to both places, as configured in advanced.yml private TextComponent textComponent;
* If isBeingSentToActionBar is false, then messages will ALWAYS be sent to the chat bar
* isMessageAlsoBeingSentToChat just indicates a copy of that message will be sent to chat
*/
private boolean isMessageAlsoBeingSentToChat;
public McMMOPlayerNotificationEvent(Player who, NotificationType notificationType, TextComponent notificationTextComponent, ChatMessageType chatMessageType, boolean isMessageAlsoBeingSentToChat) { public McMMOPlayerNotificationEvent(NotificationType notificationType, Player recipient, PlayerNotification playerNotification, TextComponent textComponent) {
super(false); super(false);
this.notificationType = notificationType; this.notificationType = notificationType;
this.notificationTextComponent = notificationTextComponent; this.recipient = recipient;
this.chatMessageType = chatMessageType; this.playerNotification = playerNotification;
this.isMessageAlsoBeingSentToChat = isMessageAlsoBeingSentToChat; this.textComponent = textComponent;
isCancelled = false; isCancelled = false;
} }
@ -37,33 +36,80 @@ public class McMMOPlayerNotificationEvent extends Event implements Cancellable {
* Getters & Setters * Getters & Setters
*/ */
/**
* Whether or not this notification event uses a text component
* @return true if this notification has a text component
*/
public boolean hasTextComponent() {
return textComponent != null;
}
/**
* The recipient of this notification
* @return the recipient of this notification
*/
public Player getRecipient() {
return recipient;
}
public void setRecipient(Player recipient) {
this.recipient = recipient;
}
/**
* Is this notification being sent to chat
* @return true if being sent to chat
*/
public boolean isBeingSentToChat() {
return playerNotification.isSendToChat();
}
/**
* Is this notification being sent to action bar
* @return true if being sent to action bar
*/
public boolean isBeingSentToActionBar() {
return playerNotification.isSendToActionBar();
}
/**
* Change whether or not this notification sends to chat
* @param sendToChat new value
*/
public void setSendToChat(boolean sendToChat) {
playerNotification.setSendToChat(sendToChat);
}
/**
* Change whether or not this notification sends to action bar
* @param sendToActionBar new value
*/
public void setSendToActionBar(boolean sendToActionBar) {
playerNotification.setSendToActionBar(sendToActionBar);
}
public static HandlerList getHandlerList() { public static HandlerList getHandlerList() {
return handlers; return handlers;
} }
public boolean isMessageAlsoBeingSentToChat() { /**
return isMessageAlsoBeingSentToChat; * Get the text component if it exists
} * @return the text component if it exists
*/
public void setMessageAlsoBeingSentToChat(boolean messageAlsoBeingSentToChat) {
isMessageAlsoBeingSentToChat = messageAlsoBeingSentToChat;
}
public TextComponent getNotificationTextComponent() { public TextComponent getNotificationTextComponent() {
return notificationTextComponent; return textComponent;
} }
public void setNotificationTextComponent(TextComponent notificationTextComponent) { /**
this.notificationTextComponent = notificationTextComponent; * Override the text component for this event
* Note that not all events are using a text component
* If you set one and it didn't exist before, then mcMMO will use the text component instead of the raw message
* @param textComponent new text component
*/
public void setNotificationTextComponent(TextComponent textComponent) {
this.textComponent = textComponent;
} }
public ChatMessageType getChatMessageType() {
return chatMessageType;
}
public void setChatMessageType(ChatMessageType chatMessageType) {
this.chatMessageType = chatMessageType;
}
/* /*
* Custom Event Boilerplate * Custom Event Boilerplate

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.util.player; package com.gmail.nossr50.util.player;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.hocon.notifications.PlayerNotification;
import com.gmail.nossr50.datatypes.interactions.NotificationType; import com.gmail.nossr50.datatypes.interactions.NotificationType;
import com.gmail.nossr50.datatypes.notifications.SensitiveCommandType; import com.gmail.nossr50.datatypes.notifications.SensitiveCommandType;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
@ -22,7 +23,23 @@ import org.bukkit.SoundCategory;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.HashMap;
public class NotificationManager { public class NotificationManager {
private HashMap<NotificationType, PlayerNotification> playerNotificationHashMap;
public NotificationManager() {
playerNotificationHashMap = new HashMap<>();
initMaps();
}
private void initMaps() {
//Copy the map
playerNotificationHashMap = new HashMap<>(mcMMO.getConfigManager().getConfigNotifications().getNotificationSettingHashMap());
}
/** /**
* Sends players notifications from mcMMO * Sends players notifications from mcMMO
* This does this by sending out an event so other plugins can cancel it * This does this by sending out an event so other plugins can cancel it