mirror of
https://github.com/FancyInnovations/FancyPlugins.git
synced 2025-12-06 07:43:36 +00:00
fancyholograms v3: Add Lamp and translations
This commit is contained in:
@@ -78,6 +78,8 @@ dependencies {
|
||||
implementation("de.oliver.FancyAnalytics:mc-api:0.1.8")
|
||||
implementation("de.oliver.FancyAnalytics:logger:0.0.6")
|
||||
|
||||
implementation("io.github.revxrsal:lamp.common:4.0.0-rc.12")
|
||||
implementation("io.github.revxrsal:lamp.bukkit:4.0.0-rc.12")
|
||||
compileOnly(project(":plugins:fancynpcs:fn-api"))
|
||||
compileOnly("org.lushplugins:ChatColorHandler:5.1.6")
|
||||
compileOnly("com.viaversion:viaversion-api:5.2.1")
|
||||
|
||||
@@ -64,4 +64,11 @@ public interface HologramConfiguration {
|
||||
* @return {@code true} if holograms should be shown to players with an old client version, {@code false} otherwise.
|
||||
*/
|
||||
boolean isHologramsForOldClientsEnabled();
|
||||
|
||||
/**
|
||||
* Returns the language used by the plugin.
|
||||
*
|
||||
* @return The language used by the plugin.
|
||||
*/
|
||||
String getLanguage();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package de.oliver.fancyholograms.commands.lampCommands.fancyholograms;
|
||||
|
||||
import com.fancyinnovations.config.Config;
|
||||
import com.fancyinnovations.config.ConfigField;
|
||||
import de.oliver.fancyholograms.main.FancyHologramsPlugin;
|
||||
import de.oliver.fancylib.translations.Translator;
|
||||
import revxrsal.commands.annotation.Command;
|
||||
import revxrsal.commands.annotation.Description;
|
||||
import revxrsal.commands.bukkit.actor.BukkitCommandActor;
|
||||
import revxrsal.commands.bukkit.annotation.CommandPermission;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
|
||||
public final class ConfigCMD {
|
||||
|
||||
public static final ConfigCMD INSTANCE = new ConfigCMD();
|
||||
|
||||
private final FancyHologramsPlugin plugin = FancyHologramsPlugin.get();
|
||||
private final Translator translator = FancyHologramsPlugin.get().getTranslator();
|
||||
|
||||
private ConfigCMD() {
|
||||
}
|
||||
|
||||
@Command("fancyholograms config show")
|
||||
@Description("Shows the current configuration")
|
||||
@CommandPermission("fancyholograms.commands.fancyholograms.config.show")
|
||||
public void show(
|
||||
final BukkitCommandActor actor
|
||||
) {
|
||||
Config config = plugin.getFHConfiguration().getConfig();
|
||||
Collection<ConfigField<?>> fields = config.getFields().values()
|
||||
.stream()
|
||||
.sorted(Comparator.comparing(ConfigField::path))
|
||||
.toList();
|
||||
|
||||
translator.translate("commands.fancyholograms.config.show.settings_header")
|
||||
.send(actor.sender());
|
||||
|
||||
for (ConfigField<?> field : fields) {
|
||||
if (!field.path().startsWith("settings.")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
translator.translate("commands.fancyholograms.config.show.entry")
|
||||
.replace("path", field.path().substring("settings.".length()))
|
||||
.replace("value", config.get(field.path()).toString())
|
||||
.replace("default", String.valueOf(field.defaultValue()))
|
||||
.send(actor.sender());
|
||||
}
|
||||
|
||||
actor.sender().sendMessage(" ");
|
||||
|
||||
translator.translate("commands.fancyholograms.config.show.experimental_header")
|
||||
.send(actor.sender());
|
||||
|
||||
for (ConfigField<?> field : fields) {
|
||||
if (!field.path().startsWith("experimental_features.")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
translator.translate("commands.fancyholograms.config.show.entry")
|
||||
.replace("path", field.path().substring("experimental_features.".length()))
|
||||
.replace("value", config.get(field.path()).toString())
|
||||
.replace("default", String.valueOf(field.defaultValue()))
|
||||
.send(actor.sender());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,21 +7,23 @@ import de.oliver.fancyholograms.main.FancyHologramsPlugin;
|
||||
|
||||
public final class FHConfiguration implements HologramConfiguration {
|
||||
|
||||
public static final String LOG_LEVEL_PATH = "settings.logging.level";
|
||||
|
||||
public static final String MUTE_VERSION_NOTIFICATION_PATH = "settings.logging.version_notification";
|
||||
public static final String ENABLE_AUTOSAVE_PATH = "settings.saving.autosave.enabled";
|
||||
public static final String AUTOSAVE_INTERVAL_PATH = "settings.saving.autosave.interval";
|
||||
|
||||
public static final String SAVE_ON_CHANGED_PATH = "settings.saving.save_on_changed";
|
||||
public static final String VISIBILITY_DISTANCE_PATH = "settings.visibility_distance";
|
||||
|
||||
public static final String REGISTER_COMMANDS_PATH = "settings.register_commands";
|
||||
|
||||
public static final String LANGUAGE_PATH = "settings.language";
|
||||
|
||||
public static final String DISABLE_HOLOGRAMS_FOR_BEDROCK_PLAYERS_PATH = "experimental_features.disable_holograms_for_bedrock_players";
|
||||
public static final String DISABLE_HOLOGRAMS_FOR_OLD_CLIENTS = "experimental_features.disable_holograms_for_old_clients";
|
||||
|
||||
private static final String CONFIG_FILE_PATH = "plugins/FancyHolograms/config.yml";
|
||||
|
||||
private static final String LOG_LEVEL_PATH = "settings.logging.level";
|
||||
private static final String MUTE_VERSION_NOTIFICATION_PATH = "settings.logging.version_notification";
|
||||
|
||||
private static final String ENABLE_AUTOSAVE_PATH = "settings.saving.autosave.enabled";
|
||||
private static final String AUTOSAVE_INTERVAL_PATH = "settings.saving.autosave.interval";
|
||||
private static final String SAVE_ON_CHANGED_PATH = "settings.saving.save_on_changed";
|
||||
|
||||
private static final String VISIBILITY_DISTANCE_PATH = "settings.visibility_distance";
|
||||
private static final String REGISTER_COMMANDS_PATH = "settings.register_commands";
|
||||
|
||||
private static final String DISABLE_HOLOGRAMS_FOR_BEDROCK_PLAYERS_PATH = "experimental_features.disable_holograms_for_bedrock_players";
|
||||
private static final String DISABLE_HOLOGRAMS_FOR_OLD_CLIENTS = "experimental_features.disable_holograms_for_old_clients";
|
||||
|
||||
private Config config;
|
||||
|
||||
public void init() {
|
||||
@@ -96,7 +98,7 @@ public final class FHConfiguration implements HologramConfiguration {
|
||||
|
||||
config.addField(new ConfigField<>(
|
||||
DISABLE_HOLOGRAMS_FOR_BEDROCK_PLAYERS_PATH,
|
||||
"Do not show holograms to bedrock players",
|
||||
"Do not show holograms to bedrock players,",
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
@@ -105,13 +107,22 @@ public final class FHConfiguration implements HologramConfiguration {
|
||||
|
||||
config.addField(new ConfigField<>(
|
||||
DISABLE_HOLOGRAMS_FOR_OLD_CLIENTS,
|
||||
"Do not show holograms to clients with a version older than 1.19.4",
|
||||
"Do not show holograms to clients with a version older than 1.19.4.",
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
Boolean.class
|
||||
));
|
||||
|
||||
config.addField(new ConfigField<>(
|
||||
LANGUAGE_PATH,
|
||||
"The language to use for the plugin.",
|
||||
false,
|
||||
"default",
|
||||
false,
|
||||
String.class
|
||||
));
|
||||
|
||||
config.reload();
|
||||
}
|
||||
|
||||
@@ -119,6 +130,10 @@ public final class FHConfiguration implements HologramConfiguration {
|
||||
config.reload();
|
||||
}
|
||||
|
||||
public Config getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areVersionNotificationsMuted() {
|
||||
return config.get(MUTE_VERSION_NOTIFICATION_PATH);
|
||||
@@ -163,4 +178,9 @@ public final class FHConfiguration implements HologramConfiguration {
|
||||
public boolean isHologramsForOldClientsEnabled() {
|
||||
return !(boolean) config.get(DISABLE_HOLOGRAMS_FOR_OLD_CLIENTS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLanguage() {
|
||||
return config.get(LANGUAGE_PATH);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import de.oliver.fancyholograms.api.hologram.Hologram;
|
||||
import de.oliver.fancyholograms.commands.FancyHologramsCMD;
|
||||
import de.oliver.fancyholograms.commands.FancyHologramsTestCMD;
|
||||
import de.oliver.fancyholograms.commands.HologramCMD;
|
||||
import de.oliver.fancyholograms.commands.lampCommands.fancyholograms.ConfigCMD;
|
||||
import de.oliver.fancyholograms.config.FHConfiguration;
|
||||
import de.oliver.fancyholograms.controller.HologramControllerImpl;
|
||||
import de.oliver.fancyholograms.converter.FHConversionRegistry;
|
||||
@@ -36,6 +37,9 @@ import de.oliver.fancyholograms.util.PluginUtils;
|
||||
import de.oliver.fancylib.FancyLib;
|
||||
import de.oliver.fancylib.VersionConfig;
|
||||
import de.oliver.fancylib.serverSoftware.ServerSoftware;
|
||||
import de.oliver.fancylib.translations.Language;
|
||||
import de.oliver.fancylib.translations.TextConfig;
|
||||
import de.oliver.fancylib.translations.Translator;
|
||||
import de.oliver.fancylib.versionFetcher.MasterVersionFetcher;
|
||||
import de.oliver.fancylib.versionFetcher.VersionFetcher;
|
||||
import de.oliver.fancysitula.api.IFancySitula;
|
||||
@@ -46,6 +50,9 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import revxrsal.commands.Lamp;
|
||||
import revxrsal.commands.bukkit.BukkitLamp;
|
||||
import revxrsal.commands.bukkit.actor.BukkitCommandActor;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
@@ -73,6 +80,7 @@ public final class FancyHologramsPlugin extends JavaPlugin implements FancyHolog
|
||||
private final ExecutorService storageThread;
|
||||
|
||||
private final FHConfiguration configuration;
|
||||
private final Translator translator;
|
||||
|
||||
private Function<HologramData, Hologram> hologramFactory;
|
||||
|
||||
@@ -118,6 +126,8 @@ public final class FancyHologramsPlugin extends JavaPlugin implements FancyHolog
|
||||
);
|
||||
|
||||
configuration = new FHConfiguration();
|
||||
|
||||
translator = new Translator(new TextConfig("#32e347", "#35ad1d", "#81E366", "#E3CA66", "#E36666", ""));
|
||||
}
|
||||
|
||||
public static @NotNull FancyHologramsPlugin get() {
|
||||
@@ -172,6 +182,12 @@ public final class FancyHologramsPlugin extends JavaPlugin implements FancyHolog
|
||||
return;
|
||||
}
|
||||
|
||||
translator.loadLanguages(getDataFolder().getAbsolutePath());
|
||||
final Language selectedLanguage = translator.getLanguages().stream()
|
||||
.filter(language -> language.getLanguageName().equals(configuration.getLanguage()))
|
||||
.findFirst().orElse(translator.getFallbackLanguage());
|
||||
translator.setSelectedLanguage(selectedLanguage);
|
||||
|
||||
fancyLogger.info("Successfully loaded FancyHolograms version %s".formatted(getDescription().getVersion()));
|
||||
}
|
||||
|
||||
@@ -180,6 +196,7 @@ public final class FancyHologramsPlugin extends JavaPlugin implements FancyHolog
|
||||
new FancyLib(INSTANCE);
|
||||
|
||||
registerCommands();
|
||||
registerLampCommands();
|
||||
registerListeners();
|
||||
|
||||
versionConfig.load();
|
||||
@@ -263,6 +280,20 @@ public final class FancyHologramsPlugin extends JavaPlugin implements FancyHolog
|
||||
}
|
||||
}
|
||||
|
||||
private void registerLampCommands() {
|
||||
Lamp.Builder<BukkitCommandActor> lampBuilder = BukkitLamp
|
||||
.builder(this);
|
||||
|
||||
// lampBuilder.parameterTypes(builder -> {
|
||||
// builder.addParameterType(Dialog.class, DialogCommandType.INSTANCE);
|
||||
// });
|
||||
// lampBuilder.exceptionHandler(DialogCommandType.INSTANCE);
|
||||
|
||||
Lamp<BukkitCommandActor> lamp = lampBuilder.build();
|
||||
|
||||
lamp.register(ConfigCMD.INSTANCE);
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
|
||||
|
||||
@@ -374,4 +405,8 @@ public final class FancyHologramsPlugin extends JavaPlugin implements FancyHolog
|
||||
public FHConfiguration getFHConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public Translator getTranslator() {
|
||||
return translator;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
language_name: default
|
||||
messages:
|
||||
commands:
|
||||
fancyholograms:
|
||||
config:
|
||||
show:
|
||||
settings_header: "<dark_gray>› <gray>FancyHolograms settings:"
|
||||
experimental_header: "<dark_gray>› <gray>FancyHolograms experimental features:"
|
||||
entry: "<dark_gray>› <gray> - {warningColor}{path}<gray>: {value} (default: {default})"
|
||||
Reference in New Issue
Block a user