From 2e182d13a54f1eb99be9128a048e736577256bfa Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 25 Jul 2016 16:34:42 +0200 Subject: [PATCH] Push --- .gitignore | 89 +++++++++++++++++++ pom.xml | 43 +++++++++ .../cf/semikolon/teamspeak/FileSystem.java | 70 +++++++++++++++ .../cf/semikolon/teamspeak/MainClass.java | 47 ++++++++++ .../cf/semikolon/teamspeak/ServerQuery.java | 35 ++++++++ src/main/resources/plugin.yml | 5 ++ 6 files changed, 289 insertions(+) create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/main/java/cf/semikolon/teamspeak/FileSystem.java create mode 100644 src/main/java/cf/semikolon/teamspeak/MainClass.java create mode 100644 src/main/java/cf/semikolon/teamspeak/ServerQuery.java create mode 100644 src/main/resources/plugin.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..64adf36 --- /dev/null +++ b/.gitignore @@ -0,0 +1,89 @@ +### Java template +*.class +# Mobile Tools for Java (J2ME) +.mtj.tmp/ +# Package Files # +*.jar +*.war +*.ear +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +### Eclipse template +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath +.recommenders +# Eclipse Core +.project +# External tool builders +.externalToolBuilders/ +# Locally stored "Eclipse launch configurations" +*.launch +# PyDev specific (Python IDE for Eclipse) +*.pydevproject +# CDT-specific (C/C++ Development Tooling) +.cproject +# JDT-specific (Eclipse Java Development Tools) +.classpath +# Java annotation processor (APT) +.factorypath +# PDT-specific (PHP Development Tools) +.buildpath +# sbteclipse plugin +.target +# Tern plugin +.tern-project +# TeXlipse plugin +.texlipse +# STS (Spring Tool Suite) +.springBeans +# Code Recommenders +.recommenders/ +### NetBeans template +nbproject/private/ +build/ +nbbuild/ +dist/ +nbdist/ +nbactions.xml +.nb-gradle/ +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 +# User-specific stuff: +.idea/* +*.iml +# Sensitive or high-churn files: +.idea/dataSources.ids +.idea/dataSources.xml +.idea/dataSources.local.xml +.idea/sqlDataSources.xml +.idea/dynamic.xml +.idea/uiDesigner.xml +# Gradle: +.idea/gradle.xml +.idea/libraries +# Mongo Explorer plugin: +.idea/mongoSettings.xml +## File-based project format: +*.iws +## Plugin-specific files: +# IntelliJ +/out/ +# mpeltonen/sbt-idea plugin +.idea_modules/ +# JIRA plugin +atlassian-ide-plugin.xml +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties +# Created by .ignore support plugin (hsz.mobi) \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..8cac90d --- /dev/null +++ b/pom.xml @@ -0,0 +1,43 @@ + + + 4.0.0 + + cf.semikolon + teamspeak + 1.0-SNAPSHOT + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/groups/public/ + + + + TeamSpeak-3-Java-API-mvn-repo + https://raw.githubusercontent.com/TheHolyWaffle/TeamSpeak-3-Java-API/mvn-repo/ + + true + always + + + + + + + + org.spigotmc + spigot-api + 1.8-R0.1-SNAPSHOT + + + + com.github.theholywaffle + teamspeak3-api + [1.0.0,2.0.0) + + + + diff --git a/src/main/java/cf/semikolon/teamspeak/FileSystem.java b/src/main/java/cf/semikolon/teamspeak/FileSystem.java new file mode 100644 index 0000000..232619a --- /dev/null +++ b/src/main/java/cf/semikolon/teamspeak/FileSystem.java @@ -0,0 +1,70 @@ +package cf.semikolon.teamspeak; + +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.File; +import java.io.IOException; + +/** + * Created by jan on 25.07.16. + * + * @version 4.0 + */ +public abstract class FileSystem { + + File cfgFile = null; + YamlConfiguration cfg = null; + + public FileSystem(String pluginName, String fileName) { + this.cfgFile = new File("plugins/" + pluginName, fileName + ".yml"); + this.cfg = YamlConfiguration.loadConfiguration(cfgFile); + if (!this.cfgFile.exists()) { + try { + this.cfgFile.createNewFile(); + load(); + } catch (IOException e) { + System.err.println("Fehler beim erstellen!"); + } + initConfig(); + } + + } + + public File getCfgFile() { + return cfgFile; + } + + public abstract void initConfig(); + + public void load() { + + try { + if (!this.cfgFile.exists()) { + this.cfgFile.createNewFile(); + } else { + cfg.load(this.cfgFile); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void reload() { + save(); + load(); + } + + public void save() { + + try { + this.cfg.save(this.cfgFile); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public YamlConfiguration getCfg() { + return cfg; + } + +} diff --git a/src/main/java/cf/semikolon/teamspeak/MainClass.java b/src/main/java/cf/semikolon/teamspeak/MainClass.java new file mode 100644 index 0000000..91bb56e --- /dev/null +++ b/src/main/java/cf/semikolon/teamspeak/MainClass.java @@ -0,0 +1,47 @@ +package cf.semikolon.teamspeak; + +import org.bukkit.plugin.java.JavaPlugin; + +/** + * Created by jan on 25.07.16. + */ +public class MainClass extends JavaPlugin { + + private static MainClass INSTANCE; + private ServerQuery serverQuery; + + FileSystem cfg = new FileSystem("TeamspekAuth", "config") { + @Override + public void initConfig() { + getCfg().set("tsHost", "127.0.0.1"); + getCfg().set("queryPort", 10011); + getCfg().set("queryUser", "serveradmin"); + getCfg().set("queryPassword", "password"); + getCfg().set("tsPort", 9987); + getCfg().set("botNickname", "TeamspeakAuth"); + } + }; + + @Override + public void onEnable() { + INSTANCE = this; + System.out.println("Plugin TeamspeakAuth by Semikolon\nconnecting..."); + serverQuery = new ServerQuery(cfg.getCfg().getString("tsHost"), + cfg.getCfg().getInt("queryPort"), + cfg.getCfg().getInt("tsPort"), + cfg.getCfg().getString("queryUser"), + cfg.getCfg().getString("queryPassword"), + cfg.getCfg().getString("botNickname")); + + + } + + @Override + public void onDisable() { + + } + + public static MainClass getInstance() { + return INSTANCE; + } +} diff --git a/src/main/java/cf/semikolon/teamspeak/ServerQuery.java b/src/main/java/cf/semikolon/teamspeak/ServerQuery.java new file mode 100644 index 0000000..70d0b5e --- /dev/null +++ b/src/main/java/cf/semikolon/teamspeak/ServerQuery.java @@ -0,0 +1,35 @@ +package cf.semikolon.teamspeak; + +import com.github.theholywaffle.teamspeak3.TS3ApiAsync; +import com.github.theholywaffle.teamspeak3.TS3Config; +import com.github.theholywaffle.teamspeak3.TS3Query; +import com.github.theholywaffle.teamspeak3.api.reconnect.ReconnectStrategy; + +import java.util.logging.Level; + +/** + * Created by jan on 25.07.16. + */ +public class ServerQuery { + private TS3Config tsconfig = new TS3Config(); + private TS3Query query; + private TS3ApiAsync api; + + public ServerQuery(String host, int queryPort, int tsPort, String queryUser, String queryPassword, String nickname) { + this.tsconfig.setHost(host); + this.tsconfig.setQueryPort(queryPort); + this.tsconfig.setDebugLevel(Level.ALL); + this.query = new TS3Query(tsconfig); + this.query.connect(); + System.out.println("Successfully connected to TeamSpeak!\n Logging in..."); + this.api = query.getAsyncApi(); + this.api.login(queryUser, queryPassword); + System.out.println("Login successfully"); + this.api.selectVirtualServerByPort(tsPort); + this.api.setNickname(nickname); + } + + public TS3ApiAsync getApi() { + return api; + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..98fbe2f --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,5 @@ +name: TeamspeakAuth +version: 1.0 +author: Semikolon +main: cf.semikolon.teamspeak.MainClass +commands: \ No newline at end of file