3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-19 14:30:16 +01:00

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
Dieser Commit ist enthalten in:
KennyTV 2021-04-28 11:10:16 +02:00
Ursprung cadb5ec64c
Commit a2b3906c9e
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
20 geänderte Dateien mit 149 neuen und 350 gelöschten Zeilen

Datei anzeigen

@ -78,16 +78,16 @@ public class Via<T> implements ViaAPI<T> {
@Override @Override
public BossBar createBossBar(String title, BossColor color, BossStyle style) { public BossBar createBossBar(String title, BossColor color, BossStyle style) {
return new BossBar(com.viaversion.viaversion.api.Via.getAPI().createBossBar(title, return new BossBar(com.viaversion.viaversion.api.Via.getAPI().legacyAPI().createLegacyBossBar(title,
com.viaversion.viaversion.api.boss.BossColor.values()[color.ordinal()], com.viaversion.viaversion.api.legacy.bossbar.BossColor.values()[color.ordinal()],
com.viaversion.viaversion.api.boss.BossStyle.values()[style.ordinal()])); com.viaversion.viaversion.api.legacy.bossbar.BossStyle.values()[style.ordinal()]));
} }
@Override @Override
public BossBar createBossBar(String title, float health, BossColor color, BossStyle style) { public BossBar createBossBar(String title, float health, BossColor color, BossStyle style) {
return new BossBar(com.viaversion.viaversion.api.Via.getAPI().createBossBar(title, health, return new BossBar(com.viaversion.viaversion.api.Via.getAPI().legacyAPI().createLegacyBossBar(title, health,
com.viaversion.viaversion.api.boss.BossColor.values()[color.ordinal()], com.viaversion.viaversion.api.legacy.bossbar.BossColor.values()[color.ordinal()],
com.viaversion.viaversion.api.boss.BossStyle.values()[style.ordinal()])); com.viaversion.viaversion.api.legacy.bossbar.BossStyle.values()[style.ordinal()]));
} }
@Override @Override

Datei anzeigen

@ -28,9 +28,9 @@ import java.util.UUID;
@Deprecated @Deprecated
public class BossBar<T> { public class BossBar<T> {
private final com.viaversion.viaversion.api.boss.BossBar<T> bossBar; private final com.viaversion.viaversion.api.legacy.bossbar.BossBar bossBar;
public BossBar(com.viaversion.viaversion.api.boss.BossBar<T> bossBar) { public BossBar(com.viaversion.viaversion.api.legacy.bossbar.BossBar bossBar) {
this.bossBar = bossBar; this.bossBar = bossBar;
} }
@ -57,7 +57,7 @@ public class BossBar<T> {
} }
public BossBar setColor(BossColor color) { 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; return this;
} }
@ -66,12 +66,12 @@ public class BossBar<T> {
} }
public BossBar setStyle(BossStyle style) { 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; return this;
} }
@Deprecated
public BossBar addPlayer(T player) { public BossBar addPlayer(T player) {
bossBar.addPlayer(player);
return this; return this;
} }
@ -82,13 +82,11 @@ public class BossBar<T> {
@Deprecated @Deprecated
public BossBar addPlayers(T... players) { public BossBar addPlayers(T... players) {
bossBar.addPlayers(players);
return this; return this;
} }
@Deprecated @Deprecated
public BossBar removePlayer(T player) { public BossBar removePlayer(T player) {
bossBar.removePlayer(player);
return this; return this;
} }
@ -98,17 +96,17 @@ public class BossBar<T> {
} }
public BossBar addFlag(BossFlag flag) { 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; return this;
} }
public BossBar removeFlag(BossFlag flag) { 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; return this;
} }
public boolean hasFlag(BossFlag flag) { 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<UUID> getPlayers() { public Set<UUID> getPlayers() {

Datei anzeigen

@ -22,10 +22,8 @@
*/ */
package com.viaversion.viaversion.api; 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.connection.ConnectionManager;
import com.viaversion.viaversion.api.legacy.LegacyViaAPI;
import com.viaversion.viaversion.api.platform.ViaPlatform; import com.viaversion.viaversion.api.platform.ViaPlatform;
import com.viaversion.viaversion.api.protocol.ProtocolManager; import com.viaversion.viaversion.api.protocol.ProtocolManager;
import com.viaversion.viaversion.api.protocol.version.ServerProtocolVersion; import com.viaversion.viaversion.api.protocol.version.ServerProtocolVersion;
@ -102,27 +100,6 @@ public interface ViaAPI<T> {
*/ */
void sendRawPacket(UUID uuid, ByteBuf packet); 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. * Returns the supported protocol versions.
* This method removes any blocked protocol versions. * This method removes any blocked protocol versions.
@ -138,4 +115,11 @@ public interface ViaAPI<T> {
* @return a list of protocol versions * @return a list of protocol versions
*/ */
SortedSet<Integer> getFullSupportedVersions(); SortedSet<Integer> getFullSupportedVersions();
/**
* Returns legacy api only applicable on/to legacy versions.
*
* @return legacy api only applicable on/to legacy versions
*/
LegacyViaAPI<T> legacyAPI();
} }

Datei anzeigen

@ -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 <T> player type
*/
public interface LegacyViaAPI<T> {
/**
* 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);
}
}

Datei anzeigen

@ -20,22 +20,21 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. * 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 com.viaversion.viaversion.api.connection.UserConnection;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
public abstract class BossBar<T> { public interface BossBar {
/** /**
* Get the current title * Get the current title
* *
* @return the title * @return the title
*/ */
public abstract String getTitle(); String getTitle();
/** /**
* Change the title * Change the title
@ -43,14 +42,14 @@ public abstract class BossBar<T> {
* @param title Title can be in either JSON or just text * @param title Title can be in either JSON or just text
* @return The BossBar object * @return The BossBar object
*/ */
public abstract BossBar setTitle(String title); BossBar setTitle(String title);
/** /**
* Get the health * Get the health
* *
* @return float between 0F - 1F * @return float between 0F - 1F
*/ */
public abstract float getHealth(); float getHealth();
/** /**
* Change the health * Change the health
@ -58,14 +57,14 @@ public abstract class BossBar<T> {
* @param health this float has to be between 0F - 1F * @param health this float has to be between 0F - 1F
* @return The BossBar object * @return The BossBar object
*/ */
public abstract BossBar setHealth(float health); BossBar setHealth(float health);
/** /**
* Get the bossbar color * Get the bossbar color
* *
* @return The colour * @return The colour
*/ */
public abstract BossColor getColor(); BossColor getColor();
/** /**
* Yay colors! * Yay colors!
@ -73,14 +72,14 @@ public abstract class BossBar<T> {
* @param color Whatever color you want! * @param color Whatever color you want!
* @return The BossBar object * @return The BossBar object
*/ */
public abstract BossBar setColor(BossColor color); BossBar setColor(BossColor color);
/** /**
* Get the bosbar style * Get the bosbar style
* *
* @return BossStyle * @return BossStyle
*/ */
public abstract BossStyle getStyle(); BossStyle getStyle();
/** /**
* Change the bosbar style * Change the bosbar style
@ -88,19 +87,7 @@ public abstract class BossBar<T> {
* @param style BossStyle * @param style BossStyle
* @return The BossBar object * @return The BossBar object
*/ */
public abstract BossBar setStyle(BossStyle style); 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());
}
/** /**
* Show the bossbar to a player (uuid). This only works for frontend connections. Use #addConnection(UserConnection) for other types. * 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<T> {
* @param player uuid of the player * @param player uuid of the player
* @return The BossBar object * @return The BossBar object
*/ */
public abstract BossBar addPlayer(UUID player); BossBar addPlayer(UUID player);
/** /**
* Show the bossbar to a player connection. * Show the bossbar to a player connection.
@ -116,31 +103,7 @@ public abstract class BossBar<T> {
* @param conn UserConnection of the connection * @param conn UserConnection of the connection
* @return The BossBar object * @return The BossBar object
*/ */
public abstract BossBar addConnection(UserConnection conn); 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());
}
/** /**
* Removes the bossbar from a player. This only works for frontend connections. For others types, use #removeConnection(UserConnection) * 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<T> {
* @param uuid The players UUID * @param uuid The players UUID
* @return The BossBar object * @return The BossBar object
*/ */
public abstract BossBar removePlayer(UUID uuid); BossBar removePlayer(UUID uuid);
/** /**
* Removes the bossbar from a player connection. * Removes the bossbar from a player connection.
@ -156,7 +119,7 @@ public abstract class BossBar<T> {
* @param conn The UserConnection * @param conn The UserConnection
* @return The BossBar object * @return The BossBar object
*/ */
public abstract BossBar removeConnection(UserConnection conn); BossBar removeConnection(UserConnection conn);
/** /**
* Add flags * Add flags
@ -164,7 +127,7 @@ public abstract class BossBar<T> {
* @param flag The flag to add * @param flag The flag to add
* @return The BossBar object * @return The BossBar object
*/ */
public abstract BossBar addFlag(BossFlag flag); BossBar addFlag(BossFlag flag);
/** /**
* Remove flags. * Remove flags.
@ -172,53 +135,53 @@ public abstract class BossBar<T> {
* @param flag The flag to remove * @param flag The flag to remove
* @return The BossBar object * @return The BossBar object
*/ */
public abstract BossBar removeFlag(BossFlag flag); BossBar removeFlag(BossFlag flag);
/** /**
* @param flag The flag to check against * @param flag The flag to check against
* @return True if it has the flag * @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() * Get players. Only returns UUIDs which are front-end. For all connections, use #getConnections()
* *
* @return UUIDS from players (sorry I lied) * @return UUIDS from players (sorry I lied)
*/ */
public abstract Set<UUID> getPlayers(); Set<UUID> getPlayers();
/** /**
* Get UserConnections. * Get UserConnections.
* *
* @return UserConnection from players * @return UserConnection from players
*/ */
public abstract Set<UserConnection> getConnections(); Set<UserConnection> getConnections();
/** /**
* Show the bossbar to everyone (In the getPlayer set) * Show the bossbar to everyone (In the getPlayer set)
* *
* @return The BossBar object * @return The BossBar object
*/ */
public abstract BossBar show(); BossBar show();
/** /**
* Hide the bossbar from everyone (In the getPlayer set) * Hide the bossbar from everyone (In the getPlayer set)
* *
* @return The BossBar object * @return The BossBar object
*/ */
public abstract BossBar hide(); BossBar hide();
/** /**
* Is it visible? * Is it visible?
* *
* @return visibility changable with show() and hide() * @return visibility changable with show() and hide()
*/ */
public abstract boolean isVisible(); boolean isVisible();
/** /**
* Get the UUID of this bossbar * Get the UUID of this bossbar
* *
* @return Unique Id for this bossbar * @return Unique Id for this bossbar
*/ */
public abstract UUID getId(); UUID getId();
} }

