Push
This commit is contained in:
70
src/main/java/cf/semikolon/teamspeak/FileSystem.java
Normal file
70
src/main/java/cf/semikolon/teamspeak/FileSystem.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
47
src/main/java/cf/semikolon/teamspeak/MainClass.java
Normal file
47
src/main/java/cf/semikolon/teamspeak/MainClass.java
Normal 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;
|
||||
}
|
||||
}
|
||||
35
src/main/java/cf/semikolon/teamspeak/ServerQuery.java
Normal file
35
src/main/java/cf/semikolon/teamspeak/ServerQuery.java
Normal 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;
|
||||
}
|
||||
}
|
||||
5
src/main/resources/plugin.yml
Normal file
5
src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
name: TeamspeakAuth
|
||||
version: 1.0
|
||||
author: Semikolon
|
||||
main: cf.semikolon.teamspeak.MainClass
|
||||
commands:
|
||||
Reference in New Issue
Block a user