3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-25 15:50:10 +01:00

Add packet sending to API

Dieser Commit ist enthalten in:
Myles 2016-03-04 19:24:44 +00:00
Ursprung 12df86a142
Commit f71e51c85e
3 geänderte Dateien mit 41 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -1,5 +1,7 @@
package us.myles.ViaVersion; package us.myles.ViaVersion;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -75,4 +77,9 @@ public class ConnectionInfo {
public void setActive(boolean active) { public void setActive(boolean active) {
this.active = active; this.active = active;
} }
public void sendRawPacket(ByteBuf packet) {
ChannelHandler handler = channel.pipeline().get("encoder");
channel.pipeline().context(handler).writeAndFlush(packet);
}
} }

Datei anzeigen

@ -1,5 +1,6 @@
package us.myles.ViaVersion; package us.myles.ViaVersion;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
@ -16,12 +17,12 @@ import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.ViaVersionAPI; import us.myles.ViaVersion.api.ViaVersionAPI;
import us.myles.ViaVersion.commands.ViaVersionCommand; import us.myles.ViaVersion.commands.ViaVersionCommand;
import us.myles.ViaVersion.handlers.ViaVersionInitializer; import us.myles.ViaVersion.handlers.ViaVersionInitializer;
import us.myles.ViaVersion.listeners.ArmorFix;
import us.myles.ViaVersion.util.ReflectionUtil; import us.myles.ViaVersion.util.ReflectionUtil;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -29,7 +30,7 @@ import java.util.concurrent.TimeUnit;
public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI { public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI {
private final Set<UUID> portedPlayers = Collections.newSetFromMap(new ConcurrentHashMap<UUID, Boolean>()); private final Map<UUID, ConnectionInfo> portedPlayers = new ConcurrentHashMap<UUID, ConnectionInfo>();
@Override @Override
public void onEnable() { public void onEnable() {
@ -50,9 +51,10 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI {
Bukkit.getPluginManager().registerEvents(new Listener() { Bukkit.getPluginManager().registerEvents(new Listener() {
@EventHandler @EventHandler
public void onPlayerQuit(PlayerQuitEvent e) { public void onPlayerQuit(PlayerQuitEvent e) {
setPorted(e.getPlayer().getUniqueId(), false); removePortedClient(e.getPlayer().getUniqueId());
} }
}, this); }, this);
Bukkit.getPluginManager().registerEvents(new ArmorFix(), this);
getCommand("viaversion").setExecutor(new ViaVersionCommand()); getCommand("viaversion").setExecutor(new ViaVersionCommand());
} }
@ -88,7 +90,7 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI {
@Override @Override
public boolean isPorted(Player player) { public boolean isPorted(Player player) {
return portedPlayers.contains(player.getUniqueId()); return portedPlayers.containsKey(player.getUniqueId());
} }
@Override @Override
@ -96,12 +98,18 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI {
return getDescription().getVersion(); return getDescription().getVersion();
} }
public void setPorted(UUID id, boolean value) { public void sendRawPacket(Player player, ByteBuf packet) throws IllegalArgumentException {
if (value) { if (!isPorted(player)) throw new IllegalArgumentException("This player is not on 1.9");
portedPlayers.add(id); ConnectionInfo ci = portedPlayers.get(player.getUniqueId());
} else { ci.sendRawPacket(packet);
portedPlayers.remove(id); }
}
public void addPortedClient(ConnectionInfo info) {
portedPlayers.put(info.getUUID(), info);
}
public void removePortedClient(UUID clientID) {
portedPlayers.remove(clientID);
} }
public static ItemStack getHandItem(final ConnectionInfo info) { public static ItemStack getHandItem(final ConnectionInfo info) {

Datei anzeigen

@ -1,13 +1,27 @@
package us.myles.ViaVersion.api; package us.myles.ViaVersion.api;
import io.netty.buffer.ByteBuf;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public interface ViaVersionAPI { public interface ViaVersionAPI {
/** /**
* Is player using 1.9? * Is player using 1.9?
* @param player * @param player
* @return * @return True if the client is on 1.9
*/ */
boolean isPorted(Player player); boolean isPorted(Player player);
/**
* Get the version of the plugin
* @return Plugin version
*/
String getVersion(); String getVersion();
/**
* Send a raw packet to the player (Use new IDs)
* @param player The player to send packet
* @param packet The packet, you need a VarInt ID then the packet contents.
* @throws IllegalArgumentException If not on 1.9 throws IllegalArg
*/
void sendRawPacket(Player player, ByteBuf packet) throws IllegalArgumentException;
} }