Add chat helpers to libzontreck
This commit is contained in:
parent
6789b0f329
commit
fefb02bc8d
3 changed files with 77 additions and 2 deletions
|
@ -5,5 +5,5 @@ org.gradle.daemon=false
|
||||||
|
|
||||||
mc_version=1.18.2
|
mc_version=1.18.2
|
||||||
forge_version=40.2.1
|
forge_version=40.2.1
|
||||||
myversion=1.0.5.3
|
myversion=1.0.5.4
|
||||||
parchment_version=2022.11.06
|
parchment_version=2022.11.06
|
75
src/main/java/dev/zontreck/libzontreck/util/ChatHelpers.java
Normal file
75
src/main/java/dev/zontreck/libzontreck/util/ChatHelpers.java
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
package dev.zontreck.libzontreck.util;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import dev.zontreck.libzontreck.LibZontreck;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||||
|
import net.minecraftforge.network.NetworkHooks;
|
||||||
|
|
||||||
|
public class ChatHelpers {
|
||||||
|
public static void broadcastActionBar(Component message, MinecraftServer server)
|
||||||
|
{
|
||||||
|
server.execute(new Runnable(){
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
for (ServerPlayer player : server.getPlayerList().getPlayers()) {
|
||||||
|
player.displayClientMessage(message, true);
|
||||||
|
}
|
||||||
|
LibZontreck.LOGGER.info("[ALL] "+message.getContents());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void broadcast(Component message, MinecraftServer server)
|
||||||
|
{
|
||||||
|
server.execute(new Runnable(){
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
for (ServerPlayer player : server.getPlayerList().getPlayers()) {
|
||||||
|
player.displayClientMessage(message, false);
|
||||||
|
}
|
||||||
|
LibZontreck.LOGGER.info("[ALL] "+message.getContents());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void broadcastTo(UUID ID, Component message, MinecraftServer server, boolean actionBar)
|
||||||
|
{
|
||||||
|
server.execute(new Runnable(){
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
ServerPlayer play = server.getPlayerList().getPlayer(ID);
|
||||||
|
play.displayClientMessage(message, actionBar);
|
||||||
|
|
||||||
|
LibZontreck.LOGGER.info("[SERVER] -> ["+play.getName().getContents()+"] "+message.getContents());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void broadcastTo(UUID ID, Component message, MinecraftServer server)
|
||||||
|
{
|
||||||
|
broadcastTo(ID, message, server, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void broadcastToAbove(UUID ID, Component message, MinecraftServer server)
|
||||||
|
{
|
||||||
|
broadcastTo(ID, message, server, true);
|
||||||
|
}
|
||||||
|
public static void broadcastTo(Player ID, Component message, MinecraftServer server)
|
||||||
|
{
|
||||||
|
broadcastTo(ID.getUUID(), message, server, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void broadcastToAbove(Player ID, Component message, MinecraftServer server)
|
||||||
|
{
|
||||||
|
broadcastTo(ID.getUUID(), message, server, true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,7 +19,7 @@ modId="libzontreck" #mandatory
|
||||||
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
|
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
|
||||||
# ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata
|
# ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata
|
||||||
# see the associated build.gradle script for how to populate this completely automatically during a build
|
# see the associated build.gradle script for how to populate this completely automatically during a build
|
||||||
version="1.0.5.3" #mandatory
|
version="1.0.5.4" #mandatory
|
||||||
# A display name for the mod
|
# A display name for the mod
|
||||||
displayName="LibZontreck" #mandatory
|
displayName="LibZontreck" #mandatory
|
||||||
# A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/
|
# A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/
|
||||||
|
|
Reference in a new issue