Сделал много изменений, сами все посмотрите.
This commit is contained in:
parent
c6f609b3a0
commit
11dc48831a
3 changed files with 87 additions and 25 deletions
|
@ -13,6 +13,8 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static ru.neroduckale.nerodays.nerodays.LOGGER;
|
||||
|
||||
/**
|
||||
* Class used to execute Discord Webhooks with low effort
|
||||
*/
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package ru.neroduckale.nerodays;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
|
@ -9,6 +7,7 @@ import net.minecraftforge.event.ServerChatEvent;
|
|||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
||||
import net.minecraftforge.event.entity.player.AdvancementEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
|
||||
import java.awt.*;
|
||||
|
@ -39,35 +38,44 @@ public class Events {
|
|||
|
||||
|
||||
@SubscribeEvent
|
||||
public void NewDay(TickEvent.LevelTickEvent worldTickEvent) throws IOException {
|
||||
public void NewDay(TickEvent.LevelTickEvent worldTickEvent) {
|
||||
if (worldTickEvent.level.getDayTime() % 24000 == 0) {
|
||||
var a = worldTickEvent.level.getDayTime() / 24000;
|
||||
if (days != a) {
|
||||
days = (int) a;
|
||||
} else {return;}
|
||||
var m = "Новый день! День: " + a;
|
||||
LOGGER.error(m);
|
||||
serverwebhook.setContent(m);
|
||||
serverwebhook.execute();
|
||||
serverwebhook.setContent("");
|
||||
DiscordWebhook.EmbedObject embed = new DiscordWebhook.EmbedObject()
|
||||
.setTitle(m)
|
||||
.setColor(Color.white);
|
||||
serverwebhook.addEmbed(embed);
|
||||
try {
|
||||
serverwebhook.execute();
|
||||
} catch (IOException exception) {
|
||||
LOGGER.error(exception.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SubscribeEvent
|
||||
public void NewMsg(ServerChatEvent event) throws IOException {
|
||||
public void NewMsg(ServerChatEvent event) {
|
||||
var nickname = event.getUsername();
|
||||
var message = event.getMessage().getString();
|
||||
webhook.setUsername(nickname);
|
||||
webhook.setContent(message);
|
||||
webhook.setAvatarUrl("https://ely.by/services/skins-renderer?url=http://skinsystem.ely.by/skins/%s&scale=10&renderFace=1".formatted(nickname));
|
||||
webhook.execute();
|
||||
try {
|
||||
webhook.execute();
|
||||
} catch (IOException exception) {
|
||||
LOGGER.error(exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@SubscribeEvent
|
||||
public void Death(LivingDeathEvent event) throws IOException {
|
||||
public void Death(LivingDeathEvent event) {
|
||||
|
||||
if (event.getEntity() instanceof ServerPlayer player) {
|
||||
var nickname = player.getDisplayName().getString();
|
||||
|
@ -79,25 +87,79 @@ public class Events {
|
|||
.setTitle(chlen)
|
||||
.setColor(Color.red);
|
||||
serverwebhook.addEmbed(embed);
|
||||
serverwebhook.execute();
|
||||
try {
|
||||
serverwebhook.execute();
|
||||
} catch (IOException exception) {
|
||||
LOGGER.error(exception.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SubscribeEvent
|
||||
public void onNewAchivment(AdvancementEvent.AdvancementEarnEvent event) throws IOException {
|
||||
public void onNewAchievement(AdvancementEvent.AdvancementEarnEvent event) {
|
||||
if (event.getAdvancement().getDisplay() == null) return;
|
||||
String id = event.getAdvancement().getId().getPath().replace("/", ".");
|
||||
|
||||
String description;
|
||||
String title;
|
||||
if (json.get("advancements.%s.description".formatted(id)).getAsString() == null) {
|
||||
description = event.getAdvancement().getDisplay().getDescription().getString();
|
||||
} else {
|
||||
description = json.get("advancements.%s.description".formatted(id)).getAsString();
|
||||
}
|
||||
|
||||
if (json.get("advancements.%s.title".formatted(id)).getAsString() == null) {
|
||||
title = event.getAdvancement().getDisplay().getTitle().getString();
|
||||
} else {
|
||||
title = json.get("advancements.%s.title".formatted(id)).getAsString();
|
||||
}
|
||||
|
||||
var nickname = event.getEntity().getDisplayName().getString();
|
||||
var achivka = event.getAdvancement().toString();
|
||||
var message = nickname + " получил ачивку!";
|
||||
DiscordWebhook.EmbedObject embed = new DiscordWebhook.EmbedObject()
|
||||
.setAuthor(message, "", "https://ely.by/services/skins-renderer?url=http://skinsystem.ely.by/skins/%s&scale=10&renderFace=1".formatted(nickname))
|
||||
.setTitle(achivka)
|
||||
.setColor(Color.red);
|
||||
.setTitle(title)
|
||||
.setDescription(description)
|
||||
.setColor(Color.green);
|
||||
serverwebhook.addEmbed(embed);
|
||||
serverwebhook.execute(); //НЕ ПРОВЕРЯЛ
|
||||
try {
|
||||
serverwebhook.execute();
|
||||
} catch (IOException exception) {
|
||||
LOGGER.error(exception.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@SubscribeEvent
|
||||
public void playerJoin(PlayerEvent.PlayerLoggedInEvent event) {
|
||||
var nickname = event.getEntity().getDisplayName().getString();
|
||||
String message = nickname + " зашел на сервер!";
|
||||
DiscordWebhook.EmbedObject embed = new DiscordWebhook.EmbedObject()
|
||||
.setAuthor(message, "", "https://ely.by/services/skins-renderer?url=http://skinsystem.ely.by/skins/%s&scale=10&renderFace=1".formatted(nickname))
|
||||
.setColor(Color.green);
|
||||
serverwebhook.addEmbed(embed);
|
||||
try {
|
||||
serverwebhook.execute();
|
||||
} catch (IOException exception) {
|
||||
LOGGER.error(exception.getMessage());
|
||||
}
|
||||
}
|
||||
@SubscribeEvent
|
||||
public void playerLeave(PlayerEvent.PlayerLoggedOutEvent event) {
|
||||
var nickname = event.getEntity().getDisplayName().getString();
|
||||
String message = nickname + " вышел с сервера.";
|
||||
DiscordWebhook.EmbedObject embed = new DiscordWebhook.EmbedObject()
|
||||
.setAuthor(message, "", "https://ely.by/services/skins-renderer?url=http://skinsystem.ely.by/skins/%s&scale=10&renderFace=1".formatted(nickname))
|
||||
.setColor(Color.red);
|
||||
serverwebhook.addEmbed(embed);
|
||||
try {
|
||||
serverwebhook.execute();
|
||||
} catch (IOException exception) {
|
||||
LOGGER.error(exception.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,23 +1,21 @@
|
|||
package ru.neroduckale.nerodays;
|
||||
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.mojang.logging.LogUtils;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.server.ServerStartingEvent;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.event.server.ServerStartingEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
|
||||
@Mod(nerodays.MODID)
|
||||
|
@ -31,21 +29,21 @@ public class nerodays
|
|||
public static JsonObject json;
|
||||
|
||||
|
||||
public nerodays() throws UnsupportedEncodingException {
|
||||
public nerodays() throws IOException {
|
||||
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
MinecraftForge.EVENT_BUS.register(new Events());
|
||||
|
||||
var readIn = new BufferedReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("assets/nerodays/ru_ru.json"), "UTF-8"));
|
||||
var readIn = new BufferedReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("assets/nerodays/ru_ru.json"), StandardCharsets.UTF_8));
|
||||
json = JsonParser.parseReader(readIn).getAsJsonObject();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onServerStarting(ServerStartingEvent event) throws IOException {
|
||||
serverwebhook.setContent("Сервер запущен!");
|
||||
serverwebhook.addEmbed(new DiscordWebhook.EmbedObject().setTitle("Сервер включен!").setColor(Color.white));
|
||||
serverwebhook.execute();
|
||||
serverwebhook.setContent("");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue