Also: Removed login "Chat room:" notice Removed "Joined chat room:" on command The room in "has left the chat room" is now correct Removed prefix from global Fixed double kill message
This commit is contained in:
parent
0d54e71294
commit
a3e3cc4b57
8 changed files with 107 additions and 48 deletions
|
@ -39,6 +39,9 @@ Chat rooms players can freely create and join. Alerts like death and join messag
|
||||||
`/chat` - switch chat room \
|
`/chat` - switch chat room \
|
||||||
`/chatmanage` - create, delete, modify etc. (`tweaks724.chatmanage`)
|
`/chatmanage` - create, delete, modify etc. (`tweaks724.chatmanage`)
|
||||||
|
|
||||||
|
### Proximity chat
|
||||||
|
Self-explanatory
|
||||||
|
|
||||||
### Compass
|
### Compass
|
||||||
Holding a compass shows a bar with 4 directions and stuff like beds, lodestones, death pos (TODO) etc.
|
Holding a compass shows a bar with 4 directions and stuff like beds, lodestones, death pos (TODO) etc.
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ public record TweaksConfig(
|
||||||
boolean chatEnabled,
|
boolean chatEnabled,
|
||||||
boolean chatLocalEvents,
|
boolean chatLocalEvents,
|
||||||
String chatDefaultName,
|
String chatDefaultName,
|
||||||
|
int chatRadius,
|
||||||
|
|
||||||
boolean compassEnabled,
|
boolean compassEnabled,
|
||||||
int compassWidth,
|
int compassWidth,
|
||||||
|
@ -91,6 +92,7 @@ public record TweaksConfig(
|
||||||
boolean chatEnabled = config.getBoolean("chat.enabled");
|
boolean chatEnabled = config.getBoolean("chat.enabled");
|
||||||
boolean chatLocalEvents = config.getBoolean("chat.localEvents");
|
boolean chatLocalEvents = config.getBoolean("chat.localEvents");
|
||||||
String chatDefaultName = config.getString("chat.defaultName");
|
String chatDefaultName = config.getString("chat.defaultName");
|
||||||
|
int chatRadius = config.getInt("chat.radius");
|
||||||
|
|
||||||
boolean compassEnabled = config.getBoolean("compass.enabled");
|
boolean compassEnabled = config.getBoolean("compass.enabled");
|
||||||
int compassWidth = config.getInt("compass.width");
|
int compassWidth = config.getInt("compass.width");
|
||||||
|
@ -117,7 +119,7 @@ public record TweaksConfig(
|
||||||
brandEnabled, brandText, brandShowPing, brandShowMspt,
|
brandEnabled, brandText, brandShowPing, brandShowMspt,
|
||||||
doorEnabled, doorDoubleOpen, doorKnocking,
|
doorEnabled, doorDoubleOpen, doorKnocking,
|
||||||
motdEnabled, motdSet,
|
motdEnabled, motdSet,
|
||||||
chatEnabled, chatLocalEvents, chatDefaultName,
|
chatEnabled, chatLocalEvents, chatDefaultName, chatRadius,
|
||||||
compassEnabled, compassWidth, compassPrecision,
|
compassEnabled, compassWidth, compassPrecision,
|
||||||
pomodoroEnabled, pomodoroForce,
|
pomodoroEnabled, pomodoroForce,
|
||||||
updaterEnabled,
|
updaterEnabled,
|
||||||
|
|
|
@ -9,9 +9,6 @@ package eu.m724.tweaks.chat;
|
||||||
import eu.m724.tweaks.Language;
|
import eu.m724.tweaks.Language;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
|
||||||
import net.md_5.bungee.api.chat.HoverEvent;
|
|
||||||
import net.md_5.bungee.api.chat.hover.content.Text;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
@ -71,15 +68,16 @@ public class ChatCommands implements CommandExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (authenticated) {
|
if (authenticated) {
|
||||||
|
/*component = new ComponentBuilder(Language.getComponent("chatJoined", ChatColor.GOLD))
|
||||||
|
.append(" ")
|
||||||
|
.append(ChatFormatUtils.formatChatRoom(chatRoom)).color(newRoom.color)
|
||||||
|
.build();*/
|
||||||
|
player.sendMessage("");
|
||||||
manager.setPlayerChatRoom(newRoom, player);
|
manager.setPlayerChatRoom(newRoom, player);
|
||||||
component = new ComponentBuilder(Language.getComponent("chatJoined", ChatColor.GOLD))
|
} else {
|
||||||
.append(newRoom.id).color(newRoom.color)
|
player.spigot().sendMessage(component);
|
||||||
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(newRoom.getInfoComponent())))
|
|
||||||
.append(Language.getComponent("chatPlayers", ChatColor.GOLD, newRoom.players.size()))
|
|
||||||
.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
player.spigot().sendMessage(component);
|
|
||||||
}
|
}
|
||||||
} else if (command.getName().equals("chatmanage")) {
|
} else if (command.getName().equals("chatmanage")) {
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
|
|
|
@ -10,6 +10,7 @@ import eu.m724.tweaks.TweaksConfig;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import net.md_5.bungee.api.chat.TranslatableComponent;
|
import net.md_5.bungee.api.chat.TranslatableComponent;
|
||||||
import net.md_5.bungee.chat.ComponentSerializer;
|
import net.md_5.bungee.chat.ComponentSerializer;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
@ -25,11 +26,27 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
public class ChatListener implements Listener {
|
public class ChatListener implements Listener {
|
||||||
private final ChatManager chatManager;
|
private final ChatManager chatManager;
|
||||||
private final boolean localEvents;
|
private final String defaultRoom = TweaksConfig.getConfig().chatDefaultName();
|
||||||
|
private final boolean localEvents = TweaksConfig.getConfig().chatLocalEvents();
|
||||||
|
private final int radius;
|
||||||
|
|
||||||
public ChatListener(ChatManager chatManager) {
|
public ChatListener(ChatManager chatManager) {
|
||||||
this.chatManager = chatManager;
|
this.chatManager = chatManager;
|
||||||
this.localEvents = TweaksConfig.getConfig().chatLocalEvents();
|
if (TweaksConfig.getConfig().chatRadius() < 0) {
|
||||||
|
radius = 0;
|
||||||
|
} else {
|
||||||
|
radius = (int) Math.pow(TweaksConfig.getConfig().chatRadius(), 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private BaseComponent chatPrefix(ChatRoom room) {
|
||||||
|
if (room.id.equals(defaultRoom))
|
||||||
|
return new TextComponent();
|
||||||
|
return ChatFormatUtils.chatRoomPrefixShort(room);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean proximityFor(ChatRoom room) {
|
||||||
|
return radius > 0 && room.id.equals(defaultRoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -37,17 +54,20 @@ public class ChatListener implements Listener {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
ChatRoom chatRoom = chatManager.getPlayerChatRoom(player);
|
ChatRoom chatRoom = chatManager.getPlayerChatRoom(player);
|
||||||
|
|
||||||
BaseComponent[] component = new ComponentBuilder("Chat room: ").color(ChatColor.GOLD)
|
|
||||||
.append(ChatFormatUtils.formatChatRoom(chatRoom))
|
|
||||||
.create();
|
|
||||||
player.spigot().sendMessage(component);
|
|
||||||
|
|
||||||
if (localEvents) {
|
if (localEvents) {
|
||||||
chatRoom.broadcast(
|
var cb = new ComponentBuilder()
|
||||||
new ComponentBuilder(ChatFormatUtils.chatRoomPrefixShort(chatRoom))
|
.append(chatPrefix(chatRoom))
|
||||||
.append(new TranslatableComponent("multiplayer.player.joined", ChatFormatUtils.formatPlayer(player))).color(ChatColor.GREEN)
|
.append(new TranslatableComponent("multiplayer.player.joined", ChatFormatUtils.formatPlayer(player)));
|
||||||
.create()
|
|
||||||
|
if (proximityFor(chatRoom)) {
|
||||||
|
chatRoom.broadcastNearCond(
|
||||||
|
player.getLocation(), radius,
|
||||||
|
cb.color(ChatColor.GREEN).create(),
|
||||||
|
cb.color(ChatColor.of("#77AA77")).create()
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
chatRoom.broadcast(cb.color(ChatColor.GREEN).create());
|
||||||
|
}
|
||||||
|
|
||||||
// remove Minecraft join message
|
// remove Minecraft join message
|
||||||
event.setJoinMessage(null);
|
event.setJoinMessage(null);
|
||||||
|
@ -60,11 +80,19 @@ public class ChatListener implements Listener {
|
||||||
ChatRoom chatRoom = chatManager.removePlayer(player);
|
ChatRoom chatRoom = chatManager.removePlayer(player);
|
||||||
|
|
||||||
if (localEvents) {
|
if (localEvents) {
|
||||||
chatRoom.broadcast(
|
var cb = new ComponentBuilder()
|
||||||
new ComponentBuilder(ChatFormatUtils.chatRoomPrefixShort(chatRoom))
|
.append(chatPrefix(chatRoom))
|
||||||
.append(new TranslatableComponent("multiplayer.player.left", ChatFormatUtils.formatPlayer(player))).color(ChatColor.RED)
|
.append(new TranslatableComponent("multiplayer.player.left", ChatFormatUtils.formatPlayer(player)));
|
||||||
.create()
|
|
||||||
|
if (proximityFor(chatRoom)) {
|
||||||
|
chatRoom.broadcastNearCond(
|
||||||
|
player.getLocation(), radius,
|
||||||
|
cb.color(ChatColor.RED).create(),
|
||||||
|
cb.color(ChatColor.of("#AA7777")).create()
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
chatRoom.broadcast(cb.color(ChatColor.RED).create());
|
||||||
|
}
|
||||||
|
|
||||||
// remove Minecraft quit message
|
// remove Minecraft quit message
|
||||||
event.setQuitMessage(null);
|
event.setQuitMessage(null);
|
||||||
|
@ -82,22 +110,28 @@ public class ChatListener implements Listener {
|
||||||
|
|
||||||
// TODO make players ChatFormatUtils
|
// TODO make players ChatFormatUtils
|
||||||
|
|
||||||
chatRoom.broadcast(
|
var component = new ComponentBuilder()
|
||||||
new ComponentBuilder()
|
.append(chatPrefix(chatRoom))
|
||||||
.append(ChatFormatUtils.chatRoomPrefixShort(chatRoom))
|
|
||||||
.append(deathMessage)
|
.append(deathMessage)
|
||||||
.create()
|
.color(ChatColor.YELLOW)
|
||||||
);
|
.create();
|
||||||
|
|
||||||
|
if (proximityFor(chatRoom)) {
|
||||||
|
chatRoom.broadcastNear(player.getLocation(), radius, component);
|
||||||
|
} else {
|
||||||
|
chatRoom.broadcast(component);
|
||||||
|
}
|
||||||
|
|
||||||
// broadcast to killer if available
|
// broadcast to killer if available
|
||||||
if (player.getLastDamageCause().getDamageSource().getCausingEntity() instanceof Player killer) {
|
if (player.getLastDamageCause().getDamageSource().getCausingEntity() instanceof Player killer) {
|
||||||
ChatRoom chatRoom2 = chatManager.getPlayerChatRoom(killer);
|
ChatRoom chatRoom2 = chatManager.getPlayerChatRoom(killer);
|
||||||
chatRoom2.broadcast(
|
if (chatRoom != chatRoom2) {
|
||||||
new ComponentBuilder()
|
if (proximityFor(chatRoom)) {
|
||||||
.append(ChatFormatUtils.chatRoomPrefixShort(chatRoom2))
|
chatRoom2.broadcastNear(killer.getLocation(), radius, component);
|
||||||
.append(deathMessage)
|
} else {
|
||||||
.create()
|
chatRoom2.broadcast(component);
|
||||||
);
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove Minecraft death message
|
// remove Minecraft death message
|
||||||
|
@ -111,12 +145,17 @@ public class ChatListener implements Listener {
|
||||||
ChatRoom chatRoom = chatManager.getPlayerChatRoom(player);
|
ChatRoom chatRoom = chatManager.getPlayerChatRoom(player);
|
||||||
String message = event.getMessage();
|
String message = event.getMessage();
|
||||||
|
|
||||||
ComponentBuilder builder = new ComponentBuilder();
|
var component = new ComponentBuilder()
|
||||||
builder.append(ChatFormatUtils.chatRoomPrefixShort(chatRoom));
|
.append(chatPrefix(chatRoom))
|
||||||
builder.append(ChatFormatUtils.formatPlayer(player)).append(": ");
|
.append(ChatFormatUtils.formatPlayer(player)).append(": ")
|
||||||
builder.append(message).color(chatRoom.color);
|
.append(message).color(chatRoom.color)
|
||||||
|
.create();
|
||||||
|
|
||||||
chatRoom.broadcast(builder.create());
|
if (proximityFor(chatRoom)) {
|
||||||
|
chatRoom.broadcastNear(player.getLocation(), radius, component);
|
||||||
|
} else {
|
||||||
|
chatRoom.broadcast(component);
|
||||||
|
}
|
||||||
|
|
||||||
// remove the original message
|
// remove the original message
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
|
@ -97,7 +97,7 @@ public class ChatManager {
|
||||||
|
|
||||||
oldRoom.broadcast(
|
oldRoom.broadcast(
|
||||||
new ComponentBuilder()
|
new ComponentBuilder()
|
||||||
.append(ChatFormatUtils.chatRoomPrefixShort(chatRoom))
|
.append(ChatFormatUtils.chatRoomPrefixShort(oldRoom))
|
||||||
.append(ChatFormatUtils.formatPlayer(player))
|
.append(ChatFormatUtils.formatPlayer(player))
|
||||||
.append(" has left the chat room").color(ChatColor.RED)
|
.append(" has left the chat room").color(ChatColor.RED)
|
||||||
.create()
|
.create()
|
||||||
|
|
|
@ -9,6 +9,7 @@ package eu.m724.tweaks.chat;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@ -69,4 +70,20 @@ public class ChatRoom {
|
||||||
players.forEach(p -> p.spigot().sendMessage(component));
|
players.forEach(p -> p.spigot().sendMessage(component));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void broadcastNear(Location source, int diameter, BaseComponent[] component) {
|
||||||
|
players.forEach(p -> {
|
||||||
|
double distance = p.getLocation().distanceSquared(source);
|
||||||
|
if (distance < diameter) p.spigot().sendMessage(component);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void broadcastNearCond(Location source, int diameter, BaseComponent[] near, BaseComponent[] far) {
|
||||||
|
players.forEach(p -> {
|
||||||
|
double distance = p.getLocation().distanceSquared(source);
|
||||||
|
|
||||||
|
if (distance < diameter) p.spigot().sendMessage(near);
|
||||||
|
else p.spigot().sendMessage(far);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,9 @@ chat:
|
||||||
localEvents: true
|
localEvents: true
|
||||||
# Name of the default / global chatroom
|
# Name of the default / global chatroom
|
||||||
defaultName: "global"
|
defaultName: "global"
|
||||||
|
# Proximity only works in the global chat room
|
||||||
|
# Value is in blocks, set it to more than 0 to enable proximity chat
|
||||||
|
radius: 0
|
||||||
|
|
||||||
# Compass shown in a text form on the actionbar
|
# Compass shown in a text form on the actionbar
|
||||||
compass:
|
compass:
|
||||||
|
|
|
@ -19,9 +19,6 @@ chatPasswordProtected = This room is password protected
|
||||||
chatWrongPassword = Wrong password
|
chatWrongPassword = Wrong password
|
||||||
chatNoSuchRoom = No room named %s
|
chatNoSuchRoom = No room named %s
|
||||||
chatAlreadyHere = You're already in this room
|
chatAlreadyHere = You're already in this room
|
||||||
# Room name is added at end
|
|
||||||
chatJoined = Joined chat room:
|
|
||||||
chatPlayers = %d other players are here
|
|
||||||
|
|
||||||
# Used when a player joins using the wrong key or no key
|
# Used when a player joins using the wrong key or no key
|
||||||
authKickWrongKey = You're connecting to the wrong server address. You must connect to the one you're registered to.
|
authKickWrongKey = You're connecting to the wrong server address. You must connect to the one you're registered to.
|
||||||
|
|
Loading…
Reference in a new issue