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

Translations update from Hosted Weblate #120

Open
wants to merge 20 commits into
base: 1.19.3
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.0.+'
id 'fabric-loom' version '1.1.+'
id 'maven-publish'
}

Expand All @@ -24,10 +24,10 @@ dependencies {

modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modImplementation 'xyz.nucleoid:plasmid:0.5+1.19.3-SNAPSHOT'
modImplementation include('xyz.nucleoid:more-codecs:0.3.0+1.19.3')
modImplementation 'xyz.nucleoid:plasmid:0.5+1.19.4-SNAPSHOT'
modImplementation include('xyz.nucleoid:more-codecs:0.3.1+1.19.4')

modCompileOnly "com.viaversion:viaversion-api:4.5.1-SNAPSHOT"
//modCompileOnly "com.viaversion:viaversion-api:4.5.1-SNAPSHOT"
modCompileOnly "dev.gegy:player-roles-api:1.6.0"
}

Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
org.gradle.jvmargs=-Xmx1G

# Fabric Properties
minecraft_version=1.19.3
yarn_mappings=1.19.3+build.2
loader_version=0.14.11
minecraft_version=1.19.4
yarn_mappings=1.19.4+build.1
loader_version=0.14.17

# Dependencies
fabric_version=0.68.1+1.19.3
fabric_version=0.75.3+1.19.4

# Mod Properties
mod_version=1.3.1
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/xyz/nucleoid/extras/NucleoidExtras.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package xyz.nucleoid.extras;

import eu.pb4.playerdata.api.PlayerDataApi;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.server.MinecraftServer;
Expand All @@ -8,14 +9,14 @@
import org.apache.logging.log4j.Logger;
import xyz.nucleoid.extras.chat_filter.ChatFilter;
import xyz.nucleoid.extras.command.CommandAliases;
import xyz.nucleoid.extras.command.ExtraCommands;
import xyz.nucleoid.extras.error.ExtrasErrorReporter;
import xyz.nucleoid.extras.game_portal.ExtrasGamePortals;
import xyz.nucleoid.extras.game_portal.ServerChangePortalBackend;
import xyz.nucleoid.extras.integrations.NucleoidIntegrations;
import xyz.nucleoid.extras.lobby.NEBlocks;
import xyz.nucleoid.extras.lobby.NECriteria;
import xyz.nucleoid.extras.lobby.NEEntities;
import xyz.nucleoid.extras.lobby.NEItems;
import xyz.nucleoid.extras.integrations.http.NucleoidHttpClient;
import xyz.nucleoid.extras.lobby.*;
import xyz.nucleoid.extras.lobby.contributor.ContributorData;
import xyz.nucleoid.extras.placeholder.ExtraPlaceholders;
import xyz.nucleoid.extras.scheduled_stop.ScheduledStop;
import xyz.nucleoid.extras.sidebar.NucleoidSidebar;
Expand All @@ -36,10 +37,15 @@ public void onInitialize() {
ScheduledStop.register();

NucleoidIntegrations.register();
NucleoidHttpClient.register();
ContributorData.register();

ExtrasErrorReporter.register();
ExtraPlaceholders.register();
ExtrasGamePortals.register();
ExtraCommands.register();

PlayerDataApi.register(PlayerLobbyState.STORAGE);

ServerTickEvents.END_SERVER_TICK.register(NucleoidExtras::onServerTick);
ServerChangePortalBackend.register();
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/xyz/nucleoid/extras/NucleoidExtrasConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import net.minecraft.util.Identifier;
import xyz.nucleoid.codecs.MoreCodecs;
import xyz.nucleoid.extras.chat_filter.ChatFilterConfig;
import xyz.nucleoid.extras.command.CommandAliasConfig;
import xyz.nucleoid.extras.error.ErrorReportingConfig;
import xyz.nucleoid.extras.integrations.IntegrationsConfig;
import xyz.nucleoid.extras.util.ExtraCodecs;

import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -30,8 +34,10 @@ public record NucleoidExtrasConfig(
@Nullable IntegrationsConfig integrations,
@Nullable CommandAliasConfig aliases,
@Nullable ChatFilterConfig chatFilter,
@Nullable URL contributorDataUrl,
ErrorReportingConfig errorReporting,
boolean devServer
boolean devServer,
URI httpApi
) {
private static final Path PATH = Paths.get("config/nucleoid.json");

Expand All @@ -44,17 +50,19 @@ public record NucleoidExtrasConfig(
IntegrationsConfig.CODEC.optionalFieldOf("integrations").forGetter(config -> Optional.ofNullable(config.integrations())),
CommandAliasConfig.CODEC.optionalFieldOf("aliases").forGetter(config -> Optional.ofNullable(config.aliases())),
ChatFilterConfig.CODEC.optionalFieldOf("chat_filter").forGetter(config -> Optional.ofNullable(config.chatFilter())),
MoreCodecs.url("https").optionalFieldOf("contributor_data_url").forGetter(config -> Optional.ofNullable(config.contributorDataUrl())),
ErrorReportingConfig.CODEC.optionalFieldOf("error_reporting", ErrorReportingConfig.NONE).forGetter(NucleoidExtrasConfig::errorReporting),
Codec.BOOL.optionalFieldOf("devServer", false).forGetter(NucleoidExtrasConfig::devServer)
).apply(instance, (sidebar, gamePortalOpener, integrations, aliases, filter, errorReporting, devServer) ->
new NucleoidExtrasConfig(sidebar, gamePortalOpener, integrations.orElse(null), aliases.orElse(null), filter.orElse(null), errorReporting, devServer)
Codec.BOOL.optionalFieldOf("dev_server", false).forGetter(NucleoidExtrasConfig::devServer),
ExtraCodecs.URI.optionalFieldOf("http_api").forGetter(config -> Optional.ofNullable(config.httpApi()))
).apply(instance, (sidebar, gamePortalOpener, integrations, aliases, filter, contributorDataUrl, errorReporting, devServer, httpApiUrl) ->
new NucleoidExtrasConfig(sidebar, gamePortalOpener, integrations.orElse(null), aliases.orElse(null), filter.orElse(null), contributorDataUrl.orElse(null), errorReporting, devServer, httpApiUrl.orElse(null))
)
);

private static NucleoidExtrasConfig instance;

private NucleoidExtrasConfig() {
this(false, Optional.empty(), null, null, null, ErrorReportingConfig.NONE, false);
this(false, Optional.empty(), null, null, null, null, ErrorReportingConfig.NONE, false, null);
}

@NotNull
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/xyz/nucleoid/extras/command/ExtraCommands.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package xyz.nucleoid.extras.command;

import com.mojang.brigadier.CommandDispatcher;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.stat.Stat;

public class ExtraCommands {
public static void register() {
CommandRegistrationCallback.EVENT.register(ExtraCommands::register);
}

private static void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
StatsCommand.register(dispatcher);
}
}
94 changes: 94 additions & 0 deletions src/main/java/xyz/nucleoid/extras/command/StatsCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package xyz.nucleoid.extras.command;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import eu.pb4.sgui.api.GuiHelpers;
import eu.pb4.sgui.api.elements.GuiElementBuilder;
import eu.pb4.sgui.api.elements.GuiElementInterface;
import eu.pb4.sgui.api.gui.SimpleGui;
import net.minecraft.item.Items;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
import xyz.nucleoid.extras.integrations.game.StatisticsIntegration;
import xyz.nucleoid.extras.integrations.http.NucleoidHttpClient;
import xyz.nucleoid.extras.util.CommonGuiElements;
import xyz.nucleoid.extras.util.PagedGui;
import xyz.nucleoid.plasmid.game.stats.GameStatisticBundle;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Map;

import static net.minecraft.server.command.CommandManager.literal;

public class StatsCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(literal("stats").executes(StatsCommand::openScreen));
}

private static int openScreen(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {


var base = Text.translatable("text.nucleoid_extras.statistics.waiting").append(" ");

var gui = new SimpleGui(ScreenHandlerType.GENERIC_9X6, context.getSource().getPlayerOrThrow(), false) {
int tick = 0;

@Override
public void onTick() {
this.setTitle(base.copy().append(".".repeat((this.tick / 20) % 4)));
tick++;
}
};

while (gui.getFirstEmptySlot() != -1) {
gui.addSlot(CommonGuiElements.white());
}

gui.setTitle(base.copy());

gui.open();

NucleoidHttpClient.getPlayerStats(context.getSource().getPlayerOrThrow().getUuid()).thenAcceptAsync(data -> {
openMain(data, context.getSource().getPlayer());
}, context.getSource().getServer());

return 0;
}

private static void openMain(Map<String, Map<Identifier, Number>> stats, ServerPlayerEntity player) {
var list = new ArrayList<GuiElementInterface>();
for (var entry : stats.entrySet()) {
var builder = new GuiElementBuilder(Items.PAPER);
builder.setName(Text.translatable(GameStatisticBundle.getTranslationKey(entry.getKey())));
builder.setCallback((a, b, c, d) -> {
PagedGui.playClickSound(player);
openTargetStats(entry.getKey(), entry.getValue(), player);
});
list.add(builder.build());
}
list.sort(Comparator.comparing(x -> x.getItemStack().getName().getString()));
var gui = PagedGui.of(player, list, null);
gui.setTitle(Text.translatable("text.nucleoid_extras.statistics.list_ui"));
gui.open();
}

private static void openTargetStats(String key, Map<Identifier, Number> value, ServerPlayerEntity player) {
var cGui = GuiHelpers.getCurrentGui(player);
var list = new ArrayList<GuiElementInterface>();
for (var entry : value.entrySet()) {
var builder = new GuiElementBuilder(Items.NAME_TAG);
builder.setName(Text.empty().append(Util.createTranslationKey("statistic", entry.getKey())).append(": ").append(StatisticsIntegration.convertForDisplay(entry.getKey(), entry.getValue())));
list.add(builder.build());
}
list.sort(Comparator.comparing(x -> x.getItemStack().getName().getString()));
var g = PagedGui.of(player, list, (id) -> id == 8 ? CommonGuiElements.back(cGui::open).build() : null);
g.setTitle(Text.translatable(GameStatisticBundle.getTranslationKey(key)));
g.open();
}
}
6 changes: 3 additions & 3 deletions src/main/java/xyz/nucleoid/extras/error/DiscordWebhook.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

