55 lines
2.3 KiB
Java
55 lines
2.3 KiB
Java
package systems.brn.gotifymc;
|
|
|
|
import net.fabricmc.fabric.api.networking.v1.PacketSender;
|
|
import net.minecraft.network.message.MessageType;
|
|
import net.minecraft.network.message.SignedMessage;
|
|
import net.minecraft.server.MinecraftServer;
|
|
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
|
import net.minecraft.server.network.ServerPlayerEntity;
|
|
import net.minecraft.stat.Stats;
|
|
import net.minecraft.text.Text;
|
|
|
|
import static systems.brn.gotifymc.GotifyAPI.sendNotification;
|
|
|
|
public class NotificationEvent {
|
|
public static void serverStarting(MinecraftServer server) {
|
|
sendNotification("Startup", "The server is starting", 5);
|
|
}
|
|
|
|
public static void serverStarted(MinecraftServer server) {
|
|
sendNotification("Started", "The server is started", 5);
|
|
}
|
|
|
|
public static void serverStopping(MinecraftServer server) {
|
|
sendNotification("Stopping", "The server is stopping", 5);
|
|
}
|
|
|
|
public static void serverStopped(MinecraftServer server) {
|
|
sendNotification("Stopped", "The server is stopped", 5);
|
|
}
|
|
|
|
public static void connect(ServerPlayNetworkHandler serverPlayNetworkHandler, PacketSender packetSender, MinecraftServer server) {
|
|
if (packetSender instanceof ServerPlayerEntity player) {
|
|
if (player.getStatHandler().getStat(Stats.CUSTOM, Stats.LEAVE_GAME) == 0) {
|
|
sendNotification("NEW player connecting", "A %s is connecting from %s".formatted(player.getDisplayName(), player.getIp()), 6);
|
|
} else {
|
|
sendNotification("Player connecting", "A %s is connecting from %s".formatted(player.getDisplayName(), player.getIp()), 4);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void afterRespawn(ServerPlayerEntity oldPlayer, ServerPlayerEntity newPlayer, boolean alive) {
|
|
sendNotification("Respawning", "%s died".formatted(oldPlayer.getDisplayName()), 2);
|
|
}
|
|
|
|
public static void chatMessage(SignedMessage signedMessage, ServerPlayerEntity player, MessageType.Parameters parameters) {
|
|
sendNotification("Chat message", "<%s> %s".formatted(player.getDisplayName(), signedMessage.getContent().getString()), 3);
|
|
}
|
|
|
|
public static void gameMessage(MinecraftServer server, Text text, boolean b) {
|
|
if (!b) {
|
|
sendNotification("Server message", text.getString(), 3);
|
|
}
|
|
}
|
|
}
|