Skip to content
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 .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ jobs:
fi

grep -Fq "main: io.github.silentdevelopment.headdb.paper.HeadDBPlugin" /tmp/paper-plugin.yml
grep -Fq "api-version: '1.21'" /tmp/paper-plugin.yml
grep -Fq "api-version: '26.1.2'" /tmp/paper-plugin.yml
grep -Fq 'Vault:' /tmp/paper-plugin.yml
grep -Fq 'required: false' /tmp/paper-plugin.yml

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ jobs:
fi

grep -Fq "main: io.github.silentdevelopment.headdb.paper.HeadDBPlugin" /tmp/paper-plugin.yml
grep -Fq "api-version: '1.21'" /tmp/paper-plugin.yml
grep -Fq "api-version: '26.1.2'" /tmp/paper-plugin.yml
grep -Fq 'Vault:' /tmp/paper-plugin.yml
grep -Fq 'required: false' /tmp/paper-plugin.yml

Expand Down
2 changes: 1 addition & 1 deletion .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
wrapperVersion=3.3.4
distributionType=only-script
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
2 changes: 1 addition & 1 deletion headdb-platforms/headdb-paper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<lib.relay.version>3fc62454e3</lib.relay.version>
<lib.hermes.version>3505fd1883</lib.hermes.version>
<lib.grafik.version>d78876b0e2</lib.grafik.version>
<lib.prompts.version>9f15982383</lib.prompts.version>
<lib.prompts.version>22456310ef</lib.prompts.version>
<lib.strata.version>403557ff80</lib.strata.version>

