mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-25 02:04:44 +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);
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@CommandAlias("a|adminchat") //Kept for historical reasons
|
||||
@CommandAlias("a|adminchat|achat") //Kept for historical reasons
|
||||
public class AdminChatCommand extends BaseCommand {
|
||||
private final @NotNull mcMMO pluginRef;
|
||||
|
||||
|
@ -11,11 +11,12 @@ import com.gmail.nossr50.datatypes.party.Party;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.party.PartyManager;
|
||||
import com.gmail.nossr50.util.StringUtils;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@CommandAlias("p|partychat") //Kept for historical reasons
|
||||
@CommandAlias("p|partychat|pchat") //Kept for historical reasons
|
||||
public class PartyChatCommand extends BaseCommand {
|
||||
private final @NotNull mcMMO pluginRef;
|
||||
|
||||
@ -78,7 +79,7 @@ public class PartyChatCommand extends BaseCommand {
|
||||
Party targetParty = PartyManager.getParty(args[0]);
|
||||
|
||||
if(targetParty != null) {
|
||||
pluginRef.getChatManager().processConsoleMessage(args, targetParty);
|
||||
pluginRef.getChatManager().processConsoleMessage(StringUtils.buildStringAfterNthElement(args, 1), targetParty);
|
||||
} else {
|
||||
mcMMO.p.getLogger().severe("A party with that name doesn't exist!");
|
||||
}
|
||||
|
@ -50,14 +50,14 @@ public class ArcheryManager extends SkillManager {
|
||||
* Calculate bonus XP awarded for Archery when hitting a far-away target.
|
||||
*
|
||||
* @param target The {@link LivingEntity} damaged by the arrow
|
||||
* @param damager The {@link Entity} who shot the arrow
|
||||
* @param arrow The {@link Entity} who shot the arrow
|
||||
*/
|
||||
public double distanceXpBonusMultiplier(LivingEntity target, Entity damager) {
|
||||
public double distanceXpBonusMultiplier(LivingEntity target, Entity arrow) {
|
||||
//Hacky Fix - some plugins spawn arrows and assign them to players after the ProjectileLaunchEvent fires
|
||||
if(!damager.hasMetadata(mcMMO.arrowDistanceKey))
|
||||
return damager.getLocation().distance(target.getLocation());
|
||||
if(!arrow.hasMetadata(mcMMO.arrowDistanceKey))
|
||||
return arrow.getLocation().distance(target.getLocation());
|
||||
|
||||
Location firedLocation = (Location) damager.getMetadata(mcMMO.arrowDistanceKey).get(0).value();
|
||||
Location firedLocation = (Location) arrow.getMetadata(mcMMO.arrowDistanceKey).get(0).value();
|
||||
Location targetLocation = target.getLocation();
|
||||
|
||||
if (firedLocation.getWorld() != targetLocation.getWorld()) {
|
||||
|
@ -6,6 +6,7 @@ import org.bukkit.Material;
|
||||
import org.bukkit.block.data.Ageable;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@ -22,6 +23,25 @@ public class StringUtils {
|
||||
return target.substring(0, 1).toUpperCase() + target.substring(1).toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string from an array skipping the first n elements
|
||||
* @param args the array to iterate over when forming the string
|
||||
* @param index the amount of elements to skip over
|
||||
* @return the "trimmed" string
|
||||
*/
|
||||
public static String buildStringAfterNthElement(@NotNull String @NotNull []args, int index) {
|
||||
StringBuilder trimMessage = new StringBuilder();
|
||||
|
||||
for (int i = index; i < args.length; i++) {
|
||||
if(i + 1 >= args.length)
|
||||
trimMessage.append(args[i]);
|
||||
else
|
||||
trimMessage.append(args[i]).append(" ");
|
||||
}
|
||||
|
||||
return trimMessage.toString();
|
||||
}
|
||||
|
||||
public static String getPrettyItemString(Material material) {
|
||||
return createPrettyString(material.toString());
|
||||
}
|
||||
|
Reference in New Issue
Block a user