Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make notifications individually configurable #165

Merged
merged 1 commit into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

dependencies {

api("com.github.GTNewHorizons:GTNHLib:0.5.22:dev")
api("com.github.GTNewHorizons:GTNHLib:0.6.0:dev")
compileOnly("com.github.GTNewHorizons:NotEnoughItems:2.7.0-GTNH:dev")
compileOnly("com.github.GTNewHorizons:EnderIO:2.8.22:dev")
compileOnly("com.github.GTNewHorizons:Navigator:1.0.15:dev")
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/serverutils/ServerUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.IChatComponent;

import org.apache.logging.log4j.LogManager;
Expand All @@ -24,7 +25,6 @@
import cpw.mods.fml.common.network.NetworkCheckHandler;
import cpw.mods.fml.relauncher.Side;
import serverutils.lib.command.CommandUtils;
import serverutils.lib.util.SidedUtils;

@Mod(
modid = ServerUtilities.MOD_ID,
Expand All @@ -49,7 +49,11 @@ public class ServerUtilities {
public static ServerUtilitiesCommon PROXY;

public static IChatComponent lang(@Nullable ICommandSender sender, String key, Object... args) {
return SidedUtils.lang(sender, MOD_ID, key, args);
return lang(key, args);
}

public static IChatComponent lang(String key, Object... args) {
return new ChatComponentTranslation(key, args);
}

public static CommandException error(@Nullable ICommandSender sender, String key, Object... args) {
Expand Down
132 changes: 83 additions & 49 deletions src/main/java/serverutils/ServerUtilitiesNotifications.java
Original file line number Diff line number Diff line change
@@ -1,54 +1,74 @@
package serverutils;

import static serverutils.lib.EnumMessageLocation.ACTION_BAR;
import static serverutils.lib.EnumMessageLocation.CHAT;

import javax.annotation.Nullable;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;

import serverutils.data.ClaimedChunk;
import serverutils.data.ClaimedChunks;
import serverutils.data.ServerUtilitiesPlayerData;
import serverutils.lib.EnumMessageLocation;
import serverutils.lib.data.ForgeTeam;
import serverutils.lib.math.ChunkDimPos;
import serverutils.lib.util.ServerUtils;
import serverutils.lib.util.StringUtils;
import serverutils.lib.util.text_components.Notification;

public class ServerUtilitiesNotifications {

public static final ResourceLocation CHUNK_MODIFIED = new ResourceLocation(
ServerUtilities.MOD_ID,
"chunk_modified");
public static final ResourceLocation CHUNK_CHANGED = new ResourceLocation(ServerUtilities.MOD_ID, "chunk_changed");
public static final ResourceLocation CHUNK_CANT_CLAIM = new ResourceLocation(
ServerUtilities.MOD_ID,
"cant_claim_chunk");
public static final ResourceLocation UNCLAIMED_ALL = new ResourceLocation(ServerUtilities.MOD_ID, "unclaimed_all");
public static final String TELEPORT = "teleport";
public static final ResourceLocation TELEPORT_WARMUP = new ResourceLocation(
ServerUtilities.MOD_ID,
"teleport_warmup");
public static final ResourceLocation RELOAD_SERVER = new ResourceLocation(ServerUtilities.MOD_ID, "reload_server");
public static final ResourceLocation BACKUP_START = new ResourceLocation(ServerUtilities.MOD_ID, "backup_start");
public static final ResourceLocation BACKUP_END1 = new ResourceLocation(ServerUtilities.MOD_ID, "backup_end1");
public static final ResourceLocation BACKUP_END2 = new ResourceLocation(ServerUtilities.MOD_ID, "backup_end2");
public static final ResourceLocation CONFIG_CHANGED = new ResourceLocation(
ServerUtilities.MOD_ID,
"config_changed");
public static final String RESTART_TIMER_ID = "restart_timer";

public static final Notification NO_TEAM = Notification.of(
new ResourceLocation(ServerUtilities.MOD_ID, "no_team"),
new ChatComponentTranslation("serverutilities.lang.team.error.no_team")).setError();

public static void sendCantModifyChunk(MinecraftServer server, EntityPlayerMP player) {
Notification
.of(
new ResourceLocation(ServerUtilities.MOD_ID, "cant_modify_chunk"),
ServerUtilities.lang(player, "serverutilities.lang.chunks.cant_modify_chunk"))
.setError().send(server, player);
public enum ServerUtilitiesNotifications {

CHUNK_MODIFIED("chunk_modified", ACTION_BAR),
CHUNK_CHANGED("chunk_changed", ACTION_BAR),
CANT_MODIFY_CHUNK("cant_modify_chunk", ACTION_BAR),
TELEPORT("teleport", ACTION_BAR),
TELEPORT_WARMUP("teleport_warmup", ACTION_BAR),
BACKUP("backup", ACTION_BAR),
CONFIG_CHANGED("config_changed", ACTION_BAR),
RESTART_TIMER("restart_timer", ACTION_BAR),
CLEANUP("cleanup", ACTION_BAR),
PLAYER_AFK("player_afk", CHAT);

public static final ServerUtilitiesNotifications[] VALUES = values();

private final String id;
private final String desc;
private EnumMessageLocation location;

ServerUtilitiesNotifications(String id, EnumMessageLocation defaultLocation) {
this.id = id;
this.desc = StatCollector.translateToLocal(ServerUtilities.MOD_ID + ".notifications." + id + ".desc");
this.location = defaultLocation;
}

public Notification createNotification(IChatComponent component) {
return Notification.of(id, component);
}

public Notification createNotification(String key, Object... args) {
return createNotification(ServerUtilities.lang(key, args));
}

public void send(EntityPlayer player, String key, Object... args) {
createNotification(key, args).send(player);
}

public void send(EntityPlayer player, IChatComponent component) {
createNotification(component).send(player);
}

public void sendAll(String key, Object... args) {
createNotification(key, args).sendToAll();
}

public void sendAll(IChatComponent component) {
createNotification(component).sendToAll();
}

public static void updateChunkMessage(EntityPlayerMP player, ChunkDimPos pos) {
Expand All @@ -68,29 +88,43 @@ public static void updateChunkMessage(EntityPlayerMP player, ChunkDimPos pos) {
}

if (team != null) {
Notification notification = Notification.of(CHUNK_CHANGED, team.getTitle());
Notification notification = CHUNK_CHANGED.createNotification(team.getTitle());

if (!team.getDesc().isEmpty()) {
notification.addLine(StringUtils.italic(new ChatComponentText(team.getDesc()), true));
}

notification.send(player.mcServer, player);
notification.send(player);
} else {
Notification.of(
CHUNK_CHANGED,
StringUtils.color(
ServerUtilities.lang(player, "serverutilities.lang.chunks.wilderness"),
EnumChatFormatting.DARK_GREEN))
.send(player.mcServer, player);
CHUNK_CHANGED.send(
player,
StringUtils.color("serverutilities.lang.chunks.wilderness", EnumChatFormatting.DARK_GREEN));
}
}
}

public static void backupNotification(ResourceLocation id, String key, Object... args) {
if (!ServerUtilitiesConfig.backups.silent_backup) {
Notification
.of(id, StringUtils.color(ServerUtilities.lang(null, key, args), EnumChatFormatting.LIGHT_PURPLE))
.send(ServerUtils.getServer(), null);
public String getId() {
return id;
}

public String getDesc() {
return desc;
}

public void setLocation(EnumMessageLocation enabled) {
this.location = enabled;
}

public EnumMessageLocation getLocation() {
return location;
}

public static @Nullable ServerUtilitiesNotifications getFromId(ResourceLocation id) {
for (ServerUtilitiesNotifications n : VALUES) {
if (n.id.equalsIgnoreCase(id.getResourcePath())) {
return n;
}
}
return null;
}
}
16 changes: 0 additions & 16 deletions src/main/java/serverutils/client/EnumNotificationLocation.java

This file was deleted.

Loading
Loading