Commit 735996da authored by Bert T.'s avatar Bert T.

Added Sponge Support (because apparently Sponge is used)

parent 39cd6712
......@@ -16,5 +16,6 @@
<modules>
<module>common</module>
<module>bukkit</module>
<module>sponge</module>
</modules>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>co.melondev</groupId>
<artifactId>CubedPay</artifactId>
<version>0.4.4</version>
</parent>
<artifactId>CubedPay-sponge</artifactId>
<repositories>
<repository>
<id>sponge-repo</id>
<url>https://repo.spongepowered.org/maven</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>co.melondev</groupId>
<artifactId>CubedPay-common</artifactId>
<version>0.4.4</version>
</dependency>
<dependency>
<groupId>org.spongepowered</groupId>
<artifactId>spongeapi</artifactId>
<version>7.0.0</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<defaultGoal>clean package</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
<relocations>
<relocation>
<pattern>com.google.gson</pattern>
<shadedPattern>com.google.shaded.gson</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
package co.melondev.cubedpay;
import com.google.common.reflect.TypeToken;
import com.google.inject.Inject;
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
import ninja.leaping.configurate.loader.ConfigurationLoader;
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
import org.slf4j.Logger;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.config.DefaultConfig;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.state.GameStartingServerEvent;
import org.spongepowered.api.event.game.state.GameStoppingServerEvent;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.scheduler.Task;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@Plugin(id = "cubedpayplugin", name = "CubedPayPlugin", version = "0.4.4", authors = {"Melon Development", "Bert Towne"}, url = "https://cubedpay.com/")
public class CubedPayPlugin {
private static CubedPayAPI api;
private static List<String> shops = new ArrayList<>();
@Inject
private Logger logger;
@Inject
@DefaultConfig(sharedRoot = true)
private File configFile;
@Inject
@DefaultConfig(sharedRoot = true)
private ConfigurationLoader<CommentedConfigurationNode> configManager;
private CommentedConfigurationNode config;
@Listener
public void onEnable(GameStartingServerEvent event) {
if (!configFile.exists()) {
try {
configFile.createNewFile();
try {
config = configManager.load();
} catch (IOException ex) {
ex.printStackTrace();
}
config.getNode("appId").setValue("");
config.getNode("accessToken").setValue("");
config.getNode("shops").setValue(new TypeToken<ArrayList<String>>() {}, new ArrayList<>());
try {
configManager.save(config);
} catch (IOException ex) {
ex.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
try {
config = configManager.load();
} catch (IOException ex) {
ex.printStackTrace();
}
}
String appId = config.getNode("appId").getString("");
String token = config.getNode("accessToken").getString("");
boolean disable = false;
if (appId.isEmpty()) {
logger.error("appId is blank in the config!");
disable = true;
}
if (token.isEmpty()) {
logger.error("accessToken is blank in the config!");
disable = true;
}
if (disable) {
logger.error("CubedPayPlugin will now disable.");
this.disable();
return;
}
api = new CubedPayAPI(appId, token);
List<String> shopList = null;
try {
shopList = config.getNode("shops").getList(TypeToken.of(String.class));
} catch (ObjectMappingException e) {
e.printStackTrace();
}
shops = shopList;
if (shops != null) {
if (shops.isEmpty()) {
logger.warn("No shops defined in the config! Events will not poll without api assistance!");
return;
}
shops.stream()
.filter(shop -> !shop.trim().isEmpty())
.peek(shop -> logger.info("Starting events for shop " + shop))
.forEach(api::startEvents);
}
}
@Listener
public void onDisable(GameStoppingServerEvent event) {
if (api == null) return;
try {
api.shutdown();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private void disable() {
Sponge.getEventManager().unregisterPluginListeners(this);
Sponge.getCommandManager().getOwnedBy(this).forEach(Sponge.getCommandManager()::removeMapping);
Sponge.getScheduler().getScheduledTasks(this).forEach(Task::cancel);
}
public static CubedPayAPI getAPI() {
return api;
}
public static List<String> getShops() {
return shops;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment