Various new things
Dieser Commit ist enthalten in:
Ursprung
0b719be633
Commit
df834fab5f
@ -1,5 +1,7 @@
|
||||
package de.warking.bungeecore;
|
||||
|
||||
import de.warking.bungeecore.arenasystem.ArenaSystem;
|
||||
import de.warking.bungeecore.commands.*;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
@ -9,15 +11,22 @@ import net.md_5.bungee.config.YamlConfiguration;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class BungeeCore extends Plugin {
|
||||
|
||||
private Configuration config;
|
||||
public static BungeeCore instance;
|
||||
public static String ChatPrefix;
|
||||
public static DateTimeFormatter DateFormat = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm");
|
||||
public static final String TeamchatPrefix = "§4T§7c§r §e";
|
||||
public static final DateTimeFormatter DateFormat = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm");
|
||||
public static String LobbyServer;
|
||||
public static final HashMap<String, String> serverPermissions = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void onEnable(){
|
||||
instance = this;
|
||||
try{
|
||||
if(!getDataFolder().exists()){
|
||||
getDataFolder().mkdir();
|
||||
@ -27,11 +36,14 @@ public class BungeeCore extends Plugin {
|
||||
configFile.createNewFile();
|
||||
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
|
||||
config.set("prefix", "[WarKing] ");
|
||||
config.set("lobbyserver", "Lobby");
|
||||
config.set("db.url", "jdbc:mysql://127.0.0.1:3306/core");
|
||||
config.set("db.weburl", "jdbc:mysql://127.0.0.1:3306/Website");
|
||||
config.set("db.username", "root");
|
||||
config.set("db.password", "$password");
|
||||
config.set("servers.l.server", "HunjyLobby");
|
||||
config.set("servers.l.permission", "bungeecore.server.user");
|
||||
String [] cmds = {"l", "hub", "lobby"};
|
||||
config.set("servers.HunjyLobby.commands", cmds);
|
||||
config.set("servers.HunjyLobby.permission", "bungeecore.server.user");
|
||||
ConfigurationProvider.getProvider(YamlConfiguration.class).save(config, configFile);
|
||||
}
|
||||
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
|
||||
@ -41,8 +53,10 @@ public class BungeeCore extends Plugin {
|
||||
}
|
||||
|
||||
ChatPrefix = config.getString("prefix");
|
||||
LobbyServer = config.getString("lobbyserver");
|
||||
sql.connect(
|
||||
config.getString("db.url"),
|
||||
config.getString("db.weburl"),
|
||||
config.getString("db.username"),
|
||||
config.getString("db.password")
|
||||
);
|
||||
@ -50,18 +64,35 @@ public class BungeeCore extends Plugin {
|
||||
getProxy().getPluginManager().registerListener(this, new PlayerListener());
|
||||
|
||||
final Configuration servers = config.getSection("servers");
|
||||
for(final String cmd : servers.getKeys()){
|
||||
final Configuration server = servers.getSection(cmd);
|
||||
for(final String serverName : servers.getKeys()){
|
||||
final Configuration server = servers.getSection(serverName);
|
||||
List<String> commands = server.getStringList("commands");
|
||||
serverPermissions.put(serverName, "bungeecore.server." + server.getString("permission"));
|
||||
String cmd = commands.remove(0);
|
||||
addCmd(new ServerSwitchCommand(
|
||||
cmd,
|
||||
server.getString("server"),
|
||||
server.getString("permission")
|
||||
serverName,
|
||||
serverPermissions.get(serverName),
|
||||
commands.toArray(new String[0])
|
||||
));
|
||||
}
|
||||
|
||||
addCmd(new TeamchatCommand());
|
||||
addCmd(new MsgCommand());
|
||||
addCmd(new RCommand());
|
||||
addCmd(new PingCommand());
|
||||
//addCmd(new DenyCommand("list", "pl", "plugins", "ver", "version", "about"));
|
||||
addCmd(new WebpwCommand());
|
||||
addCmd(new AlertCommand());
|
||||
addCmd(new KickCommand());
|
||||
addCmd(new JoinmeCommand());
|
||||
addCmd(new FightCommand());
|
||||
addCmd(new HelpCommand());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable(){
|
||||
ArenaSystem.shutdown();
|
||||
sql.close();
|
||||
}
|
||||
|
||||
|
120
src/de/warking/bungeecore/PlayerListener.java
Normale Datei
120
src/de/warking/bungeecore/PlayerListener.java
Normale Datei
@ -0,0 +1,120 @@
|
||||
package de.warking.bungeecore;
|
||||
|
||||
import net.md_5.bungee.api.AbstractReconnectHandler;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.*;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onLogin(LoginEvent event) {
|
||||
WarkingUser user = new WarkingUser(event.getConnection());
|
||||
if(user.isBanned()) {
|
||||
event.setCancelled(true);
|
||||
if (user.BanTime.before(WarkingUser.PermaBan)) {
|
||||
event.setCancelReason(new TextComponent(BungeeCore.ChatPrefix + "§cDu bist permanent gebannt. §r§lGrund§r: §c" + user.BanReason));
|
||||
} else {
|
||||
event.setCancelReason(new TextComponent(BungeeCore.ChatPrefix + " Du bist bis zum " +
|
||||
user.BanTime.toLocalDateTime().format(BungeeCore.DateFormat) + " gebannt. §r§lGrund§r: §c" + user.BanReason));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPostLogin(PostLoginEvent event) {
|
||||
ProxiedPlayer player = event.getPlayer();
|
||||
WarkingUser user = new WarkingUser(player);
|
||||
player.removeGroups("Admin", "team");
|
||||
switch(user.UserGroup){
|
||||
case "Admin":
|
||||
case "Developer":
|
||||
player.addGroups("admin", "team", "default");
|
||||
break;
|
||||
case "Moderator":
|
||||
case "Supporter":
|
||||
case "Builder":
|
||||
player.addGroups("team", "default");
|
||||
break;
|
||||
case "Member":
|
||||
default:
|
||||
player.addGroups("default");
|
||||
break;
|
||||
}
|
||||
|
||||
//player.getModList(); For the Future!
|
||||
}
|
||||
|
||||
/** To redirect players to the lobby in case of server closure. */
|
||||
@EventHandler
|
||||
public void onServerKickEvent(ServerKickEvent ev)
|
||||
{
|
||||
ServerInfo kickedFrom;
|
||||
|
||||
if (ev.getPlayer().getServer() != null){
|
||||
kickedFrom = ev.getPlayer().getServer().getInfo();
|
||||
}else if (ProxyServer.getInstance().getReconnectHandler() != null){
|
||||
kickedFrom = ProxyServer.getInstance().getReconnectHandler().getServer(ev.getPlayer());
|
||||
}else{
|
||||
kickedFrom = AbstractReconnectHandler.getForcedHost(ev.getPlayer().getPendingConnection());
|
||||
if (kickedFrom == null){
|
||||
kickedFrom = ProxyServer.getInstance().getServerInfo(ev.getPlayer().getPendingConnection().getListener().getDefaultServer());
|
||||
}
|
||||
}
|
||||
|
||||
ServerInfo kickTo = ProxyServer.getInstance().getServerInfo(BungeeCore.LobbyServer);
|
||||
|
||||
if (kickedFrom != null && kickedFrom.equals(kickTo)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ev.setCancelled(true);
|
||||
ev.setCancelServer(kickTo);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChatEvent(ChatEvent e){
|
||||
if(e.isCommand()){
|
||||
String [] command = e.getMessage().split(" ");
|
||||
if(command[0].contains(":")){
|
||||
e.setCancelled(true);
|
||||
if(e.getSender() instanceof ProxiedPlayer){
|
||||
ProxiedPlayer sender = (ProxiedPlayer) e.getSender();
|
||||
sender.sendMessage(BungeeCore.ChatPrefix + "§cUnbekannter Befehl.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTabCompleteEvent(TabCompleteEvent e){
|
||||
List<String> suggestions = e.getSuggestions();
|
||||
String [] cursor = e.getCursor().split(" ");
|
||||
String last = cursor[cursor.length - 1];
|
||||
for(ProxiedPlayer player : ProxyServer.getInstance().getPlayers()){
|
||||
String name = player.getName();
|
||||
if(last.isEmpty() || name.startsWith(last)){
|
||||
suggestions.add(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTabCompleteResponseEvent(TabCompleteResponseEvent e){
|
||||
List<String> suggestions = e.getSuggestions();
|
||||
for(int i = 0; i < suggestions.size(); i++){
|
||||
String suggestion = suggestions.get(i);
|
||||
if(suggestion.startsWith("/") && suggestion.contains(":")){
|
||||
suggestions.remove(suggestion);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
97
src/de/warking/bungeecore/arenasystem/Arena.java
Normale Datei
97
src/de/warking/bungeecore/arenasystem/Arena.java
Normale Datei
@ -0,0 +1,97 @@
|
||||
package de.warking.bungeecore.arenasystem;
|
||||
|
||||
import de.warking.bungeecore.BungeeCore;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Vector;
|
||||
|
||||
public class Arena implements Runnable{
|
||||
|
||||
public final String serverName;
|
||||
public final int arenenNummer;
|
||||
private Process p;
|
||||
private ServerInfo server;
|
||||
private boolean started = false;
|
||||
private Vector<ArenaPlayer> cachedPlayers = new Vector<>();
|
||||
private PrintWriter writer;
|
||||
|
||||
public Arena(String modus, int id){
|
||||
arenenNummer = id;
|
||||
serverName = modus + id;
|
||||
int port = 2500 + arenenNummer;
|
||||
ProcessBuilder pb = new ProcessBuilder(
|
||||
"/home/netuser/mc",
|
||||
"-a", modus, serverName, Integer.toString(port));
|
||||
try{
|
||||
p = pb.start();
|
||||
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.instance, this);
|
||||
InetSocketAddress address = new InetSocketAddress("127.0.0.1", port);
|
||||
server = ProxyServer.getInstance().constructServerInfo(
|
||||
serverName, address, "WarKing.de - Arena", false);
|
||||
ProxyServer.getInstance().getServers().put(serverName, server);
|
||||
writer = new PrintWriter( p.getOutputStream(), true);
|
||||
}catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
||||
public void sendPlayer(ArenaPlayer p){
|
||||
if(!started) {
|
||||
p.player.sendMessage(new TextComponent(BungeeCore.ChatPrefix + "Die Arena wird gestartet, einen Moment bitte..."));
|
||||
cachedPlayers.add(p);
|
||||
}else
|
||||
p.player.connect(server);
|
||||
}
|
||||
|
||||
protected void stop(){
|
||||
if(p != null && p.isAlive()){
|
||||
for(ProxiedPlayer player : server.getPlayers()){
|
||||
player.connect(ProxyServer.getInstance().getServerInfo(BungeeCore.LobbyServer));
|
||||
}
|
||||
writer.println("stop");
|
||||
try{
|
||||
p.waitFor();
|
||||
}catch(InterruptedException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
ProxyServer.getInstance().getServers().remove(serverName);
|
||||
ArenaSystem.arenen.remove(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||
String line;
|
||||
|
||||
while (!started && (line = reader.readLine()) != null) {
|
||||
started = line.contains(" INFO]: Done (");
|
||||
}
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
||||
for(ArenaPlayer aP : cachedPlayers){
|
||||
sendPlayer(aP);
|
||||
}
|
||||
cachedPlayers.clear();
|
||||
|
||||
p.waitFor();
|
||||
}catch(IOException e){
|
||||
e.printStackTrace();
|
||||
}catch(InterruptedException e){
|
||||
System.out.println("Arena "+serverName+" was interrupted!");
|
||||
}
|
||||
stop();
|
||||
}
|
||||
}
|
13
src/de/warking/bungeecore/arenasystem/ArenaPlayer.java
Normale Datei
13
src/de/warking/bungeecore/arenasystem/ArenaPlayer.java
Normale Datei
@ -0,0 +1,13 @@
|
||||
package de.warking.bungeecore.arenasystem;
|
||||
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
public class ArenaPlayer {
|
||||
public ProxiedPlayer player;
|
||||
public ArenaRole role;
|
||||
|
||||
public ArenaPlayer(ProxiedPlayer p, ArenaRole r){
|
||||
player = p;
|
||||
role = r;
|
||||
}
|
||||
}
|
9
src/de/warking/bungeecore/arenasystem/ArenaRole.java
Normale Datei
9
src/de/warking/bungeecore/arenasystem/ArenaRole.java
Normale Datei
@ -0,0 +1,9 @@
|
||||
package de.warking.bungeecore.arenasystem;
|
||||
|
||||
public enum ArenaRole {
|
||||
RED_LEADER,
|
||||
RED_MEMBER,
|
||||
BLUE_LEADER,
|
||||
BLUE_MEMBER,
|
||||
SPECTATOR
|
||||
}
|
36
src/de/warking/bungeecore/arenasystem/ArenaSystem.java
Normale Datei
36
src/de/warking/bungeecore/arenasystem/ArenaSystem.java
Normale Datei
@ -0,0 +1,36 @@
|
||||
package de.warking.bungeecore.arenasystem;
|
||||
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
public class ArenaSystem {
|
||||
|
||||
protected static Vector<Arena> arenen = new Vector<>();
|
||||
|
||||
private static int freeId(){
|
||||
int id = 0;
|
||||
boolean isFree = false;
|
||||
while(!isFree){
|
||||
id++;
|
||||
isFree = true;
|
||||
for(Arena arena : arenen){
|
||||
if(arena.arenenNummer == id){
|
||||
isFree = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
public static Arena startServer(String modus){
|
||||
Arena arena = new Arena(modus, freeId());
|
||||
arenen.add(arena);
|
||||
return arena;
|
||||
}
|
||||
|
||||
public static void shutdown(){
|
||||
while(!arenen.isEmpty())
|
||||
arenen.firstElement().stop();
|
||||
}
|
||||
}
|
31
src/de/warking/bungeecore/commands/AlertCommand.java
Normale Datei
31
src/de/warking/bungeecore/commands/AlertCommand.java
Normale Datei
@ -0,0 +1,31 @@
|
||||
package de.warking.bungeecore.commands;
|
||||
|
||||
import de.warking.bungeecore.BungeeCore;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
public class AlertCommand extends Command {
|
||||
|
||||
public AlertCommand() {
|
||||
super("bc", "bungeecore.alert");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(args.length == 0){
|
||||
sender.sendMessage(new TextComponent(BungeeCore.ChatPrefix + "/alert [Nachricht]"));
|
||||
}
|
||||
|
||||
StringBuilder msgBuilder = new StringBuilder();
|
||||
msgBuilder.append(BungeeCore.ChatPrefix);
|
||||
for (String arg : args){
|
||||
msgBuilder.append(arg).append(" ");
|
||||
}
|
||||
String msg = msgBuilder.toString();
|
||||
msg = ChatColor.translateAlternateColorCodes('&', msg);
|
||||
ProxyServer.getInstance().broadcast(msg);
|
||||
}
|
||||
}
|
22
src/de/warking/bungeecore/commands/DenyCommand.java
Normale Datei
22
src/de/warking/bungeecore/commands/DenyCommand.java
Normale Datei
@ -0,0 +1,22 @@
|
||||
package de.warking.bungeecore.commands;
|
||||
|
||||
import de.warking.bungeecore.BungeeCore;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
public class DenyCommand extends Command {
|
||||
|
||||
public DenyCommand(String cmd, String ...aliases) {
|
||||
super(cmd, "", aliases);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(sender instanceof ProxiedPlayer){
|
||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||
player.sendMessage(new TextComponent(BungeeCore.ChatPrefix + "§cUnbekannter Befehl."));
|
||||
}
|
||||
}
|
||||
}
|
39
src/de/warking/bungeecore/commands/FightCommand.java
Normale Datei
39
src/de/warking/bungeecore/commands/FightCommand.java
Normale Datei
@ -0,0 +1,39 @@
|
||||
package de.warking.bungeecore.commands;
|
||||
|
||||
import de.warking.bungeecore.BungeeCore;
|
||||
import de.warking.bungeecore.arenasystem.Arena;
|
||||
import de.warking.bungeecore.arenasystem.ArenaPlayer;
|
||||
import de.warking.bungeecore.arenasystem.ArenaRole;
|
||||
import de.warking.bungeecore.arenasystem.ArenaSystem;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
public class FightCommand extends Command {
|
||||
|
||||
public FightCommand() {
|
||||
super("fight", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(args.length != 1){
|
||||
sender.sendMessage(BungeeCore.ChatPrefix + "/fight airship");
|
||||
return;
|
||||
}
|
||||
if(sender instanceof ProxiedPlayer){
|
||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||
switch(args[0].toLowerCase()){
|
||||
case "as":
|
||||
case "airship":
|
||||
Arena arena = ArenaSystem.startServer("Airship");
|
||||
arena.sendPlayer(new ArenaPlayer(player, ArenaRole.RED_LEADER));
|
||||
break;
|
||||
default:
|
||||
sender.sendMessage(new TextComponent(BungeeCore.ChatPrefix + "§cUnbekannter Spielmodus: " + args[0]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
32
src/de/warking/bungeecore/commands/HelpCommand.java
Normale Datei
32
src/de/warking/bungeecore/commands/HelpCommand.java
Normale Datei
@ -0,0 +1,32 @@
|
||||
package de.warking.bungeecore.commands;
|
||||
|
||||
import de.warking.bungeecore.BungeeCore;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
public class HelpCommand extends Command {
|
||||
public HelpCommand() {
|
||||
super("help", "", "?");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
|
||||
if(args.length != 1){
|
||||
sender.sendMessage(new TextComponent(BungeeCore.ChatPrefix + "§l§7Hilfe"));
|
||||
|
||||
TextComponent tc = new TextComponent(BungeeCore.ChatPrefix + "Klicke hier, um dem Server beizutreten!");
|
||||
tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§cServer beitreten").create()));
|
||||
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/help "));
|
||||
|
||||
}else{
|
||||
switch(args[0]){
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
46
src/de/warking/bungeecore/commands/JoinmeCommand.java
Normale Datei
46
src/de/warking/bungeecore/commands/JoinmeCommand.java
Normale Datei
@ -0,0 +1,46 @@
|
||||
package de.warking.bungeecore.commands;
|
||||
|
||||
import de.warking.bungeecore.BungeeCore;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
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 JoinmeCommand extends Command {
|
||||
|
||||
public JoinmeCommand() {
|
||||
super("join", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(sender instanceof ProxiedPlayer) {
|
||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||
|
||||
if (args.length == 0) {
|
||||
if(player.hasPermission("bungeecore.joinme")){
|
||||
TextComponent tc = new TextComponent(BungeeCore.ChatPrefix + "Klicke hier, um dem Server " + player.getServer().getInfo().getName() + " beizutreten!");
|
||||
tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§cServer beitreten").create()));
|
||||
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName()));
|
||||
ProxyServer.getInstance().broadcast(tc);
|
||||
}else {
|
||||
player.sendMessage(new TextComponent(BungeeCore.ChatPrefix + "§cDu hast dazu keine Berechtigung."));
|
||||
}
|
||||
} else if (args.length == 1) {
|
||||
//TODO: Joinme to player
|
||||
ServerInfo server = ProxyServer.getInstance().getPlayer(args[0]).getServer().getInfo();
|
||||
String ServerPerm = BungeeCore.serverPermissions.get(server.getName());
|
||||
if(ServerPerm == null || !player.hasPermission(ServerPerm)){
|
||||
player.sendMessage(new TextComponent(BungeeCore.ChatPrefix + "§cDiesen Server gibt es nicht."));
|
||||
return;
|
||||
}
|
||||
player.connect(server);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
40
src/de/warking/bungeecore/commands/KickCommand.java
Normale Datei
40
src/de/warking/bungeecore/commands/KickCommand.java
Normale Datei
@ -0,0 +1,40 @@
|
||||
package de.warking.bungeecore.commands;
|
||||
|
||||
import de.warking.bungeecore.BungeeCore;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
public class KickCommand extends Command {
|
||||
|
||||
public KickCommand() {
|
||||
super("kick", "bungeecore.kick");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(args.length == 0){
|
||||
sender.sendMessage(new TextComponent(BungeeCore.ChatPrefix + "/kick [Spieler] [Nachricht]"));
|
||||
}
|
||||
|
||||
ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]);
|
||||
if(target == null){
|
||||
sender.sendMessage(new TextComponent(BungeeCore.ChatPrefix + "§cDieser Spieler ist derzeit nicht online!"));
|
||||
return;
|
||||
}
|
||||
|
||||
if(args.length == 1){
|
||||
target.disconnect(new TextComponent(BungeeCore.ChatPrefix + "§cDu wurdest gekickt."));
|
||||
}else{
|
||||
StringBuilder msgBuilder = new StringBuilder();
|
||||
msgBuilder.append(BungeeCore.ChatPrefix).append("§c");
|
||||
for (int i = 1; i < args.length; i++){
|
||||
msgBuilder.append(args[i]).append(" ");
|
||||
}
|
||||
target.disconnect(new TextComponent(msgBuilder.toString()));
|
||||
}
|
||||
sender.sendMessage(new TextComponent(BungeeCore.ChatPrefix + "Der Spieler " + target.getName() + " wurde gekickt."));
|
||||
}
|
||||
}
|
56
src/de/warking/bungeecore/commands/MsgCommand.java
Normale Datei
56
src/de/warking/bungeecore/commands/MsgCommand.java
Normale Datei
@ -0,0 +1,56 @@
|
||||
package de.warking.bungeecore.commands;
|
||||
|
||||
import de.warking.bungeecore.BungeeCore;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class MsgCommand extends Command {
|
||||
|
||||
public static HashMap<String, ProxiedPlayer> lastChats = new HashMap<>();
|
||||
|
||||
public MsgCommand() {
|
||||
super("msg", "", "w", "tell");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(sender instanceof ProxiedPlayer){
|
||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||
|
||||
if (args.length < 2) {
|
||||
player.sendMessage(new TextComponent(BungeeCore.ChatPrefix + "/msg [Benutzer] [Nachricht]"));
|
||||
return;
|
||||
}
|
||||
|
||||
ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]);
|
||||
if(target == null){
|
||||
player.sendMessage(new TextComponent(BungeeCore.ChatPrefix + "§cDieser Spieler ist derzeit nicht online!"));
|
||||
return;
|
||||
}else if(target.getChatMode() != ProxiedPlayer.ChatMode.SHOWN){
|
||||
player.sendMessage(new TextComponent(BungeeCore.ChatPrefix + "§cDieser Spieler empfängt derzeit keine Chatnachrichten!"));
|
||||
return;
|
||||
}else if(target.equals(player)){
|
||||
player.sendMessage(new TextComponent(BungeeCore.ChatPrefix + "§cNachrichten an dich selbst hast du wirklich nicht nötig!"));
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder msgBuilder = new StringBuilder();
|
||||
msgBuilder.append("§5").append(player.getName()).append("§8»§5").append(target.getName()).append(" §r§7");
|
||||
for (int i = 1; i < args.length; i++){
|
||||
msgBuilder.append(args[i]).append(" ");
|
||||
}
|
||||
TextComponent msg = new TextComponent(msgBuilder.toString());
|
||||
player.sendMessage(msg);
|
||||
target.sendMessage(msg);
|
||||
|
||||
lastChats.put(player.getName().toLowerCase(), target);
|
||||
lastChats.put(target.getName().toLowerCase(), player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
22
src/de/warking/bungeecore/commands/PingCommand.java
Normale Datei
22
src/de/warking/bungeecore/commands/PingCommand.java
Normale Datei
@ -0,0 +1,22 @@
|
||||
package de.warking.bungeecore.commands;
|
||||
|
||||
import de.warking.bungeecore.BungeeCore;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
public class PingCommand extends Command {
|
||||
|
||||
public PingCommand() {
|
||||
super("ping", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(sender instanceof ProxiedPlayer){
|
||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||
player.sendMessage(new TextComponent(BungeeCore.ChatPrefix + "§7Dein Ping beträgt §c" + player.getPing() + "§r§7 ms!"));
|
||||
}
|
||||
}
|
||||
}
|
50
src/de/warking/bungeecore/commands/RCommand.java
Normale Datei
50
src/de/warking/bungeecore/commands/RCommand.java
Normale Datei
@ -0,0 +1,50 @@
|
||||
package de.warking.bungeecore.commands;
|
||||
|
||||
import de.warking.bungeecore.BungeeCore;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
public class RCommand extends Command {
|
||||
|
||||
public RCommand() {
|
||||
super("r", "", "reply");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(sender instanceof ProxiedPlayer){
|
||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||
if(args.length == 0){
|
||||
player.sendMessage(new TextComponent(BungeeCore.ChatPrefix + "/r [Antwort]"));
|
||||
return;
|
||||
}
|
||||
|
||||
ProxiedPlayer target = MsgCommand.lastChats.get(player.getName().toLowerCase());
|
||||
if(target == null){
|
||||
player.sendMessage(new TextComponent(BungeeCore.ChatPrefix + "§cDu hast bisher mit niemandem geschrieben!"));
|
||||
return;
|
||||
}
|
||||
|
||||
if(!target.isConnected()){
|
||||
player.sendMessage(new TextComponent(BungeeCore.ChatPrefix + "§cDieser Spieler ist derzeit nicht online!"));
|
||||
return;
|
||||
}else if(target.getChatMode() != ProxiedPlayer.ChatMode.SHOWN){
|
||||
player.sendMessage(new TextComponent(BungeeCore.ChatPrefix + "§cDieser Spieler empfängt derzeit keine Chatnachrichten!"));
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder msgBuilder = new StringBuilder();
|
||||
msgBuilder.append("§5").append(player.getName()).append("§8»§5").append(target.getName()).append(" §r§7");
|
||||
for (String arg : args){
|
||||
msgBuilder.append(arg).append(" ");
|
||||
}
|
||||
TextComponent msg = new TextComponent(msgBuilder.toString());
|
||||
player.sendMessage(msg);
|
||||
target.sendMessage(msg);
|
||||
|
||||
MsgCommand.lastChats.put(target.getName().toLowerCase(), player);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
package de.warking.bungeecore;
|
||||
package de.warking.bungeecore.commands;
|
||||
|
||||
import de.warking.bungeecore.BungeeCore;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
@ -23,7 +25,7 @@ public class ServerSwitchCommand extends Command {
|
||||
ServerInfo target = ProxyServer.getInstance().getServerInfo(serverName);
|
||||
player.connect(target);
|
||||
}else{
|
||||
player.sendMessage(BungeeCore.ChatPrefix + "§cDu bist bereits auf diesem Server!");
|
||||
player.sendMessage(new TextComponent(BungeeCore.ChatPrefix + "§cDu bist bereits auf diesem Server!"));
|
||||
}
|
||||
}
|
||||
}
|
44
src/de/warking/bungeecore/commands/TeamchatCommand.java
Normale Datei
44
src/de/warking/bungeecore/commands/TeamchatCommand.java
Normale Datei
@ -0,0 +1,44 @@
|
||||
package de.warking.bungeecore.commands;
|
||||
|
||||
import de.warking.bungeecore.BungeeCore;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
public class TeamchatCommand extends Command {
|
||||
|
||||
public TeamchatCommand() {
|
||||
super("tc", "bungeecore.teamchat","teamchat");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(sender instanceof ProxiedPlayer){
|
||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||
|
||||
if(args.length == 0){
|
||||
player.sendMessage(new TextComponent(BungeeCore.TeamchatPrefix + "/teamchat [Nachricht an das Team]"));
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder msgBuilder = new StringBuilder();
|
||||
msgBuilder.append(BungeeCore.TeamchatPrefix).append(sender.getName()).append("› §r");
|
||||
for (String arg : args){
|
||||
msgBuilder.append(arg).append(" ");
|
||||
}
|
||||
String msg = msgBuilder.toString();
|
||||
msg = ChatColor.translateAlternateColorCodes('&', msg);
|
||||
TextComponent message = new TextComponent(msg);
|
||||
|
||||
for (ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){
|
||||
if ((target.hasPermission("bungeecore.teamchat") || target.hasPermission("bungeecore.*"))
|
||||
&& target.getChatMode() == ProxiedPlayer.ChatMode.SHOWN){
|
||||
target.sendMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
36
src/de/warking/bungeecore/commands/WebpwCommand.java
Normale Datei
36
src/de/warking/bungeecore/commands/WebpwCommand.java
Normale Datei
@ -0,0 +1,36 @@
|
||||
package de.warking.bungeecore.commands;
|
||||
|
||||
import de.warking.bungeecore.BungeeCore;
|
||||
import de.warking.bungeecore.WarkingUser;
|
||||
import de.warking.bungeecore.sql;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
public class WebpwCommand extends Command {
|
||||
|
||||
public WebpwCommand() {
|
||||
super("webpw", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(sender instanceof ProxiedPlayer){
|
||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||
if(args.length != 2){
|
||||
player.sendMessage(new TextComponent(BungeeCore.ChatPrefix + "/webpw [Passwort] [Passwort wiederholen]"));
|
||||
return;
|
||||
}else if(!args[0].equals(args[1])){
|
||||
player.sendMessage(new TextComponent(BungeeCore.ChatPrefix + "§cDie Passwörter stimmen nicht überein!"));
|
||||
return;
|
||||
}else if(args[0].length() < 6){
|
||||
player.sendMessage(new TextComponent(BungeeCore.ChatPrefix + "§cDas Passwort muss mindestens 6 Zeichen lang sein!"));
|
||||
return;
|
||||
}
|
||||
|
||||
sql.setWebpw(new WarkingUser(player), args[0]);
|
||||
player.sendMessage(new TextComponent(BungeeCore.ChatPrefix + "Webpasswort gesetzt!"));
|
||||
}
|
||||
}
|
||||
}
|
@ -9,11 +9,21 @@ package de.warking.bungeecore;
|
||||
|
||||
public class sql {
|
||||
private static Connection con;
|
||||
private static Connection webcon;
|
||||
private static String url;
|
||||
private static String weburl;
|
||||
private static String user;
|
||||
private static String password;
|
||||
|
||||
|
||||
public static void connect(String url, String user, String password) {
|
||||
public static void connect(String url, String weburl, String user, String password) {
|
||||
sql.url = url;
|
||||
sql.weburl = weburl;
|
||||
sql.user = user;
|
||||
sql.password = password;
|
||||
try {
|
||||
con = DriverManager.getConnection(url + "?autoreconnect=true", user, password);
|
||||
webcon = DriverManager.getConnection(weburl + "?autoreconnect=true", user, password);
|
||||
}catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -23,6 +33,8 @@ public class sql {
|
||||
try {
|
||||
if(con != null)
|
||||
con.close();
|
||||
if(webcon != null)
|
||||
webcon.close();
|
||||
}catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -33,17 +45,30 @@ public class sql {
|
||||
PreparedStatement st = con.prepareStatement(qry);
|
||||
st.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
close();
|
||||
connect(url, weburl, user, password);
|
||||
try {
|
||||
PreparedStatement st = con.prepareStatement(qry);
|
||||
st.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ResultSet select(String qry){
|
||||
|
||||
try {
|
||||
PreparedStatement st = con.prepareStatement(qry);
|
||||
return st.executeQuery();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
close();
|
||||
connect(url, weburl, user, password);
|
||||
try {
|
||||
PreparedStatement st = con.prepareStatement(qry);
|
||||
return st.executeQuery();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -51,4 +76,34 @@ public class sql {
|
||||
public static Connection getCon(){
|
||||
return con;
|
||||
}
|
||||
|
||||
public static void setWebpw(WarkingUser user, String password){
|
||||
try {
|
||||
PreparedStatement st = webcon.prepareStatement("INSERT INTO User\n" +
|
||||
" (UID, WebPassword)\n" +
|
||||
"VALUES\n" +
|
||||
" (?, password(?))\n" +
|
||||
"ON DUPLICATE KEY UPDATE\n" +
|
||||
" WebPassword = VALUES(WebPassword)");
|
||||
st.setInt(1, user.id);
|
||||
st.setString(2, password);
|
||||
st.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
close();
|
||||
connect(url, weburl, sql.user, sql.password);
|
||||
try {
|
||||
PreparedStatement st = webcon.prepareStatement("INSERT INTO User\n" +
|
||||
" (UID, WebPassword)\n" +
|
||||
"VALUES\n" +
|
||||
" (?, password(?))\n" +
|
||||
"ON DUPLICATE KEY UPDATE\n" +
|
||||
" WebPassword = VALUES(WebPassword)");
|
||||
st.setInt(1, user.id);
|
||||
st.setString(2, password);
|
||||
st.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren