Skip to content

Commit

Permalink
Feature/jackson config (#16)
Browse files Browse the repository at this point in the history
* Migrate to jackson configuration

* Add license header

* Add updater
  • Loading branch information
rainbowdashlabs authored Apr 7, 2023
1 parent 70a6020 commit 05c6ec2
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 52 deletions.
41 changes: 38 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import de.chojo.Repo
import net.minecrell.pluginyml.bukkit.BukkitPluginDescription.Permission.Default.FALSE

plugins {
id("org.cadixdev.licenser") version "0.6.1"
id("com.github.johnrengelman.shadow") version "8.1.1"
id("de.chojo.publishdata") version "1.2.4"
id("net.minecrell.plugin-yml.bukkit") version "0.5.3"
java
`maven-publish`
}
Expand All @@ -17,10 +19,17 @@ repositories {
}

dependencies {
compileOnly("de.eldoria", "schematicbrushreborn-api", "2.4.3")
compileOnly("de.eldoria", "schematicbrushreborn-api", "2.5.0-DEV")
compileOnly("org.spigotmc", "spigot-api", "1.13.2-R0.1-SNAPSHOT")
compileOnly("com.sk89q.worldedit", "worldedit-bukkit", "7.2.14")

bukkitLibrary("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.14.2")
bukkitLibrary("com.fasterxml.jackson.core:jackson-core:2.14.2")
bukkitLibrary("com.fasterxml.jackson.core:jackson-databind:2.14.2")
bukkitLibrary("net.kyori:adventure-platform-bukkit:4.3.0")
bukkitLibrary("net.kyori:adventure-text-minimessage:4.13.0")


testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.2")
}
Expand All @@ -37,6 +46,7 @@ java {
}

publishData {
addBuildData()
addRepo(Repo.main("", "https://eldonexus.de/repository/maven-releases/", false))
addRepo(Repo.dev("DEV", "https://eldonexus.de/repository/maven-dev/", true))
addRepo(Repo.snapshot("SNAPSHOT", "https://eldonexus.de/repository/maven-snapshots/", true))
Expand Down Expand Up @@ -82,15 +92,14 @@ tasks {
shadowJar {
relocate("de.eldoria.eldoutilities", "de.eldoria.schematicbrush.libs.eldoutilities")
relocate("de.eldoria.messageblocker", "de.eldoria.schematicbrush.libs.messageblocker")
relocate("net.kyori", "de.eldoria.schematicbrush.libs.kyori")
mergeServiceFiles()
}

processResources {
from(sourceSets.main.get().resources.srcDirs) {
filesMatching("plugin.yml") {
expand(
"version" to publishData.getVersion(true)
"version" to publishData.getVersion(true)
)
}
duplicatesStrategy = DuplicatesStrategy.INCLUDE
Expand All @@ -112,3 +121,29 @@ tasks {
dependsOn(shadowJar)
}
}

bukkit {
name = "SurvivalSchematicBrush"
main = "de.eldoria.survivalbrush.SurvivalBrush"
apiVersion = "1.16"
version = publishData.getVersion(true)
authors = listOf("RainbowDashLabs")
depend = listOf("SchematicBrushReborn")

permissions {
register("survivalschematicbrush.paste.bypass") {
default = FALSE
description = "Allow to bypass block pasting check when in survival"
}

register("survivalschematicbrush.limit.bypass") {
default = FALSE
description = "Allow to bypass max schematic size"
}

register("survivalschematicbrush.limit.<limit>") {
default = FALSE
description = "Set the max blocks a schematic can have"
}
}
}
26 changes: 19 additions & 7 deletions src/main/java/de/eldoria/survivalbrush/SurvivalBrush.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,40 @@

package de.eldoria.survivalbrush;

import de.eldoria.eldoutilities.config.template.PluginBaseConfiguration;
import de.eldoria.eldoutilities.plugin.EldoPlugin;
import de.eldoria.eldoutilities.updater.lynaupdater.LynaUpdateChecker;
import de.eldoria.eldoutilities.updater.lynaupdater.LynaUpdateData;
import de.eldoria.survivalbrush.configuration.BlockSettings;
import de.eldoria.survivalbrush.configuration.Configuration;
import de.eldoria.survivalbrush.configuration.JacksonConfiguration;
import de.eldoria.survivalbrush.configuration.LegacyConfiguration;
import de.eldoria.survivalbrush.listener.PasteListener;
import org.bukkit.configuration.serialization.ConfigurationSerializable;

import java.util.List;
import java.util.logging.Level;

public class SurvivalBrush extends EldoPlugin {
@Override
public void onPluginEnable() throws Throwable {
var configuration = new Configuration(this);
var configuration = new JacksonConfiguration(this);
PluginBaseConfiguration base = configuration.secondary(PluginBaseConfiguration.KEY);
if (base.version() == 0) {
var legacyConfiguration = new LegacyConfiguration(this);
getLogger().log(Level.INFO, "Migrating configuration to jackson.");
configuration.main().blockSettings(legacyConfiguration.blockSettings());
base.version(1);
base.lastInstalledVersion(this);
configuration.save();
}

LynaUpdateChecker.lyna(LynaUpdateData.builder(this, 7).build()).start();

registerListener(new PasteListener(this, configuration));
}

@Override
public List<Class<? extends ConfigurationSerializable>> getConfigSerialization() {
return List.of(BlockSettings.class);
}

@Override
public void onPluginDisable() throws Throwable {
super.onPluginDisable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.List;
import java.util.Map;

@SuppressWarnings("FieldMayBeFinal")
public class BlockSettings implements ConfigurationSerializable {
private static final List<Material> DEFAULT_BLACKLIST = List.of(Material.SHULKER_BOX,
Material.WHITE_SHULKER_BOX,
Expand All @@ -34,7 +35,7 @@ public class BlockSettings implements ConfigurationSerializable {
Material.CHEST,
Material.TRAPPED_CHEST,
Material.FURNACE);
private final List<Material> pasteBlacklist;
private List<Material> pasteBlacklist;

public BlockSettings() {
pasteBlacklist = DEFAULT_BLACKLIST;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
*
* Copyright (C) 2021 EldoriaRPG Team and Contributor
*/

package de.eldoria.survivalbrush.configuration;

@SuppressWarnings("FieldMayBeFinal")
public class ConfigFile {
private BlockSettings blockSettings = new BlockSettings();

public BlockSettings blockSettings() {
return blockSettings;
}

public void blockSettings(BlockSettings blockSettings) {
this.blockSettings = blockSettings;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,6 @@

package de.eldoria.survivalbrush.configuration;

import de.eldoria.eldoutilities.configuration.EldoConfig;
import org.bukkit.plugin.Plugin;

public class Configuration extends EldoConfig {
private BlockSettings blockSettings;

public Configuration(Plugin plugin) {
super(plugin);
}

@Override
protected void reloadConfigs() {
blockSettings = getConfig().getObject("blockSettings", BlockSettings.class, new BlockSettings());
}

@Override
protected void saveConfigs() {
getConfig().set("blockSettings", blockSettings);
}

public BlockSettings blockSettings() {
return blockSettings;
}
public interface Configuration {
BlockSettings blockSettings();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
*
* Copyright (C) 2021 EldoriaRPG Team and Contributor
*/

package de.eldoria.survivalbrush.configuration;

import de.eldoria.eldoutilities.config.ConfigKey;
import de.eldoria.eldoutilities.config.JacksonConfig;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;

public class JacksonConfiguration extends JacksonConfig<ConfigFile> implements Configuration {
public JacksonConfiguration(@NotNull Plugin plugin) {
super(plugin, ConfigKey.defaultConfig(ConfigFile.class, ConfigFile::new));
}


@Override
public BlockSettings blockSettings() {
return main().blockSettings();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
*
* Copyright (C) 2021 EldoriaRPG Team and Contributor
*/

package de.eldoria.survivalbrush.configuration;

import de.eldoria.eldoutilities.configuration.EldoConfig;
import org.bukkit.plugin.Plugin;

public class LegacyConfiguration extends EldoConfig implements Configuration {
private BlockSettings blockSettings;

public LegacyConfiguration(Plugin plugin) {
super(plugin);
}

@Override
protected void reloadConfigs() {
blockSettings = getConfig().getObject("blockSettings", BlockSettings.class, new BlockSettings());
}

@Override
protected void saveConfigs() {
getConfig().set("blockSettings", blockSettings);
}

@Override
public BlockSettings blockSettings() {
return blockSettings;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import de.eldoria.eldoutilities.container.Pair;
import de.eldoria.schematicbrush.event.PrePasteEvent;
import de.eldoria.survivalbrush.configuration.Configuration;
import de.eldoria.survivalbrush.configuration.LegacyConfiguration;
import de.eldoria.survivalbrush.util.Permissions;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.minimessage.MiniMessage;
Expand Down
18 changes: 0 additions & 18 deletions src/main/resources/plugin.yml

This file was deleted.

0 comments on commit 05c6ec2

Please sign in to comment.