Added WooBungee files

master v1.1
Jonttu 2021-03-13 19:53:25 +02:00
commit b4de67d1be
11 changed files with 348 additions and 0 deletions

20
.classpath 100644
View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

1
.gitignore vendored 100644
View File

@ -0,0 +1 @@
/target/

23
.project 100644
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>WooBungee</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,16 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

Binary file not shown.

Binary file not shown.

4
bungee.yml 100644
View File

@ -0,0 +1,4 @@
name: WooBungee
main: woobungee.main
version: 1.0
author: 'Jonttu1237, Discord: jonttuu :3#0925, Email: jonttu@jonttucraft.com'

34
pom.xml 100644
View File

@ -0,0 +1,34 @@
<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>
<groupId>WooBungee</groupId>
<artifactId>WooBungee</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>bungeecord-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.14-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,48 @@
package woobungee;
import java.io.File;
import java.io.IOException;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;
public class WooCommand extends Command{
public WooCommand() {
super("woobungee", "woobungee.admin");
}
@Override
public void execute(CommandSender commandSender, String[] strings) {
if(strings.length != 1) {
commandSender.sendMessage(new TextComponent("Usage: /woobungee <reload/check>"));
return;
}
if(strings[0].equals("reload")) {
try {
main.config = ConfigurationProvider.getProvider(YamlConfiguration.class)
.load(new File("plugins/woobungee/config.yml"));
} catch (IOException e) {
e.printStackTrace();
}
commandSender.sendMessage(new TextComponent("WooBungee reloaded!"));
} else if(strings[0].equals("check")) {
main.update();
commandSender.sendMessage(new TextComponent("WooBungee orders updated!"));
} else {
commandSender.sendMessage(new TextComponent("Usage: /woobungee <reload/check>"));
}
}
}

View File

@ -0,0 +1,198 @@
package woobungee;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.TextComponent;
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;
public class main extends Plugin{
public static Configuration config;
@Override
public void onEnable() {
saveDefaultConfig();
try {
config = ConfigurationProvider.getProvider(YamlConfiguration.class)
.load(new File("plugins/woobungee/config.yml"));
} catch (Exception e) {
e.printStackTrace();
}
getProxy().getPluginManager().registerCommand(this, new WooCommand());
if(!update()) {
ProxyServer.getInstance().getConsole().sendMessage(new TextComponent("WooBungee update failed, check your key!"));
}
scheduleUpdate();
}
private static boolean sendUpdate(String jsonString)
{
String data = "";
try {
BufferedReader bReader = new BufferedReader(
new InputStreamReader(
new URL(config.getString("url") + "?wmc_key=" + config.getString("key") + "&processedOrders=" + jsonString)
.openConnection().getInputStream()));
String line = null;
while((line = bReader.readLine()) != null) {
if(data.equals("")) {
data = line;
} else {
data = data + "\n" + line;
}
}
} catch (Exception e) {
e.printStackTrace();
}
JsonObject o = new JsonParser().parse(data).getAsJsonObject();
return o.get("success").getAsBoolean();
}
public static boolean update() {
try {
BufferedReader bReader = new BufferedReader(
new InputStreamReader(
new URL(config.getString("url") + "?wmc_key=" + config.getString("key"))
.openConnection().getInputStream()));
String data = "";
String line = null;
while((line = bReader.readLine()) != null) {
if(data.equals("")) {
data = line;
} else {
data = data + "\n" + line;
}
}
JsonObject o = new JsonParser().parse(data).getAsJsonObject();
if(!o.get("success").getAsBoolean()) {
return false;
}
JsonArray processedData = new JsonArray();
if(!(o.get("data") instanceof JsonObject)) {
return true;
}
for(Map.Entry<String, JsonElement> entry : o.get("data").getAsJsonObject().entrySet()) {
ProxyServer.getInstance().getConsole().sendMessage(new TextComponent("WooBungee new product, executing commands!"));
String username = entry.getKey();
String orderId = null;
if(processUpdate(username)) {
for(Map.Entry<String, JsonElement> e : o.get("data").getAsJsonObject().get(username)
.getAsJsonObject().entrySet()) {
orderId = e.getKey();
}
processedData.add(Integer.parseInt(orderId));
for(int i = 0; i < o.get("data").getAsJsonObject().get(username).getAsJsonObject().get(orderId).getAsJsonArray().size(); i++) {
String command = o.get("data").getAsJsonObject().get(username).getAsJsonObject().get(orderId).getAsJsonArray().get(i).getAsString();
command = command.replaceAll("&quot;", "\"");
ProxyServer.getInstance().getConsole().sendMessage(new TextComponent("WooBungee executed command: " + command));
ProxyServer.getInstance().getPluginManager().dispatchCommand(ProxyServer.getInstance().getConsole(), command);
}
}
}
if ( 1 > processedData.size()) {
return false;
}
if(!sendUpdate(processedData.toString())) {
return false;
}
bReader.close();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
private static boolean processUpdate(String name) {
if(config.getBoolean("progressoffline")) {
return true;
}
if(ProxyServer.getInstance().getPlayer(name) != null && ProxyServer.getInstance().getPlayer(name).isConnected()) {
return true;
}
return false;
}
public void scheduleUpdate() {
ProxyServer.getInstance().getScheduler().schedule(this, new Runnable() {
@Override
public void run() {
update();
scheduleUpdate();
}
}, config.getInt("update_interval"), TimeUnit.SECONDS);
}
private void saveDefaultConfig() {
new File("plugins/woobungee/").mkdirs();
File file = new File("plugins/woobungee/config.yml");
if(!file.exists()) {
Configuration config = new Configuration();
config.set("update_interval", 1500);
config.set("url", "http://playground.dev");
config.set("key", "");
config.set("progressoffline", false);
try {
ConfigurationProvider.getProvider(YamlConfiguration.class)
.save(config, new File("plugins/woobungee/config.yml"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
}