Skip to content

Commit

Permalink
Nucleus integration updated to Nucleus V2
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohron committed Feb 20, 2021
1 parent ef5c765 commit 7087102
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 113 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Change Log

# Beta 31
**REQUIRED: Sponge API 7.3+; Grief Defender 1.5.9+; LuckPerms 5.2.X;**
**OPTIONAL: Nucleus 2.3.2+**
- **BREAKING CHANGE:** Nucleus integration updated to Nucleus V2
- Updated bStats to version 2.2.1 (Fixes incompatibility with older versions)
- Removed `World` > `Void-Worlds` config. The `skyclaims:void` modifier will no longer be automatically applied
- Added `World` > `SkyClaims-World-UUID` config. This config can be used instead of `World` > `SkyClaims-World` (world name)
- Added special handling for migrating to an island claim with the same owner but with a different UUID

# Beta 30 - Grief Defender Port
**REQUIRED: Sponge API 7.1 (SF 3682+); Grief Defender 1.12.2-4.3.0.622+; Permissions Plugin (ie. LuckPerms)**
**OPTIONAL: Nucleus 1.9.0-S7.1+**
Expand Down
9 changes: 6 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ repositories {
jcenter()
maven {
name = "Sponge"
url = "http://repo.spongepowered.org/maven"
url = "https://repo.spongepowered.org/maven"
}
maven {
name = "Forge"
url = "http://files.minecraftforge.net/maven"
url = "https://files.minecraftforge.net/maven"
}
maven {
name = "Nucleus"
url = "http://repo.drnaylor.co.uk/artifactory/list/minecraft"
url = "https://repo.drnaylor.co.uk/artifactory/list/minecraft"
}
maven {
name = "LuckPerms"
Expand Down Expand Up @@ -75,8 +75,11 @@ lombok {
shadowJar {
archiveClassifier.set("plugin")
dependencies {
include(dependency("org.bstats:bstats-base:${bstats}"))
include(dependency("org.bstats:bstats-sponge:${bstats}"))
}
relocate "org.bstats", "net.mohron.skyclaims.metrics"

minimize()
}

Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
## Version
major=0
minor=30
patch=1
api=S7.1
minor=31
patch=0
api=S7.13
suffix=GRIEF-DEFENDER-SNAPSHOT
## Dependencies
spongeapi=7.1.0
spongeapi=7.3.0
spongeforge=1.12.2-2768-7.1.4
forge=14.23.5.2768
griefdefender=1.0.0
nucleus=1.9.0-S7.1
nucleus=2.3.2
bstats=2.2.1
79 changes: 52 additions & 27 deletions src/main/java/net/mohron/skyclaims/SkyClaims.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import com.google.inject.Inject;
import com.griefdefender.api.GriefDefender;
import java.nio.file.Path;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -62,7 +61,10 @@
import net.mohron.skyclaims.world.region.Region;
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
import ninja.leaping.configurate.loader.ConfigurationLoader;
import org.bstats.sponge.Metrics2;
import org.bstats.charts.DrilldownPie;
import org.bstats.charts.SimplePie;
import org.bstats.charts.SingleLineChart;
import org.bstats.sponge.Metrics;
import org.slf4j.Logger;
import org.spongepowered.api.Game;
import org.spongepowered.api.Platform;
Expand All @@ -71,6 +73,7 @@
import org.spongepowered.api.block.BlockTypes;
import org.spongepowered.api.config.ConfigDir;
import org.spongepowered.api.config.DefaultConfig;
import org.spongepowered.api.data.DataQuery;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.Order;
import org.spongepowered.api.event.filter.Getter;
Expand All @@ -88,6 +91,8 @@
import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.scheduler.Task;
import org.spongepowered.api.service.permission.PermissionService;
import org.spongepowered.api.util.Tristate;
import org.spongepowered.api.util.metric.MetricsConfigManager;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.gen.WorldGeneratorModifier;
Expand All @@ -112,13 +117,16 @@ public class SkyClaims {
@Inject
private PluginContainer pluginContainer;

@Inject
private MetricsConfigManager metricsConfigManager;

@Inject
private Logger logger;

@Inject
private Game game;

private Metrics2 metrics;
private Metrics metrics;

@Inject
@ConfigDir(sharedRoot = false)
Expand All @@ -142,7 +150,7 @@ public class SkyClaims {
private static final String ISLAND_CLEANUP = "skyclaims.island.cleanup";

@Inject
public SkyClaims(Metrics2.Factory metricsFactory) {
public SkyClaims(Metrics.Factory metricsFactory) {
metrics = metricsFactory.make(96);
}

Expand Down Expand Up @@ -230,12 +238,6 @@ public void onGameRegistry(GameRegistryEvent.Register<WorldGeneratorModifier> ev

@Listener
public void onConstructWorldProperties(ConstructWorldPropertiesEvent event, @Getter(value = "getWorldProperties") WorldProperties properties) {
if (!properties.isInitialized() && config.getWorldConfig().getVoidDimensions().contains(properties.getWorldName())) {
Collection<WorldGeneratorModifier> modifiers = properties.getGeneratorModifiers();
modifiers.add(voidGenModifier);
properties.setGeneratorModifiers(modifiers);
logger.info("{} set to use SkyClaims' Enhanced Void World Generation Modifier.", properties.getWorldName());
}
if (!properties.isInitialized() && properties.getWorldName()
.equalsIgnoreCase(config.getWorldConfig().getWorldName())) {
setupSpawn = true;
Expand Down Expand Up @@ -273,9 +275,19 @@ public void onServerStarted(GameStartedServerEvent event) {

Optional<World> world = config.getWorldConfig().loadWorld();
if (!world.isPresent()) {
logger.error("Unable to load world '{}'.", config.getWorldConfig().getWorldUuid() != null ? config.getWorldConfig().getWorldUuid() : config.getWorldConfig().getWorldName());
unload();
this.enabled = false;
logger.error("Unable to load world '{}'.", config.getWorldConfig().getWorldUuid().map(UUID::toString).orElse(config.getWorldConfig().getWorldName()));
return;
}
if (logger.isInfoEnabled()) {
logger.info(
"Using world: {} | DIM {} | {}",
world.get().getName(),
world.get().getProperties().getAdditionalProperties().getInt(DataQuery.of("SpongeData", "dimensionId")).map(String::valueOf).orElse("?"),
world.get().getUniqueId()
);
}

database = initializeDatabase();
schematicManager.load();
Expand All @@ -287,6 +299,10 @@ public void onServerStarted(GameStartedServerEvent event) {
database.saveData(IslandManager.saveQueue);
}

// SkyClaims Metrics are enabled by default
if (this.metricsConfigManager.getCollectionState(this.pluginContainer) == Tristate.UNDEFINED) {
Sponge.getCommandManager().process(Sponge.getServer().getConsole(), "sponge metrics " + ID + " enable");
}
addCustomMetrics();

logger.info("Initialization complete.");
Expand All @@ -305,23 +321,32 @@ public void onReload(GameReloadEvent event) {
reload();
}

public void reload() {
// Load Plugin Config
configManager.load();
// Load Schematics
schematicManager.load();
// Load Database
IslandManager.ISLANDS = database.loadData();
// Reload Listeners
private void unload() {
// Unregister Listeners
Sponge.getEventManager().unregisterPluginListeners(this);
registerListeners();
// Reload Tasks
// Cancel Tasks
Sponge.getScheduler().getTasksByName(ISLAND_CLEANUP).forEach(Task::cancel);
registerTasks();
// Reload Commands
// Remove Commands
Sponge.getCommandManager().getOwnedBy(this).forEach(Sponge.getCommandManager()::removeMapping);
CommandIsland.clearSubCommands();
registerCommands();
}

public void reload() {
if (enabled) {
unload();
// Load Plugin Config
configManager.load();
// Load Schematics
schematicManager.load();
// Load Database
IslandManager.ISLANDS = database.loadData();
// Reload Listeners
registerListeners();
// Reload Tasks
registerTasks();
// Reload Commands
registerCommands();
}
}

private void registerListeners() {
Expand Down Expand Up @@ -366,16 +391,16 @@ private IDatabase initializeDatabase() {
}

private void addCustomMetrics() {
metrics.addCustomChart(new Metrics2.SingleLineChart("islands", () -> IslandManager.ISLANDS.size()));
metrics.addCustomChart(new Metrics2.DrilldownPie("sponge_version", () -> {
metrics.addCustomChart(new SingleLineChart("islands", IslandManager.ISLANDS::size));
metrics.addCustomChart(new DrilldownPie("sponge_version", () -> {
Map<String, Map<String, Integer>> map = new HashMap<>();
String api = Sponge.getPlatform().getContainer(Platform.Component.API).getVersion().orElse("?").split("-")[0];
Map<String, Integer> entry = new HashMap<>();
entry.put(Sponge.getPlatform().getContainer(Platform.Component.IMPLEMENTATION).getVersion().orElse(null), 1);
map.put(api, entry);
return map;
}));
metrics.addCustomChart(new Metrics2.SimplePie("allocated_ram", () ->
metrics.addCustomChart(new SimplePie("allocated_ram", () ->
String.format("%s GB", Math.round((Runtime.getRuntime().maxMemory() / 1024.0 / 1024.0 / 1024.0) * 2.0) / 2.0))
);
}
Expand Down
17 changes: 8 additions & 9 deletions src/main/java/net/mohron/skyclaims/config/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import net.mohron.skyclaims.SkyClaims;
import net.mohron.skyclaims.config.type.GlobalConfig;
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
import ninja.leaping.configurate.commented.SimpleCommentedConfigurationNode;
import ninja.leaping.configurate.loader.ConfigurationLoader;
import ninja.leaping.configurate.objectmapping.ObjectMapper;
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
Expand All @@ -35,10 +34,10 @@
public class ConfigManager {

public static final int CONFIG_VERSION = 1;
private final SkyClaims PLUGIN = SkyClaims.getInstance();
private final Logger LOGGER = PLUGIN.getLogger();
private static final SkyClaims PLUGIN = SkyClaims.getInstance();
private static final Logger LOGGER = PLUGIN.getLogger();
private final ConfigurationLoader<CommentedConfigurationNode> loader;
private ObjectMapper<GlobalConfig>.BoundInstance configMapper;
private ConfigurationLoader<CommentedConfigurationNode> loader;

public ConfigManager(ConfigurationLoader<CommentedConfigurationNode> loader) {
this.loader = loader;
Expand All @@ -57,11 +56,11 @@ public ConfigManager(ConfigurationLoader<CommentedConfigurationNode> loader) {
*/
public void save() {
try {
SimpleCommentedConfigurationNode out = SimpleCommentedConfigurationNode.root();
CommentedConfigurationNode out = CommentedConfigurationNode.root();
this.configMapper.serialize(out);
this.loader.save(out);
} catch (ObjectMappingException | IOException e) {
LOGGER.error(String.format("Failed to save config.\r\n %s", e.getMessage()));
LOGGER.error("Failed to save config", e);
}
}

Expand All @@ -71,8 +70,8 @@ public void save() {
public void load() {
try {
this.configMapper.populate(this.loader.load());
} catch (ObjectMappingException | IOException e) {
LOGGER.error(String.format("Failed to load config.\r\n %s", e.getMessage()));
} catch (Exception e) {
LOGGER.error("Failed to load config", e);
}
}

Expand All @@ -85,7 +84,7 @@ private void initializeData() {
try {
Files.createDirectory(path);
} catch (IOException e) {
LOGGER.error(String.format("Failed to create data directory.\r\n %s", e.getMessage()));
LOGGER.error("Failed to create data directory", e);
}
}
}
Expand Down
19 changes: 6 additions & 13 deletions src/main/java/net/mohron/skyclaims/config/type/WorldConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

package net.mohron.skyclaims.config.type;

import com.google.common.collect.Lists;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.UUID;
Expand All @@ -33,15 +31,14 @@

@ConfigSerializable
public class WorldConfig {
private static final UUID NIL_UUID = new UUID(0, 0);

@Setting(value = "SkyClaims-World-UUID", comment = "Sponge UUID of the world to manage islands in")
private UUID worldUuid = null;
private UUID worldUuid = NIL_UUID;
@Setting(value = "SkyClaims-World", comment = "Name of the world to manage islands in. Ignored if the UUID is provided Default: world")
private String worldName = "world";
@Setting(value = "Spawn-World", comment = "Use to override the world used when sending players to spawn.")
private String spawnWorld = "";
@Setting(value = "Void-Dimensions", comment = "A list of world names to generate as void. Default: world, DIM-1, DIM1")
private List<String> voidDimensions = Lists.newArrayList("world", "DIM-1", "DIM1");
@Setting(value = "Island-Height", comment = "Height to build islands at (1-255). Default: 72")
private int islandHeight = 72;
@Setting(value = "Spawn-Regions", comment = "The height & width of regions to reserve for spawn (min 1). Default: 1")
Expand All @@ -52,20 +49,20 @@ public class WorldConfig {
@Setting(value = "Regen-On-Create", comment = "If enabled, SkyClaims will regen the target region before an island is created.")
private boolean regenOnCreate = false;

public UUID getWorldUuid() {
return worldUuid;
public Optional<UUID> getWorldUuid() {
return worldUuid.equals(NIL_UUID) ? Optional.empty() : Optional.of(worldUuid);
}

public String getWorldName() {
return worldName;
}

private Optional<World> getWorldOptional() {
return worldUuid != null ? Sponge.getServer().getWorld(worldUuid) : Sponge.getServer().getWorld(worldName);
return getWorldUuid().map(uuid -> Sponge.getServer().getWorld(uuid)).orElseGet(() -> Sponge.getServer().getWorld(worldName));
}

public Optional<World> loadWorld() {
return worldUuid != null ? Sponge.getServer().loadWorld(worldUuid) : Sponge.getServer().loadWorld(worldName);
return getWorldUuid().map(uuid -> Sponge.getServer().loadWorld(uuid)).orElseGet(() -> Sponge.getServer().loadWorld(worldName));
}

public World getWorld() {
Expand All @@ -85,10 +82,6 @@ public Location<World> getSpawn() {
return world.isLoaded() ? world.getSpawnLocation() : getWorld().getSpawnLocation();
}

public List<String> getVoidDimensions() {
return voidDimensions;
}

public boolean isSeparateSpawn() {
return !StringUtils.isEmpty(spawnWorld) && Sponge.getServer().getWorld(spawnWorld).isPresent();
}
Expand Down
Loading

0 comments on commit 7087102

Please sign in to comment.