Compare commits
6 commits
b267985be1
...
799833b685
Author | SHA1 | Date | |
---|---|---|---|
799833b685 | |||
49c6139d99 | |||
94f6b62a28 | |||
6183ccd6bf | |||
760f52df71 | |||
e53a0880f1 |
8 changed files with 49 additions and 25 deletions
|
@ -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
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
modules that require nms / reflections / protocollib:
|
|
||||||
- MOTD
|
|
||||||
- brand
|
|
||||||
- worldborder
|
|
|
@ -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(" "));
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,10 +44,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.joined", ChatFormatUtils.formatPlayer(player))).color(ChatColor.GREEN)
|
||||||
.append(ChatFormatUtils.formatPlayer(player))
|
|
||||||
.append(" has joined the server").color(ChatColor.GREEN)
|
|
||||||
.create()
|
.create()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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))
|
||||||
|
|
|
@ -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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
Loading…
Reference in a new issue