mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-29 12:14:43 +02:00
Better party chat logging in console, some style changes to admin/party chat as well
This commit is contained in:
@ -11,8 +11,10 @@ import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.StringUtils;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
//TODO: Micro optimization - Cache audiences and update cache when needed
|
||||
public class ChatManager {
|
||||
@ -20,11 +22,15 @@ public class ChatManager {
|
||||
private final @NotNull AdminChatMailer adminChatMailer;
|
||||
private final @NotNull PartyChatMailer partyChatMailer;
|
||||
|
||||
private @Nullable ConsoleAuthor consoleAuthor;
|
||||
private final @NotNull ConsoleAuthor consoleAuthor;
|
||||
private final @NotNull Audience consoleAudience;
|
||||
|
||||
public ChatManager(@NotNull mcMMO pluginRef) {
|
||||
adminChatMailer = new AdminChatMailer(pluginRef);
|
||||
partyChatMailer = new PartyChatMailer(pluginRef);
|
||||
|
||||
this.consoleAuthor = new ConsoleAuthor(LocaleLoader.getString("Chat.Identity.Console"));
|
||||
this.consoleAudience = mcMMO.getAudiences().filter((cs) -> cs instanceof ConsoleCommandSender);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,27 +102,11 @@ public class ChatManager {
|
||||
partyChatMailer.processChatMessage(getConsoleAuthor(), rawMessage, party, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles console messaging to a specific party
|
||||
* @param args raw command args from the console
|
||||
* @param party target party
|
||||
*/
|
||||
public void processConsoleMessage(@NotNull String[] args, @NotNull Party party) {
|
||||
String chatMessageWithoutCommand = buildChatMessage(args);
|
||||
|
||||
processConsoleMessage(chatMessageWithoutCommand, party);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a console author
|
||||
* Constructs one if it doesn't already exist
|
||||
* @return a {@link ConsoleAuthor}
|
||||
*/
|
||||
private @NotNull Author getConsoleAuthor() {
|
||||
if (consoleAuthor == null) {
|
||||
consoleAuthor = new ConsoleAuthor(LocaleLoader.getString("Chat.Identity.Console"));
|
||||
}
|
||||
|
||||
return consoleAuthor;
|
||||
}
|
||||
|
||||
@ -180,5 +170,14 @@ public class ChatManager {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends just the console a message
|
||||
* @param author author of the message
|
||||
* @param message message contents in component form
|
||||
*/
|
||||
public void sendConsoleMessage(@NotNull Author author, @NotNull TextComponent message) {
|
||||
consoleAudience.sendMessage(author, message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ public class SamePartyPredicate<T extends CommandSender> implements Predicate<T>
|
||||
public boolean test(T t) {
|
||||
//Include the console in the audience
|
||||
if(t instanceof ConsoleCommandSender) {
|
||||
return true;
|
||||
return false; //Party audiences are special, we exclude console from them to avoid double messaging since we send a more verbose version to consoles
|
||||
} else {
|
||||
if(t instanceof Player) {
|
||||
Player player = (Player) t;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.gmail.nossr50.chat.author;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.google.common.base.Objects;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -38,7 +39,10 @@ public class AdminAuthor implements Author {
|
||||
return overrideName;
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Set the name of this author
|
||||
* @param newName value of the new name
|
||||
*/
|
||||
public void setName(@NotNull String newName) {
|
||||
overrideName = newName;
|
||||
}
|
||||
@ -57,4 +61,18 @@ public class AdminAuthor implements Author {
|
||||
public @NonNull UUID uuid() {
|
||||
return player.getUniqueId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
AdminAuthor that = (AdminAuthor) o;
|
||||
return Objects.equal(player, that.player) &&
|
||||
Objects.equal(overrideName, that.overrideName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(player, overrideName);
|
||||
}
|
||||
}
|
||||
|
@ -11,12 +11,6 @@ public interface Author extends Identity {
|
||||
*/
|
||||
@NotNull String getAuthoredName();
|
||||
|
||||
/**
|
||||
* Set the name of this author
|
||||
* @param newName value of the new name
|
||||
*/
|
||||
void setName(@NotNull String newName);
|
||||
|
||||
/**
|
||||
* Whether or not this author is a {@link org.bukkit.command.ConsoleCommandSender}
|
||||
*
|
||||
|
@ -7,7 +7,7 @@ import java.util.UUID;
|
||||
|
||||
public class ConsoleAuthor implements Author {
|
||||
private final UUID uuid;
|
||||
private @NotNull String name;
|
||||
private final @NotNull String name;
|
||||
|
||||
public ConsoleAuthor(@NotNull String name) {
|
||||
this.name = name;
|
||||
@ -19,11 +19,6 @@ public class ConsoleAuthor implements Author {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(@NotNull String newName) {
|
||||
this.name = newName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConsole() {
|
||||
return true;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.gmail.nossr50.chat.author;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.google.common.base.Objects;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -30,7 +31,10 @@ public class PartyAuthor implements Author {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Set the name of this author
|
||||
* @param newName value of the new name
|
||||
*/
|
||||
public void setName(@NotNull String newName) {
|
||||
overrideName = newName;
|
||||
}
|
||||
@ -45,8 +49,26 @@ public class PartyAuthor implements Author {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull UUID uuid() {
|
||||
return player.getUniqueId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
PartyAuthor that = (PartyAuthor) o;
|
||||
return Objects.equal(player, that.player) &&
|
||||
Objects.equal(overrideName, that.overrideName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(player, overrideName);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.gmail.nossr50.chat.message;
|
||||
|
||||
import com.gmail.nossr50.chat.author.Author;
|
||||
import com.google.common.base.Objects;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
@ -56,4 +57,21 @@ public abstract class AbstractChatMessage implements ChatMessage {
|
||||
public void setAudience(@NotNull Audience newAudience) {
|
||||
audience = newAudience;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
AbstractChatMessage that = (AbstractChatMessage) o;
|
||||
return Objects.equal(pluginRef, that.pluginRef) &&
|
||||
Objects.equal(author, that.author) &&
|
||||
Objects.equal(rawMessage, that.rawMessage) &&
|
||||
Objects.equal(componentMessage, that.componentMessage) &&
|
||||
Objects.equal(audience, that.audience);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(pluginRef, author, rawMessage, componentMessage, audience);
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,10 @@ package com.gmail.nossr50.chat.message;
|
||||
import com.gmail.nossr50.chat.author.Author;
|
||||
import com.gmail.nossr50.datatypes.party.Party;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import com.google.common.base.Objects;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
@ -31,18 +33,28 @@ public class PartyChatMessage extends AbstractChatMessage {
|
||||
|
||||
@Override
|
||||
public void sendMessage() {
|
||||
/*
|
||||
* It should be noted that Party messages don't include console as part of the audience to avoid double messaging
|
||||
* The console gets a message that has the party name included, player parties do not
|
||||
*/
|
||||
|
||||
//Sends to everyone but console
|
||||
audience.sendMessage(author, componentMessage);
|
||||
TextComponent spyMessage = Component.text(LocaleLoader.getString("Chat.Spy.Party", author.getAuthoredName(), rawMessage, party.getName()));
|
||||
|
||||
//Relay to spies
|
||||
TextComponent textComponent = Component.text("[" + getParty().getName() + "] ->" ).append(getChatMessage());
|
||||
relayChatToSpies(textComponent);
|
||||
messagePartyChatSpies(spyMessage);
|
||||
|
||||
//Console message
|
||||
mcMMO.p.getChatManager().sendConsoleMessage(author, spyMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Console and Party Chat Spies get a more verbose version of the message
|
||||
* Party Chat Spies will get a copy of the message as well
|
||||
* @param spyMessage the message to copy to spies
|
||||
*/
|
||||
private void relayChatToSpies(@NotNull TextComponent spyMessage) {
|
||||
private void messagePartyChatSpies(@NotNull TextComponent spyMessage) {
|
||||
//Find the people with permissions
|
||||
for(McMMOPlayer mcMMOPlayer : UserManager.getPlayers()) {
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
@ -60,4 +72,18 @@ public class PartyChatMessage extends AbstractChatMessage {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
PartyChatMessage that = (PartyChatMessage) o;
|
||||
return Objects.equal(party, that.party);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(super.hashCode(), party);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user