Compare commits

...

6 commits

Author SHA1 Message Date
799833b685
Make local events translated
All checks were successful
/ deploy (push) Successful in 2m36s
2024-12-05 20:33:06 +01:00
49c6139d99
Fix instant sleep 2024-12-05 20:32:39 +01:00
94f6b62a28
Make "has left the chat room" sent to the correct channel 2024-12-05 20:24:33 +01:00
6183ccd6bf
Disallow joining same chatroom 2024-12-05 19:59:31 +01:00
760f52df71
Fix default chat room 2024-12-05 19:56:34 +01:00
e53a0880f1
Janitor stuff 2024-12-05 19:39:21 +01:00
8 changed files with 49 additions and 25 deletions

View file

@ -12,7 +12,8 @@ Please report all suspicious behavior. You can do so on any of those:
Stuff no<sub><sup>t many</sup></sub> other plugins do. Stuff no<sub><sup>t many</sup></sub> other plugins do.
Dependencies: Dependencies:
- **1.21.1** this is mandatory as the plugin uses NMS for some stuff - **1.21.1** this is mandatory as the plugin uses NMS for some stuff\
The focus is on [a widely used version](https://bstats.org/global/bukkit) that has [good mod support](https://modrinth.com/modpack/fabulously-optimized/versions?c=release)
- [ProtocolLib](https://www.spigotmc.org/resources/protocollib.1997/) (optional, but you lose a lot) - [ProtocolLib](https://www.spigotmc.org/resources/protocollib.1997/) (optional, but you lose a lot)
# Features # Features

View file

@ -1,4 +0,0 @@
modules that require nms / reflections / protocollib:
- MOTD
- brand
- worldborder

View file

@ -40,6 +40,12 @@ public class ChatCommands implements CommandExecutor {
player.spigot().sendMessage(chatRoom.getInfoComponent()); player.spigot().sendMessage(chatRoom.getInfoComponent());
} else { // join room } else { // join room
String id = args[0]; String id = args[0];
if (id.equals(chatRoom.id)) {
sender.spigot().sendMessage(Language.getComponent("chatAlreadyHere", ChatColor.GRAY));
return true;
}
String password = null; String password = null;
if (args.length > 1) { if (args.length > 1) {
password = Arrays.stream(args).skip(1).collect(Collectors.joining(" ")); password = Arrays.stream(args).skip(1).collect(Collectors.joining(" "));

View file

@ -14,32 +14,32 @@ import net.md_5.bungee.api.chat.hover.content.Text;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class ChatFormatUtils { public class ChatFormatUtils {
public static BaseComponent[] formatPlayer(Player player) { public static BaseComponent formatPlayer(Player player) {
ChatColor nameColor = ChatColor.of("#" + Integer.toHexString(player.getName().hashCode()).substring(0, 6)); ChatColor nameColor = ChatColor.of("#" + Integer.toHexString(player.getName().hashCode()).substring(0, 6));
if (player.getCustomName() != null) { if (player.getCustomName() != null) {
return new ComponentBuilder() return new ComponentBuilder()
.append("~" + player.getCustomName()).color(nameColor) .append("~" + player.getCustomName()).color(nameColor)
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(player.getName()))) .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(player.getName())))
.create(); .build();
} else { } else {
return new ComponentBuilder() return new ComponentBuilder()
.append(player.getName()).color(nameColor) .append(player.getName()).color(nameColor)
.create(); .build();
} }
} }
public static BaseComponent[] chatRoomPrefixShort(ChatRoom chatRoom) { public static BaseComponent chatRoomPrefixShort(ChatRoom chatRoom) {
ChatColor prefixColor = ChatColor.of(chatRoom.color.getColor().darker()); ChatColor prefixColor = ChatColor.of(chatRoom.color.getColor().darker());
return new ComponentBuilder(chatRoom.id.charAt(0) + " ").color(prefixColor) return new ComponentBuilder(chatRoom.id.charAt(0) + " ").color(prefixColor)
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(chatRoom.getInfoComponent()))) .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(chatRoom.getInfoComponent())))
.create(); .build();
} }
public static BaseComponent[] formatChatRoom(ChatRoom chatRoom) { public static BaseComponent formatChatRoom(ChatRoom chatRoom) {
return new ComponentBuilder(chatRoom.id).color(chatRoom.color) return new ComponentBuilder(chatRoom.id).color(chatRoom.color)
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(chatRoom.getInfoComponent()))) .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(chatRoom.getInfoComponent())))
.create(); .build();
} }
} }

View file

@ -10,6 +10,11 @@ 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.TranslatableComponent;
import net.md_5.bungee.chat.ComponentSerializer;
import net.minecraft.network.chat.Component;
import org.bukkit.craftbukkit.v1_21_R1.CraftRegistry;
import org.bukkit.craftbukkit.v1_21_R1.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -39,11 +44,9 @@ public class ChatListener implements Listener {
if (localEvents) { if (localEvents) {
chatRoom.broadcast( chatRoom.broadcast(
new ComponentBuilder() new ComponentBuilder(ChatFormatUtils.chatRoomPrefixShort(chatRoom))
.append(ChatFormatUtils.chatRoomPrefixShort(chatRoom)) .append(new TranslatableComponent("multiplayer.player.joined", ChatFormatUtils.formatPlayer(player))).color(ChatColor.GREEN)
.append(ChatFormatUtils.formatPlayer(player)) .create()
.append(" has joined the server").color(ChatColor.GREEN)
.create()
); );
// remove Minecraft join message // remove Minecraft join message
@ -58,10 +61,8 @@ public class ChatListener implements Listener {
if (localEvents) { if (localEvents) {
chatRoom.broadcast( chatRoom.broadcast(
new ComponentBuilder() new ComponentBuilder(ChatFormatUtils.chatRoomPrefixShort(chatRoom))
.append(ChatFormatUtils.chatRoomPrefixShort(chatRoom)) .append(new TranslatableComponent("multiplayer.player.left", ChatFormatUtils.formatPlayer(player))).color(ChatColor.RED)
.append(ChatFormatUtils.formatPlayer(player))
.append(" has left the server").color(ChatColor.RED)
.create() .create()
); );
@ -76,13 +77,29 @@ public class ChatListener implements Listener {
Player player = event.getEntity(); Player player = event.getEntity();
ChatRoom chatRoom = chatManager.getPlayerChatRoom(player); ChatRoom chatRoom = chatManager.getPlayerChatRoom(player);
// would be easier on Paper but this is not Paper
BaseComponent deathMessage = ComponentSerializer.deserialize(Component.Serializer.toJson(((CraftPlayer)player).getHandle().getCombatTracker().getDeathMessage(), CraftRegistry.getMinecraftRegistry()));
// TODO make players ChatFormatUtils
chatRoom.broadcast( chatRoom.broadcast(
new ComponentBuilder() new ComponentBuilder()
.append(ChatFormatUtils.chatRoomPrefixShort(chatRoom)) .append(ChatFormatUtils.chatRoomPrefixShort(chatRoom))
.append(event.getDeathMessage()) .append(deathMessage)
.create() .create()
); );
// broadcast to killer if available
if (player.getLastDamageCause().getDamageSource().getCausingEntity() instanceof Player killer) {
ChatRoom chatRoom2 = chatManager.getPlayerChatRoom(killer);
chatRoom2.broadcast(
new ComponentBuilder()
.append(ChatFormatUtils.chatRoomPrefixShort(chatRoom2))
.append(deathMessage)
.create()
);
}
// remove Minecraft death message // remove Minecraft death message
event.setDeathMessage(null); event.setDeathMessage(null);
} }

View file

@ -67,7 +67,7 @@ public class ChatManager {
if (chatRoom == null) { if (chatRoom == null) {
if (id.equals(defaultRoom)) { if (id.equals(defaultRoom)) {
return new ChatRoom(defaultRoom, null, null); chatRoom = new ChatRoom(defaultRoom, null, null);
} else { } else {
chatRoom = ChatRoomLoader.load(plugin, id); chatRoom = ChatRoomLoader.load(plugin, id);
} }
@ -86,13 +86,16 @@ public class ChatManager {
*/ */
public void setPlayerChatRoom(ChatRoom chatRoom, Player player) { public void setPlayerChatRoom(ChatRoom chatRoom, Player player) {
ChatRoom oldRoom = getPlayerChatRoom(player); ChatRoom oldRoom = getPlayerChatRoom(player);
if (chatRoom.equals(oldRoom)) return; // no change if changing to the same room
oldRoom.players.remove(player); oldRoom.players.remove(player);
player.getPersistentDataContainer().set(chatRoomKey, PersistentDataType.STRING, chatRoom.id); player.getPersistentDataContainer().set(chatRoomKey, PersistentDataType.STRING, chatRoom.id);
playerMap.put(player, chatRoom); playerMap.put(player, chatRoom);
chatRoom.players.add(player); chatRoom.players.add(player);
chatRoom.broadcast( oldRoom.broadcast(
new ComponentBuilder() new ComponentBuilder()
.append(ChatFormatUtils.chatRoomPrefixShort(chatRoom)) .append(ChatFormatUtils.chatRoomPrefixShort(chatRoom))
.append(ChatFormatUtils.formatPlayer(player)) .append(ChatFormatUtils.formatPlayer(player))

View file

@ -39,7 +39,7 @@ public class SleepListener implements Listener {
if (!skippedCurrentNight.contains(event.getPlayer())) { if (!skippedCurrentNight.contains(event.getPlayer())) {
double onePlayerRatio = 1 / (event.getPlayer().getServer().getOnlinePlayers().size() * (world.getGameRuleValue(GameRule.PLAYERS_SLEEPING_PERCENTAGE) / 100.0)); double onePlayerRatio = 1 / (event.getPlayer().getServer().getOnlinePlayers().size() * (world.getGameRuleValue(GameRule.PLAYERS_SLEEPING_PERCENTAGE) / 100.0));
world.setTime((long) ((23459 - world.getTime()) * onePlayerRatio)); world.setTime(Math.min(world.getTime() + (long) (10917 * onePlayerRatio), 23459));
skippedCurrentNight.add(event.getPlayer()); skippedCurrentNight.add(event.getPlayer());
} }
} }

View file

@ -18,6 +18,7 @@ updatesClickToOpen = Click to open on SpigotMC "%s"
chatPasswordProtected = This room is password protected 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
# Room name is added at end # Room name is added at end
chatJoined = Joined chat room: chatJoined = Joined chat room:
chatPlayers = %d other players are here chatPlayers = %d other players are here