<sqlite-jdbc.version>3.53.2.0</sqlite-jdbc.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@
import io.github.silentdevelopment.headdb.paper.item.DefaultHeadItemFactory;
import io.github.silentdevelopment.headdb.paper.item.HeadItemFactory;
import io.github.silentdevelopment.headdb.paper.local.HeadRegistry;
import io.github.silentdevelopment.headdb.paper.local.custom.CachedCustomHeadStore;
import io.github.silentdevelopment.headdb.paper.local.custom.CustomHeadStore;
import io.github.silentdevelopment.headdb.paper.local.override.CachedRemoteHeadOverrideStore;
import io.github.silentdevelopment.headdb.paper.local.override.RemoteHeadOverrideStore;
import io.github.silentdevelopment.headdb.paper.local.player.BukkitPlayerHeadService;
import io.github.silentdevelopment.headdb.paper.local.player.DisabledPlayerHeadService;
import io.github.silentdevelopment.headdb.paper.local.player.PlayerHeadCache;
import io.github.silentdevelopment.headdb.paper.local.player.PlayerHeadService;
import io.github.silentdevelopment.headdb.paper.local.storage.SqliteStorageMigrator;
import io.github.silentdevelopment.headdb.paper.local.storage.StrataLocalStores;
import io.github.silentdevelopment.headdb.paper.local.taxonomy.CustomTaxonomyService;
import io.github.silentdevelopment.headdb.paper.local.storage.NoopLocalStores;
import io.github.silentdevelopment.headdb.paper.message.Messages;
import io.github.silentdevelopment.headdb.paper.metrics.HeadDBMetrics;
Expand All @@ -35,6 +38,9 @@
import io.github.silentdevelopment.headdb.paper.runtime.RuntimeDiagnostics;
import io.github.silentdevelopment.headdb.paper.runtime.StartupChecks;
import io.github.silentdevelopment.headdb.paper.service.PaperHeadDBService;
import io.github.silentdevelopment.headdb.paper.sound.HeadSoundService;
import io.github.silentdevelopment.headdb.paper.sound.SoundConfig;
import io.github.silentdevelopment.headdb.paper.sound.SoundConfigLoader;
import io.github.silentdevelopment.headdb.paper.updater.UpdateService;
import io.github.silentdevelopment.hermes.id.LocaleId;
import io.github.silentdevelopment.hermes.paper.core.Hermes;
Expand All @@ -60,7 +66,10 @@ public final class HeadDBPlugin extends JavaPlugin {
private final AdminModeService adminModes = new AdminModeService();
private FavoriteHeadService favoriteHeadService;
private CustomCategoryService customCategoryService;
private CustomTaxonomyService customTagService;
private CustomTaxonomyService customCollectionService;
private EconomyService economyService;
private HeadSoundService soundService;
private UpdateService updateService;

@Override
Expand Down Expand Up @@ -117,7 +126,10 @@ public void onDisable() {
adminModes.clear();
favoriteHeadService = null;
customCategoryService = null;
customTagService = null;
customCollectionService = null;
economyService = null;
soundService = null;
updateService = null;
runtime = null;
config = null;
Expand All @@ -136,17 +148,21 @@ public synchronized void reload() throws ConfigException {
PluginConfig loadedConfig = new ConfigLoader(getDataFolder().toPath()).load();
GuiConfig loadedGuiConfig = new GuiConfigLoader(this).load();
EconomyConfig loadedEconomyConfig = EconomyConfig.load(this);
SoundConfig loadedSoundConfig = new SoundConfigLoader(this).load();
Messages loadedMessages = createMessages(loadedConfig);
PluginRuntime createdRuntime = PluginRuntime.create(this, loadedConfig);
Path localStoreDatabase = loadedConfig.localStoreDatabase(getDataFolder().toPath());

SqliteStorageMigrator.migrate(localStoreDatabase);

HeadRegistry createdHeadRegistry = createHeadRegistry(loadedConfig, createdRuntime);
HeadItemFactory createdItemFactory = createItemFactory(loadedConfig);
CustomTaxonomyService createdCustomTagService = new CustomTaxonomyService(localStoreDatabase, "tag", "Local custom tag.");
CustomTaxonomyService createdCustomCollectionService = new CustomTaxonomyService(localStoreDatabase, "collection", "Local custom collection.");
HeadRegistry createdHeadRegistry = createHeadRegistry(loadedConfig, createdRuntime, createdCustomTagService, createdCustomCollectionService);
HeadItemFactory createdItemFactory = createItemFactory(loadedConfig, createdHeadRegistry);
FavoriteHeadService createdFavoriteHeadService = new FavoriteHeadService(localStoreDatabase);
CustomCategoryService createdCustomCategoryService = new CustomCategoryService(localStoreDatabase);
EconomyService createdEconomyService = EconomyService.create(this, loadedEconomyConfig);
HeadSoundService createdSoundService = new HeadSoundService(this, loadedSoundConfig);
GuiService createdGuiService = new GuiService(this, createdItemFactory);
UpdateService createdUpdateService = new UpdateService(this, loadedConfig);

Expand All @@ -156,8 +172,6 @@ public synchronized void reload() throws ConfigException {
StartupChecks.run(this, loadedConfig, createdRuntime);
}

createdRuntime.start();

PluginRuntime previousRuntime = this.runtime;
UpdateService previousUpdateService = this.updateService;

Expand All @@ -170,7 +184,10 @@ public synchronized void reload() throws ConfigException {
this.guiService = createdGuiService;
this.favoriteHeadService = createdFavoriteHeadService;
this.customCategoryService = createdCustomCategoryService;
this.customTagService = createdCustomTagService;
this.customCollectionService = createdCustomCollectionService;
this.economyService = createdEconomyService;
this.soundService = createdSoundService;
this.updateService = createdUpdateService;

clearItemCache();
Expand All @@ -184,6 +201,8 @@ public synchronized void reload() throws ConfigException {
previousRuntime.close();
}

createdRuntime.start();

RuntimeDiagnostics.logRuntimeState(this, createdRuntime);

registerServices();
Expand Down Expand Up @@ -308,6 +327,23 @@ public synchronized void reloadGuiConfigOnly() throws ConfigException {
}



public @NotNull CustomTaxonomyService customTags() {
CustomTaxonomyService currentCustomTagService = customTagService;
if (currentCustomTagService == null) {
throw new IllegalStateException("HeadDB custom tag service is not initialized");
}
return currentCustomTagService;
}

public @NotNull CustomTaxonomyService customCollections() {
CustomTaxonomyService currentCustomCollectionService = customCollectionService;
if (currentCustomCollectionService == null) {
throw new IllegalStateException("HeadDB custom collection service is not initialized");
}
return currentCustomCollectionService;
}

public @NotNull EconomyService economy() {
EconomyService currentEconomyService = economyService;
if (currentEconomyService == null) {
Expand All @@ -316,6 +352,14 @@ public synchronized void reloadGuiConfigOnly() throws ConfigException {
return currentEconomyService;
}

public @NotNull HeadSoundService sounds() {
HeadSoundService currentSoundService = soundService;
if (currentSoundService == null) {
throw new IllegalStateException("HeadDB sound service is not initialized");
}
return currentSoundService;
}

public @NotNull UpdateService updater() {
UpdateService currentUpdateService = updateService;
if (currentUpdateService == null) {
Expand Down Expand Up @@ -354,6 +398,27 @@ public int itemCacheSize() {
return cache.size();
}


public void invalidateHeadRegistry() {
HeadRegistry currentHeadRegistry = headRegistry;

if (currentHeadRegistry == null) {
return;
}

currentHeadRegistry.invalidate();
}

public void warmHeadRegistry() {
HeadRegistry currentHeadRegistry = headRegistry;

if (currentHeadRegistry == null) {
return;
}

currentHeadRegistry.warm();
}

public void clearSearchCache() {
GuiService currentGuiService = guiService;

Expand All @@ -375,31 +440,34 @@ private void unregisterServices() {
getServer().getServicesManager().unregisterAll(this);
}

private @NotNull HeadRegistry createHeadRegistry(@NotNull PluginConfig config, @NotNull PluginRuntime runtime) {
private @NotNull HeadRegistry createHeadRegistry(@NotNull PluginConfig config, @NotNull PluginRuntime runtime, @NotNull CustomTaxonomyService customTags, @NotNull CustomTaxonomyService customCollections) {
Objects.requireNonNull(config, "config");
Objects.requireNonNull(runtime, "runtime");
Objects.requireNonNull(customTags, "customTags");
Objects.requireNonNull(customCollections, "customCollections");

Path localStoreDatabase = config.localStoreDatabase(getDataFolder().toPath());
StrataLocalStores localStores = StrataLocalStores.sqlite(localStoreDatabase, runnable -> getServer().getAsyncScheduler().runNow(this, task -> runnable.run()));
RemoteHeadOverrideStore overrideStore = config.remoteOverridesEnabled() ? localStores.remoteOverrides() : NoopLocalStores.remoteOverrides();
CustomHeadStore customHeadStore = config.customHeadsEnabled() ? localStores.customHeads() : NoopLocalStores.customHeads();
RemoteHeadOverrideStore overrideStore = config.remoteOverridesEnabled() ? new CachedRemoteHeadOverrideStore(localStores.remoteOverrides()) : NoopLocalStores.remoteOverrides();
CustomHeadStore customHeadStore = config.customHeadsEnabled() ? new CachedCustomHeadStore(localStores.customHeads()) : NoopLocalStores.customHeads();
PlayerHeadCache playerHeadCache = config.playerHeadsEnabled() ? localStores.playerHeadCache(config.playerHeadCacheTtl()) : NoopLocalStores.playerHeadCache();
PlayerHeadService playerHeadService = config.playerHeadsEnabled()
? new BukkitPlayerHeadService(this, playerHeadCache, config.playerHeadCacheTtl(), config.playerHeadFailedCacheTtl(), config.playerHeadsAllowExternalLookup())
: new DisabledPlayerHeadService();

return new HeadRegistry(runtime.database(), overrideStore, customHeadStore, playerHeadService);
return new HeadRegistry(runtime.database(), overrideStore, customHeadStore, playerHeadService, customTags, customCollections);
}

private @NotNull HeadItemFactory createItemFactory(@NotNull PluginConfig config) {
private @NotNull HeadItemFactory createItemFactory(@NotNull PluginConfig config, @NotNull HeadRegistry registry) {
Objects.requireNonNull(config, "config");
Objects.requireNonNull(registry, "registry");

HeadItemFactory baseFactory = new DefaultHeadItemFactory(this);
if (!config.cacheItemEnabled()) {
return baseFactory;
}

return new CachingHeadItemFactory(baseFactory, config.cacheItemMaxSize());
return new CachingHeadItemFactory(baseFactory, config.cacheItemMaxSize(), registry::revision);
}

private @NotNull Messages createMessages(@NotNull PluginConfig config) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.silentdevelopment.headdb.paper.command;

import io.github.silentdevelopment.headdb.paper.HeadDBPlugin;
import io.github.silentdevelopment.headdb.paper.sound.SoundKey;
import io.github.silentdevelopment.relay.command.Command;
import io.github.silentdevelopment.relay.command.Signature;
import io.github.silentdevelopment.relay.paper.text.PaperCommandResponseRenderer;
Expand Down Expand Up @@ -29,26 +30,31 @@ public CommandResponseRenderer(@NotNull HeadDBPlugin plugin) {

@Override
public @NotNull Component renderUnknownCommand(@NotNull CommandSender source) {
play(source, SoundKey.INVALID);
return plugin.messages().relayUnknownCommand(source);
}

@Override
public @NotNull Component renderNoHandler(@NotNull CommandSender source) {
play(source, SoundKey.INVALID);
return plugin.messages().relayNoHandler(source);
}

@Override
public @NotNull Component renderRequirementFailure(@NotNull CommandSender source, @NotNull CommandText message) {
play(source, SoundKey.NO_PERMISSION);
return plugin.messages().render(source, message);
}

@Override
public @NotNull Component renderAbort(@NotNull CommandSender source, @NotNull CommandText message) {
play(source, SoundKey.INVALID);
return plugin.messages().render(source, message);
}

@Override
public @NotNull Component renderInvalidUsage(@NotNull CommandSender source, @NotNull CommandText message, @NotNull List<String> usages) {
play(source, SoundKey.INVALID);
Component component = plugin.messages().relayInvalidUsage(source, message);

if (usages.isEmpty()) {
Expand All @@ -68,6 +74,7 @@ public CommandResponseRenderer(@NotNull HeadDBPlugin plugin) {

@Override
public @NotNull Component renderInvalidUsage(@NotNull CommandSender source, @NotNull CommandText message, @NotNull String path, @NotNull Command command) {
play(source, SoundKey.INVALID);
Component component = plugin.messages().relayInvalidUsage(source, message);

if (command.signatures().isEmpty()) {
Expand All @@ -85,6 +92,14 @@ public CommandResponseRenderer(@NotNull HeadDBPlugin plugin) {
return component;
}

private void play(@NotNull CommandSender source, @NotNull SoundKey key) {
if (!(source instanceof Player player)) {
return;
}

plugin.sounds().play(player, key);
}

private static @NotNull Component usage(@NotNull CommandSender source, @NotNull String usage) {
Component component = Component.text(usage, NamedTextColor.GREEN);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ private Suggestions() {
return context -> enumValues(context.currentToken(), SortDirection.values());
}

public static @NotNull SuggestionProvider<CommandSender> taxonomyActions() {
return context -> matching(context.currentToken(), List.of("create", "delete"));
}

public static @NotNull SuggestionProvider<CommandSender> pages() {
return context -> matching(context.currentToken(), List.of("1", "2", "3", "4", "5", "10"));
}
Expand Down
Loading
Loading