This commit is contained in:
BuildTools
2016-07-25 16:34:42 +02:00
commit 2e182d13a5
6 changed files with 289 additions and 0 deletions

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,5 @@
name: TeamspeakAuth
version: 1.0
author: Semikolon
main: cf.semikolon.teamspeak.MainClass
commands: