geforkt von SteamWar/BungeeCore
Basic Packet System
Dieser Commit ist enthalten in:
Ursprung
efa6398248
Commit
65e7a7bb73
@ -39,9 +39,12 @@ import net.md_5.bungee.api.plugin.Plugin;
|
|||||||
import net.md_5.bungee.config.Configuration;
|
import net.md_5.bungee.config.Configuration;
|
||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
import net.md_5.bungee.config.ConfigurationProvider;
|
||||||
import net.md_5.bungee.config.YamlConfiguration;
|
import net.md_5.bungee.config.YamlConfiguration;
|
||||||
|
import org.yaml.snakeyaml.error.YAMLException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.MalformedInputException;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -127,6 +130,8 @@ public class BungeeCore extends Plugin {
|
|||||||
|
|
||||||
new TablistManager();
|
new TablistManager();
|
||||||
|
|
||||||
|
getProxy().registerChannel("sw:bridge");
|
||||||
|
|
||||||
getProxy().getScheduler().schedule(this, () -> {
|
getProxy().getScheduler().schedule(this, () -> {
|
||||||
SteamwarUser.clearCache();
|
SteamwarUser.clearCache();
|
||||||
Team.clearCache();
|
Team.clearCache();
|
||||||
@ -208,7 +213,28 @@ public class BungeeCore extends Plugin {
|
|||||||
ProxyServer.getInstance().stop("Could not save conig file");
|
ProxyServer.getInstance().stop("Could not save conig file");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
|
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
|
||||||
|
}
|
||||||
|
catch (YAMLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
CHAT_PREFIX = "§eSteam§8War» §r";
|
||||||
|
WORLD_FOLDER = "/home/minecraft/userworlds/";
|
||||||
|
BAUWELT_PROTOTYP = "/home/minecraft/backbone/server/UserBau/Bauwelt2";
|
||||||
|
LOBBY_SERVER = "Lobby";
|
||||||
|
USERWORLDS15 = "/home/minecraft/userworlds15/";
|
||||||
|
BAUWELT15 = "/home/minecraft/backbone/server/Bau15/Bauwelt";
|
||||||
|
Broadcaster.setBroadCastMsgs(new String[] {""});
|
||||||
|
Persistent.setChatPrefix(CHAT_PREFIX);
|
||||||
|
Persistent.setLobbyServer(LOBBY_SERVER);
|
||||||
|
|
||||||
|
SQL.connect(
|
||||||
|
"jdbc:mysql://127.0.0.1:3306/developer",
|
||||||
|
"",
|
||||||
|
""
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}catch(IOException e){
|
}catch(IOException e){
|
||||||
log("Could not save/load config.yml", e);
|
log("Could not save/load config.yml", e);
|
||||||
ProxyServer.getInstance().stop();
|
ProxyServer.getInstance().stop();
|
||||||
|
@ -67,8 +67,8 @@ public class CheckCommand extends BasicCommand {
|
|||||||
|
|
||||||
ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {
|
ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {
|
||||||
List<Schematic> schematics = getSchemsToCheck();
|
List<Schematic> schematics = getSchemsToCheck();
|
||||||
if(!schematics.isEmpty())
|
if(schematics.size() != currentCheckers.size())
|
||||||
ServerTeamchatCommand.sendToTeam("§7Es sind §e" + schematics.size() + " §7Schematics zu prüfen§8!");
|
ServerTeamchatCommand.sendToTeam("§7Es sind §e" + (schematics.size() - currentCheckers.size()) + " §7Schematics zu prüfen§8!");
|
||||||
}, 10, 10, TimeUnit.MINUTES);
|
}, 10, 10, TimeUnit.MINUTES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
24
src/de/steamwar/bungeecore/coms/packets/PingPacket.java
Normale Datei
24
src/de/steamwar/bungeecore/coms/packets/PingPacket.java
Normale Datei
@ -0,0 +1,24 @@
|
|||||||
|
package de.steamwar.bungeecore.coms.packets;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
|
import de.steamwar.bungeecore.coms.sender.Packet;
|
||||||
|
|
||||||
|
public class PingPacket extends Packet {
|
||||||
|
|
||||||
|
String UUID;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "Ping";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
|
||||||
|
byteArrayDataOutput.writeUTF(UUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PingPacket setUUID(String UUID) {
|
||||||
|
this.UUID = UUID;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
10
src/de/steamwar/bungeecore/coms/receiver/Handler.java
Normale Datei
10
src/de/steamwar/bungeecore/coms/receiver/Handler.java
Normale Datei
@ -0,0 +1,10 @@
|
|||||||
|
package de.steamwar.bungeecore.coms.receiver;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
|
||||||
|
public abstract class Handler {
|
||||||
|
|
||||||
|
protected abstract String getName();
|
||||||
|
|
||||||
|
public abstract void handle(ByteArrayDataInput byteArrayDataInput);
|
||||||
|
}
|
31
src/de/steamwar/bungeecore/coms/receiver/PacketHandler.java
Normale Datei
31
src/de/steamwar/bungeecore/coms/receiver/PacketHandler.java
Normale Datei
@ -0,0 +1,31 @@
|
|||||||
|
package de.steamwar.bungeecore.coms.receiver;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import de.steamwar.bungeecore.listeners.BasicListener;
|
||||||
|
import net.md_5.bungee.api.event.PluginMessageEvent;
|
||||||
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class PacketHandler extends BasicListener {
|
||||||
|
|
||||||
|
private static Map<String, Handler> handlerMap = new HashMap<>();
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPluginMessage(PluginMessageEvent event) {
|
||||||
|
if(!event.getTag().equalsIgnoreCase("sw:bridge"))
|
||||||
|
return;
|
||||||
|
ByteArrayDataInput in = ByteStreams.newDataInput( event.getData() );
|
||||||
|
handlerMap.get(in.readUTF()).handle(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerHandler(Handler handler) {
|
||||||
|
handlerMap.put(handler.getName(), handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
//TODO Register Handlers
|
||||||
|
}
|
||||||
|
}
|
20
src/de/steamwar/bungeecore/coms/sender/Packet.java
Normale Datei
20
src/de/steamwar/bungeecore/coms/sender/Packet.java
Normale Datei
@ -0,0 +1,20 @@
|
|||||||
|
package de.steamwar.bungeecore.coms.sender;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.api.connection.Server;
|
||||||
|
|
||||||
|
public abstract class Packet {
|
||||||
|
|
||||||
|
public void send(Server server) {
|
||||||
|
PacketSender.sendPacket(this, server);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(ProxiedPlayer player) {
|
||||||
|
PacketSender.sendPacket(this, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract String getName();
|
||||||
|
|
||||||
|
public abstract void writeVars(ByteArrayDataOutput byteArrayDataOutput);
|
||||||
|
}
|
31
src/de/steamwar/bungeecore/coms/sender/PacketSender.java
Normale Datei
31
src/de/steamwar/bungeecore/coms/sender/PacketSender.java
Normale Datei
@ -0,0 +1,31 @@
|
|||||||
|
package de.steamwar.bungeecore.coms.sender;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.api.connection.Server;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
|
|
||||||
|
public class PacketSender {
|
||||||
|
|
||||||
|
public static void sendPacket(Packet packet, ProxiedPlayer player) {
|
||||||
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
|
out.writeUTF(packet.getName());
|
||||||
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
packet.writeVars(out);
|
||||||
|
out.writeUTF(outputStream.toByteArray().toString());
|
||||||
|
player.getServer().sendData("sw:bridge", out.toByteArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendPacket(Packet packet, Server server) {
|
||||||
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
|
out.writeUTF(packet.getName());
|
||||||
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
packet.writeVars(out);
|
||||||
|
out.writeUTF(outputStream.toByteArray().toString());
|
||||||
|
server.sendData("sw:bridge", out.toByteArray());
|
||||||
|
}
|
||||||
|
}
|
@ -24,6 +24,7 @@ import de.steamwar.bungeecore.Servertype;
|
|||||||
import de.steamwar.bungeecore.Subserver;
|
import de.steamwar.bungeecore.Subserver;
|
||||||
import de.steamwar.bungeecore.commands.BauCommand;
|
import de.steamwar.bungeecore.commands.BauCommand;
|
||||||
import de.steamwar.bungeecore.commands.TpCommand;
|
import de.steamwar.bungeecore.commands.TpCommand;
|
||||||
|
import de.steamwar.bungeecore.coms.packets.PingPacket;
|
||||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
import de.steamwar.bungeecore.sql.Team;
|
import de.steamwar.bungeecore.sql.Team;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
@ -188,6 +189,7 @@ public class ChatListener extends BasicListener {
|
|||||||
for (String curr : msgSplits) {
|
for (String curr : msgSplits) {
|
||||||
if(curr.equalsIgnoreCase("@" + target.getName())) {
|
if(curr.equalsIgnoreCase("@" + target.getName())) {
|
||||||
builder.append("§e@").append(target.getName()).append(chatcolor).append(" ");
|
builder.append("§e@").append(target.getName()).append(chatcolor).append(" ");
|
||||||
|
new PingPacket().setUUID(target.getUniqueId().toString()).send(target);
|
||||||
}else {
|
}else {
|
||||||
builder.append(curr).append(" ");
|
builder.append(curr).append(" ");
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren