From ea9a98ec11f13719d52001679f11d563685bde65 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 27 Apr 2021 14:49:28 +0200 Subject: [PATCH] Add custom Branding for Bungee --- src/de/steamwar/bungeecore/BungeeCore.java | 1 + .../bungeecore/listeners/BrandListener.java | 66 +++++++++++++++++++ .../steamwar/messages/BungeeCore.properties | 2 + 3 files changed, 69 insertions(+) create mode 100644 src/de/steamwar/bungeecore/listeners/BrandListener.java diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 6ca3220..2344d56 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -84,6 +84,7 @@ public class BungeeCore extends Plugin { new CheckListener(); new ModLoaderBlocker(); new WorldDownloader(); + new BrandListener(); commands.put("/b", null); commands.put("/gs", null); diff --git a/src/de/steamwar/bungeecore/listeners/BrandListener.java b/src/de/steamwar/bungeecore/listeners/BrandListener.java new file mode 100644 index 0000000..313476e --- /dev/null +++ b/src/de/steamwar/bungeecore/listeners/BrandListener.java @@ -0,0 +1,66 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + */ + +package de.steamwar.bungeecore.listeners; + +import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.Message; +import de.steamwar.bungeecore.sql.SteamwarUser; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufAllocator; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.event.PluginMessageEvent; +import net.md_5.bungee.event.EventHandler; +import net.md_5.bungee.protocol.DefinedPacket; +import net.md_5.bungee.protocol.ProtocolConstants; +import net.md_5.bungee.protocol.packet.PluginMessage; + +import java.util.concurrent.TimeUnit; + +public class BrandListener extends BasicListener { + + @EventHandler + public void onServerSwitch(PluginMessageEvent event) { + if(event.getTag().equals("minecraft:brand") || event.getTag().equals("MC|Brand")) { + return; + } + + if(event.getReceiver().getAddress().getHostName().contains("localhost")) { + return; + } + + BungeeCore.get().getProxy().getScheduler().schedule(BungeeCore.get(), () -> { + ProxiedPlayer player = (ProxiedPlayer) event.getReceiver(); + SteamwarUser user = SteamwarUser.get(player); + + String channel = player.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_13 ? "minecraft:brand" : "MC|Brand"; + StringBuilder serverBrand = new StringBuilder(); + for (byte b:event.getData()) { + serverBrand.append((char) b); + } + + String brandString = Message.parse("STEAMWAR_BRAND", player, user.getUserGroup().getColorCode(), player.getName(), BungeeCore.get().getProxy().getName(), player.getServer().getInfo().getName(), serverBrand.substring(1)); + + ByteBuf brand = ByteBufAllocator.DEFAULT.heapBuffer(); + DefinedPacket.writeString(brandString, brand); + player.sendData(channel, DefinedPacket.toArray(brand)); + brand.release(); + }, 50, TimeUnit.MILLISECONDS); + } +} diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 911b24d..2c72c5a 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -7,6 +7,8 @@ UNKNOWN_PLAYER=§cDiesen Spieler gibt es nicht. UNKNOWN_TEAM=§cDieses Team gibt es nicht. INVALID_TIME=§cUngültige Zeitangabe. +STEAMWAR_BRAND={0}{1} §r<- §eSteam§8War.de §7({2}) §r<- §e{3} §7({4})§r + #ModLoader blocker MODLOADER_INSTALLED=§7Du hast §e{0} §7installiert. Daher kannst du keinen Arenen beitreten. MODLOADER_DENIED=§cMit Fabric, Forge und LiteLoader kannst du keinen Arenen beitreten.