Commit cea24fc3 authored by Bert T.'s avatar Bert T.

Add BungeeCord Support

parent 08ee5882
<?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.5</version>
</parent>
<artifactId>CubedPay-bungeecord</artifactId>
<repositories>
<repository>
<id>bungeecord-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>co.melondev</groupId>
<artifactId>CubedPay-common</artifactId>
<version>0.4.5</version>
</dependency>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.12-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
</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.io.ByteStreams;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class CubedPayPlugin extends Plugin {
private static CubedPayAPI api;
private static List<String> shops = new ArrayList<>();
@Override
public void onEnable() {
File dir = getDataFolder();
if (!dir.exists()) dir.mkdir();
File configFile = new File(dir, "config.yml");
if (!configFile.exists()) saveDefaultConfig();
boolean disable = false;
try {
Configuration config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "config.yml"));
String appId = config.getString("appId", "");
String token = config.getString("accessToken", "");
if (appId.isEmpty()) {
getLogger().severe("appId is blank in the config!");
disable = true;
}
if (token.isEmpty()) {
getLogger().severe("accessToken is blank in the config!");
disable = true;
}
if (disable) {
getLogger().severe("CubedPayPlugin will now disable.");
disable();
return;
}
api = new CubedPayAPI(appId, token);
shops = config.getStringList("shops");
if (shops.isEmpty()) {
getLogger().warning("No shops defined in the config! Events will not poll without api assistance!");
return;
}
shops.stream()
.filter(shop -> !shop.trim().isEmpty())
.peek(shop -> getLogger().info("Starting events for shop " + shop))
.forEach(api::startEvents);
} catch (IOException ex) {
getLogger().severe("Error loading config.yml!");
ex.printStackTrace();
disable();
}
}
@Override
public void onDisable() {
if (api == null) return;
try {
api.shutdown();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private void saveDefaultConfig() {
if (!getDataFolder().exists()) {
getDataFolder().mkdir();
}
File configFile = new File(getDataFolder(), "config.yml");
if (!configFile.exists()) {
try {
configFile.createNewFile();
try (InputStream is = getResourceAsStream("config.yml"); OutputStream os = new FileOutputStream(configFile)) {
ByteStreams.copy(is, os);
}
} catch (IOException ex) {
throw new RuntimeException("Unable to create config file", ex);
}
}
}
private void disable() {
getProxy().getPluginManager().unregisterCommands(this);
getProxy().getPluginManager().unregisterListeners(this);
getProxy().getScheduler().cancel(this);
}
public static CubedPayAPI getAPI() {
return api;
}
public static List<String> getShops() {
return shops;
}
}
\ No newline at end of file
appId: ''
accessToken: ''
shops:
- ''
name: CubedPayPlugin
author: Melon Development
version: ${project.version}
website: cubedpay.com
main: co.melondev.cubedpay.CubedPayPlugin
......@@ -17,5 +17,6 @@
<module>common</module>
<module>bukkit</module>
<module>sponge</module>
<module>bungeecord</module>
</modules>
</project>
......@@ -19,7 +19,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@Plugin(id = "cubedpayplugin", name = "CubedPayPlugin", version = "0.4.5", authors = {"Melon Development", "Bert Towne"}, url = "https://cubedpay.com/")
@Plugin(id = "cubedpayplugin", name = "CubedPayPlugin", version = "0.4.5", authors = {"Melon Development"}, url = "https://cubedpay.com/")
public class CubedPayPlugin {
private static CubedPayAPI api;
......
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