SteamWar/BungeeCore
Archiviert
13
2

Basic Packet System

Dieser Commit ist enthalten in:
Chaoscaot 2020-09-15 22:47:58 +02:00
Ursprung efa6398248
Commit 65e7a7bb73
8 geänderte Dateien mit 147 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -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.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;
import org.yaml.snakeyaml.error.YAMLException;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.MalformedInputException;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
@ -127,6 +130,8 @@ public class BungeeCore extends Plugin {
new TablistManager();
getProxy().registerChannel("sw:bridge");
getProxy().getScheduler().schedule(this, () -> {
SteamwarUser.clearCache();
Team.clearCache();
@ -208,7 +213,28 @@ public class BungeeCore extends Plugin {
ProxyServer.getInstance().stop("Could not save conig file");
return;
}
try {
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){
log("Could not save/load config.yml", e);
ProxyServer.getInstance().stop();

Datei anzeigen

@ -67,8 +67,8 @@ public class CheckCommand extends BasicCommand {
ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {
List<Schematic> schematics = getSchemsToCheck();
if(!schematics.isEmpty())
ServerTeamchatCommand.sendToTeam("§7Es sind §e" + schematics.size() + " §7Schematics zu prüfen§8!");
if(schematics.size() != currentCheckers.size())
ServerTeamchatCommand.sendToTeam("§7Es sind §e" + (schematics.size() - currentCheckers.size()) + " §7Schematics zu prüfen§8!");
}, 10, 10, TimeUnit.MINUTES);
}

Datei anzeigen

@ -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;
}
}

Datei anzeigen

@ -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);
}

Datei anzeigen

@ -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
}
}

Datei anzeigen

@ -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);
}

Datei anzeigen

@ -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());
}
}

Datei anzeigen

@ -24,6 +24,7 @@ import de.steamwar.bungeecore.Servertype;
import de.steamwar.bungeecore.Subserver;
import de.steamwar.bungeecore.commands.BauCommand;
import de.steamwar.bungeecore.commands.TpCommand;
import de.steamwar.bungeecore.coms.packets.PingPacket;
import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.sql.Team;
import net.md_5.bungee.api.ChatColor;
@ -188,6 +189,7 @@ public class ChatListener extends BasicListener {
for (String curr : msgSplits) {
if(curr.equalsIgnoreCase("@" + target.getName())) {
builder.append("§e@").append(target.getName()).append(chatcolor).append(" ");
new PingPacket().setUUID(target.getUniqueId().toString()).send(target);
}else {
builder.append(curr).append(" ");
}