From ea9a98ec11f13719d52001679f11d563685bde65 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 27 Apr 2021 14:49:28 +0200 Subject: [PATCH 1/3] 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. -- 2.39.2 From ead209af0a68fdad987d7eb3ced147c7bed65823 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 28 Apr 2021 12:27:32 +0200 Subject: [PATCH 2/3] Reduce Brand Info --- src/de/steamwar/bungeecore/listeners/BrandListener.java | 3 +-- src/de/steamwar/messages/BungeeCore.properties | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/BrandListener.java b/src/de/steamwar/bungeecore/listeners/BrandListener.java index 313476e..b7bbe79 100644 --- a/src/de/steamwar/bungeecore/listeners/BrandListener.java +++ b/src/de/steamwar/bungeecore/listeners/BrandListener.java @@ -47,7 +47,6 @@ public class BrandListener extends BasicListener { 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(); @@ -55,7 +54,7 @@ public class BrandListener extends BasicListener { 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)); + String brandString = Message.parse("STEAMWAR_BRAND", player, BungeeCore.get().getProxy().getName(), player.getServer().getInfo().getName(), serverBrand.substring(1)); ByteBuf brand = ByteBufAllocator.DEFAULT.heapBuffer(); DefinedPacket.writeString(brandString, brand); diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 2c72c5a..6b8e93c 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -7,7 +7,7 @@ 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 +STEAMWAR_BRAND=§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. -- 2.39.2 From a0f87e4916182b1ec1f1292cb1c82c93c342cccf Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 28 Apr 2021 12:28:10 +0200 Subject: [PATCH 3/3] Fix Params --- src/de/steamwar/messages/BungeeCore.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 6b8e93c..98f81c8 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -7,7 +7,7 @@ UNKNOWN_PLAYER=§cDiesen Spieler gibt es nicht. UNKNOWN_TEAM=§cDieses Team gibt es nicht. INVALID_TIME=§cUngültige Zeitangabe. -STEAMWAR_BRAND=§eSteam§8War.de §7({2}) §r<- §e{3} §7({4})§r +STEAMWAR_BRAND=§eSteam§8War.de §7({0}) §r<- §e{1} §7({2})§r #ModLoader blocker MODLOADER_INSTALLED=§7Du hast §e{0} §7installiert. Daher kannst du keinen Arenen beitreten. -- 2.39.2