Skip to content

Commit

Permalink
Update cloudcore to v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
booky10 committed May 26, 2024
1 parent 81fc74a commit a2dac87
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
5 changes: 3 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "dev.booky"
version = "1.0.4-SNAPSHOT"
version = "1.0.5-SNAPSHOT"

val plugin: Configuration by configurations.creating {
isTransitive = false
Expand All @@ -22,11 +22,12 @@ dependencies {
compileOnly(libs.paperapi)

compileOnlyApi(libs.cloudcore)
compileOnlyApi(libs.commandapi.bukkit.core)
implementation(libs.bstats)

// testserver dependency plugins
plugin(variantOf(libs.cloudcore) { classifier("all") })
plugin(libs.commandapi.plugin)
plugin(libs.commandapi.bukkit.plugin)
}

java {
Expand Down
7 changes: 4 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ shadow = "8.1.7"
minecraft = "1.20.6"
paperapi = "1.20.6-R0.1-SNAPSHOT"

cloudcore = "1.0.3-SNAPSHOT"
cloudcore = "1.1.0-SNAPSHOT"

bstats = "3.0.2"
commandapi = "9.4.0"
commandapi = "9.5.0-SNAPSHOT"

[plugins]
pluginyml-bukkit = { id = "net.minecrell.plugin-yml.bukkit", version.ref = "pluginyml" }
Expand All @@ -22,4 +22,5 @@ paperapi = { module = "io.papermc.paper:paper-api", version.ref = "paperapi" }
cloudcore = { module = "dev.booky:cloudcore", version.ref = "cloudcore" }

bstats = { module = "org.bstats:bstats-bukkit", version.ref = "bstats" }
commandapi-plugin = { module = "dev.jorel:commandapi-bukkit-plugin", version.ref = "commandapi" }
commandapi-bukkit-core = { module = "dev.jorel:commandapi-bukkit-core", version.ref = "commandapi" }
commandapi-bukkit-plugin = { module = "dev.jorel:commandapi-bukkit-plugin", version.ref = "commandapi" }
11 changes: 8 additions & 3 deletions src/main/java/dev/booky/cloudprotections/ProtectionsMain.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
package dev.booky.cloudprotections;
// Created by booky10 in CloudCore (10:35 14.03.23)

import dev.booky.cloudcore.util.TranslationLoader;
import dev.booky.cloudcore.i18n.CloudTranslator;
import dev.booky.cloudprotections.commands.ProtectionsCommand;
import dev.booky.cloudprotections.listener.ProtectionListener;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.plugin.ServicePriority;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.Locale;

public class ProtectionsMain extends JavaPlugin {

private ProtectionsManager manager;
private TranslationLoader i18n;
private CloudTranslator i18n;

@Override
public void onLoad() {
this.manager = new ProtectionsManager(this);
new Metrics(this, 18100);

this.i18n = new TranslationLoader(this);
this.i18n = new CloudTranslator(this.getClassLoader(),
new NamespacedKey(this, "i18n"),
Locale.GERMAN, Locale.ENGLISH);
this.i18n.load();

Bukkit.getServicesManager().register(ProtectionsManager.class, this.manager, this, ServicePriority.Normal);
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/dev/booky/cloudprotections/ProtectionsManager.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.booky.cloudprotections;
// Created by booky10 in CloudProtections (01:58 01.04.23)

import dev.booky.cloudcore.config.ConfigLoader;
import dev.booky.cloudcore.config.ConfigurateLoader;
import dev.booky.cloudprotections.config.ProtectionAreaSerializer;
import dev.booky.cloudprotections.config.ProtectionRegionSerializer;
import dev.booky.cloudprotections.region.ProtectionFlag;
Expand All @@ -17,7 +17,6 @@
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.configurate.serialize.TypeSerializerCollection;

import java.nio.file.Path;
import java.util.ArrayList;
Expand Down Expand Up @@ -54,10 +53,13 @@ public final class ProtectionsManager {
.append(Component.text("] ", NamedTextColor.GRAY))
.build().compact();

private static final Consumer<TypeSerializerCollection.Builder> CONFIG_SERIALIZERS = builder -> builder
.register(ProtectionRegion.class, ProtectionRegionSerializer.INSTANCE)
.register(IProtectionArea.class, ProtectionAreaSerializer.INSTANCE);
private static final TypeToken<List<ProtectionRegion>> REGIONS_TOKEN = new TypeToken<>() {};
private static final ConfigurateLoader<?, ?> CONFIG_LOADER = ConfigurateLoader.yamlLoader()
.withAllDefaultSerializers()
.withSerializers(builder -> builder
.register(ProtectionRegion.class, ProtectionRegionSerializer.INSTANCE)
.register(IProtectionArea.class, ProtectionAreaSerializer.INSTANCE))
.build();

private final Plugin plugin;
private final Path regionsPath;
Expand All @@ -69,13 +71,13 @@ public ProtectionsManager(Plugin plugin) {
}

public void reloadRegions() {
List<ProtectionRegion> regions = ConfigLoader.loadObject(this.regionsPath,
REGIONS_TOKEN, List::of, CONFIG_SERIALIZERS);
List<ProtectionRegion> regions = CONFIG_LOADER.loadObject(
this.regionsPath, REGIONS_TOKEN, List::of);
this.replaceRegions(regions);
}

public void saveRegions() {
ConfigLoader.saveObject(this.regionsPath, REGIONS_TOKEN, List.copyOf(this.regions.values()), CONFIG_SERIALIZERS);
CONFIG_LOADER.saveObject(this.regionsPath, List.copyOf(this.regions.values()), REGIONS_TOKEN);
}

public synchronized void updateRegions(Consumer<Map<String, ProtectionRegion>> consumer) {
Expand Down

0 comments on commit a2dac87

Please sign in to comment.