Add minimum rank to Announcement Command

This commit is contained in:
Shaun Bennett 2015-12-06 00:15:49 -05:00
parent 8d831d5228
commit 618105b4c8
3 changed files with 47 additions and 8 deletions

View File

@ -10,6 +10,7 @@ import mineplex.core.message.MessageManager;
import mineplex.serverdata.commands.AnnouncementCommand; import mineplex.serverdata.commands.AnnouncementCommand;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class AnnounceCommand extends CommandBase<MessageManager> public class AnnounceCommand extends CommandBase<MessageManager>
@ -22,13 +23,25 @@ public class AnnounceCommand extends CommandBase<MessageManager>
@Override @Override
public void Execute(Player caller, String[] args) public void Execute(Player caller, String[] args)
{ {
if (args == null || args.length == 0) if (args == null || args.length <= 1)
{ {
Plugin.Help(caller); Plugin.Help(caller);
} }
else else
{ {
new AnnouncementCommand(true, F.combine(args, 0, null, false)).publish(); Rank rank = Rank.ALL;
try
{
rank = Rank.valueOf(args[0]);
}
catch (IllegalArgumentException ex)
{
UtilPlayer.message(caller, F.main(Plugin.getName(), ChatColor.RED + "" + ChatColor.BOLD + "Invalid rank!"));
return;
}
new AnnouncementCommand(true, rank.toString(), F.combine(args, 1, null, false)).publish();
} }
} }
} }

View File

@ -1,5 +1,7 @@
package mineplex.core.message.redis; package mineplex.core.message.redis;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
@ -13,21 +15,42 @@ import org.bukkit.entity.Player;
public class AnnouncementHandler implements CommandCallback public class AnnouncementHandler implements CommandCallback
{ {
private CoreClientManager _clientManager;
public AnnouncementHandler(CoreClientManager clientManager)
{
_clientManager = clientManager;
}
public void run(ServerCommand command) public void run(ServerCommand command)
{ {
if (command instanceof AnnouncementCommand) if (command instanceof AnnouncementCommand)
{ {
AnnouncementCommand announcementCommand = (AnnouncementCommand)command; AnnouncementCommand announcementCommand = (AnnouncementCommand)command;
String message = announcementCommand.getMessage(); Rank rank;
try
{
rank = Rank.valueOf(announcementCommand.getRank());
}
catch (Exception e)
{
e.printStackTrace();
return;
}
if (announcementCommand.getDisplayTitle()) String message = announcementCommand.getMessage();
UtilTextMiddle.display(C.cYellow + "Announcement", message, 10, 120, 10);
for (Player player : Bukkit.getOnlinePlayers()) for (Player player : Bukkit.getOnlinePlayers())
{ {
if (_clientManager.hasRank(player, rank))
{
if (announcementCommand.getDisplayTitle())
UtilTextMiddle.display(C.cYellow + "Announcement", message, 10, 120, 10, player);
UtilPlayer.message(player, F.main("Announcement", C.cAqua + message)); UtilPlayer.message(player, F.main("Announcement", C.cAqua + message));
} }
} }
} }
} }
}

View File

@ -4,14 +4,17 @@ package mineplex.serverdata.commands;
public class AnnouncementCommand extends ServerCommand public class AnnouncementCommand extends ServerCommand
{ {
private boolean _displayTitle; private boolean _displayTitle;
private String _rank;
private String _message; private String _message;
public boolean getDisplayTitle() { return _displayTitle; } public boolean getDisplayTitle() { return _displayTitle; }
public String getRank() { return _rank; }
public String getMessage() { return _message; } public String getMessage() { return _message; }
public AnnouncementCommand(boolean displayTitle, String message) public AnnouncementCommand(boolean displayTitle, String rank, String message)
{ {
_displayTitle = displayTitle; _displayTitle = displayTitle;
_rank = rank;
_message = message; _message = message;
} }