From a2b3906c9efafac71fd056b6fddccfe3a2e7cdbf Mon Sep 17 00:00:00 2001 From: KennyTV Date: Wed, 28 Apr 2021 11:10:16 +0200 Subject: [PATCH] Move bossbar to new legacy package, since it only works on <1.9 The newly created LegacyViaAPI is safe to use, but should hold methods that cannot be universally used on every version --- .../java/us/myles/ViaVersion/api/Via.java | 12 +-- .../us/myles/ViaVersion/api/boss/BossBar.java | 18 ++-- .../com/viaversion/viaversion/api/ViaAPI.java | 32 ++----- .../viaversion/api/legacy/LegacyViaAPI.java | 58 +++++++++++++ .../api/{boss => legacy/bossbar}/BossBar.java | 83 +++++-------------- .../{boss => legacy/bossbar}/BossColor.java | 2 +- .../{boss => legacy/bossbar}/BossFlag.java | 2 +- .../{boss => legacy/bossbar}/BossStyle.java | 2 +- .../viaversion/boss/ViaBossBar.java | 49 ----------- .../bukkit/platform/BukkitViaAPI.java | 14 ---- .../bungee/platform/BungeeBossBar.java | 51 ------------ .../bungee/platform/BungeeViaAPI.java | 13 --- .../com/viaversion/viaversion/ViaAPIBase.java | 9 ++ .../viaversion/legacy/LegacyAPI.java | 15 ++++ .../{boss => legacy/bossbar}/CommonBoss.java | 24 +++--- .../storage/EntityTracker1_9.java | 10 +-- .../sponge/platform/SpongeBossBar.java | 50 ----------- .../sponge/platform/SpongeViaAPI.java | 13 --- .../velocity/platform/VelocityBossBar.java | 29 ------- .../velocity/platform/VelocityViaAPI.java | 13 --- 20 files changed, 149 insertions(+), 350 deletions(-) create mode 100644 api/src/main/java/com/viaversion/viaversion/api/legacy/LegacyViaAPI.java rename api/src/main/java/com/viaversion/viaversion/api/{boss => legacy/bossbar}/BossBar.java (62%) rename api/src/main/java/com/viaversion/viaversion/api/{boss => legacy/bossbar}/BossColor.java (96%) rename api/src/main/java/com/viaversion/viaversion/api/{boss => legacy/bossbar}/BossFlag.java (96%) rename api/src/main/java/com/viaversion/viaversion/api/{boss => legacy/bossbar}/BossStyle.java (96%) delete mode 100644 bukkit/src/main/java/com/viaversion/viaversion/boss/ViaBossBar.java delete mode 100644 bungee/src/main/java/com/viaversion/viaversion/bungee/platform/BungeeBossBar.java create mode 100644 common/src/main/java/com/viaversion/viaversion/legacy/LegacyAPI.java rename common/src/main/java/com/viaversion/viaversion/{boss => legacy/bossbar}/CommonBoss.java (92%) delete mode 100644 sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeBossBar.java delete mode 100644 velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityBossBar.java diff --git a/api-legacy/src/main/java/us/myles/ViaVersion/api/Via.java b/api-legacy/src/main/java/us/myles/ViaVersion/api/Via.java index c29f189e6..718bbc311 100644 --- a/api-legacy/src/main/java/us/myles/ViaVersion/api/Via.java +++ b/api-legacy/src/main/java/us/myles/ViaVersion/api/Via.java @@ -78,16 +78,16 @@ public class Via implements ViaAPI { @Override public BossBar createBossBar(String title, BossColor color, BossStyle style) { - return new BossBar(com.viaversion.viaversion.api.Via.getAPI().createBossBar(title, - com.viaversion.viaversion.api.boss.BossColor.values()[color.ordinal()], - com.viaversion.viaversion.api.boss.BossStyle.values()[style.ordinal()])); + return new BossBar(com.viaversion.viaversion.api.Via.getAPI().legacyAPI().createLegacyBossBar(title, + com.viaversion.viaversion.api.legacy.bossbar.BossColor.values()[color.ordinal()], + com.viaversion.viaversion.api.legacy.bossbar.BossStyle.values()[style.ordinal()])); } @Override public BossBar createBossBar(String title, float health, BossColor color, BossStyle style) { - return new BossBar(com.viaversion.viaversion.api.Via.getAPI().createBossBar(title, health, - com.viaversion.viaversion.api.boss.BossColor.values()[color.ordinal()], - com.viaversion.viaversion.api.boss.BossStyle.values()[style.ordinal()])); + return new BossBar(com.viaversion.viaversion.api.Via.getAPI().legacyAPI().createLegacyBossBar(title, health, + com.viaversion.viaversion.api.legacy.bossbar.BossColor.values()[color.ordinal()], + com.viaversion.viaversion.api.legacy.bossbar.BossStyle.values()[style.ordinal()])); } @Override diff --git a/api-legacy/src/main/java/us/myles/ViaVersion/api/boss/BossBar.java b/api-legacy/src/main/java/us/myles/ViaVersion/api/boss/BossBar.java index 8c7460f39..009eac477 100644 --- a/api-legacy/src/main/java/us/myles/ViaVersion/api/boss/BossBar.java +++ b/api-legacy/src/main/java/us/myles/ViaVersion/api/boss/BossBar.java @@ -28,9 +28,9 @@ import java.util.UUID; @Deprecated public class BossBar { - private final com.viaversion.viaversion.api.boss.BossBar bossBar; + private final com.viaversion.viaversion.api.legacy.bossbar.BossBar bossBar; - public BossBar(com.viaversion.viaversion.api.boss.BossBar bossBar) { + public BossBar(com.viaversion.viaversion.api.legacy.bossbar.BossBar bossBar) { this.bossBar = bossBar; } @@ -57,7 +57,7 @@ public class BossBar { } public BossBar setColor(BossColor color) { - bossBar.setColor(com.viaversion.viaversion.api.boss.BossColor.values()[color.ordinal()]); + bossBar.setColor(com.viaversion.viaversion.api.legacy.bossbar.BossColor.values()[color.ordinal()]); return this; } @@ -66,12 +66,12 @@ public class BossBar { } public BossBar setStyle(BossStyle style) { - bossBar.setStyle(com.viaversion.viaversion.api.boss.BossStyle.values()[style.ordinal()]); + bossBar.setStyle(com.viaversion.viaversion.api.legacy.bossbar.BossStyle.values()[style.ordinal()]); return this; } + @Deprecated public BossBar addPlayer(T player) { - bossBar.addPlayer(player); return this; } @@ -82,13 +82,11 @@ public class BossBar { @Deprecated public BossBar addPlayers(T... players) { - bossBar.addPlayers(players); return this; } @Deprecated public BossBar removePlayer(T player) { - bossBar.removePlayer(player); return this; } @@ -98,17 +96,17 @@ public class BossBar { } public BossBar addFlag(BossFlag flag) { - bossBar.addFlag(com.viaversion.viaversion.api.boss.BossFlag.values()[flag.ordinal()]); + bossBar.addFlag(com.viaversion.viaversion.api.legacy.bossbar.BossFlag.values()[flag.ordinal()]); return this; } public BossBar removeFlag(BossFlag flag) { - bossBar.removeFlag(com.viaversion.viaversion.api.boss.BossFlag.values()[flag.ordinal()]); + bossBar.removeFlag(com.viaversion.viaversion.api.legacy.bossbar.BossFlag.values()[flag.ordinal()]); return this; } public boolean hasFlag(BossFlag flag) { - return bossBar.hasFlag(com.viaversion.viaversion.api.boss.BossFlag.values()[flag.ordinal()]); + return bossBar.hasFlag(com.viaversion.viaversion.api.legacy.bossbar.BossFlag.values()[flag.ordinal()]); } public Set getPlayers() { diff --git a/api/src/main/java/com/viaversion/viaversion/api/ViaAPI.java b/api/src/main/java/com/viaversion/viaversion/api/ViaAPI.java index 5c2f2b227..84eaecb72 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/ViaAPI.java +++ b/api/src/main/java/com/viaversion/viaversion/api/ViaAPI.java @@ -22,10 +22,8 @@ */ package com.viaversion.viaversion.api; -import com.viaversion.viaversion.api.boss.BossBar; -import com.viaversion.viaversion.api.boss.BossColor; -import com.viaversion.viaversion.api.boss.BossStyle; import com.viaversion.viaversion.api.connection.ConnectionManager; +import com.viaversion.viaversion.api.legacy.LegacyViaAPI; import com.viaversion.viaversion.api.platform.ViaPlatform; import com.viaversion.viaversion.api.protocol.ProtocolManager; import com.viaversion.viaversion.api.protocol.version.ServerProtocolVersion; @@ -102,27 +100,6 @@ public interface ViaAPI { */ void sendRawPacket(UUID uuid, ByteBuf packet); - /** - * Create a new bossbar instance - * - * @param title The title - * @param color The color - * @param style The style - * @return BossBar instance - */ - BossBar createBossBar(String title, BossColor color, BossStyle style); - - /** - * Create a new bossbar instance - * - * @param title The title - * @param health Number between 0 and 1 - * @param color The color - * @param style The style - * @return BossBar instance - */ - BossBar createBossBar(String title, float health, BossColor color, BossStyle style); - /** * Returns the supported protocol versions. * This method removes any blocked protocol versions. @@ -138,4 +115,11 @@ public interface ViaAPI { * @return a list of protocol versions */ SortedSet getFullSupportedVersions(); + + /** + * Returns legacy api only applicable on/to legacy versions. + * + * @return legacy api only applicable on/to legacy versions + */ + LegacyViaAPI legacyAPI(); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/legacy/LegacyViaAPI.java b/api/src/main/java/com/viaversion/viaversion/api/legacy/LegacyViaAPI.java new file mode 100644 index 000000000..93adfefe8 --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/legacy/LegacyViaAPI.java @@ -0,0 +1,58 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2021 ViaVersion and contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.viaversion.viaversion.api.legacy; + +import com.viaversion.viaversion.api.legacy.bossbar.BossBar; +import com.viaversion.viaversion.api.legacy.bossbar.BossColor; +import com.viaversion.viaversion.api.legacy.bossbar.BossStyle; + +/** + * API only applicable on or to legacy versions of Minecraft. + * + * @param player type + */ +public interface LegacyViaAPI { + + /** + * Creates a new bossbar instance. This only works on pre 1.9 servers for 1.9+ clients. + * + * @param title title + * @param health health, between 0 and 1 (inclusive) + * @param color color + * @param style style + * @return new bossbar instance + */ + BossBar createLegacyBossBar(String title, float health, BossColor color, BossStyle style); + + /** + * Creates a new bossbar instance with full health. This only works on pre 1.9 servers for 1.9+ clients. + * + * @param title title + * @param color color + * @param style style + * @return new bossbar instance + */ + default BossBar createLegacyBossBar(String title, BossColor color, BossStyle style) { + return createLegacyBossBar(title, 1F, color, style); + } +} diff --git a/api/src/main/java/com/viaversion/viaversion/api/boss/BossBar.java b/api/src/main/java/com/viaversion/viaversion/api/legacy/bossbar/BossBar.java similarity index 62% rename from api/src/main/java/com/viaversion/viaversion/api/boss/BossBar.java rename to api/src/main/java/com/viaversion/viaversion/api/legacy/bossbar/BossBar.java index b04f1da1f..02dd870ce 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/boss/BossBar.java +++ b/api/src/main/java/com/viaversion/viaversion/api/legacy/bossbar/BossBar.java @@ -20,22 +20,21 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package com.viaversion.viaversion.api.boss; +package com.viaversion.viaversion.api.legacy.bossbar; -import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; import java.util.Set; import java.util.UUID; -public abstract class BossBar { +public interface BossBar { /** * Get the current title * * @return the title */ - public abstract String getTitle(); + String getTitle(); /** * Change the title @@ -43,14 +42,14 @@ public abstract class BossBar { * @param title Title can be in either JSON or just text * @return The BossBar object */ - public abstract BossBar setTitle(String title); + BossBar setTitle(String title); /** * Get the health * * @return float between 0F - 1F */ - public abstract float getHealth(); + float getHealth(); /** * Change the health @@ -58,14 +57,14 @@ public abstract class BossBar { * @param health this float has to be between 0F - 1F * @return The BossBar object */ - public abstract BossBar setHealth(float health); + BossBar setHealth(float health); /** * Get the bossbar color * * @return The colour */ - public abstract BossColor getColor(); + BossColor getColor(); /** * Yay colors! @@ -73,14 +72,14 @@ public abstract class BossBar { * @param color Whatever color you want! * @return The BossBar object */ - public abstract BossBar setColor(BossColor color); + BossBar setColor(BossColor color); /** * Get the bosbar style * * @return BossStyle */ - public abstract BossStyle getStyle(); + BossStyle getStyle(); /** * Change the bosbar style @@ -88,19 +87,7 @@ public abstract class BossBar { * @param style BossStyle * @return The BossBar object */ - public abstract BossBar setStyle(BossStyle style); - - /** - * Show the bossbar to a player. - * - * @param player The player - * @return The BossBar object - * @deprecated Deprecated use UUID's instead of Player objects {@link #addPlayer(UUID)} - */ - @Deprecated - public BossBar addPlayer(T player) { - throw new UnsupportedOperationException("This method is not implemented for the platform " + Via.getPlatform().getPlatformName()); - } + BossBar setStyle(BossStyle style); /** * Show the bossbar to a player (uuid). This only works for frontend connections. Use #addConnection(UserConnection) for other types. @@ -108,7 +95,7 @@ public abstract class BossBar { * @param player uuid of the player * @return The BossBar object */ - public abstract BossBar addPlayer(UUID player); + BossBar addPlayer(UUID player); /** * Show the bossbar to a player connection. @@ -116,31 +103,7 @@ public abstract class BossBar { * @param conn UserConnection of the connection * @return The BossBar object */ - public abstract BossBar addConnection(UserConnection conn); - - /** - * add multiple players - * - * @param players list of players - * @return The BossBar object - * @deprecated Deprecated use UUID's instead of Player objects {@link #addPlayer(UUID)} - */ - @Deprecated - public BossBar addPlayers(T... players) { - throw new UnsupportedOperationException("This method is not implemented for the platform " + Via.getPlatform().getPlatformName()); - } - - /** - * Remove the bossbar from a player - * - * @param player The player - * @return The BossBar object - * @deprecated Deprecated use UUID's instead of Player objects {@link #removePlayer(UUID)} - */ - @Deprecated - public BossBar removePlayer(T player) { - throw new UnsupportedOperationException("This method is not implemented for the platform " + Via.getPlatform().getPlatformName()); - } + BossBar addConnection(UserConnection conn); /** * Removes the bossbar from a player. This only works for frontend connections. For others types, use #removeConnection(UserConnection) @@ -148,7 +111,7 @@ public abstract class BossBar { * @param uuid The players UUID * @return The BossBar object */ - public abstract BossBar removePlayer(UUID uuid); + BossBar removePlayer(UUID uuid); /** * Removes the bossbar from a player connection. @@ -156,7 +119,7 @@ public abstract class BossBar { * @param conn The UserConnection * @return The BossBar object */ - public abstract BossBar removeConnection(UserConnection conn); + BossBar removeConnection(UserConnection conn); /** * Add flags @@ -164,7 +127,7 @@ public abstract class BossBar { * @param flag The flag to add * @return The BossBar object */ - public abstract BossBar addFlag(BossFlag flag); + BossBar addFlag(BossFlag flag); /** * Remove flags. @@ -172,53 +135,53 @@ public abstract class BossBar { * @param flag The flag to remove * @return The BossBar object */ - public abstract BossBar removeFlag(BossFlag flag); + BossBar removeFlag(BossFlag flag); /** * @param flag The flag to check against * @return True if it has the flag */ - public abstract boolean hasFlag(BossFlag flag); + boolean hasFlag(BossFlag flag); /** * Get players. Only returns UUIDs which are front-end. For all connections, use #getConnections() * * @return UUIDS from players (sorry I lied) */ - public abstract Set getPlayers(); + Set getPlayers(); /** * Get UserConnections. * * @return UserConnection from players */ - public abstract Set getConnections(); + Set getConnections(); /** * Show the bossbar to everyone (In the getPlayer set) * * @return The BossBar object */ - public abstract BossBar show(); + BossBar show(); /** * Hide the bossbar from everyone (In the getPlayer set) * * @return The BossBar object */ - public abstract BossBar hide(); + BossBar hide(); /** * Is it visible? * * @return visibility changable with show() and hide() */ - public abstract boolean isVisible(); + boolean isVisible(); /** * Get the UUID of this bossbar * * @return Unique Id for this bossbar */ - public abstract UUID getId(); + UUID getId(); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/boss/BossColor.java b/api/src/main/java/com/viaversion/viaversion/api/legacy/bossbar/BossColor.java similarity index 96% rename from api/src/main/java/com/viaversion/viaversion/api/boss/BossColor.java rename to api/src/main/java/com/viaversion/viaversion/api/legacy/bossbar/BossColor.java index c6cfe917c..c0a60ec4c 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/boss/BossColor.java +++ b/api/src/main/java/com/viaversion/viaversion/api/legacy/bossbar/BossColor.java @@ -20,7 +20,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package com.viaversion.viaversion.api.boss; +package com.viaversion.viaversion.api.legacy.bossbar; public enum BossColor { diff --git a/api/src/main/java/com/viaversion/viaversion/api/boss/BossFlag.java b/api/src/main/java/com/viaversion/viaversion/api/legacy/bossbar/BossFlag.java similarity index 96% rename from api/src/main/java/com/viaversion/viaversion/api/boss/BossFlag.java rename to api/src/main/java/com/viaversion/viaversion/api/legacy/bossbar/BossFlag.java index 50c46bea0..7b958f6eb 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/boss/BossFlag.java +++ b/api/src/main/java/com/viaversion/viaversion/api/legacy/bossbar/BossFlag.java @@ -20,7 +20,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package com.viaversion.viaversion.api.boss; +package com.viaversion.viaversion.api.legacy.bossbar; public enum BossFlag { diff --git a/api/src/main/java/com/viaversion/viaversion/api/boss/BossStyle.java b/api/src/main/java/com/viaversion/viaversion/api/legacy/bossbar/BossStyle.java similarity index 96% rename from api/src/main/java/com/viaversion/viaversion/api/boss/BossStyle.java rename to api/src/main/java/com/viaversion/viaversion/api/legacy/bossbar/BossStyle.java index b51426378..aa84618a9 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/boss/BossStyle.java +++ b/api/src/main/java/com/viaversion/viaversion/api/legacy/bossbar/BossStyle.java @@ -20,7 +20,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package com.viaversion.viaversion.api.boss; +package com.viaversion.viaversion.api.legacy.bossbar; public enum BossStyle { diff --git a/bukkit/src/main/java/com/viaversion/viaversion/boss/ViaBossBar.java b/bukkit/src/main/java/com/viaversion/viaversion/boss/ViaBossBar.java deleted file mode 100644 index 3ee189166..000000000 --- a/bukkit/src/main/java/com/viaversion/viaversion/boss/ViaBossBar.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion - * Copyright (C) 2016-2021 ViaVersion and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.viaversion.viaversion.boss; - -import com.viaversion.viaversion.api.boss.BossBar; -import com.viaversion.viaversion.api.boss.BossColor; -import com.viaversion.viaversion.api.boss.BossStyle; -import org.bukkit.entity.Player; - -public class ViaBossBar extends CommonBoss { - - public ViaBossBar(String title, float health, BossColor color, BossStyle style) { - super(title, health, color, style); - } - - @Override - public BossBar addPlayer(Player player) { - addPlayer(player.getUniqueId()); - return this; - } - - @Override - public BossBar addPlayers(Player... players) { - for (Player p : players) - addPlayer(p); - return this; - } - - @Override - public BossBar removePlayer(Player player) { - removePlayer(player.getUniqueId()); - return this; - } -} diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaAPI.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaAPI.java index 98adc3259..dcf18845e 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaAPI.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaAPI.java @@ -20,11 +20,7 @@ package com.viaversion.viaversion.bukkit.platform; import com.viaversion.viaversion.ViaAPIBase; import com.viaversion.viaversion.ViaVersionPlugin; import com.viaversion.viaversion.api.Via; -import com.viaversion.viaversion.api.boss.BossBar; -import com.viaversion.viaversion.api.boss.BossColor; -import com.viaversion.viaversion.api.boss.BossStyle; import com.viaversion.viaversion.api.connection.UserConnection; -import com.viaversion.viaversion.boss.ViaBossBar; import com.viaversion.viaversion.bukkit.util.ProtocolSupportUtil; import io.netty.buffer.ByteBuf; import org.bukkit.Bukkit; @@ -62,16 +58,6 @@ public class BukkitViaAPI extends ViaAPIBase { sendRawPacket(player.getUniqueId(), packet); } - @Override - public BossBar createBossBar(String title, BossColor color, BossStyle style) { - return new ViaBossBar(title, 1F, color, style); - } - - @Override - public BossBar createBossBar(String title, float health, BossColor color, BossStyle style) { - return new ViaBossBar(title, health, color, style); - } - /** * Returns if this version is a compatibility build for spigot. * Eg. 1.9.1 / 1.9.2 allow certain versions to connect diff --git a/bungee/src/main/java/com/viaversion/viaversion/bungee/platform/BungeeBossBar.java b/bungee/src/main/java/com/viaversion/viaversion/bungee/platform/BungeeBossBar.java deleted file mode 100644 index 0844ffda5..000000000 --- a/bungee/src/main/java/com/viaversion/viaversion/bungee/platform/BungeeBossBar.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion - * Copyright (C) 2016-2021 ViaVersion and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.viaversion.viaversion.bungee.platform; - -import com.viaversion.viaversion.api.boss.BossBar; -import com.viaversion.viaversion.api.boss.BossColor; -import com.viaversion.viaversion.api.boss.BossStyle; -import com.viaversion.viaversion.boss.CommonBoss; -import net.md_5.bungee.api.connection.ProxiedPlayer; - -public class BungeeBossBar extends CommonBoss { - - public BungeeBossBar(String title, float health, BossColor color, BossStyle style) { - super(title, health, color, style); - } - - - @Override - public BossBar addPlayer(ProxiedPlayer player) { - addPlayer(player.getUniqueId()); - return this; - } - - @Override - public BossBar addPlayers(ProxiedPlayer... players) { - for (ProxiedPlayer p : players) - addPlayer(p); - return this; - } - - @Override - public BossBar removePlayer(ProxiedPlayer player) { - removePlayer(player.getUniqueId()); - return this; - } -} diff --git a/bungee/src/main/java/com/viaversion/viaversion/bungee/platform/BungeeViaAPI.java b/bungee/src/main/java/com/viaversion/viaversion/bungee/platform/BungeeViaAPI.java index 96715ce60..bcdaf69b9 100644 --- a/bungee/src/main/java/com/viaversion/viaversion/bungee/platform/BungeeViaAPI.java +++ b/bungee/src/main/java/com/viaversion/viaversion/bungee/platform/BungeeViaAPI.java @@ -18,9 +18,6 @@ package com.viaversion.viaversion.bungee.platform; import com.viaversion.viaversion.ViaAPIBase; -import com.viaversion.viaversion.api.boss.BossBar; -import com.viaversion.viaversion.api.boss.BossColor; -import com.viaversion.viaversion.api.boss.BossStyle; import com.viaversion.viaversion.bungee.service.ProtocolDetectorService; import io.netty.buffer.ByteBuf; import net.md_5.bungee.api.config.ServerInfo; @@ -38,16 +35,6 @@ public class BungeeViaAPI extends ViaAPIBase { sendRawPacket(player.getUniqueId(), packet); } - @Override - public BossBar createBossBar(String title, BossColor color, BossStyle style) { - return new BungeeBossBar(title, 1F, color, style); - } - - @Override - public BossBar createBossBar(String title, float health, BossColor color, BossStyle style) { - return new BungeeBossBar(title, health, color, style); - } - /** * Forces ViaVersion to probe a server * diff --git a/common/src/main/java/com/viaversion/viaversion/ViaAPIBase.java b/common/src/main/java/com/viaversion/viaversion/ViaAPIBase.java index d9c2b9923..a78168840 100644 --- a/common/src/main/java/com/viaversion/viaversion/ViaAPIBase.java +++ b/common/src/main/java/com/viaversion/viaversion/ViaAPIBase.java @@ -20,7 +20,9 @@ package com.viaversion.viaversion; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.ViaAPI; import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.legacy.LegacyViaAPI; import com.viaversion.viaversion.api.protocol.version.ServerProtocolVersion; +import com.viaversion.viaversion.legacy.LegacyAPI; import io.netty.buffer.ByteBuf; import java.util.SortedSet; @@ -29,6 +31,8 @@ import java.util.UUID; public abstract class ViaAPIBase implements ViaAPI { + private final LegacyAPI legacy = new LegacyAPI<>(); + @Override public ServerProtocolVersion getServerVersion() { return Via.getManager().getProtocolManager().getServerProtocolVersion(); @@ -71,4 +75,9 @@ public abstract class ViaAPIBase implements ViaAPI { public SortedSet getFullSupportedVersions() { return Via.getManager().getProtocolManager().getSupportedVersions(); } + + @Override + public LegacyViaAPI legacyAPI() { + return legacy; + } } diff --git a/common/src/main/java/com/viaversion/viaversion/legacy/LegacyAPI.java b/common/src/main/java/com/viaversion/viaversion/legacy/LegacyAPI.java new file mode 100644 index 000000000..83292deea --- /dev/null +++ b/common/src/main/java/com/viaversion/viaversion/legacy/LegacyAPI.java @@ -0,0 +1,15 @@ +package com.viaversion.viaversion.legacy; + +import com.viaversion.viaversion.api.legacy.LegacyViaAPI; +import com.viaversion.viaversion.api.legacy.bossbar.BossBar; +import com.viaversion.viaversion.api.legacy.bossbar.BossColor; +import com.viaversion.viaversion.api.legacy.bossbar.BossStyle; +import com.viaversion.viaversion.legacy.bossbar.CommonBoss; + +public final class LegacyAPI implements LegacyViaAPI { + + @Override + public BossBar createLegacyBossBar(String title, float health, BossColor color, BossStyle style) { + return new CommonBoss(title, health, color, style); + } +} diff --git a/common/src/main/java/com/viaversion/viaversion/boss/CommonBoss.java b/common/src/main/java/com/viaversion/viaversion/legacy/bossbar/CommonBoss.java similarity index 92% rename from common/src/main/java/com/viaversion/viaversion/boss/CommonBoss.java rename to common/src/main/java/com/viaversion/viaversion/legacy/bossbar/CommonBoss.java index c54efd60f..9e23f652e 100644 --- a/common/src/main/java/com/viaversion/viaversion/boss/CommonBoss.java +++ b/common/src/main/java/com/viaversion/viaversion/legacy/bossbar/CommonBoss.java @@ -15,17 +15,18 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.viaversion.viaversion.boss; +package com.viaversion.viaversion.legacy.bossbar; import com.google.common.base.Preconditions; import com.viaversion.viaversion.api.Via; -import com.viaversion.viaversion.api.boss.BossBar; -import com.viaversion.viaversion.api.boss.BossColor; -import com.viaversion.viaversion.api.boss.BossFlag; -import com.viaversion.viaversion.api.boss.BossStyle; import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.legacy.bossbar.BossBar; +import com.viaversion.viaversion.api.legacy.bossbar.BossColor; +import com.viaversion.viaversion.api.legacy.bossbar.BossFlag; +import com.viaversion.viaversion.api.legacy.bossbar.BossStyle; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9; import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8; import java.util.ArrayList; @@ -37,7 +38,7 @@ import java.util.UUID; import java.util.WeakHashMap; import java.util.stream.Collectors; -public abstract class CommonBoss extends BossBar { +public class CommonBoss implements BossBar { private final UUID uuid; private final Set connections; private final Set flags; @@ -127,8 +128,9 @@ public abstract class CommonBoss extends BossBar { @Override public BossBar addFlag(BossFlag flag) { Preconditions.checkNotNull(flag); - if (!hasFlag(flag)) + if (!hasFlag(flag)) { flags.add(flag); + } sendPacket(CommonBoss.UpdateAction.UPDATE_FLAGS); return this; } @@ -136,8 +138,9 @@ public abstract class CommonBoss extends BossBar { @Override public BossBar removeFlag(BossFlag flag) { Preconditions.checkNotNull(flag); - if (hasFlag(flag)) + if (hasFlag(flag)) { flags.remove(flag); + } sendPacket(CommonBoss.UpdateAction.UPDATE_FLAGS); return this; } @@ -232,7 +235,7 @@ public abstract class CommonBoss extends BossBar { private PacketWrapper getPacket(UpdateAction action, UserConnection connection) { try { - PacketWrapper wrapper = PacketWrapper.create(0x0C, null, connection); // TODO don't use fixed packet ids for future support + PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.BOSSBAR, null, connection); wrapper.write(Type.UUID, uuid); wrapper.write(Type.VAR_INT, action.getId()); switch (action) { @@ -269,8 +272,9 @@ public abstract class CommonBoss extends BossBar { private int flagToBytes() { int bitmask = 0; - for (BossFlag flag : flags) + for (BossFlag flag : flags) { bitmask |= flag.getId(); + } return bitmask; } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/storage/EntityTracker1_9.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/storage/EntityTracker1_9.java index cee583e9e..7382772db 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/storage/EntityTracker1_9.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/storage/EntityTracker1_9.java @@ -20,9 +20,9 @@ package com.viaversion.viaversion.protocols.protocol1_9to1_8.storage; import com.google.common.cache.CacheBuilder; import com.google.common.collect.Sets; import com.viaversion.viaversion.api.Via; -import com.viaversion.viaversion.api.boss.BossBar; -import com.viaversion.viaversion.api.boss.BossColor; -import com.viaversion.viaversion.api.boss.BossStyle; +import com.viaversion.viaversion.api.legacy.bossbar.BossBar; +import com.viaversion.viaversion.api.legacy.bossbar.BossColor; +import com.viaversion.viaversion.api.legacy.bossbar.BossStyle; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.entities.Entity1_10Types.EntityType; @@ -254,7 +254,7 @@ public class EntityTracker1_9 extends EntityTracker { String title = (String) metadata.getValue(); title = title.isEmpty() ? (type == EntityType.ENDER_DRAGON ? "Ender Dragon" : "Wither") : title; if (bar == null) { - bar = Via.getAPI().createBossBar(title, BossColor.PINK, BossStyle.SOLID); + bar = Via.getAPI().legacyAPI().createLegacyBossBar(title, BossColor.PINK, BossStyle.SOLID); bossBarMap.put(entityId, bar); bar.addConnection(getUser()); bar.show(); @@ -271,7 +271,7 @@ public class EntityTracker1_9 extends EntityTracker { float health = Math.max(0.0f, Math.min(((float) metadata.getValue()) / maxHealth, 1.0f)); if (bar == null) { String title = type == EntityType.ENDER_DRAGON ? "Ender Dragon" : "Wither"; - bar = Via.getAPI().createBossBar(title, health, BossColor.PINK, BossStyle.SOLID); + bar = Via.getAPI().legacyAPI().createLegacyBossBar(title, health, BossColor.PINK, BossStyle.SOLID); bossBarMap.put(entityId, bar); bar.addConnection(getUser()); bar.show(); diff --git a/sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeBossBar.java b/sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeBossBar.java deleted file mode 100644 index c5e143c8a..000000000 --- a/sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeBossBar.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion - * Copyright (C) 2016-2021 ViaVersion and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.viaversion.viaversion.sponge.platform; - -import com.viaversion.viaversion.api.boss.BossBar; -import com.viaversion.viaversion.api.boss.BossColor; -import com.viaversion.viaversion.api.boss.BossStyle; -import com.viaversion.viaversion.boss.CommonBoss; -import org.spongepowered.api.entity.living.player.Player; - -public class SpongeBossBar extends CommonBoss { - - public SpongeBossBar(String title, float health, BossColor color, BossStyle style) { - super(title, health, color, style); - } - - @Override - public BossBar addPlayer(Player player) { - addPlayer(player.getUniqueId()); - return this; - } - - @Override - public BossBar addPlayers(Player... players) { - for (Player p : players) - addPlayer(p); - return this; - } - - @Override - public BossBar removePlayer(Player player) { - removePlayer(player.getUniqueId()); - return this; - } -} diff --git a/sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeViaAPI.java b/sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeViaAPI.java index 32a2ecd45..1595d2239 100644 --- a/sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeViaAPI.java +++ b/sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeViaAPI.java @@ -18,9 +18,6 @@ package com.viaversion.viaversion.sponge.platform; import com.viaversion.viaversion.ViaAPIBase; -import com.viaversion.viaversion.api.boss.BossBar; -import com.viaversion.viaversion.api.boss.BossColor; -import com.viaversion.viaversion.api.boss.BossStyle; import io.netty.buffer.ByteBuf; import org.spongepowered.api.entity.living.player.Player; @@ -35,14 +32,4 @@ public class SpongeViaAPI extends ViaAPIBase { public void sendRawPacket(Player player, ByteBuf packet) throws IllegalArgumentException { sendRawPacket(player.getUniqueId(), packet); } - - @Override - public BossBar createBossBar(String title, BossColor color, BossStyle style) { - return new SpongeBossBar(title, 1F, color, style); - } - - @Override - public BossBar createBossBar(String title, float health, BossColor color, BossStyle style) { - return new SpongeBossBar(title, health, color, style); - } } diff --git a/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityBossBar.java b/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityBossBar.java deleted file mode 100644 index cc4b67516..000000000 --- a/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityBossBar.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion - * Copyright (C) 2016-2021 ViaVersion and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.viaversion.viaversion.velocity.platform; - -import com.velocitypowered.api.proxy.Player; -import com.viaversion.viaversion.api.boss.BossColor; -import com.viaversion.viaversion.api.boss.BossStyle; -import com.viaversion.viaversion.boss.CommonBoss; - -public class VelocityBossBar extends CommonBoss { - public VelocityBossBar(String title, float health, BossColor color, BossStyle style) { - super(title, health, color, style); - } -} diff --git a/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityViaAPI.java b/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityViaAPI.java index c7571a6aa..1c75e27ec 100644 --- a/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityViaAPI.java +++ b/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityViaAPI.java @@ -19,9 +19,6 @@ package com.viaversion.viaversion.velocity.platform; import com.velocitypowered.api.proxy.Player; import com.viaversion.viaversion.ViaAPIBase; -import com.viaversion.viaversion.api.boss.BossBar; -import com.viaversion.viaversion.api.boss.BossColor; -import com.viaversion.viaversion.api.boss.BossStyle; import io.netty.buffer.ByteBuf; public class VelocityViaAPI extends ViaAPIBase { @@ -35,14 +32,4 @@ public class VelocityViaAPI extends ViaAPIBase { public void sendRawPacket(Player player, ByteBuf packet) throws IllegalArgumentException { sendRawPacket(player.getUniqueId(), packet); } - - @Override - public BossBar createBossBar(String title, BossColor color, BossStyle style) { - return new VelocityBossBar(title, 1F, color, style); - } - - @Override - public BossBar createBossBar(String title, float health, BossColor color, BossStyle style) { - return new VelocityBossBar(title, health, color, style); - } }