diff --git a/pom.xml b/pom.xml index 4efe43f..ce9d7cb 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,14 @@ de.warking BungeeCore - 1.0-SNAPSHOT + 1.0 + jar + BungeeCore + https://maven.apache.org + + + UTF-8 + @@ -16,6 +23,16 @@ + src + + + src + + **/*.java + **/*.kt + + + org.apache.maven.plugins diff --git a/src/de/warking/bungeecore/BungeeCore.java b/src/de/warking/bungeecore/BungeeCore.java index ed5746f..13854b5 100644 --- a/src/de/warking/bungeecore/BungeeCore.java +++ b/src/de/warking/bungeecore/BungeeCore.java @@ -1,4 +1,67 @@ package de.warking.bungeecore; -public class BungeeCore { +import net.md_5.bungee.api.plugin.Command; +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.File; +import java.io.IOException; + +public class BungeeCore extends Plugin { + + private Configuration config; + public static String ChatPrefix; + + @Override + public void onEnable(){ + try{ + if(!getDataFolder().exists()){ + getDataFolder().mkdir(); + } + File configFile = new File(getDataFolder().getPath(), "config.yml"); + if(!configFile.exists()){ + configFile.createNewFile(); + config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile); + config.set("prefix", "[WarKing] "); + config.set("db.url", "jdbc:mysql://127.0.0.1:3306/core"); + config.set("db.username", "root"); + config.set("db.password", "$password"); + config.set("servers.l.server", "HunjyLobby"); + config.set("servers.l.permission", "bungeecore.server.user"); + ConfigurationProvider.getProvider(YamlConfiguration.class).save(config, configFile); + } + config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile); + }catch(IOException e){ + System.err.println("Error not create/load config.yml, Aborting!"); + return; + } + + ChatPrefix = config.getString("prefix"); + sql.connect( + config.getString("db.url"), + config.getString("db.username"), + config.getString("db.password") + ); + + final Configuration servers = config.getSection("servers"); + for(final String cmd : servers.getKeys()){ + final Configuration server = servers.getSection(cmd); + addCmd(new ServerSwitchCommand( + cmd, + server.getString("server"), + server.getString("permission") + )); + } + } + + @Override + public void onDisable(){ + sql.close(); + } + + private void addCmd(Command cmd){ + getProxy().getPluginManager().registerCommand(this, cmd); + } } diff --git a/src/de/warking/bungeecore/ServerSwitchCommand.java b/src/de/warking/bungeecore/ServerSwitchCommand.java new file mode 100644 index 0000000..a0c2a76 --- /dev/null +++ b/src/de/warking/bungeecore/ServerSwitchCommand.java @@ -0,0 +1,30 @@ +package de.warking.bungeecore; + +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.config.ServerInfo; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.plugin.Command; + +public class ServerSwitchCommand extends Command { + + private String serverName; + + public ServerSwitchCommand(String cmd, String name, String permission, String... aliases) { + super(cmd, permission, aliases); + serverName = name; + } + + @Override + public void execute(CommandSender sender, String[] strings) { + if(sender instanceof ProxiedPlayer){ + ProxiedPlayer player = (ProxiedPlayer) sender; + if(!player.getServer().getInfo().getName().equalsIgnoreCase(serverName)){ + ServerInfo target = ProxyServer.getInstance().getServerInfo(serverName); + player.connect(target); + }else{ + player.sendMessage(BungeeCore.ChatPrefix + "§cDu bist bereits auf diesem Server!"); + } + } + } +} diff --git a/src/de/warking/bungeecore/sql.java b/src/de/warking/bungeecore/sql.java new file mode 100644 index 0000000..6d48879 --- /dev/null +++ b/src/de/warking/bungeecore/sql.java @@ -0,0 +1,51 @@ +package de.warking.bungeecore; + + import java.sql.Connection; + import java.sql.DriverManager; + import java.sql.PreparedStatement; + import java.sql.ResultSet; + import java.sql.SQLException; + + +public class sql { + private static Connection con; + + + public static void connect(String url, String user, String password) { + try { + con = DriverManager.getConnection(url + "?autoreconnect=true", user, password); + }catch (SQLException e) { + e.printStackTrace(); + } + } + + public static void close() { + try { + if(con != null) + con.close(); + }catch (SQLException e) { + e.printStackTrace(); + } + } + + public static void update(String qry) { + try { + PreparedStatement st = con.prepareStatement(qry); + st.executeUpdate(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public static ResultSet select(String qry) { + + try { + PreparedStatement st = con.prepareStatement(qry); + return st.executeQuery(); + } catch (SQLException e) { + e.printStackTrace(); + } + + return null; + } +} diff --git a/src/plugin.yml b/src/plugin.yml new file mode 100644 index 0000000..ff5e537 --- /dev/null +++ b/src/plugin.yml @@ -0,0 +1,4 @@ +name: BungeeCore +main: de.warking.bungeecore.BungeeCore +version: 1.0 +author: Lixfel \ No newline at end of file