Compare commits

..

No commits in common. "799833b685be89e5c62731419906ad798a40c006" and "b267985be1c1f6e5899a075fb78ae5fa8f69ac5c" have entirely different histories.

8 changed files with 25 additions and 49 deletions

View file

@ -12,8 +12,7 @@ Please report all suspicious behavior. You can do so on any of those:
Stuff no<sub><sup>t many</sup></sub> other plugins do.
Dependencies:
- **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)
- **1.21.1** this is mandatory as the plugin uses NMS for some stuff
- [ProtocolLib](https://www.spigotmc.org/resources/protocollib.1997/) (optional, but you lose a lot)
# Features

4
reflections.txt Normal file
View file

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

View file

@ -40,12 +40,6 @@ public class ChatCommands implements CommandExecutor {
player.spigot().sendMessage(chatRoom.getInfoComponent());
} else { // join room
String id = args[0];
if (id.equals(chatRoom.id)) {
sender.spigot().sendMessage(Language.getComponent("chatAlreadyHere", ChatColor.GRAY));
return true;
}
String password = null;
if (args.length > 1) {
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;
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));
if (player.getCustomName() != null) {
return new ComponentBuilder()
.append("~" + player.getCustomName()).color(nameColor)
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(player.getName())))
.build();
.create();
} else {
return new ComponentBuilder()
.append(player.getName()).color(nameColor)
.build();
.create();
}
}
public static BaseComponent chatRoomPrefixShort(ChatRoom chatRoom) {
public static BaseComponent[] chatRoomPrefixShort(ChatRoom chatRoom) {
ChatColor prefixColor = ChatColor.of(chatRoom.color.getColor().darker());
return new ComponentBuilder(chatRoom.id.charAt(0) + " ").color(prefixColor)
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(chatRoom.getInfoComponent())))
.build();
.create();
}
public static BaseComponent formatChatRoom(ChatRoom chatRoom) {
public static BaseComponent[] formatChatRoom(ChatRoom chatRoom) {
return new ComponentBuilder(chatRoom.id).color(chatRoom.color)
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(chatRoom.getInfoComponent())))
.build();
.create();
}
}

View file

@ -10,11 +10,6 @@ import eu.m724.tweaks.TweaksConfig;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
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.event.EventHandler;
import org.bukkit.event.Listener;
@ -44,9 +39,11 @@ public class ChatListener implements Listener {
if (localEvents) {
chatRoom.broadcast(
new ComponentBuilder(ChatFormatUtils.chatRoomPrefixShort(chatRoom))
.append(new TranslatableComponent("multiplayer.player.joined", ChatFormatUtils.formatPlayer(player))).color(ChatColor.GREEN)
.create()
new ComponentBuilder()
.append(ChatFormatUtils.chatRoomPrefixShort(chatRoom))
.append(ChatFormatUtils.formatPlayer(player))
.append(" has joined the server").color(ChatColor.GREEN)
.create()
);
// remove Minecraft join message
@ -61,8 +58,10 @@ public class ChatListener implements Listener {
if (localEvents) {
chatRoom.broadcast(
new ComponentBuilder(ChatFormatUtils.chatRoomPrefixShort(chatRoom))
.append(new TranslatableComponent("multiplayer.player.left", ChatFormatUtils.formatPlayer(player))).color(ChatColor.RED)
new ComponentBuilder()
.append(ChatFormatUtils.chatRoomPrefixShort(chatRoom))
.append(ChatFormatUtils.formatPlayer(player))
.append(" has left the server").color(ChatColor.RED)
.create()
);
@ -77,29 +76,13 @@ public class ChatListener implements Listener {
Player player = event.getEntity();
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(
new ComponentBuilder()
.append(ChatFormatUtils.chatRoomPrefixShort(chatRoom))
.append(deathMessage)
.append(event.getDeathMessage())
.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
event.setDeathMessage(null);
}

View file

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

View file

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

View file

@ -18,7 +18,6 @@ updatesClickToOpen = Click to open on SpigotMC "%s"
chatPasswordProtected = This room is password protected
chatWrongPassword = Wrong password
chatNoSuchRoom = No room named %s
chatAlreadyHere = You're already in this room
# Room name is added at end
chatJoined = Joined chat room:
chatPlayers = %d other players are here