2021-03-22 23:06:40 +01:00
|
|
|
/*
|
|
|
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
2024-01-01 12:39:45 +01:00
|
|
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
2021-03-22 23:06:40 +01:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
2021-04-26 20:52:34 +02:00
|
|
|
package com.viaversion.viaversion.bukkit.platform;
|
2016-09-25 15:39:37 +02:00
|
|
|
|
2021-04-27 13:41:39 +02:00
|
|
|
import com.viaversion.viaversion.ViaAPIBase;
|
2021-04-26 20:52:34 +02:00
|
|
|
import com.viaversion.viaversion.ViaVersionPlugin;
|
|
|
|
import com.viaversion.viaversion.api.Via;
|
2021-04-26 21:35:29 +02:00
|
|
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
2021-04-26 20:52:34 +02:00
|
|
|
import com.viaversion.viaversion.bukkit.util.ProtocolSupportUtil;
|
2021-04-27 13:41:39 +02:00
|
|
|
import io.netty.buffer.ByteBuf;
|
2023-02-12 11:44:25 +01:00
|
|
|
import java.util.UUID;
|
2021-04-27 13:41:39 +02:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.entity.Player;
|
2016-09-25 15:39:37 +02:00
|
|
|
|
2021-03-22 23:06:40 +01:00
|
|
|
public class BukkitViaAPI extends ViaAPIBase<Player> {
|
2019-08-23 22:13:37 +02:00
|
|
|
private final ViaVersionPlugin plugin;
|
2016-09-25 15:39:37 +02:00
|
|
|
|
2020-02-10 10:05:56 +01:00
|
|
|
public BukkitViaAPI(ViaVersionPlugin plugin) {
|
|
|
|
this.plugin = plugin;
|
|
|
|
}
|
|
|
|
|
2016-09-25 15:39:37 +02:00
|
|
|
@Override
|
2020-04-13 20:58:24 +02:00
|
|
|
public int getPlayerVersion(Player player) {
|
2020-02-10 10:05:56 +01:00
|
|
|
return getPlayerVersion(player.getUniqueId());
|
2016-09-25 15:39:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-04-13 20:58:24 +02:00
|
|
|
public int getPlayerVersion(UUID uuid) {
|
2021-03-24 15:21:18 +01:00
|
|
|
UserConnection connection = Via.getManager().getConnectionManager().getConnectedClient(uuid);
|
2022-11-10 13:32:25 +01:00
|
|
|
if (connection != null) {
|
|
|
|
return connection.getProtocolInfo().getProtocolVersion();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isProtocolSupport()) {
|
2021-01-17 13:59:26 +01:00
|
|
|
Player player = Bukkit.getPlayer(uuid);
|
2022-11-10 13:32:25 +01:00
|
|
|
if (player != null) {
|
2021-01-17 13:59:26 +01:00
|
|
|
return ProtocolSupportUtil.getProtocolVersion(player);
|
|
|
|
}
|
2016-09-25 15:39:37 +02:00
|
|
|
}
|
2022-11-10 13:32:25 +01:00
|
|
|
return -1;
|
2016-09-25 15:39:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void sendRawPacket(Player player, ByteBuf packet) throws IllegalArgumentException {
|
|
|
|
sendRawPacket(player.getUniqueId(), packet);
|
|
|
|
}
|
|
|
|
|
2020-02-10 10:05:56 +01:00
|
|
|
/**
|
|
|
|
* Returns if ProtocolSupport is also being used.
|
|
|
|
*
|
|
|
|
* @return true if ProtocolSupport is used
|
|
|
|
*/
|
2016-09-25 15:39:37 +02:00
|
|
|
public boolean isProtocolSupport() {
|
|
|
|
return plugin.isProtocolSupport();
|
|
|
|
}
|
|
|
|
}
|