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.
This commit is contained in:
NuclearW 2013-01-26 22:13:49 -05:00
parent 251c152efa
commit 7ccadae489
9 changed files with 10 additions and 31 deletions

View File

@ -36,6 +36,7 @@ Version 1.4.00-dev
! Changed Fisherman's Diet and Farmer's Diet to use two seperate config values ! 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. ! 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 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 Version 1.3.14
+ Added new Hylian Luck skill to Herbalism. + Added new Hylian Luck skill to Herbalism.

View File

@ -35,7 +35,7 @@ public final class ChatAPI {
*/ */
@Deprecated @Deprecated
public static void sendPartyChat(String sender, String party, String message) { 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 @Deprecated
public static void sendAdminChat(String sender, String message) { public static void sendAdminChat(String sender, String message) {
ChatManager.handleAdminChat(sender, message); sendAdminChat(null, sender, message);
} }
} }

View File

@ -9,8 +9,4 @@ public class McMMOAdminChatEvent extends McMMOChatEvent {
public McMMOAdminChatEvent(Plugin plugin, String sender, String message) { public McMMOAdminChatEvent(Plugin plugin, String sender, String message) {
super(plugin, sender, message); super(plugin, sender, message);
} }
public McMMOAdminChatEvent(String sender, String message) {
this(null, sender, message);
}
} }

View File

@ -5,8 +5,6 @@ import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import com.gmail.nossr50.mcMMO;
public class McMMOChatEvent extends Event implements Cancellable { public class McMMOChatEvent extends Event implements Cancellable {
private boolean cancelled; private boolean cancelled;
private Plugin plugin; private Plugin plugin;
@ -14,17 +12,13 @@ public class McMMOChatEvent extends Event implements Cancellable {
private String message; private String message;
protected McMMOChatEvent(Plugin plugin, String sender, String message) { protected McMMOChatEvent(Plugin plugin, String sender, String message) {
if (plugin == null) {
plugin = mcMMO.p;
}
this.plugin = plugin; this.plugin = plugin;
this.sender = sender; this.sender = sender;
this.message = message; 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() { public Plugin getPlugin() {
return plugin; return plugin;

View File

@ -13,10 +13,6 @@ public class McMMOPartyChatEvent extends McMMOChatEvent {
this.party = party; 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 * @return String name of the party the message will be sent to
*/ */

View File

@ -341,11 +341,11 @@ public class PlayerListener implements Listener {
return; return;
} }
ChatManager.handlePartyChat(party, player.getName(), event.getMessage()); ChatManager.handlePartyChat(plugin, party, player.getName(), event.getMessage());
event.setCancelled(true); event.setCancelled(true);
} }
else if (profile.getAdminChatMode()) { else if (profile.getAdminChatMode()) {
ChatManager.handleAdminChat(player.getName(), event.getMessage()); ChatManager.handleAdminChat(plugin, player.getName(), event.getMessage());
event.setCancelled(true); event.setCancelled(true);
} }
} }

View File

@ -61,7 +61,7 @@ public class ACommand implements CommandExecutor {
if (sender instanceof Player) { if (sender instanceof Player) {
Player player = (Player) sender; 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); mcMMO.p.getServer().getPluginManager().callEvent(chatEvent);
if (chatEvent.isCancelled()) { if (chatEvent.isCancelled()) {
@ -80,7 +80,7 @@ public class ACommand implements CommandExecutor {
} }
} }
else { else {
McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent("Console", message); McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent(mcMMO.p, "Console", message);
mcMMO.p.getServer().getPluginManager().callEvent(chatEvent); mcMMO.p.getServer().getPluginManager().callEvent(chatEvent);
if (chatEvent.isCancelled()) { if (chatEvent.isCancelled()) {

View File

@ -74,7 +74,7 @@ public class PCommand implements CommandExecutor {
String message = buffer.toString(); 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); plugin.getServer().getPluginManager().callEvent(chatEvent);
if (chatEvent.isCancelled()) { if (chatEvent.isCancelled()) {
@ -111,7 +111,7 @@ public class PCommand implements CommandExecutor {
String message = buffer.toString(); 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); plugin.getServer().getPluginManager().callEvent(chatEvent);
if (chatEvent.isCancelled()) { if (chatEvent.isCancelled()) {

View File

@ -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) { public static void handlePartyChat(Plugin plugin, Party party, String playerName, String message) {
String partyName = party.getName(); String partyName = party.getName();
@ -53,8 +49,4 @@ public final class ChatManager {
member.sendMessage(LocaleLoader.getString("Commands.Party.Chat.Prefix", new Object[] {playerName}) + partyMessage); 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);
}
} }