geforkt von SteamWar/BungeeCore
Adding serverSwitcher
Dieser Commit ist enthalten in:
Ursprung
7f2ce30727
Commit
9cac4c6dcd
19
pom.xml
19
pom.xml
@ -6,7 +6,14 @@
|
||||
|
||||
<groupId>de.warking</groupId>
|
||||
<artifactId>BungeeCore</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<version>1.0</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>BungeeCore</name>
|
||||
<url>https://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
@ -16,6 +23,16 @@
|
||||
</repositories>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src</directory>
|
||||
<excludes>
|
||||
<exclude>**/*.java</exclude>
|
||||
<exclude>**/*.kt</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
30
src/de/warking/bungeecore/ServerSwitchCommand.java
Normale Datei
30
src/de/warking/bungeecore/ServerSwitchCommand.java
Normale Datei
@ -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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
51
src/de/warking/bungeecore/sql.java
Normale Datei
51
src/de/warking/bungeecore/sql.java
Normale Datei
@ -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;
|
||||
}
|
||||
}
|
4
src/plugin.yml
Normale Datei
4
src/plugin.yml
Normale Datei
@ -0,0 +1,4 @@
|
||||
name: BungeeCore
|
||||
main: de.warking.bungeecore.BungeeCore
|
||||
version: 1.0
|
||||
author: Lixfel
|
In neuem Issue referenzieren
Einen Benutzer sperren