Add minimum rank to Announcement Command
This commit is contained in:
parent
8d831d5228
commit
618105b4c8
@ -10,6 +10,7 @@ import mineplex.core.message.MessageManager;
|
||||
import mineplex.serverdata.commands.AnnouncementCommand;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class AnnounceCommand extends CommandBase<MessageManager>
|
||||
@ -22,13 +23,25 @@ public class AnnounceCommand extends CommandBase<MessageManager>
|
||||
@Override
|
||||
public void Execute(Player caller, String[] args)
|
||||
{
|
||||
if (args == null || args.length == 0)
|
||||
if (args == null || args.length <= 1)
|
||||
{
|
||||
Plugin.Help(caller);
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
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.F;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
@ -13,20 +15,41 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public class AnnouncementHandler implements CommandCallback
|
||||
{
|
||||
private CoreClientManager _clientManager;
|
||||
|
||||
public AnnouncementHandler(CoreClientManager clientManager)
|
||||
{
|
||||
_clientManager = clientManager;
|
||||
}
|
||||
|
||||
public void run(ServerCommand command)
|
||||
{
|
||||
if (command instanceof AnnouncementCommand)
|
||||
{
|
||||
AnnouncementCommand announcementCommand = (AnnouncementCommand)command;
|
||||
|
||||
|
||||
Rank rank;
|
||||
try
|
||||
{
|
||||
rank = Rank.valueOf(announcementCommand.getRank());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
String message = announcementCommand.getMessage();
|
||||
|
||||
if (announcementCommand.getDisplayTitle())
|
||||
UtilTextMiddle.display(C.cYellow + "Announcement", message, 10, 120, 10);
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Announcement", C.cAqua + message));
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,14 +4,17 @@ package mineplex.serverdata.commands;
|
||||
public class AnnouncementCommand extends ServerCommand
|
||||
{
|
||||
private boolean _displayTitle;
|
||||
private String _rank;
|
||||
private String _message;
|
||||
|
||||
public boolean getDisplayTitle() { return _displayTitle; }
|
||||
public String getRank() { return _rank; }
|
||||
public String getMessage() { return _message; }
|
||||
|
||||
public AnnouncementCommand(boolean displayTitle, String message)
|
||||
public AnnouncementCommand(boolean displayTitle, String rank, String message)
|
||||
{
|
||||
_displayTitle = displayTitle;
|
||||
_rank = rank;
|
||||
_message = message;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user