Dieser Commit ist enthalten in:
Ursprung
ead97b9f87
Commit
ba106edd58
@ -24,6 +24,7 @@ import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||
import de.steamwar.bungeecore.commands.*;
|
||||
import de.steamwar.bungeecore.listeners.*;
|
||||
import de.steamwar.bungeecore.listeners.mods.*;
|
||||
import de.steamwar.bungeecore.listeners.mods.lunar.Lunar;
|
||||
import de.steamwar.bungeecore.listeners.ping.PingListener;
|
||||
import de.steamwar.bungeecore.network.BungeeNetworkHandler;
|
||||
import de.steamwar.bungeecore.network.NetworkReceiver;
|
||||
@ -122,6 +123,7 @@ public class BungeeCore extends Plugin {
|
||||
new Fabric();
|
||||
new SubserverProtocolFixer();
|
||||
new PingListener();
|
||||
new Lunar();
|
||||
|
||||
local = new Node.LocalNode();
|
||||
if(MAIN_SERVER) {
|
||||
|
74
src/de/steamwar/bungeecore/listeners/mods/lunar/ByteBufWrapper.java
Normale Datei
74
src/de/steamwar/bungeecore/listeners/mods/lunar/ByteBufWrapper.java
Normale Datei
@ -0,0 +1,74 @@
|
||||
package de.steamwar.bungeecore.listeners.mods.lunar;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ByteBufWrapper {
|
||||
|
||||
private final ByteBuf buf;
|
||||
|
||||
public ByteBufWrapper(ByteBuf buf) {
|
||||
this.buf = buf;
|
||||
}
|
||||
|
||||
public void writeVarInt(int b) {
|
||||
while ((b & -128) != 0) {
|
||||
this.buf.writeByte(b & 127 | 128);
|
||||
b >>>= 7;
|
||||
}
|
||||
|
||||
this.buf.writeByte(b);
|
||||
}
|
||||
|
||||
public int readVarInt() {
|
||||
int i = 0;
|
||||
int chunk = 0;
|
||||
byte b;
|
||||
|
||||
do {
|
||||
b = this.buf.readByte();
|
||||
i |= (b & 127) << chunk++ * 7;
|
||||
|
||||
if (chunk > 5) {
|
||||
throw new RuntimeException("VarInt too big");
|
||||
}
|
||||
} while ((b & 128) == 128);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
public void writeString(String s) {
|
||||
byte[] arr = s.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
this.writeVarInt(arr.length);
|
||||
this.buf.writeBytes(arr);
|
||||
}
|
||||
|
||||
public String readString() {
|
||||
int len = readVarInt();
|
||||
|
||||
byte[] buffer = new byte[len];
|
||||
buf.readBytes(buffer);
|
||||
|
||||
return new String(buffer, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public void writeUUID(UUID uuid) {
|
||||
this.buf.writeLong(uuid.getMostSignificantBits());
|
||||
this.buf.writeLong(uuid.getLeastSignificantBits());
|
||||
}
|
||||
|
||||
public UUID readUUID() {
|
||||
long mostSigBits = this.buf.readLong();
|
||||
long leastSigBits = this.buf.readLong();
|
||||
|
||||
return new UUID(mostSigBits, leastSigBits);
|
||||
}
|
||||
|
||||
public ByteBuf buf() {
|
||||
return buf;
|
||||
}
|
||||
|
||||
}
|
44
src/de/steamwar/bungeecore/listeners/mods/lunar/LCPacket.java
Normale Datei
44
src/de/steamwar/bungeecore/listeners/mods/lunar/LCPacket.java
Normale Datei
@ -0,0 +1,44 @@
|
||||
package de.steamwar.bungeecore.listeners.mods.lunar;
|
||||
|
||||
import de.steamwar.bungeecore.listeners.mods.lunar.packets.LCPacketModSettings;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class LCPacket {
|
||||
|
||||
private static final Map<Class<? extends LCPacket>, Integer> classToId = new HashMap<>();
|
||||
|
||||
static {
|
||||
addPacket(31, LCPacketModSettings.class);
|
||||
}
|
||||
|
||||
public static byte[] getPacketData(LCPacket packet) {
|
||||
return getPacketBuf(packet).array();
|
||||
}
|
||||
|
||||
public abstract void write(ByteBufWrapper buf) throws IOException;
|
||||
|
||||
public static ByteBuf getPacketBuf(LCPacket packet) {
|
||||
ByteBufWrapper wrappedBuffer = new ByteBufWrapper(Unpooled.buffer());
|
||||
wrappedBuffer.writeVarInt(classToId.get(packet.getClass()));
|
||||
|
||||
try {
|
||||
packet.write(wrappedBuffer);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return wrappedBuffer.buf();
|
||||
}
|
||||
|
||||
private static void addPacket(int id, Class<? extends LCPacket> clazz) {
|
||||
if (classToId.containsKey(clazz)) {
|
||||
throw new IllegalArgumentException("Duplicate packet class (" + clazz.getSimpleName() + "), already used by " + classToId.get(clazz));
|
||||
}
|
||||
classToId.put(clazz, id);
|
||||
}
|
||||
}
|
33
src/de/steamwar/bungeecore/listeners/mods/lunar/Lunar.java
Normale Datei
33
src/de/steamwar/bungeecore/listeners/mods/lunar/Lunar.java
Normale Datei
@ -0,0 +1,33 @@
|
||||
package de.steamwar.bungeecore.listeners.mods.lunar;
|
||||
|
||||
import de.steamwar.bungeecore.BungeeCore;
|
||||
import de.steamwar.bungeecore.listeners.BasicListener;
|
||||
import de.steamwar.bungeecore.listeners.mods.lunar.packets.LCPacketModSettings;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Lunar extends BasicListener {
|
||||
|
||||
public static final String MESSAGE_CHANNEL = "lunarclient:pm";
|
||||
|
||||
@EventHandler
|
||||
public void onPostLogin(PostLoginEvent e) {
|
||||
BungeeCore.get().getProxy().registerChannel(MESSAGE_CHANNEL);
|
||||
|
||||
ProxiedPlayer player = e.getPlayer();
|
||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||
|
||||
LCPacketModSettings modSettingsPacket = new LCPacketModSettings();
|
||||
|
||||
ModSettings modSettings = new ModSettings();
|
||||
|
||||
modSettings.addModSetting("freelook", new ModSettings.ModSetting(false, new HashMap<>()));
|
||||
|
||||
player.getServer().sendData(MESSAGE_CHANNEL, LCPacket.getPacketData(modSettingsPacket));
|
||||
}
|
||||
}
|
71
src/de/steamwar/bungeecore/listeners/mods/lunar/ModSettings.java
Normale Datei
71
src/de/steamwar/bungeecore/listeners/mods/lunar/ModSettings.java
Normale Datei
@ -0,0 +1,71 @@
|
||||
package de.steamwar.bungeecore.listeners.mods.lunar;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ModSettings {
|
||||
|
||||
public static final Gson GSON = new GsonBuilder().registerTypeHierarchyAdapter(ModSettings.class, new ModSettingsAdapter()).create();
|
||||
|
||||
private Map<String, ModSetting> modSettings = new HashMap<>();
|
||||
|
||||
public ModSettings addModSetting(String modId, ModSetting setting) {
|
||||
modSettings.put(modId, setting);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ModSetting getModSetting(String modId) {
|
||||
return this.modSettings.get(modId);
|
||||
}
|
||||
|
||||
public Map<String, ModSetting> getModSettings() {
|
||||
return modSettings;
|
||||
}
|
||||
|
||||
public static class ModSetting {
|
||||
private boolean enabled;
|
||||
private Map<String, Object> properties;
|
||||
|
||||
public ModSetting() { } // for serialization
|
||||
|
||||
public ModSetting(boolean enabled, Map<String, Object> properties) {
|
||||
this.enabled = enabled;
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public Map<String, Object> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ModSetting{" +
|
||||
"enabled=" + enabled +
|
||||
", properties=" + properties +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ModSetting that = (ModSetting) o;
|
||||
return enabled == that.enabled &&
|
||||
Objects.equals(properties, that.properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(enabled, properties);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package de.steamwar.bungeecore.listeners.mods.lunar;
|
||||
|
||||
import com.google.gson.*;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
public class ModSettingsAdapter implements JsonSerializer<ModSettings> {
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(ModSettings modSettings, Type type, JsonSerializationContext jsonSerializationContext) {
|
||||
JsonObject object = new JsonObject();
|
||||
for (Map.Entry<String, ModSettings.ModSetting> entry : modSettings.getModSettings().entrySet()) {
|
||||
object.add(entry.getKey(), serializeModSetting(entry.getValue()));
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
private JsonObject serializeModSetting(ModSettings.ModSetting setting) {
|
||||
JsonObject object = new JsonObject();
|
||||
JsonObject properties = new JsonObject();
|
||||
object.addProperty("enabled", setting.isEnabled());
|
||||
for (Map.Entry<String, Object> entry : setting.getProperties().entrySet()) {
|
||||
|
||||
JsonPrimitive primitive;
|
||||
if (entry.getValue() instanceof Boolean) {
|
||||
primitive = new JsonPrimitive((Boolean) entry.getValue());
|
||||
} else if (entry.getValue() instanceof String) {
|
||||
primitive = new JsonPrimitive((String) entry.getValue());
|
||||
} else if (entry.getValue() instanceof Number) {
|
||||
primitive = new JsonPrimitive((Number) entry.getValue());
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
properties.add(entry.getKey(), primitive);
|
||||
}
|
||||
object.add("properties", properties);
|
||||
return object;
|
||||
}
|
||||
|
||||
private ModSettings.ModSetting deserializeModSetting(JsonObject object) {
|
||||
JsonObject propertiesObject = object.get("properties").getAsJsonObject();
|
||||
Map<String, Object> properties = new HashMap<>();
|
||||
for (Map.Entry<String, JsonElement> entry : propertiesObject.entrySet()) {
|
||||
if (!entry.getValue().isJsonPrimitive()) {
|
||||
continue;
|
||||
}
|
||||
JsonPrimitive primitive = entry.getValue().getAsJsonPrimitive();
|
||||
Object toSet;
|
||||
if (primitive.isString()) {
|
||||
toSet = primitive.getAsString();
|
||||
} else if (primitive.isNumber()) {
|
||||
toSet = primitive.getAsNumber();
|
||||
} else if (primitive.isBoolean()) {
|
||||
toSet = primitive.getAsBoolean();
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
properties.put(entry.getKey(), toSet);
|
||||
}
|
||||
return new ModSettings.ModSetting(object.get("enabled").getAsBoolean(), properties);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package de.steamwar.bungeecore.listeners.mods.lunar.packets;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import de.steamwar.bungeecore.listeners.mods.lunar.ByteBufWrapper;
|
||||
import de.steamwar.bungeecore.listeners.mods.lunar.LCPacket;
|
||||
import de.steamwar.bungeecore.listeners.mods.lunar.ModSettings;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class LCPacketModSettings extends LCPacket {
|
||||
|
||||
private ModSettings settings;
|
||||
|
||||
public LCPacketModSettings() {}
|
||||
|
||||
public LCPacketModSettings(ModSettings modSettings) {
|
||||
this.settings = modSettings;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void write(ByteBufWrapper buf) throws IOException {
|
||||
buf.writeString(ModSettings.GSON.toJson(this.settings));
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren