Skip to content

Commit

Permalink
nearly complete port to Sponge API 8
Browse files Browse the repository at this point in the history
  • Loading branch information
Pulverizer committed Oct 12, 2023
1 parent 4162164 commit 80247ab
Show file tree
Hide file tree
Showing 90 changed files with 2,169 additions and 1,992 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,6 @@ nb-configuration.xml
/gradle/forge/.gradle/
/gradle/forge/build/
/gradle/vanilla/build/
/forge/.gradle/
/forge/build/
/vanilla/build/
1 change: 1 addition & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

181 changes: 166 additions & 15 deletions .idea/workspace.xml

Large diffs are not rendered by default.

55 changes: 54 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,59 @@
import org.spongepowered.gradle.plugin.config.PluginLoaders
import org.spongepowered.plugin.metadata.model.PluginDependency

repositories {
gradlePluginPortal()
mavenCentral()
maven {
setUrl("https://repo.spongepowered.org/repository/maven-public/")
}
}

plugins {
id("io.github.pulverizer.movecraft.common_build")
id("org.spongepowered.gradle.vanilla")
id("org.spongepowered.gradle.plugin")
id("org.spongepowered.gradle.ore") // for Ore publishing
}

sponge {
apiVersion("8.2.0")
license("GPL-3.0")
loader {
name(PluginLoaders.JAVA_PLAIN)
version("1.0")
}
plugin("movecraft") {
displayName("Movecraft for Sponge")
entrypoint("io.github.pulverizer.movecraft.Movecraft")
description("Making vehicles out of blocks")
links {
homepage("https://ore.spongepowered.org/BernardisGood/Movecraft-for-Sponge")
source("https://github.com/Pulverizer/Movecraft-for-Sponge")
issues("https://github.com/Pulverizer/Movecraft-for-Sponge/issues")
}
contributor("BernardisGood") {
description("Lead Developer")
}
dependency("spongeapi") {
loadOrder(PluginDependency.LoadOrder.AFTER)
optional(false)
}
}
}

// Optional: configure publication to Ore
// Publish using the publishToOre task
// An API token is needed for this, by default read from the ORE_TOKEN environment variable
oreDeployment {
// The default publication here is automatically configured by SpongeGradle
// using the first-created plugin"s ID as the project ID
// A version body is optional, to provide additional information about the release
/*
defaultPublication {
// Read the version body from the file whose path is provided to the changelog gradle property
versionBody.set(providers.gradleProperty("changelog").map { file(it).readText(Charsets.UTF_8) }.orElse(""))
}*/
}

