mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-08-02 12:35:27 +02:00
Rewrite NotificationManager to handle more flexible config options
This commit is contained in:
@@ -16,7 +16,7 @@ import com.gmail.nossr50.config.hocon.metrics.ConfigMetrics;
|
||||
import com.gmail.nossr50.config.hocon.mobs.ConfigMobs;
|
||||
import com.gmail.nossr50.config.hocon.motd.ConfigMOTD;
|
||||
import com.gmail.nossr50.config.hocon.notifications.ConfigNotifications;
|
||||
import com.gmail.nossr50.config.hocon.notifications.PlayerNotification;
|
||||
import com.gmail.nossr50.config.hocon.notifications.PlayerNotificationSettings;
|
||||
import com.gmail.nossr50.config.hocon.particles.ConfigParticles;
|
||||
import com.gmail.nossr50.config.hocon.party.ConfigParty;
|
||||
import com.gmail.nossr50.config.hocon.party.data.ConfigPartyData;
|
||||
@@ -273,7 +273,7 @@ public final class ConfigManager {
|
||||
customSerializers.registerType(TypeToken.of(SkillCeiling.class), new SkillCeilingSerializer());
|
||||
customSerializers.registerType(TypeToken.of(SkillRankProperty.class), new SkillRankPropertySerializer());
|
||||
customSerializers.registerType(TypeToken.of(MaxBonusLevel.class), new MaxBonusLevelSerializer());
|
||||
customSerializers.registerType(TypeToken.of(PlayerNotification.class), new PlayerNotificationSerializer());
|
||||
customSerializers.registerType(TypeToken.of(PlayerNotificationSettings.class), new PlayerNotificationSerializer());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -49,11 +49,11 @@ public class ConfigNotifications {
|
||||
return configNotificationGeneral;
|
||||
}
|
||||
|
||||
public HashMap<NotificationType, PlayerNotification> getNotificationSettingHashMap() {
|
||||
public HashMap<NotificationType, PlayerNotificationSettings> getNotificationSettingHashMap() {
|
||||
return playerNotifications.getNotificationSettingHashMap();
|
||||
}
|
||||
|
||||
public PlayerNotification getPlayerNotification(NotificationType notificationType) {
|
||||
public PlayerNotificationSettings getPlayerNotification(NotificationType notificationType) {
|
||||
return playerNotifications.getPlayerNotification(notificationType);
|
||||
}
|
||||
}
|
||||
|
@@ -9,36 +9,36 @@ import java.util.HashMap;
|
||||
@ConfigSerializable
|
||||
public class ConfigPlayerNotifications {
|
||||
|
||||
private final static HashMap<NotificationType, PlayerNotification> NOTIFICATION_MAP_DEFAULT;
|
||||
private final static HashMap<NotificationType, PlayerNotificationSettings> NOTIFICATION_MAP_DEFAULT;
|
||||
|
||||
static {
|
||||
NOTIFICATION_MAP_DEFAULT = new HashMap<>();
|
||||
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.ABILITY_OFF, new PlayerNotification(true, false, true));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.HARDCORE_MODE, new PlayerNotification(true, true, true));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.REQUIREMENTS_NOT_MET, new PlayerNotification(true, false, true));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.ABILITY_COOLDOWN, new PlayerNotification(true, false, true));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.LEVEL_UP_MESSAGE, new PlayerNotification(true, true, true));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.HOLIDAY, new PlayerNotification(true, true, true));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.TOOL, new PlayerNotification(true, false, true));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.SUBSKILL_MESSAGE, new PlayerNotification(true, false, true));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.SUBSKILL_MESSAGE_FAILED, new PlayerNotification(true, true, false));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.SUBSKILL_UNLOCKED, new PlayerNotification(true, true, true));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.SUPER_ABILITY, new PlayerNotification(true, false, true));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.SUPER_ABILITY_ALERT_OTHERS, new PlayerNotification(true, true, false));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.ITEM_MESSAGE, new PlayerNotification(true, false, true));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.NO_PERMISSION, new PlayerNotification(true, true, false));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.PARTY_MESSAGE, new PlayerNotification(true, true, false));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.ABILITY_OFF, new PlayerNotificationSettings(true, false, true));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.HARDCORE_MODE, new PlayerNotificationSettings(true, true, true));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.REQUIREMENTS_NOT_MET, new PlayerNotificationSettings(true, false, true));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.ABILITY_COOLDOWN, new PlayerNotificationSettings(true, false, true));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.LEVEL_UP_MESSAGE, new PlayerNotificationSettings(true, true, true));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.HOLIDAY, new PlayerNotificationSettings(true, true, true));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.TOOL, new PlayerNotificationSettings(true, false, true));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.SUBSKILL_MESSAGE, new PlayerNotificationSettings(true, false, true));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.SUBSKILL_MESSAGE_FAILED, new PlayerNotificationSettings(true, true, false));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.SUBSKILL_UNLOCKED, new PlayerNotificationSettings(true, true, true));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.SUPER_ABILITY, new PlayerNotificationSettings(true, false, true));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.SUPER_ABILITY_ALERT_OTHERS, new PlayerNotificationSettings(true, true, false));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.ITEM_MESSAGE, new PlayerNotificationSettings(true, false, true));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.NO_PERMISSION, new PlayerNotificationSettings(true, true, false));
|
||||
NOTIFICATION_MAP_DEFAULT.put(NotificationType.PARTY_MESSAGE, new PlayerNotificationSettings(true, true, false));
|
||||
}
|
||||
|
||||
@Setting(value = "Notification-Settings")
|
||||
private HashMap<NotificationType, PlayerNotification> notificationSettingHashMap = NOTIFICATION_MAP_DEFAULT;
|
||||
private HashMap<NotificationType, PlayerNotificationSettings> notificationSettingHashMap = NOTIFICATION_MAP_DEFAULT;
|
||||
|
||||
public HashMap<NotificationType, PlayerNotification> getNotificationSettingHashMap() {
|
||||
public HashMap<NotificationType, PlayerNotificationSettings> getNotificationSettingHashMap() {
|
||||
return notificationSettingHashMap;
|
||||
}
|
||||
|
||||
public PlayerNotification getPlayerNotification(NotificationType notificationType) {
|
||||
public PlayerNotificationSettings getPlayerNotification(NotificationType notificationType) {
|
||||
return notificationSettingHashMap.get(notificationType);
|
||||
}
|
||||
}
|
@@ -1,12 +1,12 @@
|
||||
package com.gmail.nossr50.config.hocon.notifications;
|
||||
|
||||
public class PlayerNotification {
|
||||
public class PlayerNotificationSettings {
|
||||
|
||||
private boolean enabled;
|
||||
private boolean sendToChat;
|
||||
private boolean sendToActionBar;
|
||||
|
||||
public PlayerNotification(boolean enabled, boolean sendToChat, boolean sendToActionBar) {
|
||||
public PlayerNotificationSettings(boolean enabled, boolean sendToChat, boolean sendToActionBar) {
|
||||
this.enabled = enabled;
|
||||
this.sendToChat = sendToChat;
|
||||
this.sendToActionBar = sendToActionBar;
|
@@ -1,6 +1,6 @@
|
||||
package com.gmail.nossr50.config.hocon.serializers;
|
||||
|
||||
import com.gmail.nossr50.config.hocon.notifications.PlayerNotification;
|
||||
import com.gmail.nossr50.config.hocon.notifications.PlayerNotificationSettings;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
|
||||
@@ -8,24 +8,24 @@ import ninja.leaping.configurate.objectmapping.serialize.TypeSerializer;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class PlayerNotificationSerializer implements TypeSerializer<PlayerNotification> {
|
||||
public class PlayerNotificationSerializer implements TypeSerializer<PlayerNotificationSettings> {
|
||||
private static final String ENABLED_NODE = "Enabled";
|
||||
private static final String SEND_TO_CHAT_NODE = "Send-To-Chat";
|
||||
private static final String SEND_TO_ACTION_BAR_NODE = "Send-To-Action-Bar";
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PlayerNotification deserialize(@NonNull TypeToken<?> type, @NonNull ConfigurationNode value) throws ObjectMappingException {
|
||||
public PlayerNotificationSettings deserialize(@NonNull TypeToken<?> type, @NonNull ConfigurationNode value) throws ObjectMappingException {
|
||||
Boolean enabled = value.getNode(ENABLED_NODE).getValue(TypeToken.of(Boolean.class));
|
||||
Boolean sendTochat = value.getNode(SEND_TO_CHAT_NODE).getValue(TypeToken.of(Boolean.class));
|
||||
Boolean sendToActionBar = value.getNode(SEND_TO_ACTION_BAR_NODE).getValue(TypeToken.of(Boolean.class));
|
||||
|
||||
PlayerNotification playerNotification = new PlayerNotification(enabled, sendTochat, sendToActionBar);
|
||||
return playerNotification;
|
||||
PlayerNotificationSettings playerNotificationSettings = new PlayerNotificationSettings(enabled, sendTochat, sendToActionBar);
|
||||
return playerNotificationSettings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(@NonNull TypeToken<?> type, @Nullable PlayerNotification obj, @NonNull ConfigurationNode value) throws ObjectMappingException {
|
||||
public void serialize(@NonNull TypeToken<?> type, @Nullable PlayerNotificationSettings obj, @NonNull ConfigurationNode value) throws ObjectMappingException {
|
||||
value.getNode(ENABLED_NODE).setValue(obj.isEnabled());
|
||||
value.getNode(SEND_TO_CHAT_NODE).setValue(obj.isSendToChat());
|
||||
value.getNode(SEND_TO_ACTION_BAR_NODE).setValue(obj.isSendToActionBar());
|
||||
|
Reference in New Issue
Block a user