Skip to content

Commit

Permalink
Release 2.6.0 (#355)
Browse files Browse the repository at this point in the history
  • Loading branch information
rainbowdashlabs authored Jan 24, 2024
2 parents 77c4a91 + 2804baf commit 9d34ca8
Show file tree
Hide file tree
Showing 25 changed files with 114 additions and 100 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = "de.eldoria"
version = "2.5.6"
version = "2.6.0"

var publishModules = setOf("schematicbrushreborn-api",
"schematicbrushreborn-core",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ default void save() {
* Called when the plugin shuts down and the storages get unregistered.
*/
default void shutdown() {
}

/**
* Reload the data for that storage from disk
*/
default void reload(){
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ public interface StorageRegistry extends Registry<Nameable, Storage> {
* @return Returns a future which completes once all underlying processes complete
*/
CompletableFuture<Void> migrate(Nameable source, Nameable target);

default void reload() {
registry().values().forEach(Storage::reload);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public class SchematicBrushRebornImpl extends SchematicBrushReborn {
private JacksonConfiguration configuration;
private RenderService renderService;
private StorageRegistryImpl storageRegistry;
private Storage storage;
private SimpleModule sbrModule;

public SchematicBrushRebornImpl() {
Expand Down Expand Up @@ -147,7 +146,6 @@ public void onPluginEnable() {
ILocalizer.create(this, "en_US").setLocale("en_US");

schematics.register(SchematicCache.STORAGE, new SchematicBrushCache(this, configuration));
storage = storageRegistry.activeStorage();

var notifyListener = new NotifyListener(this, configuration);
renderService = new RenderService(this, configuration);
Expand All @@ -161,11 +159,11 @@ public void onPluginEnable() {
messageBlocker = MessageBlocker.dummy(this);
}

var brushCommand = new Brush(this, schematics, storage, settingsRegistry, messageBlocker);
var presetCommand = new de.eldoria.schematicbrush.commands.Preset(this, storage, messageBlocker);
var brushCommand = new Brush(this, schematics, storageRegistry, settingsRegistry, messageBlocker);
var presetCommand = new de.eldoria.schematicbrush.commands.Preset(this, storageRegistry, messageBlocker);
var adminCommand = new Admin(this, schematics, storageRegistry);
var settingsCommand = new Settings(this, configuration, renderService, notifyListener, messageBlocker);
var brushPresetsCommand = new BrushPresets(this, storage, messageBlocker, settingsRegistry);
var brushPresetsCommand = new BrushPresets(this, storageRegistry, messageBlocker, settingsRegistry);
var modifyCommand = new Modify(this, settingsRegistry);

enableMetrics();
Expand Down Expand Up @@ -261,6 +259,7 @@ public void onPostStart() throws Throwable {

public void reload() {
schematics.reload();
storageRegistry.reload();
configuration.reload();
renderService.restart();
}
Expand Down Expand Up @@ -290,10 +289,10 @@ private void enableMetrics() {
() -> reduceMetricValue(schematics.directoryCount(), 100, 10, 50, 100)));

metrics.addCustomChart(new SimplePie("preset_count",
() -> reduceMetricValue(storage.presets().count().join(), 100, 10, 50, 100)));
() -> reduceMetricValue(storageRegistry.activeStorage().presets().count().join(), 100, 10, 50, 100)));

metrics.addCustomChart(new SimplePie("brush_count",
() -> reduceMetricValue(storage.brushes().count().join(), 100, 10, 50, 100)));
() -> reduceMetricValue(storageRegistry.activeStorage().brushes().count().join(), 100, 10, 50, 100)));

metrics.addCustomChart(new SimplePie("premium",
() -> String.valueOf(UserData.get(this).isPremium())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@
import de.eldoria.schematicbrush.commands.brush.ShowSets;
import de.eldoria.schematicbrush.schematics.SchematicRegistry;
import de.eldoria.schematicbrush.storage.Storage;
import de.eldoria.schematicbrush.storage.StorageRegistry;
import de.eldoria.schematicbrush.util.Permissions;
import org.bukkit.plugin.Plugin;

/**
* Command which is used to create a new brush. Rewrite of old schbr command.
*/
public class Brush extends AdvancedCommand {
public Brush(Plugin plugin, SchematicRegistry schematics, Storage storage, BrushSettingsRegistry setting, MessageBlocker messageBlocker) {
public Brush(Plugin plugin, SchematicRegistry schematics, StorageRegistry storage, BrushSettingsRegistry setting, MessageBlocker messageBlocker) {
super(plugin, CommandMeta.builder("sbr")
.withPermission(Permissions.Brush.USE)
.buildSubCommands((cmds, self) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import de.eldoria.schematicbrush.commands.brushpresets.List;
import de.eldoria.schematicbrush.commands.brushpresets.Remove;
import de.eldoria.schematicbrush.storage.Storage;
import de.eldoria.schematicbrush.storage.StorageRegistry;
import de.eldoria.schematicbrush.util.Permissions;
import org.bukkit.plugin.Plugin;

Expand All @@ -23,17 +24,17 @@
* Brush to create and modify brush presets.
*/
public class BrushPresets extends AdvancedCommand {
public BrushPresets(Plugin plugin, Storage config, MessageBlocker messageBlocker, BrushSettingsRegistry registry) {
public BrushPresets(Plugin plugin, StorageRegistry storage, MessageBlocker messageBlocker, BrushSettingsRegistry registry) {
super(plugin);
meta(CommandMeta.builder("sbrbp")
.withPermission(Permissions.BrushPreset.USE)
.buildSubCommands((cmds, builder) -> {
var list = new List(plugin, config, messageBlocker, registry);
var list = new List(plugin, storage, messageBlocker, registry);
builder.withDefaultCommand(list);
cmds.add(new Descr(plugin, config));
cmds.add(new Info(plugin, config, messageBlocker, registry));
cmds.add(new Descr(plugin, storage));
cmds.add(new Info(plugin, storage, messageBlocker, registry));
cmds.add(list);
cmds.add(new Remove(plugin, config));
cmds.add(new Remove(plugin, storage));
}).build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import de.eldoria.schematicbrush.commands.preset.List;
import de.eldoria.schematicbrush.commands.preset.Remove;
import de.eldoria.schematicbrush.storage.Storage;
import de.eldoria.schematicbrush.storage.StorageRegistry;
import de.eldoria.schematicbrush.util.Permissions;
import org.bukkit.plugin.Plugin;

Expand All @@ -22,17 +23,17 @@
* Brush to create and modify brush presets.
*/
public class Preset extends AdvancedCommand {
public Preset(Plugin plugin, Storage config, MessageBlocker messageBlocker) {
public Preset(Plugin plugin, StorageRegistry storage, MessageBlocker messageBlocker) {
super(plugin);
meta(CommandMeta.builder("sbrp")
.withPermission(Permissions.Preset.USE)
.buildSubCommands((cmds, builder) -> {
var list = new List(plugin, config, messageBlocker);
var list = new List(plugin, storage, messageBlocker);
builder.withDefaultCommand(list);
cmds.add(new Descr(plugin, config));
cmds.add(new Info(plugin, config, messageBlocker));
cmds.add(new Descr(plugin, storage));
cmds.add(new Info(plugin, storage, messageBlocker));
cmds.add(list);
cmds.add(new Remove(plugin, config));
cmds.add(new Remove(plugin, storage));
}).build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import de.eldoria.eldoutilities.utils.Consumers;
import de.eldoria.eldoutilities.utils.Futures;
import de.eldoria.schematicbrush.storage.Storage;
import de.eldoria.schematicbrush.storage.StorageRegistry;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
Expand All @@ -25,9 +26,9 @@

public class AddPreset extends AdvancedCommand implements IPlayerTabExecutor {
private final Sessions sessions;
private final Storage storage;
private final StorageRegistry storage;

public AddPreset(Plugin plugin, Sessions sessions, Storage storage) {
public AddPreset(Plugin plugin, Sessions sessions, StorageRegistry storage) {
super(plugin, CommandMeta.builder("addpreset")
.addUnlocalizedArgument("name", true)
.hidden()
Expand All @@ -41,10 +42,10 @@ public void onCommand(@NotNull Player player, @NotNull String alias, @NotNull Ar
var session = sessions.getOrCreateSession(player);
var name = args.asString(0);
var strippedName = name.replaceAll("^g:", "");
storage.presets().containerByName(player, name)
storage.activeStorage().presets().containerByName(player, name)
.get(strippedName)
.whenComplete(Futures.whenComplete(preset -> {
CommandAssertions.isTrue(preset.isPresent(), "Unkown preset.");
CommandAssertions.isTrue(preset.isPresent(), "Unknown preset.");

for (var builder : preset.get().schematicSetsCopy()) {
session.addSchematicSet(builder.copy());
Expand All @@ -57,7 +58,7 @@ public void onCommand(@NotNull Player player, @NotNull String alias, @NotNull Ar
@Override
public @Nullable List<String> onTabComplete(@NotNull Player player, @NotNull String alias, @NotNull Arguments args) {
if (args.size() == 1) {
return storage.presets().complete(player, args.asString(0));
return storage.activeStorage().presets().complete(player, args.asString(0));
}
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import de.eldoria.schematicbrush.brush.config.BrushSettingsRegistry;
import de.eldoria.schematicbrush.schematics.SchematicRegistry;
import de.eldoria.schematicbrush.storage.Storage;
import de.eldoria.schematicbrush.storage.StorageRegistry;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
Expand All @@ -27,11 +28,11 @@

public class LoadBrush extends AdvancedCommand implements IPlayerTabExecutor {
private final Sessions sessions;
private final Storage storage;
private final StorageRegistry storage;
private final BrushSettingsRegistry settingsRegistry;
private final SchematicRegistry schematicRegistry;

public LoadBrush(Plugin plugin, Sessions sessions, Storage storage, BrushSettingsRegistry settingsRegistry, SchematicRegistry schematicRegistry) {
public LoadBrush(Plugin plugin, Sessions sessions, StorageRegistry storage, BrushSettingsRegistry settingsRegistry, SchematicRegistry schematicRegistry) {
super(plugin, CommandMeta.builder("loadbrush")
.addUnlocalizedArgument("name", true)
.build());
Expand All @@ -45,7 +46,7 @@ public LoadBrush(Plugin plugin, Sessions sessions, Storage storage, BrushSetting
public void onCommand(@NotNull Player player, @NotNull String alias, @NotNull Arguments args) throws CommandException {
var name = args.asString(0);
var strippedName = name.replaceAll("^g:", "");
storage.brushes().containerByName(player, name)
storage.activeStorage().brushes().containerByName(player, name)
.get(strippedName)
.whenComplete(Futures.whenComplete(brush -> {
CommandAssertions.isTrue(brush.isPresent(), "Unkown brush.");
Expand All @@ -59,7 +60,7 @@ public void onCommand(@NotNull Player player, @NotNull String alias, @NotNull Ar
@Override
public @Nullable List<String> onTabComplete(@NotNull Player player, @NotNull String alias, @NotNull Arguments args) {
if (args.size() == 1) {
return storage.brushes().complete(player, args.asString(0));
return storage.activeStorage().brushes().complete(player, args.asString(0));
}
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import de.eldoria.eldoutilities.commands.executor.IPlayerTabExecutor;
import de.eldoria.eldoutilities.utils.Futures;
import de.eldoria.schematicbrush.storage.Storage;
import de.eldoria.schematicbrush.storage.StorageRegistry;
import de.eldoria.schematicbrush.storage.brush.Brush;
import de.eldoria.schematicbrush.util.Permissions;
import org.bukkit.entity.Player;
Expand All @@ -28,10 +29,10 @@

public class SaveBrush extends AdvancedCommand implements IPlayerTabExecutor {

private final Storage storage;
private final StorageRegistry storage;
private final Sessions sessions;

public SaveBrush(Plugin plugin, Sessions sessions, Storage storage) {
public SaveBrush(Plugin plugin, Sessions sessions, StorageRegistry storage) {
super(plugin, CommandMeta.builder("saveBrush")
.addUnlocalizedArgument("name", true)
.withPermission(Permissions.BrushPreset.USE)
Expand All @@ -49,24 +50,24 @@ public void onCommand(@NotNull Player player, @NotNull String alias, @NotNull Ar
CompletableFuture<Optional<Brush>> addition;
if (args.flags().has("g")) {
CommandAssertions.permission(player, false, Permissions.BrushPreset.GLOBAL);
addition = storage.brushes().globalContainer().get(brush.name())
addition = storage.activeStorage().brushes().globalContainer().get(brush.name())
.whenComplete(Futures.whenComplete(succ -> {
if (succ.isPresent()) {
CommandAssertions.isTrue(args.flags().has("f"), "Brush already exists. Use -f to override");
}
storage.brushes().globalContainer().add(brush).join();
storage.activeStorage().brushes().globalContainer().add(brush).join();
}, err -> handleCommandError(player, err)));
} else {
addition = storage.brushes().playerContainer(player).get(brush.name())
addition = storage.activeStorage().brushes().playerContainer(player).get(brush.name())
.whenComplete(Futures.whenComplete(succ -> {
if (succ.isPresent()) {
CommandAssertions.isTrue(args.flags().has("f"), "Brush already exists. Use -f to override");
}
storage.brushes().playerContainer(player).add(brush).join();
storage.activeStorage().brushes().playerContainer(player).add(brush).join();
}, err -> handleCommandError(player, err)));
}
addition.whenComplete(Futures.whenComplete(res -> {
storage.save();
storage.activeStorage().save();
messageSender().sendMessage(player, "Brush saved.");
}, err -> handleCommandError(player, err)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import de.eldoria.eldoutilities.utils.Futures;
import de.eldoria.schematicbrush.brush.config.builder.SchematicSetBuilder;
import de.eldoria.schematicbrush.storage.Storage;
import de.eldoria.schematicbrush.storage.StorageRegistry;
import de.eldoria.schematicbrush.storage.preset.Preset;
import de.eldoria.schematicbrush.util.Permissions;
import org.bukkit.entity.Player;
Expand All @@ -29,10 +30,10 @@

public class SavePreset extends AdvancedCommand implements IPlayerTabExecutor {

private final Storage storage;
private final StorageRegistry storage;
private final Sessions sessions;

public SavePreset(Plugin plugin, Sessions sessions, Storage storage) {
public SavePreset(Plugin plugin, Sessions sessions, StorageRegistry storage) {
super(plugin, CommandMeta.builder("savePreset")
.addUnlocalizedArgument("name", true)
.withPermission(Permissions.Preset.USE)
Expand All @@ -52,25 +53,25 @@ public void onCommand(@NotNull Player player, @NotNull String alias, @NotNull Ar
CompletableFuture<Optional<Preset>> addition;
if (args.flags().has("g")) {
CommandAssertions.permission(player, false, Permissions.Preset.GLOBAL);
addition = storage.presets().globalContainer().get(preset.name())
addition = storage.activeStorage().presets().globalContainer().get(preset.name())
.whenComplete(Futures.whenComplete(succ -> {
if (succ.isPresent()) {
CommandAssertions.isTrue(args.flags().has("f"), "Preset already exists. Use -f to override");
}
storage.presets().globalContainer().add(preset).join();
storage.activeStorage().presets().globalContainer().add(preset).join();
}, err -> handleCommandError(player, err)));
} else {
addition = storage.presets().playerContainer(player).get(preset.name())
addition = storage.activeStorage().presets().playerContainer(player).get(preset.name())
.whenComplete(Futures.whenComplete(succ -> {
if (succ.isPresent()) {
CommandAssertions.isTrue(args.flags().has("f"), "Preset already exists. Use -f to override");
}
storage.presets().playerContainer(player).add(preset).join();
storage.activeStorage().presets().playerContainer(player).add(preset).join();
}, err -> handleCommandError(player, err)));
}
addition.whenComplete(Futures.whenComplete(res -> {
//TODO: Think about storage saving
storage.save();
storage.activeStorage().save();
messageSender().sendMessage(player, "Preset saved.");
}, err -> handleCommandError(player, err)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import de.eldoria.eldoutilities.localization.Replacement;
import de.eldoria.eldoutilities.utils.Futures;
import de.eldoria.schematicbrush.storage.Storage;
import de.eldoria.schematicbrush.storage.StorageRegistry;
import de.eldoria.schematicbrush.util.Permissions;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
Expand All @@ -25,9 +26,9 @@
import java.util.List;

public class Descr extends AdvancedCommand implements IPlayerTabExecutor {
private final Storage storage;
private final StorageRegistry storage;

public Descr(Plugin plugin, Storage storage) {
public Descr(Plugin plugin, StorageRegistry storage) {
super(plugin, CommandMeta.builder("descr")
.addUnlocalizedArgument("name", true)
.addUnlocalizedArgument("descr", true)
Expand All @@ -43,7 +44,7 @@ public void onCommand(@NotNull Player player, @NotNull String alias, @NotNull Ar
if (name.startsWith("g:")) CommandAssertions.permission(player, false, Permissions.Preset.GLOBAL);

var strippedName = name.replaceAll("^g:", "");
var container = storage.brushes().containerByName(player, name);
var container = storage.activeStorage().brushes().containerByName(player, name);
container.get(strippedName)
.whenComplete(Futures.whenComplete(brush -> {
CommandAssertions.isTrue(brush.isPresent(), "error.unkownBrush", Replacement.create("name", name).addFormatting('b'));
Expand All @@ -57,7 +58,7 @@ public void onCommand(@NotNull Player player, @NotNull String alias, @NotNull Ar
@Override
public @Nullable List<String> onTabComplete(@NotNull Player player, @NotNull String alias, @NotNull Arguments args) {
if (args.size() == 1) {
return storage.brushes().complete(player, args.asString(0));
return storage.activeStorage().brushes().complete(player, args.asString(0));
}
return Collections.emptyList();
}
Expand Down
Loading

0 comments on commit 9d34ca8

Please sign in to comment.