minecraft - 如何向服务器上的所有玩家发送消息?(服务器端)
问题描述
我如何向服务器上的所有玩家发送消息?(尝试这样做时,它只输出到控制台,我相信这是因为客户端没有安装mod。)
我一直在尝试为 1.7.10 服务器制作一个模组(放入 1.7.10 模组包),它可以在线向所有玩家发送消息。我已经查过这个问题,但没有找到任何答案。
@SideOnly(Side.SERVER)
@SubscribeEvent
public void onDeath(PlayerEvent.Clone event)
{
if (event.wasDeath) {
final String[] messages = {"Oh boiss we got a respawner O_O", "How dare ye respawn on me?", "GAAH! You died again!", "._. Just why...", "Was taht me or waas that you? -.-","Why isn't this in hardcore mode? It should be..."};
Random random = new Random();
int index = random.nextInt(messages.length);
ChatComponentText text = new ChatComponentText(messages[index]);
ChatStyle style = new ChatStyle();
style.setColor(EnumChatFormatting.LIGHT_PURPLE);
text.setChatStyle(style);
FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().sendChatMsg(text);
System.out.println("Respawned");
}
}
我希望服务器会向所有人发送消息,但只会输出到控制台。
解决方案
一个非常快速的处理方法是为玩家加入时创建一个 EventHandler。然后将它们添加到 ArrayList。然后当他们离开时(检查踢/退出事件)。从 ArrayList 中删除它们。通过拥有一个数组列表,您可以运行它并向每个玩家发送消息。
推荐阅读
- r - 从 txt 文件到 R 中的分组条形图
- dart - 格式化时崩溃(Dart sdk: '>=2.0.0-dev.65.0 <2.0.0')
- reactjs - VsCode (Ctrl + K + D) - JSX 元素没有对应的结束标签
- python - Golang net.Listen 绑定到已经在使用的端口
- html - 在控制器“Y”上找不到公共操作方法“X”,产生 404 错误
- c++ - 使用 cin、if 语句和数组不起作用
- excel - 如何将单词表导入excel并保持格式?
- python - 无法执行用于 CNM 社区检测的 snap.py 代码
- php - Laravel 访问 hasMany 的 hasOne
- javascript - Material Design 组件文本字段的标签不浮动到左上角