Admin notifications convenience methods handled by NotificationManager

This commit is contained in:
nossr50
2019-05-18 10:09:45 -07:00
parent b0dc41b4d9
commit 04c6bd8750
7 changed files with 69 additions and 29 deletions

View File

@ -3,6 +3,7 @@ package com.gmail.nossr50.commands;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.notifications.SensitiveCommandType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.Permissions;
@ -52,15 +53,8 @@ public class XprateCommand implements TabExecutor {
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Commands.Event.Stop.Subtitle"));
}
String senderName = LocaleLoader.getString("Server.ConsoleName");
if(sender instanceof Player)
{
senderName = ((Player) sender).getDisplayName();
}
NotificationManager.sendAdminNotification(LocaleLoader.getString("XPRate.AdminDetails.End", senderName));
sender.sendMessage(LocaleLoader.getString("XPRate.End"));
NotificationManager.processSensitiveCommandNotification(sender, SensitiveCommandType.XPRATE_END);
sender.sendMessage(LocaleLoader.getString("Notifications.Admin.XPRate.End.Self"));
mcMMO.p.toggleXpEventEnabled();
}
@ -112,16 +106,9 @@ 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)
{
senderName = ((Player) sender).getDisplayName();
}
//Admin notification
NotificationManager.sendAdminNotification(LocaleLoader.getString("XPRate.AdminDetails.Start", senderName, newXpRate));
sender.sendMessage(LocaleLoader.getString("XPRate.Modified", newXpRate));
NotificationManager.processSensitiveCommandNotification(sender, SensitiveCommandType.XPRATE_MODIFY, String.valueOf(newXpRate));
sender.sendMessage(LocaleLoader.getString("Notifications.Admin.XPRate.Start.Self", newXpRate));
return true;

View File

@ -570,4 +570,6 @@ public class Config extends AutoUpdateConfigLoader {
public boolean broadcastEventMessages() { return config.getBoolean("General.EventBroadcasts", true);}
public boolean playerJoinEventInfo() { return config.getBoolean("General.EventInfoOnPlayerJoin", true);}
public boolean adminNotifications() { return config.getBoolean("General.AdminNotifications", true);}
}

View File

@ -0,0 +1,7 @@
package com.gmail.nossr50.datatypes.notifications;
public enum SensitiveCommandType {
XPRATE_MODIFY,
XPRATE_END,
MMOEDIT
}

View File

@ -1,7 +1,9 @@
package com.gmail.nossr50.util.player;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.interactions.NotificationType;
import com.gmail.nossr50.datatypes.notifications.SensitiveCommandType;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
@ -19,6 +21,7 @@ import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.SoundCategory;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class NotificationManager {
@ -163,7 +166,7 @@ public class NotificationManager {
* Admins are currently players with either Operator status or Admin Chat permission
* @param msg message contents
*/
public static void sendAdminNotification(String msg) {
private static void sendAdminNotification(String msg) {
for(Player player : Bukkit.getServer().getOnlinePlayers())
{
if(player.isOp() || Permissions.adminChat(player))
@ -175,4 +178,36 @@ public class NotificationManager {
//Copy it out to Console too
mcMMO.p.getLogger().info(LocaleLoader.getString("Notifications.Admin", msg));
}
/**
* Convenience method to report info about a command sender using a sensitive command
* @param commandSender the command user
* @param sensitiveCommandType type of command issued
*/
public static void processSensitiveCommandNotification(CommandSender commandSender, SensitiveCommandType sensitiveCommandType, String... args) {
//If its not enabled exit
if(!Config.getInstance().adminNotifications())
return;
/*
* Determine the 'identity' of the one who executed the command to pass as a parameters
*/
String senderName = LocaleLoader.getString("Server.ConsoleName");
if(commandSender instanceof Player)
{
senderName = ((Player) commandSender).getDisplayName();
}
//Send the notification
switch(sensitiveCommandType)
{
case XPRATE_MODIFY:
sendAdminNotification(LocaleLoader.getString("Notifications.Admin.XPRate.Start.Others", senderName, args));
break;
case XPRATE_END:
sendAdminNotification(LocaleLoader.getString("Notifications.Admin.XPRate.End.Others", senderName, args));
break;
}
}
}