Remove text 3.x API and associated deprecated APIs
This commit is contained in:
@@ -35,9 +35,6 @@ import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||
import com.velocitypowered.api.util.Favicon;
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import com.velocitypowered.api.util.ProxyVersion;
|
||||
import com.velocitypowered.api.util.bossbar.BossBar;
|
||||
import com.velocitypowered.api.util.bossbar.BossBarColor;
|
||||
import com.velocitypowered.api.util.bossbar.BossBarOverlay;
|
||||
import com.velocitypowered.proxy.command.VelocityCommandManager;
|
||||
import com.velocitypowered.proxy.command.builtin.GlistCommand;
|
||||
import com.velocitypowered.proxy.command.builtin.ServerCommand;
|
||||
@@ -50,7 +47,6 @@ import com.velocitypowered.proxy.network.ConnectionManager;
|
||||
import com.velocitypowered.proxy.plugin.VelocityEventManager;
|
||||
import com.velocitypowered.proxy.plugin.VelocityPluginManager;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.protocol.packet.Chat;
|
||||
import com.velocitypowered.proxy.protocol.util.FaviconSerializer;
|
||||
import com.velocitypowered.proxy.protocol.util.GameProfileSerializer;
|
||||
import com.velocitypowered.proxy.scheduler.VelocityScheduler;
|
||||
@@ -59,7 +55,6 @@ import com.velocitypowered.proxy.util.AddressUtil;
|
||||
import com.velocitypowered.proxy.util.EncryptionUtils;
|
||||
import com.velocitypowered.proxy.util.VelocityChannelRegistrar;
|
||||
import com.velocitypowered.proxy.util.bossbar.AdventureBossBarManager;
|
||||
import com.velocitypowered.proxy.util.bossbar.VelocityBossBar;
|
||||
import com.velocitypowered.proxy.util.ratelimit.Ratelimiter;
|
||||
import com.velocitypowered.proxy.util.ratelimit.Ratelimiters;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
@@ -181,15 +176,6 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
|
||||
return new ProxyVersion(implName, implVendor, implVersion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull BossBar createBossBar(
|
||||
net.kyori.text.@NonNull Component title,
|
||||
@NonNull BossBarColor color,
|
||||
@NonNull BossBarOverlay overlay,
|
||||
float progress) {
|
||||
return new VelocityBossBar(title, color, overlay, progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VelocityCommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
@@ -575,15 +561,6 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
|
||||
return Optional.ofNullable(connectionsByUuid.get(uuid));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcast(net.kyori.text.Component component) {
|
||||
Preconditions.checkNotNull(component, "component");
|
||||
Chat chat = Chat.createClientbound(component);
|
||||
for (ConnectedPlayer player : connectionsByUuid.values()) {
|
||||
player.getConnection().write(chat);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Player> matchPlayer(String partialName) {
|
||||
Objects.requireNonNull(partialName);
|
||||
|
@@ -50,7 +50,6 @@ import java.util.Random;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacytext3.LegacyText3ComponentSerializer;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
@@ -255,16 +254,6 @@ public class VelocityConfiguration implements ProxyConfig {
|
||||
return query.shouldQueryShowPlugins();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the proxy's MOTD.
|
||||
*
|
||||
* @return the MOTD
|
||||
*/
|
||||
@Override
|
||||
public net.kyori.text.Component getMotdComponent() {
|
||||
return LegacyText3ComponentSerializer.get().serialize(this.getMotd());
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component getMotd() {
|
||||
if (motdAsComponent == null) {
|
||||
|
@@ -44,11 +44,7 @@ import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||
import com.velocitypowered.api.proxy.player.PlayerSettings;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import com.velocitypowered.api.util.MessagePosition;
|
||||
import com.velocitypowered.api.util.ModInfo;
|
||||
import com.velocitypowered.api.util.title.TextTitle;
|
||||
import com.velocitypowered.api.util.title.Title;
|
||||
import com.velocitypowered.api.util.title.Titles;
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.config.VelocityConfiguration;
|
||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||
@@ -252,40 +248,6 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
return connection.getProtocolVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(net.kyori.text.Component component, MessagePosition position) {
|
||||
Preconditions.checkNotNull(component, "component");
|
||||
Preconditions.checkNotNull(position, "position");
|
||||
|
||||
byte pos = (byte) position.ordinal();
|
||||
String json;
|
||||
if (position == MessagePosition.ACTION_BAR) {
|
||||
if (getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_11) >= 0) {
|
||||
// We can use the title packet instead.
|
||||
TitlePacket pkt = new TitlePacket();
|
||||
pkt.setAction(TitlePacket.SET_ACTION_BAR);
|
||||
pkt.setComponent(net.kyori.text.serializer.gson.GsonComponentSerializer.INSTANCE
|
||||
.serialize(component));
|
||||
connection.write(pkt);
|
||||
return;
|
||||
} else {
|
||||
// Due to issues with action bar packets, we'll need to convert the text message into a
|
||||
// legacy message and then inject the legacy text into a component... yuck!
|
||||
JsonObject object = new JsonObject();
|
||||
object.addProperty("text", net.kyori.text.serializer.legacy
|
||||
.LegacyComponentSerializer.legacy().serialize(component));
|
||||
json = object.toString();
|
||||
}
|
||||
} else {
|
||||
json = net.kyori.text.serializer.gson.GsonComponentSerializer.INSTANCE.serialize(component);
|
||||
}
|
||||
|
||||
Chat chat = new Chat();
|
||||
chat.setType(pos);
|
||||
chat.setMessage(json);
|
||||
connection.write(chat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(@NonNull Identity identity, @NonNull Component message) {
|
||||
connection.write(Chat.createClientbound(identity, message, this.getProtocolVersion()));
|
||||
@@ -425,12 +387,6 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
this.profile = profile.withProperties(Preconditions.checkNotNull(properties));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public void setHeaderAndFooter(net.kyori.text.Component header, net.kyori.text.Component footer) {
|
||||
tabList.setHeaderAndFooter(header, footer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearHeaderAndFooter() {
|
||||
tabList.clearHeaderAndFooter();
|
||||
@@ -450,26 +406,6 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect(net.kyori.text.Component reason) {
|
||||
if (connection.eventLoop().inEventLoop()) {
|
||||
disconnect0(reason, false);
|
||||
} else {
|
||||
connection.eventLoop().execute(() -> disconnect0(reason, false));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects the player from the proxy.
|
||||
* @param reason the reason for disconnecting the player
|
||||
* @param duringLogin whether the disconnect happened during login
|
||||
*/
|
||||
public void disconnect0(net.kyori.text.Component reason, boolean duringLogin) {
|
||||
logger.info("{} has disconnected: {}", this,
|
||||
net.kyori.text.serializer.legacy.LegacyComponentSerializer.legacy().serialize(reason));
|
||||
connection.closeWith(Disconnect.create(reason));
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects the player from the proxy.
|
||||
* @param reason the reason for disconnecting the player
|
||||
@@ -481,54 +417,6 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
connection.closeWith(Disconnect.create(reason, this.getProtocolVersion()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTitle(Title title) {
|
||||
Preconditions.checkNotNull(title, "title");
|
||||
|
||||
ProtocolVersion protocolVersion = connection.getProtocolVersion();
|
||||
if (title.equals(Titles.reset())) {
|
||||
connection.write(TitlePacket.resetForProtocolVersion(protocolVersion));
|
||||
} else if (title.equals(Titles.hide())) {
|
||||
connection.write(TitlePacket.hideForProtocolVersion(protocolVersion));
|
||||
} else if (title instanceof TextTitle) {
|
||||
TextTitle tt = (TextTitle) title;
|
||||
|
||||
if (tt.isResetBeforeSend()) {
|
||||
connection.delayedWrite(TitlePacket.resetForProtocolVersion(protocolVersion));
|
||||
}
|
||||
|
||||
Optional<net.kyori.text.Component> titleText = tt.getTitle();
|
||||
if (titleText.isPresent()) {
|
||||
TitlePacket titlePkt = new TitlePacket();
|
||||
titlePkt.setAction(TitlePacket.SET_TITLE);
|
||||
titlePkt.setComponent(net.kyori.text.serializer.gson.GsonComponentSerializer.INSTANCE
|
||||
.serialize(titleText.get()));
|
||||
connection.delayedWrite(titlePkt);
|
||||
}
|
||||
|
||||
Optional<net.kyori.text.Component> subtitleText = tt.getSubtitle();
|
||||
if (subtitleText.isPresent()) {
|
||||
TitlePacket titlePkt = new TitlePacket();
|
||||
titlePkt.setAction(TitlePacket.SET_SUBTITLE);
|
||||
titlePkt.setComponent(net.kyori.text.serializer.gson.GsonComponentSerializer.INSTANCE
|
||||
.serialize(subtitleText.get()));
|
||||
connection.delayedWrite(titlePkt);
|
||||
}
|
||||
|
||||
if (tt.areTimesSet()) {
|
||||
TitlePacket timesPkt = TitlePacket.timesForProtocolVersion(protocolVersion);
|
||||
timesPkt.setFadeIn(tt.getFadeIn());
|
||||
timesPkt.setStay(tt.getStay());
|
||||
timesPkt.setFadeOut(tt.getFadeOut());
|
||||
connection.delayedWrite(timesPkt);
|
||||
}
|
||||
connection.flush();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown title class " + title.getClass().getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public @Nullable VelocityServerConnection getConnectedServer() {
|
||||
return connectedServer;
|
||||
}
|
||||
|
@@ -25,7 +25,6 @@ import java.util.Optional;
|
||||
import javax.annotation.Nullable;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacytext3.LegacyText3ComponentSerializer;
|
||||
|
||||
public class ConnectionRequestResults {
|
||||
|
||||
@@ -89,11 +88,6 @@ public class ConnectionRequestResults {
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<net.kyori.text.Component> getReason() {
|
||||
return Optional.ofNullable(component).map(LegacyText3ComponentSerializer.get()::serialize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Component> getReasonComponent() {
|
||||
return Optional.ofNullable(component);
|
||||
|
@@ -28,8 +28,6 @@ import java.util.List;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.text.TextComponent;
|
||||
import net.kyori.text.format.TextColor;
|
||||
import net.minecrell.terminalconsole.SimpleTerminalConsole;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -51,12 +49,6 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(net.kyori.text.Component component) {
|
||||
logger.info(net.kyori.text.serializer.legacy.LegacyComponentSerializer.legacy()
|
||||
.serialize(component));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(@NonNull Identity identity, @NonNull Component message) {
|
||||
logger.info(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection()
|
||||
|
@@ -116,18 +116,6 @@ public class Chat implements MinecraftPacket {
|
||||
return handler.handle(this);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Chat createClientbound(net.kyori.text.Component component) {
|
||||
return createClientbound(component, CHAT_TYPE, EMPTY_SENDER);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Chat createClientbound(net.kyori.text.Component component, byte type, UUID sender) {
|
||||
Preconditions.checkNotNull(component, "component");
|
||||
return new Chat(net.kyori.text.serializer.gson.GsonComponentSerializer.INSTANCE
|
||||
.serialize(component), type, sender);
|
||||
}
|
||||
|
||||
public static Chat createClientbound(Identity identity,
|
||||
net.kyori.adventure.text.Component component, ProtocolVersion version) {
|
||||
return createClientbound(component, CHAT_TYPE, identity.uuid(), version);
|
||||
|
@@ -23,8 +23,6 @@ import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.kyori.text.Component;
|
||||
import net.kyori.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class Disconnect implements MinecraftPacket {
|
||||
@@ -74,12 +72,6 @@ public class Disconnect implements MinecraftPacket {
|
||||
return handler.handle(this);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Disconnect create(Component component) {
|
||||
Preconditions.checkNotNull(component, "component");
|
||||
return new Disconnect(GsonComponentSerializer.INSTANCE.serialize(component));
|
||||
}
|
||||
|
||||
public static Disconnect create(net.kyori.adventure.text.Component component,
|
||||
ProtocolVersion version) {
|
||||
Preconditions.checkNotNull(component, "component");
|
||||
|
@@ -34,7 +34,6 @@ import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.legacytext3.LegacyText3ComponentSerializer;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class VelocityTabList implements TabList {
|
||||
@@ -48,18 +47,6 @@ public class VelocityTabList implements TabList {
|
||||
this.connection = player.getConnection();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public void setHeaderAndFooter(net.kyori.text.Component header,
|
||||
net.kyori.text.Component footer) {
|
||||
Preconditions.checkNotNull(header, "header");
|
||||
Preconditions.checkNotNull(footer, "footer");
|
||||
this.player.sendPlayerListHeaderAndFooter(
|
||||
LegacyText3ComponentSerializer.get().deserialize(header),
|
||||
LegacyText3ComponentSerializer.get().deserialize(footer)
|
||||
);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public void setHeaderAndFooter(Component header, Component footer) {
|
||||
|
@@ -22,8 +22,6 @@ import com.velocitypowered.api.proxy.player.TabListEntry;
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import com.velocitypowered.proxy.protocol.packet.PlayerListItem;
|
||||
import java.util.Optional;
|
||||
import net.kyori.adventure.text.serializer.legacytext3.LegacyText3ComponentSerializer;
|
||||
import net.kyori.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class VelocityTabListEntry implements TabListEntry {
|
||||
@@ -53,24 +51,11 @@ public class VelocityTabListEntry implements TabListEntry {
|
||||
return profile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Component> getDisplayName() {
|
||||
return Optional.ofNullable(displayName).map(LegacyText3ComponentSerializer.get()::serialize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<net.kyori.adventure.text.Component> getDisplayNameComponent() {
|
||||
return Optional.ofNullable(displayName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TabListEntry setDisplayName(@Nullable Component displayName) {
|
||||
if (displayName == null) {
|
||||
return this.setDisplayName((net.kyori.adventure.text.Component) null);
|
||||
}
|
||||
return this.setDisplayName(LegacyText3ComponentSerializer.get().deserialize(displayName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TabListEntry setDisplayName(net.kyori.adventure.text.@Nullable Component displayName) {
|
||||
this.displayName = displayName;
|
||||
|
@@ -29,12 +29,6 @@ public class VelocityTabListEntryLegacy extends VelocityTabListEntry {
|
||||
super(tabList, profile, displayName, latency, gameMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TabListEntry setDisplayName(net.kyori.text.@Nullable Component displayName) {
|
||||
getTabList().removeEntry(getProfile().getId()); // We have to remove first if updating
|
||||
return super.setDisplayName(displayName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TabListEntry setDisplayName(@Nullable Component displayName) {
|
||||
getTabList().removeEntry(getProfile().getId()); // We have to remove first if updating
|
||||
|
@@ -39,11 +39,6 @@ public class VelocityTabListLegacy extends VelocityTabList {
|
||||
super(player);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public void setHeaderAndFooter(net.kyori.text.Component header, net.kyori.text.Component footer) {
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public void setHeaderAndFooter(Component header, Component footer) {
|
||||
|
@@ -1,293 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Velocity 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.velocitypowered.proxy.util.bossbar;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.util.bossbar.BossBarColor;
|
||||
import com.velocitypowered.api.util.bossbar.BossBarFlag;
|
||||
import com.velocitypowered.api.util.bossbar.BossBarOverlay;
|
||||
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.packet.BossBar;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import net.kyori.text.Component;
|
||||
import net.kyori.text.serializer.gson.GsonComponentSerializer;
|
||||
|
||||
public class VelocityBossBar implements com.velocitypowered.api.util.bossbar.BossBar {
|
||||
|
||||
private final List<Player> players;
|
||||
private final Set<BossBarFlag> flags;
|
||||
private final UUID uuid;
|
||||
private boolean visible;
|
||||
private Component title;
|
||||
private float percent;
|
||||
private BossBarColor color;
|
||||
private BossBarOverlay overlay;
|
||||
|
||||
/**
|
||||
* Creates a new boss bar.
|
||||
* @param title the title for the bar
|
||||
* @param color the color of the bar
|
||||
* @param overlay the overlay to use
|
||||
* @param percent the percent of the bar
|
||||
*/
|
||||
public VelocityBossBar(
|
||||
Component title, BossBarColor color, BossBarOverlay overlay, float percent) {
|
||||
this.title = checkNotNull(title, "title");
|
||||
this.color = checkNotNull(color, "color");
|
||||
this.overlay = checkNotNull(overlay, "overlay");
|
||||
this.percent = percent;
|
||||
checkPercent(percent);
|
||||
this.uuid = UUID.randomUUID();
|
||||
visible = true;
|
||||
players = new ArrayList<>();
|
||||
flags = EnumSet.noneOf(BossBarFlag.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPlayers(Iterable<Player> players) {
|
||||
checkNotNull(players, "players");
|
||||
for (Player player : players) {
|
||||
addPlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPlayer(Player player) {
|
||||
checkNotNull(player, "player");
|
||||
if (!players.contains(player)) {
|
||||
players.add(player);
|
||||
}
|
||||
if (player.isActive() && visible) {
|
||||
sendPacket(player, addPacket());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePlayer(Player player) {
|
||||
checkNotNull(player, "player");
|
||||
players.remove(player);
|
||||
if (player.isActive()) {
|
||||
sendPacket(player, removePacket());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePlayers(Iterable<Player> players) {
|
||||
checkNotNull(players, "players");
|
||||
for (Player player : players) {
|
||||
removePlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAllPlayers() {
|
||||
removePlayers(ImmutableList.copyOf(players));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(Component title) {
|
||||
this.title = checkNotNull(title, "title");
|
||||
if (visible) {
|
||||
BossBar bar = new BossBar();
|
||||
bar.setUuid(uuid);
|
||||
bar.setAction(BossBar.UPDATE_NAME);
|
||||
bar.setName(GsonComponentSerializer.INSTANCE.serialize(title));
|
||||
sendToAffected(bar);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPercent() {
|
||||
return percent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPercent(float percent) {
|
||||
checkPercent(percent);
|
||||
this.percent = percent;
|
||||
if (visible) {
|
||||
BossBar bar = new BossBar();
|
||||
bar.setUuid(uuid);
|
||||
bar.setAction(BossBar.UPDATE_PERCENT);
|
||||
bar.setPercent(percent);
|
||||
sendToAffected(bar);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkPercent(final float percent) {
|
||||
if (percent < 0f || percent > 1f) {
|
||||
throw new IllegalArgumentException("Percent must be between 0 and 1");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Player> getPlayers() {
|
||||
return ImmutableList.copyOf(players);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBarColor getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColor(BossBarColor color) {
|
||||
this.color = checkNotNull(color, "color");
|
||||
if (visible) {
|
||||
sendDivisions(color, overlay);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBarOverlay getOverlay() {
|
||||
return overlay;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOverlay(BossBarOverlay overlay) {
|
||||
this.overlay = checkNotNull(overlay, "overlay");
|
||||
if (visible) {
|
||||
sendDivisions(color, overlay);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendDivisions(BossBarColor color, BossBarOverlay overlay) {
|
||||
BossBar bar = new BossBar();
|
||||
bar.setUuid(uuid);
|
||||
bar.setAction(BossBar.UPDATE_STYLE);
|
||||
bar.setColor(color.ordinal());
|
||||
bar.setOverlay(overlay.ordinal());
|
||||
sendToAffected(bar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisible(boolean visible) {
|
||||
boolean previous = this.visible;
|
||||
if (previous && !visible) {
|
||||
// The bar is being hidden
|
||||
sendToAffected(removePacket());
|
||||
} else if (!previous && visible) {
|
||||
// The bar is being shown
|
||||
sendToAffected(addPacket());
|
||||
}
|
||||
this.visible = visible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<BossBarFlag> getFlags() {
|
||||
return ImmutableList.copyOf(flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFlags(BossBarFlag... flags) {
|
||||
if (this.flags.addAll(Arrays.asList(flags)) && visible) {
|
||||
sendToAffected(updateFlags());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFlag(BossBarFlag flag) {
|
||||
checkNotNull(flag, "flag");
|
||||
if (this.flags.remove(flag) && visible) {
|
||||
sendToAffected(updateFlags());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFlags(BossBarFlag... flags) {
|
||||
if (this.flags.removeAll(Arrays.asList(flags)) && visible) {
|
||||
sendToAffected(updateFlags());
|
||||
}
|
||||
}
|
||||
|
||||
private short serializeFlags() {
|
||||
short flagMask = 0x0;
|
||||
if (flags.contains(BossBarFlag.DARKEN_SCREEN)) {
|
||||
flagMask |= 0x1;
|
||||
}
|
||||
if (flags.contains(BossBarFlag.PLAY_BOSS_MUSIC)) {
|
||||
flagMask |= 0x2;
|
||||
}
|
||||
if (flags.contains(BossBarFlag.CREATE_WORLD_FOG)) {
|
||||
flagMask |= 0x4;
|
||||
}
|
||||
return flagMask;
|
||||
}
|
||||
|
||||
private BossBar addPacket() {
|
||||
BossBar bossBar = new BossBar();
|
||||
bossBar.setUuid(uuid);
|
||||
bossBar.setAction(BossBar.ADD);
|
||||
bossBar.setName(GsonComponentSerializer.INSTANCE.serialize(title));
|
||||
bossBar.setColor(color.ordinal());
|
||||
bossBar.setOverlay(overlay.ordinal());
|
||||
bossBar.setPercent(percent);
|
||||
bossBar.setFlags(serializeFlags());
|
||||
return bossBar;
|
||||
}
|
||||
|
||||
private BossBar removePacket() {
|
||||
BossBar bossBar = new BossBar();
|
||||
bossBar.setUuid(uuid);
|
||||
bossBar.setAction(BossBar.REMOVE);
|
||||
return bossBar;
|
||||
}
|
||||
|
||||
private BossBar updateFlags() {
|
||||
BossBar bossBar = new BossBar();
|
||||
bossBar.setUuid(uuid);
|
||||
bossBar.setAction(BossBar.UPDATE_PROPERTIES);
|
||||
bossBar.setFlags(serializeFlags());
|
||||
return bossBar;
|
||||
}
|
||||
|
||||
private void sendToAffected(MinecraftPacket packet) {
|
||||
for (Player player : players) {
|
||||
if (player.isActive() && player.getProtocolVersion().getProtocol()
|
||||
>= ProtocolVersion.MINECRAFT_1_9.getProtocol()) {
|
||||
sendPacket(player, packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void sendPacket(Player player, MinecraftPacket packet) {
|
||||
ConnectedPlayer connected = (ConnectedPlayer) player;
|
||||
connected.getConnection().write(packet);
|
||||
}
|
||||
}
|
@@ -19,17 +19,11 @@ package com.velocitypowered.proxy.command;
|
||||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.permission.Tristate;
|
||||
import net.kyori.text.Component;
|
||||
|
||||
public class MockCommandSource implements CommandSource {
|
||||
|
||||
public static final CommandSource INSTANCE = new MockCommandSource();
|
||||
|
||||
@Override
|
||||
public void sendMessage(final Component component) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tristate getPermissionValue(final String permission) {
|
||||
return Tristate.UNDEFINED;
|
||||
|
Reference in New Issue
Block a user