tasks.shadowJar {
Expand All @@ -27,5 +80,5 @@ dependencies {

minecraft {
version("1.16.5")
//accessWideners(file("../src/main/resources/movecraft.accesswidener"))
accessWideners(file("./src/main/resources/movecraft.accesswidener"))
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import org.spongepowered.gradle.plugin.config.PluginLoaders
import org.spongepowered.plugin.metadata.model.PluginDependency

plugins {

`java-library`
id("com.github.johnrengelman.shadow")
id("org.spongepowered.gradle.plugin")
id("org.spongepowered.gradle.ore") // for Ore publishing

// my plugins
`maven-publish`
Expand All @@ -19,35 +14,10 @@ dependencies {
testCompileOnly(group = "org.junit.jupiter", name = "junit-jupiter", version = "5.7.0")
testCompileOnly(group = "org.mockito", name = "mockito-core", version = "3.+")
compileOnly("org.spongepowered:spongeapi:8.3.0-SNAPSHOT")
compileOnly("org.spongepowered:sponge:1.16.5-8.2.1-SNAPSHOT")
compileOnly("org.spongepowered:mixin:0.8.5")
}

sponge {
apiVersion("8.2.0")
license("GPL-3.0")
loader {
name(PluginLoaders.JAVA_PLAIN)
version("1.0")
}
plugin("movecraft") {
displayName("Movecraft for Sponge")
entrypoint("io.github.pulverizer.movecraft.Movecraft")
description("Making vehicles out of blocks")
links {
homepage("https://ore.spongepowered.org/BernardisGood/Movecraft-for-Sponge")
source("https://github.com/Pulverizer/Movecraft-for-Sponge")
issues("https://github.com/Pulverizer/Movecraft-for-Sponge/issues")
}
contributor("BernardisGood") {
description("Lead Developer")
}
dependency("spongeapi") {
loadOrder(PluginDependency.LoadOrder.AFTER)
optional(false)
}
}
}

val javaTarget = 16
java {
sourceCompatibility = JavaVersion.toVersion(javaTarget)
Expand All @@ -70,20 +40,6 @@ tasks.withType(AbstractArchiveTask::class).configureEach {
isPreserveFileTimestamps = false
}

// Optional: configure publication to Ore
// Publish using the publishToOre task
// An API token is needed for this, by default read from the ORE_TOKEN environment variable
oreDeployment {
// The default publication here is automatically configured by SpongeGradle
// using the first-created plugin"s ID as the project ID
// A version body is optional, to provide additional information about the release
/*
defaultPublication {
// Read the version body from the file whose path is provided to the changelog gradle property
versionBody.set(providers.gradleProperty("changelog").map { file(it).readText(Charsets.UTF_8) }.orElse(""))
}*/
}

configurations.create("shade")
configurations.create("provided").extendsFrom(configurations.getByName("shade"))
configurations.implementation.extendsFrom(configurations.getByName("provided"))
Expand All @@ -97,15 +53,15 @@ tasks.jar {
attributes["FMLCorePluginContainsFMLMod"] = "true"
}
}

/*
publishing {
publications {
register("movecraft", MavenPublication::class) {
from(components["java"])
}
}
}

*/
dependencies {
testCompileOnly(group = "org.junit.jupiter", name = "junit-jupiter", version = "5.7.0")
testCompileOnly(group = "org.mockito", name = "mockito-core", version = "3.+")
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ pluginManagement {

rootProject.name = 'movecraft'

include ':gradle:vanilla'
//include ':gradle:forge'
include ':vanilla'
//include ':forge'
52 changes: 28 additions & 24 deletions src/main/java/io/github/pulverizer/movecraft/Movecraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@
import io.github.pulverizer.movecraft.map_updater.MapUpdateManager;
import io.github.pulverizer.movecraft.sign.CommanderSign;
import io.github.pulverizer.movecraft.sign.CrewSign;
import org.slf4j.Logger;
import org.apache.logging.log4j.Logger;
import org.spongepowered.api.Server;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.Command;
import org.spongepowered.api.config.ConfigDir;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.Order;
import org.spongepowered.api.event.game.state.GamePreInitializationEvent;
import org.spongepowered.api.event.game.state.GameStartedServerEvent;
import org.spongepowered.api.event.lifecycle.LoadedGameEvent;
import org.spongepowered.api.event.lifecycle.RegisterCommandEvent;
import org.spongepowered.api.event.lifecycle.StartedEngineEvent;
import org.spongepowered.plugin.PluginContainer;
import org.spongepowered.api.util.Ticks;
import org.spongepowered.plugin.builtin.jvm.Plugin;
Expand All @@ -37,7 +40,6 @@
import java.sql.SQLException;

@Plugin("movecraft")

public class Movecraft {

private static Movecraft instance;
Expand Down Expand Up @@ -96,40 +98,42 @@ public void registerFeatures(RegisterFeaturesEvent event) {
CrewRoles.register();
}

@Listener
public void registerCommandsEvent(final RegisterCommandEvent<Command.Parameterized> event) {
//TODO: Re-add commands!

/*this.getCommand("movecraft").setExecutor(new MovecraftCommand());
this.getCommand("release").setExecutor(new ReleaseCommand());
this.getCommand("pilot").setExecutor(new PilotCommand());
this.getCommand("add").setExecutor(new RotateCommand());
this.getCommand("cruise").setExecutor(new CruiseCommand());
this.getCommand("manoverboard").setExecutor(new ManOverboardCommand());
this.getCommand("scuttle").setExecutor(new ScuttleCommand());*/

event.register(container, CraftReportCommand.register(), "craftreport");
event.register(container, CrewCommand.register(), "crew");
event.register(container, CraftTypesCommand.register(), "crafttypes");
event.register(container, DockCommand.register(), "dock");
event.register(container, ContactsCommand.register(), "contacts");
}

/**
* Listener for GamePreInitializationEvent. Loads the Plugin's settings.
* @param event GamePreInitializationEvent from Listener.
*/
@Listener
public void onLoad(GamePreInitializationEvent event) {
public void onLoad(final LoadedGameEvent event) {

instance = this;

// Call feature registration event
RegisterFeaturesEvent registerFeaturesEvent = new RegisterFeaturesEvent();
Sponge.eventManager().post(registerFeaturesEvent);
// All addon features (eg. craft config settings, crew roles, etc.) should now be registered
// All addon features (e.g. craft config settings, crew roles, etc.) should now be registered

ConfigManager.checkSpongeConfig();
ConfigManager.loadMainConfig();

//TODO: Re-add commands!

/*this.getCommand("movecraft").setExecutor(new MovecraftCommand());
this.getCommand("release").setExecutor(new ReleaseCommand());
this.getCommand("pilot").setExecutor(new PilotCommand());
this.getCommand("add").setExecutor(new RotateCommand());
this.getCommand("cruise").setExecutor(new CruiseCommand());
this.getCommand("manoverboard").setExecutor(new ManOverboardCommand());
this.getCommand("scuttle").setExecutor(new ScuttleCommand());*/

CraftReportCommand.register();
CrewCommand.register();
CraftTypesCommand.register();
DockCommand.register();
ContactsCommand.register();


Sponge.eventManager().registerListeners(container, new InteractListener());
Sponge.eventManager().registerListeners(container, new BlockListener());
Sponge.eventManager().registerListeners(container, new PlayerListener());
Expand All @@ -150,7 +154,7 @@ public void onLoad(GamePreInitializationEvent event) {
* @param event GameStartedServerEvent from Listener.
*/
@Listener
public void initializeManagers(GameStartedServerEvent event) {
public void initializeManagers(final StartedEngineEvent<Server> event) {

CommanderSign.initDatabase();
if (Settings.EnableCrewSigns) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.github.pulverizer.movecraft.api.config.craft;

import com.google.common.reflect.TypeToken;
import ninja.leaping.configurate.ConfigurationNode;
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
import io.leangen.geantyref.TypeToken;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.api.block.BlockType;
import org.spongepowered.configurate.serialize.SerializationException;

import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -14,9 +14,9 @@
public abstract class BlockMapCraftSetting extends CraftSetting<Map<List<BlockType>, List<Double>>> {

@Override
protected final Map<List<BlockType>, List<Double>> loadValue(ConfigurationNode config) throws ObjectMappingException {
protected final Map<List<BlockType>, List<Double>> loadValue(ConfigurationNode config) throws SerializationException {
HashMap<List<BlockType>, List<Double>> returnMap = new HashMap<>();
Map<List<BlockType>, List<String>> nodeMap = config.getNode(getNodeString()).getValue(new TypeToken<Map<List<BlockType>, List<String>>>() {}, new HashMap<>());
Map<List<BlockType>, List<String>> nodeMap = config.node(getNodeString()).get(new TypeToken<Map<List<BlockType>, List<String>>>() {}, new HashMap<>());

nodeMap.forEach((blockTypeList, minMaxValues) -> {
// then read in the limitation values, low and high
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.github.pulverizer.movecraft.api.config.craft;

import ninja.leaping.configurate.ConfigurationNode;
import org.spongepowered.configurate.ConfigurationNode;

public abstract class BooleanCraftSetting extends CraftSetting<Boolean> {

@Override
protected Boolean loadValue(ConfigurationNode config) {
return config.getNode(getNodeString()).getBoolean();
return config.node(getNodeString()).getBoolean();
}

public static abstract class True extends BooleanCraftSetting {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.github.pulverizer.movecraft.api.config.craft;

import com.google.common.reflect.TypeToken;
import ninja.leaping.configurate.ConfigurationNode;
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
import io.leangen.geantyref.TypeToken;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.serialize.SerializationException;

import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -33,8 +33,8 @@ public static Map<Class<? extends CraftSetting>, Supplier<? extends CraftSetting
* @return false if the setting is null or default
*/

public final boolean load(ConfigurationNode config) throws ObjectMappingException {
if (config.getNode(getNodeString()).isVirtual()) {
public final boolean load(ConfigurationNode config) throws SerializationException {
if (config.node(getNodeString()).virtual()) {
return false;
} else {
value = loadValue(config);
Expand Down Expand Up @@ -67,7 +67,7 @@ public String getNodeString() {
return new String(array);
}

protected T loadValue(ConfigurationNode config) throws ObjectMappingException {
return config.getNode(getNodeString()).getValue(new TypeToken<T>(getClass()) {});
protected T loadValue(ConfigurationNode config) throws SerializationException {
return (T) config.node(getNodeString()).get(TypeToken.get(getClass()));
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.github.pulverizer.movecraft.api.config.craft;

import ninja.leaping.configurate.ConfigurationNode;
import org.spongepowered.configurate.ConfigurationNode;

public abstract class DoubleCraftSetting extends CraftSetting<Double> {

@Override
protected Double loadValue(ConfigurationNode config) {
return config.getNode(getNodeString()).getDouble();
return config.node(getNodeString()).getDouble();
}

public static abstract class Zero extends DoubleCraftSetting {
Expand Down
Loading

0 comments on commit 80247ab

Please sign in to comment.