mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-10-31 23:59:33 +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
This commit is contained in:
parent
cadb5ec64c
commit
a2b3906c9e
@ -78,16 +78,16 @@ public class Via<T> implements ViaAPI<T> {
|
||||
|
||||
@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
|
||||
|
@ -28,9 +28,9 @@ import java.util.UUID;
|
||||
@Deprecated
|
||||
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;
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ public class BossBar<T> {
|
||||
}
|
||||
|
||||
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<T> {
|
||||
}
|
||||
|
||||
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<T> {
|
||||
|
||||
@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<T> {
|
||||
}
|
||||
|
||||
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<UUID> getPlayers() {
|
||||
|
@ -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<T> {
|
||||
*/
|
||||
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<T> {
|
||||
* @return a list of protocol versions
|
||||
*/
|
||||
SortedSet<Integer> getFullSupportedVersions();
|
||||
|
||||
/**
|
||||
* Returns legacy api only applicable on/to legacy versions.
|
||||
*
|
||||
* @return legacy api only applicable on/to legacy versions
|
||||
*/
|
||||
LegacyViaAPI<T> legacyAPI();
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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<T> {
|
||||
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<T> {
|
||||
* @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<T> {
|
||||
* @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<T> {
|
||||
* @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<T> {
|
||||
* @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<T> {
|
||||
* @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<T> {
|
||||
* @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<T> {
|
||||
* @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<T> {
|
||||
* @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<T> {
|
||||
* @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<T> {
|
||||
* @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<UUID> getPlayers();
|
||||
Set<UUID> getPlayers();
|
||||
|
||||
/**
|
||||
* Get UserConnections.
|
||||
*
|
||||
* @return UserConnection from players
|
||||
*/
|
||||
public abstract Set<UserConnection> getConnections();
|
||||
Set<UserConnection> 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();
|
||||
}
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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<Player> {
|
||||
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.
|
||||
* Eg. 1.9.1 / 1.9.2 allow certain versions to connect
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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<ProxiedPlayer> {
|
||||
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
|
||||
*
|
||||
|
@ -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<T> implements ViaAPI<T> {
|
||||
|
||||
private final LegacyAPI<T> legacy = new LegacyAPI<>();
|
||||
|
||||
@Override
|
||||
public ServerProtocolVersion getServerVersion() {
|
||||
return Via.getManager().getProtocolManager().getServerProtocolVersion();
|
||||
@ -71,4 +75,9 @@ public abstract class ViaAPIBase<T> implements ViaAPI<T> {
|
||||
public SortedSet<Integer> getFullSupportedVersions() {
|
||||
return Via.getManager().getProtocolManager().getSupportedVersions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LegacyViaAPI<T> legacyAPI() {
|
||||
return legacy;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -15,17 +15,18 @@
|
||||
* 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;
|
||||
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<T> extends BossBar<T> {
|
||||
public class CommonBoss implements BossBar {
|
||||
private final UUID uuid;
|
||||
private final Set<UserConnection> connections;
|
||||
private final Set<BossFlag> flags;
|
||||
@ -127,8 +128,9 @@ public abstract class CommonBoss<T> extends BossBar<T> {
|
||||
@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<T> extends BossBar<T> {
|
||||
@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<T> extends BossBar<T> {
|
||||
|
||||
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<T> extends BossBar<T> {
|
||||
|
||||
private int flagToBytes() {
|
||||
int bitmask = 0;
|
||||
for (BossFlag flag : flags)
|
||||
for (BossFlag flag : flags) {
|
||||
bitmask |= flag.getId();
|
||||
}
|
||||
return bitmask;
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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<Player> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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<Player> {
|
||||
@ -35,14 +32,4 @@ public class VelocityViaAPI extends ViaAPIBase<Player> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user