mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-25 10:14:43 +02:00
Confirmation messages for admin commands are now moved into the
convenience methods in NotificationManager
This commit is contained in:
@ -54,7 +54,6 @@ public class XprateCommand implements TabExecutor {
|
||||
}
|
||||
|
||||
NotificationManager.processSensitiveCommandNotification(sender, SensitiveCommandType.XPRATE_END);
|
||||
sender.sendMessage(LocaleLoader.getString("Notifications.Admin.XPRate.End.Self"));
|
||||
|
||||
mcMMO.p.toggleXpEventEnabled();
|
||||
}
|
||||
@ -108,7 +107,6 @@ public class XprateCommand implements TabExecutor {
|
||||
|
||||
//Admin notification
|
||||
NotificationManager.processSensitiveCommandNotification(sender, SensitiveCommandType.XPRATE_MODIFY, String.valueOf(newXpRate));
|
||||
sender.sendMessage(LocaleLoader.getString("Notifications.Admin.XPRate.Start.Self", newXpRate));
|
||||
|
||||
return true;
|
||||
|
||||
|
@ -11,6 +11,7 @@ import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.StringUtils;
|
||||
import com.gmail.nossr50.util.TextComponentFactory;
|
||||
import com.gmail.nossr50.util.commands.CommandUtils;
|
||||
import com.gmail.nossr50.util.player.NotificationManager;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import com.gmail.nossr50.util.random.RandomChanceUtil;
|
||||
import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
|
||||
@ -268,21 +269,11 @@ public abstract class SkillCommand implements TabExecutor {
|
||||
return LocaleLoader.getString(templateKey, LocaleLoader.getString(statDescriptionKey, vars));
|
||||
else
|
||||
{
|
||||
String[] mergedList = addItemToFirstPositionOfArray(LocaleLoader.getString(statDescriptionKey), vars);
|
||||
String[] mergedList = NotificationManager.addItemToFirstPositionOfArray(LocaleLoader.getString(statDescriptionKey), vars);
|
||||
return LocaleLoader.getString(templateKey, mergedList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String[] addItemToFirstPositionOfArray(String itemToAdd, String... existingArray) {
|
||||
String[] newArray = new String[existingArray.length + 1];
|
||||
newArray[0] = itemToAdd;
|
||||
|
||||
System.arraycopy(existingArray, 0, newArray, 1, existingArray.length);
|
||||
|
||||
return newArray;
|
||||
}
|
||||
|
||||
protected abstract void dataCalculations(Player player, float skillValue);
|
||||
|
||||
protected abstract void permissionsCheck(Player player);
|
||||
|
@ -164,19 +164,28 @@ public class NotificationManager {
|
||||
/**
|
||||
* 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
|
||||
* @param msg message fetched from locale
|
||||
*/
|
||||
private static void sendAdminNotification(String msg) {
|
||||
for(Player player : Bukkit.getServer().getOnlinePlayers())
|
||||
{
|
||||
if(player.isOp() || Permissions.adminChat(player))
|
||||
{
|
||||
player.sendMessage(LocaleLoader.getString("Notifications.Admin", msg));
|
||||
player.sendMessage(LocaleLoader.getString("Notifications.Admin.Format.Others", msg));
|
||||
}
|
||||
}
|
||||
|
||||
//Copy it out to Console too
|
||||
mcMMO.p.getLogger().info(LocaleLoader.getString("Notifications.Admin", msg));
|
||||
mcMMO.p.getLogger().info(LocaleLoader.getString("Notifications.Admin.Format.Others", msg));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a confirmation message to the CommandSender who just executed an admin command
|
||||
* @param commandSender target command sender
|
||||
* @param msg message fetched from locale
|
||||
*/
|
||||
private static void sendAdminCommandConfirmation(CommandSender commandSender, String msg) {
|
||||
commandSender.sendMessage(LocaleLoader.getString("Notifications.Admin.Format.Self", msg));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -203,11 +212,30 @@ public class NotificationManager {
|
||||
switch(sensitiveCommandType)
|
||||
{
|
||||
case XPRATE_MODIFY:
|
||||
sendAdminNotification(LocaleLoader.getString("Notifications.Admin.XPRate.Start.Others", senderName, args));
|
||||
sendAdminNotification(LocaleLoader.getString("Notifications.Admin.XPRate.Start.Others", addItemToFirstPositionOfArray(senderName, args)));
|
||||
sendAdminCommandConfirmation(commandSender, LocaleLoader.getString("Notifications.Admin.XPRate.Start.Self", args));
|
||||
break;
|
||||
case XPRATE_END:
|
||||
sendAdminNotification(LocaleLoader.getString("Notifications.Admin.XPRate.End.Others", senderName, args));
|
||||
sendAdminNotification(LocaleLoader.getString("Notifications.Admin.XPRate.End.Others", addItemToFirstPositionOfArray(senderName, args)));
|
||||
sendAdminCommandConfirmation(commandSender, LocaleLoader.getString("Notifications.Admin.XPRate.End.Self", args));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes an array and an object, makes a new array with object in the first position of the new array,
|
||||
* and the following elements in this new array being a copy of the existing array retaining their order
|
||||
* @param itemToAdd the string to put at the beginning of the new array
|
||||
* @param existingArray the existing array to be copied to the new array at position [0]+1 relative to their original index
|
||||
* @return the new array combining itemToAdd at the start and existing array elements following while retaining their order
|
||||
*/
|
||||
public static String[] addItemToFirstPositionOfArray(String itemToAdd, String... existingArray) {
|
||||
String[] newArray = new String[existingArray.length + 1];
|
||||
newArray[0] = itemToAdd;
|
||||
|
||||
System.arraycopy(existingArray, 0, newArray, 1, existingArray.length);
|
||||
|
||||
return newArray;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -829,11 +829,12 @@ Commands.xprate.started.1=[[GOLD]]mcMMO XP RATE IS NOW {0}x!
|
||||
|
||||
# Admin Notifications
|
||||
Server.ConsoleName=[Server Console]
|
||||
Notifications.Admin.XPRate.Start.Self=[[GREEN]]You have set the XP rate to [[GOLD]]{0}[[GREEN]]x!
|
||||
Notifications.Admin.XPRate.Start.Self=[[GRAY]]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}
|
||||
Notifications.Admin.Format.Others=[[GOLD]]([[GREEN]]mcMMO [[DARK_AQUA]]Admin Notification[[GOLD]]) [[GRAY]]{0}
|
||||
Notifications.Admin.Format.Self=[[GOLD]]([[GREEN]]mcMMO [[DARK_RED]]Admin Command Executed[[GOLD]]) [[GRAY]]{0}
|
||||
|
||||
# Event
|
||||
XPRate.Event=[[GOLD]]mcMMO is currently in an XP rate event! XP rate is {0}x!
|
||||
|
Reference in New Issue
Block a user