Datei anzeigen

@ -20,7 +20,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. * SOFTWARE.
*/ */
package com.viaversion.viaversion.api.boss; package com.viaversion.viaversion.api.legacy.bossbar;
public enum BossColor { public enum BossColor {

Datei anzeigen

@ -20,7 +20,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. * SOFTWARE.
*/ */
package com.viaversion.viaversion.api.boss; package com.viaversion.viaversion.api.legacy.bossbar;
public enum BossFlag { public enum BossFlag {

Datei anzeigen

@ -20,7 +20,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. * SOFTWARE.
*/ */
package com.viaversion.viaversion.api.boss; package com.viaversion.viaversion.api.legacy.bossbar;
public enum BossStyle { public enum BossStyle {

Datei anzeigen

@ -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 <http://www.gnu.org/licenses/>.
*/
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<Player> {
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;
}
}

Datei anzeigen

@ -20,11 +20,7 @@ package com.viaversion.viaversion.bukkit.platform;
import com.viaversion.viaversion.ViaAPIBase; import com.viaversion.viaversion.ViaAPIBase;
import com.viaversion.viaversion.ViaVersionPlugin; import com.viaversion.viaversion.ViaVersionPlugin;
import com.viaversion.viaversion.api.Via; 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.api.connection.UserConnection;
import com.viaversion.viaversion.boss.ViaBossBar;
import com.viaversion.viaversion.bukkit.util.ProtocolSupportUtil; import com.viaversion.viaversion.bukkit.util.ProtocolSupportUtil;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -62,16 +58,6 @@ public class BukkitViaAPI extends ViaAPIBase<Player> {
sendRawPacket(player.getUniqueId(), packet); sendRawPacket(player.getUniqueId(), packet);
} }
@Override
public BossBar<Player> createBossBar(String title, BossColor color, BossStyle style) {
return new ViaBossBar(title, 1F, color, style);
}
@Override
public BossBar<Player> 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. * Returns if this version is a compatibility build for spigot.
* Eg. 1.9.1 / 1.9.2 allow certain versions to connect * Eg. 1.9.1 / 1.9.2 allow certain versions to connect

Datei anzeigen

@ -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 <http://www.gnu.org/licenses/>.
*/
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<ProxiedPlayer> {
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;
}
}

Datei anzeigen

@ -18,9 +18,6 @@
package com.viaversion.viaversion.bungee.platform; package com.viaversion.viaversion.bungee.platform;
import com.viaversion.viaversion.ViaAPIBase; 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 com.viaversion.viaversion.bungee.service.ProtocolDetectorService;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.config.ServerInfo;
@ -38,16 +35,6 @@ public class BungeeViaAPI extends ViaAPIBase<ProxiedPlayer> {
sendRawPacket(player.getUniqueId(), packet); 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 * Forces ViaVersion to probe a server
* *

Datei anzeigen

@ -20,7 +20,9 @@ package com.viaversion.viaversion;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.ViaAPI; import com.viaversion.viaversion.api.ViaAPI;
import com.viaversion.viaversion.api.connection.UserConnection; 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.api.protocol.version.ServerProtocolVersion;
import com.viaversion.viaversion.legacy.LegacyAPI;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.SortedSet; import java.util.SortedSet;
@ -29,6 +31,8 @@ import java.util.UUID;
public abstract class ViaAPIBase<T> implements ViaAPI<T> { public abstract class ViaAPIBase<T> implements ViaAPI<T> {
private final LegacyAPI<T> legacy = new LegacyAPI<>();
@Override @Override
public ServerProtocolVersion getServerVersion() { public ServerProtocolVersion getServerVersion() {
return Via.getManager().getProtocolManager().getServerProtocolVersion(); return Via.getManager().getProtocolManager().getServerProtocolVersion();
@ -71,4 +75,9 @@ public abstract class ViaAPIBase<T> implements ViaAPI<T> {
public SortedSet<Integer> getFullSupportedVersions() { public SortedSet<Integer> getFullSupportedVersions() {
return Via.getManager().getProtocolManager().getSupportedVersions(); return Via.getManager().getProtocolManager().getSupportedVersions();
} }
@Override
public LegacyViaAPI<T> legacyAPI() {
return legacy;
}
} }

Datei anzeigen

@ -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<T> implements LegacyViaAPI<T> {
@Override
public BossBar createLegacyBossBar(String title, float health, BossColor color, BossStyle style) {
return new CommonBoss(title, health, color, style);
}
}

Datei anzeigen

@ -15,17 +15,18 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viaversion.boss; package com.viaversion.viaversion.legacy.bossbar;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.Via; 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.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.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type; 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 com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import java.util.ArrayList; import java.util.ArrayList;
@ -37,7 +38,7 @@ import java.util.UUID;
import java.util.WeakHashMap; import java.util.WeakHashMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public abstract class CommonBoss<T> extends BossBar<T> { public class CommonBoss implements BossBar {
private final UUID uuid; private final UUID uuid;
private final Set<UserConnection> connections; private final Set<UserConnection> connections;
private final Set<BossFlag> flags; private final Set<BossFlag> flags;
@ -127,8 +128,9 @@ public abstract class CommonBoss<T> extends BossBar<T> {
@Override @Override
public BossBar addFlag(BossFlag flag) { public BossBar addFlag(BossFlag flag) {
Preconditions.checkNotNull(flag); Preconditions.checkNotNull(flag);
if (!hasFlag(flag)) if (!hasFlag(flag)) {
flags.add(flag); flags.add(flag);
}
sendPacket(CommonBoss.UpdateAction.UPDATE_FLAGS); sendPacket(CommonBoss.UpdateAction.UPDATE_FLAGS);
return this; return this;
} }
@ -136,8 +138,9 @@ public abstract class CommonBoss<T> extends BossBar<T> {
@Override @Override
public BossBar removeFlag(BossFlag flag) { public BossBar removeFlag(BossFlag flag) {
Preconditions.checkNotNull(flag); Preconditions.checkNotNull(flag);
if (hasFlag(flag)) if (hasFlag(flag)) {
flags.remove(flag); flags.remove(flag);
}
sendPacket(CommonBoss.UpdateAction.UPDATE_FLAGS); sendPacket(CommonBoss.UpdateAction.UPDATE_FLAGS);
return this; return this;
} }
@ -232,7 +235,7 @@ public abstract class CommonBoss<T> extends BossBar<T> {
private PacketWrapper getPacket(UpdateAction action, UserConnection connection) { private PacketWrapper getPacket(UpdateAction action, UserConnection connection) {
try { 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.UUID, uuid);
wrapper.write(Type.VAR_INT, action.getId()); wrapper.write(Type.VAR_INT, action.getId());
switch (action) { switch (action) {
@ -269,8 +272,9 @@ public abstract class CommonBoss<T> extends BossBar<T> {
private int flagToBytes() { private int flagToBytes() {
int bitmask = 0; int bitmask = 0;
for (BossFlag flag : flags) for (BossFlag flag : flags) {
bitmask |= flag.getId(); bitmask |= flag.getId();
}
return bitmask; return bitmask;
} }

Datei anzeigen

@ -20,9 +20,9 @@ package com.viaversion.viaversion.protocols.protocol1_9to1_8.storage;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.boss.BossBar; import com.viaversion.viaversion.api.legacy.bossbar.BossBar;
import com.viaversion.viaversion.api.boss.BossColor; import com.viaversion.viaversion.api.legacy.bossbar.BossColor;
import com.viaversion.viaversion.api.boss.BossStyle; import com.viaversion.viaversion.api.legacy.bossbar.BossStyle;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_10Types.EntityType; 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(); String title = (String) metadata.getValue();
title = title.isEmpty() ? (type == EntityType.ENDER_DRAGON ? "Ender Dragon" : "Wither") : title; title = title.isEmpty() ? (type == EntityType.ENDER_DRAGON ? "Ender Dragon" : "Wither") : title;
if (bar == null) { 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); bossBarMap.put(entityId, bar);
bar.addConnection(getUser()); bar.addConnection(getUser());
bar.show(); 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)); float health = Math.max(0.0f, Math.min(((float) metadata.getValue()) / maxHealth, 1.0f));
if (bar == null) { if (bar == null) {
String title = type == EntityType.ENDER_DRAGON ? "Ender Dragon" : "Wither"; 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); bossBarMap.put(entityId, bar);
bar.addConnection(getUser()); bar.addConnection(getUser());
bar.show(); bar.show();

Datei anzeigen

@ -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 <http://www.gnu.org/licenses/>.
*/
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<Player> {
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;
}
}

Datei anzeigen

@ -18,9 +18,6 @@
package com.viaversion.viaversion.sponge.platform; package com.viaversion.viaversion.sponge.platform;
import com.viaversion.viaversion.ViaAPIBase; 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 io.netty.buffer.ByteBuf;
import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.entity.living.player.Player;
@ -35,14 +32,4 @@ public class SpongeViaAPI extends ViaAPIBase<Player> {
public void sendRawPacket(Player player, ByteBuf packet) throws IllegalArgumentException { public void sendRawPacket(Player player, ByteBuf packet) throws IllegalArgumentException {
sendRawPacket(player.getUniqueId(), packet); 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);
}
} }

Datei anzeigen

@ -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 <http://www.gnu.org/licenses/>.
*/
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<Player> {
public VelocityBossBar(String title, float health, BossColor color, BossStyle style) {
super(title, health, color, style);
}
}

Datei anzeigen

@ -19,9 +19,6 @@ package com.viaversion.viaversion.velocity.platform;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import com.viaversion.viaversion.ViaAPIBase; 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 io.netty.buffer.ByteBuf;
public class VelocityViaAPI extends ViaAPIBase<Player> { public class VelocityViaAPI extends ViaAPIBase<Player> {
@ -35,14 +32,4 @@ public class VelocityViaAPI extends ViaAPIBase<Player> {
public void sendRawPacket(Player player, ByteBuf packet) throws IllegalArgumentException { public void sendRawPacket(Player player, ByteBuf packet) throws IllegalArgumentException {
sendRawPacket(player.getUniqueId(), packet); 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);
}
} }