Complete rewrite of Admin & Party chat code

There are some API breaks as a result of these rewrites, I tried to keep it minimal, but I'm sure some plugins will need to update.
This commit is contained in:
nossr50
2020-10-26 16:31:02 -07:00
parent cf6a2e9e97
commit 749c83ac59
44 changed files with 1419 additions and 713 deletions

View File

@ -1,72 +1,68 @@
package com.gmail.nossr50.api;
import com.gmail.nossr50.chat.ChatManager;
import com.gmail.nossr50.chat.ChatManagerFactory;
import com.gmail.nossr50.chat.PartyChatManager;
import com.gmail.nossr50.datatypes.chat.ChatMode;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.datatypes.chat.ChatChannel;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.player.UserManager;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public final class ChatAPI {
private ChatAPI() {}
/**
* Send a message to all members of a party
* </br>
* This function is designed for API usage.
*
* @param plugin The plugin sending the message
* @param sender The name of the sender
* @param displayName The display name of the sender
* @param party The name of the party to send to
* @param message The message to send
*/
public static void sendPartyChat(Plugin plugin, String sender, String displayName, String party, String message) {
getPartyChatManager(plugin, party).handleChat(sender, displayName, message);
}
/**
* Send a message to all members of a party
* </br>
* This function is designed for API usage.
*
* @param plugin The plugin sending the message
* @param sender The name of the sender to display in the chat
* @param party The name of the party to send to
* @param message The message to send
*/
public static void sendPartyChat(Plugin plugin, String sender, String party, String message) {
getPartyChatManager(plugin, party).handleChat(sender, message);
}
/**
* Send a message to administrators
* </br>
* This function is designed for API usage.
*
* @param plugin The plugin sending the message
* @param sender The name of the sender
* @param displayName The display name of the sender
* @param message The message to send
*/
public static void sendAdminChat(Plugin plugin, String sender, String displayName, String message) {
ChatManagerFactory.getChatManager(plugin, ChatMode.ADMIN).handleChat(sender, displayName, message);
}
/**
* Send a message to administrators
* </br>
* This function is designed for API usage.
*
* @param plugin The plugin sending the message
* @param sender The name of the sender to display in the chat
* @param message The message to send
*/
public static void sendAdminChat(Plugin plugin, String sender, String message) {
ChatManagerFactory.getChatManager(plugin, ChatMode.ADMIN).handleChat(sender, message);
}
// /**
// * Send a message to all members of a party
// * </br>
// * This function is designed for API usage.
// *
// * @param plugin The plugin sending the message
// * @param sender The name of the sender
// * @param displayName The display name of the sender
// * @param party The name of the party to send to
// * @param message The message to send
// */
// public static void sendPartyChat(Plugin plugin, String sender, String displayName, String party, String message) {
// getPartyChatManager(plugin, party).handleChat(sender, displayName, message);
// }
//
// /**
// * Send a message to all members of a party
// * </br>
// * This function is designed for API usage.
// *
// * @param plugin The plugin sending the message
// * @param sender The name of the sender to display in the chat
// * @param party The name of the party to send to
// * @param message The message to send
// */
// public static void sendPartyChat(Plugin plugin, String sender, String party, String message) {
// getPartyChatManager(plugin, party).handleChat(sender, message);
// }
//
// /**
// * Send a message to administrators
// * </br>
// * This function is designed for API usage.
// *
// * @param plugin The plugin sending the message
// * @param sender The name of the sender
// * @param displayName The display name of the sender
// * @param message The message to send
// */
// public static void sendAdminChat(Plugin plugin, String sender, String displayName, String message) {
// ChatManagerFactory.getChatManager(plugin, ChatChannel.ADMIN).handleChat(sender, displayName, message);
// }
//
// /**
// * Send a message to administrators
// * </br>
// * This function is designed for API usage.
// *
// * @param plugin The plugin sending the message
// * @param sender The name of the sender to display in the chat
// * @param message The message to send
// */
// public static void sendAdminChat(Plugin plugin, String sender, String message) {
// ChatManagerFactory.getChatManager(plugin, ChatChannel.ADMIN).handleChat(sender, message);
// }
/**
* Check if a player is currently talking in party chat.
@ -75,7 +71,7 @@ public final class ChatAPI {
* @return true if the player is using party chat, false otherwise
*/
public static boolean isUsingPartyChat(Player player) {
return UserManager.getPlayer(player).isChatEnabled(ChatMode.PARTY);
return UserManager.getPlayer(player).getChatChannel() == ChatChannel.PARTY;
}
/**
@ -85,7 +81,7 @@ public final class ChatAPI {
* @return true if the player is using party chat, false otherwise
*/
public static boolean isUsingPartyChat(String playerName) {
return UserManager.getPlayer(playerName).isChatEnabled(ChatMode.PARTY);
return UserManager.getPlayer(playerName).getChatChannel() == ChatChannel.PARTY;
}
/**
@ -95,7 +91,7 @@ public final class ChatAPI {
* @return true if the player is using admin chat, false otherwise
*/
public static boolean isUsingAdminChat(Player player) {
return UserManager.getPlayer(player).isChatEnabled(ChatMode.ADMIN);
return UserManager.getPlayer(player).getChatChannel() == ChatChannel.ADMIN;
}
/**
@ -105,7 +101,7 @@ public final class ChatAPI {
* @return true if the player is using admin chat, false otherwise
*/
public static boolean isUsingAdminChat(String playerName) {
return UserManager.getPlayer(playerName).isChatEnabled(ChatMode.ADMIN);
return UserManager.getPlayer(playerName).getChatChannel() == ChatChannel.ADMIN;
}
/**
@ -114,7 +110,7 @@ public final class ChatAPI {
* @param player The player to toggle party chat on.
*/
public static void togglePartyChat(Player player) {
UserManager.getPlayer(player).toggleChat(ChatMode.PARTY);
mcMMO.p.getChatManager().setOrToggleChatChannel(UserManager.getPlayer(player), ChatChannel.PARTY);
}
/**
@ -123,7 +119,7 @@ public final class ChatAPI {
* @param playerName The name of the player to toggle party chat on.
*/
public static void togglePartyChat(String playerName) {
UserManager.getPlayer(playerName).toggleChat(ChatMode.PARTY);
mcMMO.p.getChatManager().setOrToggleChatChannel(UserManager.getPlayer(playerName), ChatChannel.PARTY);
}
/**
@ -132,7 +128,7 @@ public final class ChatAPI {
* @param player The player to toggle admin chat on.
*/
public static void toggleAdminChat(Player player) {
UserManager.getPlayer(player).toggleChat(ChatMode.ADMIN);
mcMMO.p.getChatManager().setOrToggleChatChannel(UserManager.getPlayer(player), ChatChannel.ADMIN);
}
/**
@ -141,13 +137,6 @@ public final class ChatAPI {
* @param playerName The name of the player to toggle party chat on.
*/
public static void toggleAdminChat(String playerName) {
UserManager.getPlayer(playerName).toggleChat(ChatMode.ADMIN);
}
private static ChatManager getPartyChatManager(Plugin plugin, String party) {
ChatManager chatManager = ChatManagerFactory.getChatManager(plugin, ChatMode.PARTY);
((PartyChatManager) chatManager).setParty(PartyManager.getParty(party));
return chatManager;
mcMMO.p.getChatManager().setOrToggleChatChannel(UserManager.getPlayer(playerName), ChatChannel.ADMIN);
}
}