From b0dc41b4d97a9eeb4218e7cac674b186e9ed4882 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Sat, 18 May 2019 08:12:32 -0700 Subject: [PATCH] Encapsulate admin notifications + add prefix --- .../gmail/nossr50/commands/XprateCommand.java | 24 +++---------------- .../nossr50/listeners/BlockListener.java | 5 +++- .../nossr50/listeners/EntityListener.java | 5 ---- .../nossr50/listeners/PlayerListener.java | 2 +- .../gmail/nossr50/locale/LocaleLoader.java | 7 +----- .../util/player/NotificationManager.java | 21 ++++++++++++++++ .../resources/locale/locale_en_US.properties | 5 ++-- 7 files changed, 33 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/commands/XprateCommand.java b/src/main/java/com/gmail/nossr50/commands/XprateCommand.java index 7a2ad6934..a7f5275ef 100644 --- a/src/main/java/com/gmail/nossr50/commands/XprateCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/XprateCommand.java @@ -10,7 +10,6 @@ import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.player.NotificationManager; import com.google.common.collect.ImmutableList; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -18,7 +17,6 @@ import org.bukkit.command.TabExecutor; import org.bukkit.entity.Player; import org.bukkit.util.StringUtil; -import java.security.Permission; import java.util.ArrayList; import java.util.List; @@ -61,17 +59,9 @@ public class XprateCommand implements TabExecutor { senderName = ((Player) sender).getDisplayName(); } - for(Player player : Bukkit.getServer().getOnlinePlayers()) - { - if(player.isOp() || Permissions.adminChat(player)) - { - player.sendMessage(LocaleLoader.getString("XPRate.AdminDetails.End", senderName)); - } - } - + NotificationManager.sendAdminNotification(LocaleLoader.getString("XPRate.AdminDetails.End", senderName)); sender.sendMessage(LocaleLoader.getString("XPRate.End")); - mcMMO.p.toggleXpEventEnabled(); } @@ -122,7 +112,6 @@ public class XprateCommand implements TabExecutor { mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Commands.Event.XP", newXpRate)); } - String senderName = LocaleLoader.getString("Server.ConsoleName"); if(sender instanceof Player) @@ -130,17 +119,10 @@ public class XprateCommand implements TabExecutor { senderName = ((Player) sender).getDisplayName(); } - for(Player player : Bukkit.getServer().getOnlinePlayers()) - { - if(player.isOp() || Permissions.adminChat(player)) - { - player.sendMessage(LocaleLoader.getString("XPRate.AdminDetails.Start", senderName, newXpRate)); - } - } - + //Admin notification + NotificationManager.sendAdminNotification(LocaleLoader.getString("XPRate.AdminDetails.Start", senderName, newXpRate)); sender.sendMessage(LocaleLoader.getString("XPRate.Modified", newXpRate)); - return true; default: diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index e20334dc4..eef643ec5 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -30,7 +30,10 @@ import com.gmail.nossr50.util.sounds.SoundManager; import com.gmail.nossr50.util.sounds.SoundType; import com.gmail.nossr50.worldguard.WorldGuardManager; import com.gmail.nossr50.worldguard.WorldGuardUtils; -import org.bukkit.*; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Tag; import org.bukkit.block.*; import org.bukkit.entity.Item; import org.bukkit.entity.Player; diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index 7681e196a..79c4999e3 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -4,7 +4,6 @@ import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.WorldBlacklist; import com.gmail.nossr50.config.experience.ExperienceConfig; -import com.gmail.nossr50.datatypes.meta.OldName; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.datatypes.skills.subskills.interfaces.InteractType; @@ -25,7 +24,6 @@ import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.skills.CombatUtils; import com.gmail.nossr50.worldguard.WorldGuardManager; import com.gmail.nossr50.worldguard.WorldGuardUtils; -import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.OfflinePlayer; import org.bukkit.block.Block; @@ -40,13 +38,10 @@ import org.bukkit.event.entity.EntityDamageEvent.DamageModifier; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.metadata.FixedMetadataValue; -import org.bukkit.metadata.MetadataValue; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.projectiles.ProjectileSource; -import java.util.List; - public class EntityListener implements Listener { private final mcMMO plugin; diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index 9630db029..ff9c6cd46 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -10,6 +10,7 @@ import com.gmail.nossr50.datatypes.chat.ChatMode; import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; +import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.party.ShareHandler; @@ -29,7 +30,6 @@ import com.gmail.nossr50.util.sounds.SoundManager; import com.gmail.nossr50.util.sounds.SoundType; import com.gmail.nossr50.worldguard.WorldGuardManager; import com.gmail.nossr50.worldguard.WorldGuardUtils; -import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Material; diff --git a/src/main/java/com/gmail/nossr50/locale/LocaleLoader.java b/src/main/java/com/gmail/nossr50/locale/LocaleLoader.java index 2bde9ea52..42df75d0f 100644 --- a/src/main/java/com/gmail/nossr50/locale/LocaleLoader.java +++ b/src/main/java/com/gmail/nossr50/locale/LocaleLoader.java @@ -10,12 +10,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.text.MessageFormat; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; -import java.util.MissingResourceException; -import java.util.PropertyResourceBundle; -import java.util.ResourceBundle; +import java.util.*; import java.util.logging.Level; public final class LocaleLoader { diff --git a/src/main/java/com/gmail/nossr50/util/player/NotificationManager.java b/src/main/java/com/gmail/nossr50/util/player/NotificationManager.java index 2f46df5a0..18ffed705 100644 --- a/src/main/java/com/gmail/nossr50/util/player/NotificationManager.java +++ b/src/main/java/com/gmail/nossr50/util/player/NotificationManager.java @@ -6,7 +6,10 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.events.skills.McMMOPlayerNotificationEvent; +import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.Misc; +import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.TextComponentFactory; import com.gmail.nossr50.util.sounds.SoundManager; import com.gmail.nossr50.util.sounds.SoundType; @@ -154,4 +157,22 @@ public class NotificationManager { String.valueOf(RankUtils.getRank(mcMMOPlayer.getPlayer(), subSkillType)))));*/ } + + /** + * Sends a message to all admins with the admin notification formatting from the locale + * Admins are currently players with either Operator status or Admin Chat permission + * @param msg message contents + */ + public static void sendAdminNotification(String msg) { + for(Player player : Bukkit.getServer().getOnlinePlayers()) + { + if(player.isOp() || Permissions.adminChat(player)) + { + player.sendMessage(LocaleLoader.getString("Notifications.Admin", msg)); + } + } + + //Copy it out to Console too + mcMMO.p.getLogger().info(LocaleLoader.getString("Notifications.Admin", msg)); + } } diff --git a/src/main/resources/locale/locale_en_US.properties b/src/main/resources/locale/locale_en_US.properties index ccbb855f7..34a6aad2f 100644 --- a/src/main/resources/locale/locale_en_US.properties +++ b/src/main/resources/locale/locale_en_US.properties @@ -829,9 +829,10 @@ Commands.xprate.started.1=[[GOLD]]mcMMO XP RATE IS NOW {0}x! XPRate.Modified=[[GREEN]]You have set the XP rate to [[GOLD]]{0}[[GREEN]]x! XPRate.End=[[GRAY]]You ended the XP rate event. XPRate.Event= [[GOLD]]mcMMO is currently in an XP rate event! XP rate is {0}x! -XPRate.AdminDetails.End=[[GOLD]](Admin Notification) [[GRAY]]The user {0} [[GRAY]]has ended the XP rate event -XPRate.AdminDetails.Start=[[GOLD]](Admin Notification) [[GRAY]]The user {0} [[GRAY]]has started an XP rate event of {1}x +XPRate.AdminDetails.End=The user {0} [[GRAY]]has ended the XP rate event +XPRate.AdminDetails.Start=The user {0} [[GRAY]]has started an XP rate event of {1}x Server.ConsoleName=[Server Console] +Notifications.Admin=[[GOLD]]([[GREEN]]mcMMO [[DARK_AQUA]]Admin Notification[[GOLD]]) [[GRAY]]{0} #GUIDES Guides.Available=[[GRAY]]Guide for {0} available - type /{1} ? [page]