record DiscordWebhook(String url) {
record DiscordWebhook(URL url) {
private static final Executor EXECUTOR = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder()
.setNameFormat("webhook-error-reporter")
.setDaemon(true)
Expand All @@ -27,14 +27,14 @@ record DiscordWebhook(String url) {
private static final String BOUNDARY = Long.toHexString(System.nanoTime());
private static final String CONTENT_TYPE = "multipart/form-data;boundary=\"" + BOUNDARY + "\"";

public static DiscordWebhook open(String url) {
public static DiscordWebhook open(URL url) {
return new DiscordWebhook(url);
}

public void post(Message message) {
EXECUTOR.execute(() -> {
try {
var connection = (HttpsURLConnection) new URL(this.url).openConnection();
var connection = (HttpsURLConnection) this.url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", CONTENT_TYPE);
Expand Down
19 changes: 7 additions & 12 deletions src/main/java/xyz/nucleoid/extras/error/ErrorReportingConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import joptsimple.internal.Strings;
import xyz.nucleoid.codecs.MoreCodecs;
import java.net.URL;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;

public record ErrorReportingConfig(
String discordWebhookUrl
Optional<URL> discordWebhookUrl
) {
public static final Codec<ErrorReportingConfig> CODEC = RecordCodecBuilder.create(instance ->
instance.group(
Codec.STRING.optionalFieldOf("discord_webhook_url", "").forGetter(config -> config.discordWebhookUrl)
MoreCodecs.url("https").optionalFieldOf("discord_webhook_url").forGetter(config -> config.discordWebhookUrl)
).apply(instance, ErrorReportingConfig::new)
);

public static final ErrorReportingConfig NONE = new ErrorReportingConfig(null);
public static final ErrorReportingConfig NONE = new ErrorReportingConfig(Optional.empty());

@Nullable
public DiscordGameErrorHandler openErrorHandler(String source) {
Expand All @@ -25,13 +27,6 @@ public DiscordGameErrorHandler openErrorHandler(String source) {
@Nullable
public DiscordWebhook openDiscordWebhook() {
var url = this.discordWebhookUrl();
return url != null ? DiscordWebhook.open(url) : null;
}

@Override
@Nullable
public String discordWebhookUrl() {
var url = this.discordWebhookUrl;
return !Strings.isNullOrEmpty(url) ? url : null;
return url.map(DiscordWebhook::open).orElse(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,14 @@ public void applyTo(ServerPlayerEntity player) {

var gui = new SimpleGui(ScreenHandlerType.GENERIC_9X6, player, false);
gui.setTitle(this.uiTitle);
var filler = new GuiElementBuilder(Items.PURPLE_STAINED_GLASS_PANE).setName(Text.empty());
var filler = CommonGuiElements.purple();

for (int i = 0; i < 9; i++) {
gui.setSlot(5 * 9 + i, filler);
}

if (oldGui != null) {
gui.setSlot(5 * 9 + 8, new GuiElementBuilder(Items.STRUCTURE_VOID).setName(ScreenTexts.BACK).setCallback(() -> {
PagedGui.playClickSound(player);
oldGui.open();
}));
gui.setSlot(5 * 9 + 8, CommonGuiElements.back(oldGui::open));
}
this.fill(player, gui, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import org.jetbrains.annotations.Nullable;
import xyz.nucleoid.codecs.MoreCodecs;
import xyz.nucleoid.extras.util.ExtraCodecs;

import java.net.URI;
import java.net.URL;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;

public record IntegrationsConfig(
String channel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import xyz.nucleoid.extras.integrations.connection.IntegrationsProxy;
import xyz.nucleoid.extras.integrations.game.GameStatusIntegration;
import xyz.nucleoid.extras.integrations.game.StatisticsIntegration;
import xyz.nucleoid.extras.integrations.http.NucleoidHttpClient;
import xyz.nucleoid.extras.integrations.relay.ChatRelayIntegration;
import xyz.nucleoid.extras.integrations.relay.RemoteCommandIntegration;
import xyz.nucleoid.extras.integrations.status.PlayerStatusIntegration;
Expand Down
Loading
Loading