From 7ccadae489fa8232b39befe24479a91c72eaf606 Mon Sep 17 00:00:00 2001 From: NuclearW Date: Sat, 26 Jan 2013 22:13:49 -0500 Subject: [PATCH] Changes to the changes to the ChatAPI. mcMMO will not pass null for any events that it creates about itself. Older plugins which are using depricated methods in ChatAPI will be null. Newer plugins passing null to ChatAPI will also be null. Null guarantees that it is not from mcMMO, but from an external plugin that is not specified. --- Changelog.txt | 1 + src/main/java/com/gmail/nossr50/api/ChatAPI.java | 4 ++-- .../gmail/nossr50/events/chat/McMMOAdminChatEvent.java | 4 ---- .../com/gmail/nossr50/events/chat/McMMOChatEvent.java | 8 +------- .../gmail/nossr50/events/chat/McMMOPartyChatEvent.java | 4 ---- .../java/com/gmail/nossr50/listeners/PlayerListener.java | 4 ++-- .../java/com/gmail/nossr50/party/commands/ACommand.java | 4 ++-- .../java/com/gmail/nossr50/party/commands/PCommand.java | 4 ++-- src/main/java/com/gmail/nossr50/util/ChatManager.java | 8 -------- 9 files changed, 10 insertions(+), 31 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index e7c83fba7..5b4570e45 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -36,6 +36,7 @@ Version 1.4.00-dev ! Changed Fisherman's Diet and Farmer's Diet to use two seperate config values ! Major refactoring - please take note, this WILL break any mcMMO-related plugin not properly hooking into the API. ! Changed the way party commands work, use /party ? to check how to use the new commands + ! Changed McMMOChatEvent to contain the plugin that the event originated from. Version 1.3.14 + Added new Hylian Luck skill to Herbalism. diff --git a/src/main/java/com/gmail/nossr50/api/ChatAPI.java b/src/main/java/com/gmail/nossr50/api/ChatAPI.java index 12436172f..357b285df 100644 --- a/src/main/java/com/gmail/nossr50/api/ChatAPI.java +++ b/src/main/java/com/gmail/nossr50/api/ChatAPI.java @@ -35,7 +35,7 @@ public final class ChatAPI { */ @Deprecated public static void sendPartyChat(String sender, String party, String message) { - ChatManager.handlePartyChat(PartyManager.getParty(party), sender, message); + sendPartyChat(null, party, sender, message); } /** @@ -63,6 +63,6 @@ public final class ChatAPI { */ @Deprecated public static void sendAdminChat(String sender, String message) { - ChatManager.handleAdminChat(sender, message); + sendAdminChat(null, sender, message); } } diff --git a/src/main/java/com/gmail/nossr50/events/chat/McMMOAdminChatEvent.java b/src/main/java/com/gmail/nossr50/events/chat/McMMOAdminChatEvent.java index 1fe2b0624..0f45bd33d 100644 --- a/src/main/java/com/gmail/nossr50/events/chat/McMMOAdminChatEvent.java +++ b/src/main/java/com/gmail/nossr50/events/chat/McMMOAdminChatEvent.java @@ -9,8 +9,4 @@ public class McMMOAdminChatEvent extends McMMOChatEvent { public McMMOAdminChatEvent(Plugin plugin, String sender, String message) { super(plugin, sender, message); } - - public McMMOAdminChatEvent(String sender, String message) { - this(null, sender, message); - } } diff --git a/src/main/java/com/gmail/nossr50/events/chat/McMMOChatEvent.java b/src/main/java/com/gmail/nossr50/events/chat/McMMOChatEvent.java index 108a62dbe..7143ca8ef 100644 --- a/src/main/java/com/gmail/nossr50/events/chat/McMMOChatEvent.java +++ b/src/main/java/com/gmail/nossr50/events/chat/McMMOChatEvent.java @@ -5,8 +5,6 @@ import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.bukkit.plugin.Plugin; -import com.gmail.nossr50.mcMMO; - public class McMMOChatEvent extends Event implements Cancellable { private boolean cancelled; private Plugin plugin; @@ -14,17 +12,13 @@ public class McMMOChatEvent extends Event implements Cancellable { private String message; protected McMMOChatEvent(Plugin plugin, String sender, String message) { - if (plugin == null) { - plugin = mcMMO.p; - } - this.plugin = plugin; this.sender = sender; this.message = message; } /** - * @return The plugin responsible for this event + * @return The plugin responsible for this event, note this can be null */ public Plugin getPlugin() { return plugin; diff --git a/src/main/java/com/gmail/nossr50/events/chat/McMMOPartyChatEvent.java b/src/main/java/com/gmail/nossr50/events/chat/McMMOPartyChatEvent.java index 219ca5b21..3ee44641c 100644 --- a/src/main/java/com/gmail/nossr50/events/chat/McMMOPartyChatEvent.java +++ b/src/main/java/com/gmail/nossr50/events/chat/McMMOPartyChatEvent.java @@ -13,10 +13,6 @@ public class McMMOPartyChatEvent extends McMMOChatEvent { this.party = party; } - public McMMOPartyChatEvent(String sender, String party, String message) { - this(null, sender, party, message); - } - /** * @return String name of the party the message will be sent to */ diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index c93b80e4c..937943e2f 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -341,11 +341,11 @@ public class PlayerListener implements Listener { return; } - ChatManager.handlePartyChat(party, player.getName(), event.getMessage()); + ChatManager.handlePartyChat(plugin, party, player.getName(), event.getMessage()); event.setCancelled(true); } else if (profile.getAdminChatMode()) { - ChatManager.handleAdminChat(player.getName(), event.getMessage()); + ChatManager.handleAdminChat(plugin, player.getName(), event.getMessage()); event.setCancelled(true); } } diff --git a/src/main/java/com/gmail/nossr50/party/commands/ACommand.java b/src/main/java/com/gmail/nossr50/party/commands/ACommand.java index 413774f06..f577b2014 100644 --- a/src/main/java/com/gmail/nossr50/party/commands/ACommand.java +++ b/src/main/java/com/gmail/nossr50/party/commands/ACommand.java @@ -61,7 +61,7 @@ public class ACommand implements CommandExecutor { if (sender instanceof Player) { Player player = (Player) sender; - McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent(player.getName(), message); + McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent(mcMMO.p, player.getName(), message); mcMMO.p.getServer().getPluginManager().callEvent(chatEvent); if (chatEvent.isCancelled()) { @@ -80,7 +80,7 @@ public class ACommand implements CommandExecutor { } } else { - McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent("Console", message); + McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent(mcMMO.p, "Console", message); mcMMO.p.getServer().getPluginManager().callEvent(chatEvent); if (chatEvent.isCancelled()) { diff --git a/src/main/java/com/gmail/nossr50/party/commands/PCommand.java b/src/main/java/com/gmail/nossr50/party/commands/PCommand.java index dcf68f19f..b099d03c3 100644 --- a/src/main/java/com/gmail/nossr50/party/commands/PCommand.java +++ b/src/main/java/com/gmail/nossr50/party/commands/PCommand.java @@ -74,7 +74,7 @@ public class PCommand implements CommandExecutor { String message = buffer.toString(); - McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent(player.getName(), party.getName(), message); + McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent(plugin, player.getName(), party.getName(), message); plugin.getServer().getPluginManager().callEvent(chatEvent); if (chatEvent.isCancelled()) { @@ -111,7 +111,7 @@ public class PCommand implements CommandExecutor { String message = buffer.toString(); - McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent("Console", args[0], message); + McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent(plugin, "Console", args[0], message); plugin.getServer().getPluginManager().callEvent(chatEvent); if (chatEvent.isCancelled()) { diff --git a/src/main/java/com/gmail/nossr50/util/ChatManager.java b/src/main/java/com/gmail/nossr50/util/ChatManager.java index 29dc87c98..9245f4d4b 100644 --- a/src/main/java/com/gmail/nossr50/util/ChatManager.java +++ b/src/main/java/com/gmail/nossr50/util/ChatManager.java @@ -31,10 +31,6 @@ public final class ChatManager { } } - public static void handleAdminChat(String playerName, String message) { - handleAdminChat(null, playerName, message); - } - public static void handlePartyChat(Plugin plugin, Party party, String playerName, String message) { String partyName = party.getName(); @@ -53,8 +49,4 @@ public final class ChatManager { member.sendMessage(LocaleLoader.getString("Commands.Party.Chat.Prefix", new Object[] {playerName}) + partyMessage); } } - - public static void handlePartyChat(Party party, String playerName, String message) { - handlePartyChat(null, party, playerName, message); - } }