blob: 5b6a54dfccc748bddbe3257cd2b60c00d6892977 [file] [log] [blame] [raw]
/*
* 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 us.myles.ViaVersion.api;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.UUID;
public abstract class ViaAPIBase<T> implements ViaAPI<T> {
@Override
public int getServerVersion() {
return ProtocolRegistry.SERVER_PROTOCOL;
}
@Override
public int getPlayerVersion(UUID uuid) {
UserConnection connection = Via.getManager().getConnection(uuid);
return connection != null ? connection.getProtocolInfo().getProtocolVersion() : -1;
}
@Override
public String getVersion() {
return Via.getPlatform().getPluginVersion();
}
@Override
public boolean isInjected(UUID playerUUID) {
return Via.getManager().isClientConnected(playerUUID);
}
@Override
public void sendRawPacket(UUID uuid, ByteBuf packet) throws IllegalArgumentException {
if (!isInjected(uuid)) {
throw new IllegalArgumentException("This player is not controlled by ViaVersion!");
}
UserConnection user = Via.getManager().getConnection(uuid);
user.sendRawPacket(packet);
}
@Override
public SortedSet<Integer> getSupportedVersions() {
SortedSet<Integer> outputSet = new TreeSet<>(ProtocolRegistry.getSupportedVersions());
outputSet.removeAll(Via.getPlatform().getConf().getBlockedProtocols());
return outputSet;
}
@Override
public SortedSet<Integer> getFullSupportedVersions() {
return ProtocolRegistry.getSupportedVersions();
}
}