From 58a8a32e93c3f41756d74c651a2cb7e92925b1ea Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Sat, 24 Jan 2015 01:44:22 -0800 Subject: [PATCH] Added cross-server Announcements and Global messages. --- .../core/message/AnnouncementHandler.java | 33 ++++++++++++++++++ .../message/Commands/AnnounceCommand.java | 34 +++++++++++++++++++ .../core/message/Commands/GlobalCommand.java | 32 +++++++++++++++++ .../mineplex/core/message/MessageManager.java | 18 +++++----- .../transfers/AnnouncementCommand.java | 24 +++++++++++++ 5 files changed, 131 insertions(+), 10 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/message/AnnouncementHandler.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/message/Commands/AnnounceCommand.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/message/Commands/GlobalCommand.java create mode 100644 Plugins/Mineplex.ServerData/src/mineplex/serverdata/transfers/AnnouncementCommand.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/message/AnnouncementHandler.java b/Plugins/Mineplex.Core/src/mineplex/core/message/AnnouncementHandler.java new file mode 100644 index 000000000..c692cb04a --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/message/AnnouncementHandler.java @@ -0,0 +1,33 @@ +package mineplex.core.message; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilTextMiddle; +import mineplex.serverdata.CommandCallback; +import mineplex.serverdata.ServerCommand; +import mineplex.serverdata.transfers.AnnouncementCommand; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class AnnouncementHandler implements CommandCallback +{ + public void run(ServerCommand command) + { + if (command instanceof ServerCommand) + { + AnnouncementCommand announcementCommand = (AnnouncementCommand)command; + + 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)); + } + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/message/Commands/AnnounceCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/message/Commands/AnnounceCommand.java new file mode 100644 index 000000000..d9eccd88d --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/message/Commands/AnnounceCommand.java @@ -0,0 +1,34 @@ +package mineplex.core.message.Commands; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.message.MessageManager; +import mineplex.serverdata.transfers.AnnouncementCommand; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class AnnounceCommand extends CommandBase +{ + public AnnounceCommand(MessageManager plugin) + { + super(plugin, Rank.ADMIN, "announce"); + } + + @Override + public void Execute(Player caller, String[] args) + { + if (args == null) + { + Plugin.Help(caller); + } + else + { + new AnnouncementCommand(true, F.combine(args, 0, null, false)).publish(); + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/message/Commands/GlobalCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/message/Commands/GlobalCommand.java new file mode 100644 index 000000000..a04d60d54 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/message/Commands/GlobalCommand.java @@ -0,0 +1,32 @@ +package mineplex.core.message.Commands; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.message.MessageManager; +import mineplex.serverdata.transfers.AnnouncementCommand; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class GlobalCommand extends CommandBase +{ + public GlobalCommand(MessageManager plugin) + { + super(plugin, Rank.ADMIN, "global"); + } + + @Override + public void Execute(Player caller, String[] args) + { + if (args == null) + { + Plugin.Help(caller); + } + else + { + new AnnouncementCommand(false, F.combine(args, 0, null, false)).publish(); + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/message/MessageManager.java b/Plugins/Mineplex.Core/src/mineplex/core/message/MessageManager.java index 0b5364cd9..fa3666096 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/message/MessageManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/message/MessageManager.java @@ -17,6 +17,8 @@ import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.message.Commands.*; import mineplex.core.preferences.PreferencesManager; +import mineplex.serverdata.ServerCommandManager; +import mineplex.serverdata.transfers.AnnouncementCommand; public class MessageManager extends MiniClientPlugin { @@ -31,6 +33,8 @@ public class MessageManager extends MiniClientPlugin _clientManager = clientManager; _preferences = preferences; + + ServerCommandManager.getInstance().registerCommandType("AnnouncementCommand", AnnouncementCommand.class, new AnnouncementHandler()); } //Module Functions @@ -83,21 +87,15 @@ public class MessageManager extends MiniClientPlugin addCommand(new MessageAdminCommand(this)); addCommand(new ResendAdminCommand(this)); + addCommand(new AnnounceCommand(this)); + addCommand(new GlobalCommand(this)); addCommand(new AdminCommand(this)); } public void Help(Player caller, String message) - { - UtilPlayer.message(caller, F.main(_moduleName, "Commands List:")); - UtilPlayer.message(caller, F.help("/npc add ", "Right click mob to attach npc.", Rank.OWNER)); - UtilPlayer.message(caller, F.help("/npc del ", "Right click npc to delete", Rank.OWNER)); - UtilPlayer.message(caller, F.help("/npc clear", "Removes all npcs", Rank.OWNER)); - UtilPlayer.message(caller, F.help("/npc home", " Teleport npcs to home locations.", Rank.OWNER)); - UtilPlayer.message(caller, F.help("/npc reattach", "Attempt to reattach npcs to entities.", Rank.OWNER)); - - if (message != null) - UtilPlayer.message(caller, F.main(_moduleName, ChatColor.RED + message)); + { + UtilPlayer.message(caller, F.main(_moduleName, ChatColor.RED + "Err...something went wrong?")); } public void Help(Player caller) diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/transfers/AnnouncementCommand.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/transfers/AnnouncementCommand.java new file mode 100644 index 000000000..cc2e5c271 --- /dev/null +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/transfers/AnnouncementCommand.java @@ -0,0 +1,24 @@ +package mineplex.serverdata.transfers; + +import mineplex.serverdata.ServerCommand; + +public class AnnouncementCommand extends ServerCommand +{ + private boolean _displayTitle; + private String _message; + + public boolean getDisplayTitle() { return _displayTitle; } + public String getMessage() { return _message; } + + public AnnouncementCommand(boolean displayTitle, String message) + { + _displayTitle = displayTitle; + _message = message; + } + + @Override + public void run() + { + // Utilitizes a callback functionality to seperate dependencies + } +}