mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-25 10:14:43 +02:00
Admin notifications convenience methods handled by NotificationManager
This commit is contained in:
@ -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;
|
||||
|
||||
|
@ -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);}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
package com.gmail.nossr50.datatypes.notifications;
|
||||
|
||||
public enum SensitiveCommandType {
|
||||
XPRATE_MODIFY,
|
||||
XPRATE_END,
|
||||
MMOEDIT
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ General:
|
||||
MOTD_Enabled: true
|
||||
EventBroadcasts: true
|
||||
EventInfoOnPlayerJoin: true
|
||||
AdminNotifications: true
|
||||
# Send a message to the player when his profile was successfully loaded
|
||||
Show_Profile_Loaded: false
|
||||
# Amount of time (in minutes) to wait between saves of player information
|
||||
|
@ -826,13 +826,17 @@ Commands.Event.Stop.Subtitle=[[GREEN]]I hope you had fun!
|
||||
Commands.Event.XP=[[DARK_AQUA]]XP Rate is now [[GOLD]]{0}[[DARK_AQUA]]x
|
||||
Commands.xprate.started.0=[[GOLD]]XP EVENT FOR mcMMO HAS STARTED!
|
||||
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=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
|
||||
|
||||
# Admin Notifications
|
||||
Server.ConsoleName=[Server Console]
|
||||
Notifications.Admin=[[GOLD]]([[GREEN]]mcMMO [[DARK_AQUA]]Admin Notification[[GOLD]]) [[GRAY]]{0}
|
||||
Notifications.Admin.XPRate.Start.Self=[[GREEN]]You have set the XP rate to [[GOLD]]{0}[[GREEN]]x!
|
||||
Notifications.Admin.XPRate.End.Self=[[GRAY]]You ended the XP rate event.
|
||||
Notifications.Admin.XPRate.End.Others=The user {0} [[GRAY]]has ended the XP rate event
|
||||
Notifications.Admin.XPRate.Start.Others=The user {0} [[GRAY]]has started or modified an XP rate event with properties: {1}x
|
||||
Notifications.Admin.Format=[[GOLD]]([[GREEN]]mcMMO [[DARK_AQUA]]Admin Notification[[GOLD]]) [[GRAY]]{0}
|
||||
|
||||
# Event
|
||||
XPRate.Event=[[GOLD]]mcMMO is currently in an XP rate event! XP rate is {0}x!
|
||||
|
||||
#GUIDES
|
||||
Guides.Available=[[GRAY]]Guide for {0} available - type /{1} ? [page]
|
||||
|
Reference in New Issue
Block a user