From 9383b1c65cb7e3d757a1a54bfc2d8d455e55f178 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 13 Feb 2019 09:12:53 -0800 Subject: [PATCH] expanding the abstraction again... --- .../nossr50/core/chat/AdminChatManager.java | 3 ++- .../gmail/nossr50/core/chat/ChatManager.java | 2 +- .../core/events/chat/McMMOAdminChatEvent.java | 9 ++++----- .../core/events/chat/McMMOChatEvent.java | 20 +++++++++---------- .../gmail/nossr50/core/mcmmo/Nameable.java | 6 ++++++ .../nossr50/core/mcmmo/entity/Player.java | 6 ++++++ .../nossr50/core/mcmmo/event/Cancellable.java | 2 +- .../nossr50/core/mcmmo/server/Server.java | 7 +++++++ 8 files changed, 36 insertions(+), 19 deletions(-) diff --git a/core/src/main/java/com/gmail/nossr50/core/chat/AdminChatManager.java b/core/src/main/java/com/gmail/nossr50/core/chat/AdminChatManager.java index d016c622c..a206363e8 100644 --- a/core/src/main/java/com/gmail/nossr50/core/chat/AdminChatManager.java +++ b/core/src/main/java/com/gmail/nossr50/core/chat/AdminChatManager.java @@ -1,5 +1,6 @@ package com.gmail.nossr50.core.chat; +import com.gmail.nossr50.core.McmmoCore; import com.gmail.nossr50.core.config.Config; import com.gmail.nossr50.core.events.chat.McMMOAdminChatEvent; @@ -15,6 +16,6 @@ public class AdminChatManager extends ChatManager { @Override protected void sendMessage() { - plugin.getServer().broadcast(message, "mcmmo.chat.adminchat"); + McmmoCore.getServer().broadcast(message, "mcmmo.chat.adminchat"); } } diff --git a/core/src/main/java/com/gmail/nossr50/core/chat/ChatManager.java b/core/src/main/java/com/gmail/nossr50/core/chat/ChatManager.java index 373a96c5a..d9a50846c 100644 --- a/core/src/main/java/com/gmail/nossr50/core/chat/ChatManager.java +++ b/core/src/main/java/com/gmail/nossr50/core/chat/ChatManager.java @@ -43,7 +43,7 @@ public abstract class ChatManager { McMMOPartyChatEvent partyChatEvent = (McMMOPartyChatEvent) event; //Find the people with permissions - for (Player player : event.getPlugin().getServer().getOnlinePlayers()) { + for (Player player : McmmoCore.getServer().getOnlinePlayers()) { //Check for toggled players if (UserManager.getPlayer(player).isPartyChatSpying()) { Party adminParty = UserManager.getPlayer(player).getParty(); diff --git a/core/src/main/java/com/gmail/nossr50/core/events/chat/McMMOAdminChatEvent.java b/core/src/main/java/com/gmail/nossr50/core/events/chat/McMMOAdminChatEvent.java index b307904b1..4c0764b4a 100644 --- a/core/src/main/java/com/gmail/nossr50/core/events/chat/McMMOAdminChatEvent.java +++ b/core/src/main/java/com/gmail/nossr50/core/events/chat/McMMOAdminChatEvent.java @@ -1,16 +1,15 @@ package com.gmail.nossr50.core.events.chat; -import org.bukkit.plugin.Plugin; /** * Called when a chat is sent to the admin chat channel */ public class McMMOAdminChatEvent extends McMMOChatEvent { - public McMMOAdminChatEvent(Plugin plugin, String sender, String displayName, String message) { - super(plugin, sender, displayName, message); + public McMMOAdminChatEvent(String sender, String displayName, String message) { + super(sender, displayName, message); } - public McMMOAdminChatEvent(Plugin plugin, String sender, String displayName, String message, boolean isAsync) { - super(plugin, sender, displayName, message, isAsync); + public McMMOAdminChatEvent(String sender, String displayName, String message, boolean isAsync) { + super(sender, displayName, message, isAsync); } } diff --git a/core/src/main/java/com/gmail/nossr50/core/events/chat/McMMOChatEvent.java b/core/src/main/java/com/gmail/nossr50/core/events/chat/McMMOChatEvent.java index 7708d2a47..c642181b3 100644 --- a/core/src/main/java/com/gmail/nossr50/core/events/chat/McMMOChatEvent.java +++ b/core/src/main/java/com/gmail/nossr50/core/events/chat/McMMOChatEvent.java @@ -1,9 +1,7 @@ package com.gmail.nossr50.core.events.chat; -import org.bukkit.event.Cancellable; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -import org.bukkit.plugin.Plugin; +import com.gmail.nossr50.core.mcmmo.event.Cancellable; +import com.gmail.nossr50.core.mcmmo.event.Event; public abstract class McMMOChatEvent extends Event implements Cancellable { /** @@ -11,36 +9,36 @@ public abstract class McMMOChatEvent extends Event implements Cancellable { **/ private static final HandlerList handlers = new HandlerList(); private boolean cancelled; - private Plugin plugin; private String sender; private String displayName; private String message; - protected McMMOChatEvent(Plugin plugin, String sender, String displayName, String message) { - this.plugin = plugin; + protected McMMOChatEvent(String sender, String displayName, String message) { this.sender = sender; this.displayName = displayName; this.message = message; } - protected McMMOChatEvent(Plugin plugin, String sender, String displayName, String message, boolean isAsync) { + protected McMMOChatEvent(String sender, String displayName, String message, boolean isAsync) { super(isAsync); - this.plugin = plugin; this.sender = sender; this.displayName = displayName; this.message = message; } + /* public static HandlerList getHandlerList() { return handlers; } + */ /** * @return The plugin responsible for this event, note this can be null */ - public Plugin getPlugin() { + //TODO: Why do we even need this? + /*public Plugin getPlugin() { return plugin; - } + }*/ /** * @return String name of the player who sent the chat, or "Console" diff --git a/core/src/main/java/com/gmail/nossr50/core/mcmmo/Nameable.java b/core/src/main/java/com/gmail/nossr50/core/mcmmo/Nameable.java index a69a5ca45..e3d5e1486 100644 --- a/core/src/main/java/com/gmail/nossr50/core/mcmmo/Nameable.java +++ b/core/src/main/java/com/gmail/nossr50/core/mcmmo/Nameable.java @@ -14,4 +14,10 @@ public interface Nameable extends Named { * @return the original name of this entity */ String getOriginalName(); + + /** + * This is the name used for chat messages and other things + * @return the display name of this entity + */ + String getDisplayName(); } diff --git a/core/src/main/java/com/gmail/nossr50/core/mcmmo/entity/Player.java b/core/src/main/java/com/gmail/nossr50/core/mcmmo/entity/Player.java index 8ecb7bafd..27f1c4df5 100644 --- a/core/src/main/java/com/gmail/nossr50/core/mcmmo/entity/Player.java +++ b/core/src/main/java/com/gmail/nossr50/core/mcmmo/entity/Player.java @@ -30,4 +30,10 @@ public interface Player extends Living, Nameable, InventoryHolder, Permissible { * @return the item in the main hand */ ItemStack getItemInMainHand(); + + /** + * Sends a message to this player + * @param msg the message to send + */ + void sendMessage(String msg); } diff --git a/core/src/main/java/com/gmail/nossr50/core/mcmmo/event/Cancellable.java b/core/src/main/java/com/gmail/nossr50/core/mcmmo/event/Cancellable.java index 22e71324c..5ea19cc05 100644 --- a/core/src/main/java/com/gmail/nossr50/core/mcmmo/event/Cancellable.java +++ b/core/src/main/java/com/gmail/nossr50/core/mcmmo/event/Cancellable.java @@ -10,7 +10,7 @@ public interface Cancellable { * * @return true if cancelled */ - Boolean isCancelled(); + boolean isCancelled(); /** * Sets an events cancellation to b diff --git a/core/src/main/java/com/gmail/nossr50/core/mcmmo/server/Server.java b/core/src/main/java/com/gmail/nossr50/core/mcmmo/server/Server.java index fd6a4a43e..6eb74c623 100644 --- a/core/src/main/java/com/gmail/nossr50/core/mcmmo/server/Server.java +++ b/core/src/main/java/com/gmail/nossr50/core/mcmmo/server/Server.java @@ -13,6 +13,13 @@ public interface Server { */ void broadcast(String msg); + /** + * Broadcasts a message only to players with the appropriate permission node + * @param msg the message to broadcast + * @param permission the permission node required to hear the message + */ + void broadcast(String msg, String permission); + /** * Gets the online players for this server * @return the online players for this server