Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-20 06:50:08 +01:00
Port Bukkit listeners to Sponge
Dieser Commit ist enthalten in:
Ursprung
8b9a1750de
Commit
51c469882b
1
TODOLIST
1
TODOLIST
@ -2,6 +2,5 @@ PORT STUFF TO GUAVA :D (so we dont need to include commons)
|
|||||||
Stop using new Gson() everywhere
|
Stop using new Gson() everywhere
|
||||||
Java docs (for platforms etc)
|
Java docs (for platforms etc)
|
||||||
Add comments to sponge api
|
Add comments to sponge api
|
||||||
Port bukkit listeners to sponge maybe
|
|
||||||
Fix task ids, methods for sponge
|
Fix task ids, methods for sponge
|
||||||
Find all the TODO's and check they're done.
|
Find all the TODO's and check they're done.
|
@ -18,7 +18,6 @@ import us.myles.ViaVersion.bukkit.*;
|
|||||||
import us.myles.ViaVersion.classgenerator.ClassGenerator;
|
import us.myles.ViaVersion.classgenerator.ClassGenerator;
|
||||||
import us.myles.ViaVersion.dump.PluginInfo;
|
import us.myles.ViaVersion.dump.PluginInfo;
|
||||||
import us.myles.ViaVersion.util.NMSUtil;
|
import us.myles.ViaVersion.util.NMSUtil;
|
||||||
import us.myles.ViaVersion.util.ReflectionUtil;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -8,7 +8,6 @@ import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
|||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.MovementTracker;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.MovementTracker;
|
||||||
import us.myles.ViaVersion.util.NMSUtil;
|
import us.myles.ViaVersion.util.NMSUtil;
|
||||||
import us.myles.ViaVersion.util.ReflectionUtil;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
@ -9,7 +9,6 @@ import us.myles.ViaVersion.api.ViaVersion;
|
|||||||
import us.myles.ViaVersion.handlers.ViaDecodeHandler;
|
import us.myles.ViaVersion.handlers.ViaDecodeHandler;
|
||||||
import us.myles.ViaVersion.handlers.ViaEncodeHandler;
|
import us.myles.ViaVersion.handlers.ViaEncodeHandler;
|
||||||
import us.myles.ViaVersion.util.NMSUtil;
|
import us.myles.ViaVersion.util.NMSUtil;
|
||||||
import us.myles.ViaVersion.util.ReflectionUtil;
|
|
||||||
|
|
||||||
public class ClassGenerator {
|
public class ClassGenerator {
|
||||||
private static HandlerConstructor constructor = new BasicHandlerConstructor();
|
private static HandlerConstructor constructor = new BasicHandlerConstructor();
|
||||||
|
@ -0,0 +1,53 @@
|
|||||||
|
package us.myles.ViaVersion.listeners;
|
||||||
|
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NonNull;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||||
|
import us.myles.ViaVersion.api.ViaListener;
|
||||||
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
|
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||||
|
|
||||||
|
@Getter(AccessLevel.PROTECTED)
|
||||||
|
public class ViaBukkitListener extends ViaListener implements Listener {
|
||||||
|
private final Plugin plugin;
|
||||||
|
|
||||||
|
public ViaBukkitListener(ViaVersionPlugin plugin, Class<? extends Protocol> requiredPipeline) {
|
||||||
|
super(requiredPipeline);
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the UserConnection from a player
|
||||||
|
*
|
||||||
|
* @param player Player object
|
||||||
|
* @return The UserConnection
|
||||||
|
*/
|
||||||
|
protected UserConnection getUserConnection(@NonNull Player player) {
|
||||||
|
return getUserConnection(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the player is on the selected pipe
|
||||||
|
*
|
||||||
|
* @param player Player Object
|
||||||
|
* @return True if on pipe
|
||||||
|
*/
|
||||||
|
protected boolean isOnPipe(Player player) {
|
||||||
|
return isOnPipe(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register as Bukkit event
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void register() {
|
||||||
|
if (isRegistered()) return;
|
||||||
|
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||||
|
setRegistered(true);
|
||||||
|
}
|
||||||
|
}
|
@ -15,14 +15,15 @@ import org.bukkit.inventory.CraftingInventory;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.ViaListener;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
|
import us.myles.ViaVersion.listeners.ViaBukkitListener;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ArmorType;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ArmorType;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class ArmorListener extends ViaListener {
|
public class ArmorListener extends ViaBukkitListener {
|
||||||
|
|
||||||
private static final UUID ARMOR_ATTRIBUTE = UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150");
|
private static final UUID ARMOR_ATTRIBUTE = UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150");
|
||||||
|
|
||||||
@ -107,7 +108,7 @@ public class ArmorListener extends ViaListener {
|
|||||||
|
|
||||||
public void sendDelayedArmorUpdate(final Player player) {
|
public void sendDelayedArmorUpdate(final Player player) {
|
||||||
if (!isOnPipe(player)) return; // Don't start a task if the player is not on the pipe
|
if (!isOnPipe(player)) return; // Don't start a task if the player is not on the pipe
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(), new Runnable() {
|
Via.getPlatform().runSync(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
sendArmorUpdate(player);
|
sendArmorUpdate(player);
|
||||||
|
@ -5,12 +5,12 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||||
import us.myles.ViaVersion.api.ViaListener;
|
|
||||||
import us.myles.ViaVersion.api.minecraft.Position;
|
import us.myles.ViaVersion.api.minecraft.Position;
|
||||||
|
import us.myles.ViaVersion.listeners.ViaBukkitListener;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
|
||||||
|
|
||||||
public class BlockListener extends ViaListener {
|
public class BlockListener extends ViaBukkitListener {
|
||||||
|
|
||||||
public BlockListener(ViaVersionPlugin plugin) {
|
public BlockListener(ViaVersionPlugin plugin) {
|
||||||
super(plugin, Protocol1_9TO1_8.class);
|
super(plugin, Protocol1_9TO1_8.class);
|
||||||
|
@ -18,10 +18,10 @@ import org.spacehq.opennbt.tag.builtin.ByteTag;
|
|||||||
import org.spacehq.opennbt.tag.builtin.CompoundTag;
|
import org.spacehq.opennbt.tag.builtin.CompoundTag;
|
||||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.ViaListener;
|
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.minecraft.Position;
|
import us.myles.ViaVersion.api.minecraft.Position;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
|
import us.myles.ViaVersion.listeners.ViaBukkitListener;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
||||||
import us.myles.ViaVersion.util.NMSUtil;
|
import us.myles.ViaVersion.util.NMSUtil;
|
||||||
import us.myles.ViaVersion.util.ReflectionUtil;
|
import us.myles.ViaVersion.util.ReflectionUtil;
|
||||||
@ -30,7 +30,7 @@ import java.io.DataOutput;
|
|||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
public class CommandBlockListener extends ViaListener {
|
public class CommandBlockListener extends ViaBukkitListener {
|
||||||
|
|
||||||
public CommandBlockListener(ViaVersionPlugin plugin) {
|
public CommandBlockListener(ViaVersionPlugin plugin) {
|
||||||
super(plugin, Protocol1_9TO1_8.class);
|
super(plugin, Protocol1_9TO1_8.class);
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package us.myles.ViaVersion.listeners.protocol1_9to1_8;
|
package us.myles.ViaVersion.listeners.protocol1_9to1_8;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -8,12 +7,13 @@ import org.bukkit.event.EventPriority;
|
|||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.ViaListener;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.ViaVersion;
|
import us.myles.ViaVersion.api.ViaVersion;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
|
import us.myles.ViaVersion.listeners.ViaBukkitListener;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
||||||
|
|
||||||
public class DeathListener extends ViaListener {
|
public class DeathListener extends ViaBukkitListener {
|
||||||
public DeathListener(ViaVersionPlugin plugin) {
|
public DeathListener(ViaVersionPlugin plugin) {
|
||||||
super(plugin, Protocol1_9TO1_8.class);
|
super(plugin, Protocol1_9TO1_8.class);
|
||||||
}
|
}
|
||||||
@ -34,7 +34,7 @@ public class DeathListener extends ViaListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendPacket(final Player p, final String msg) {
|
private void sendPacket(final Player p, final String msg) {
|
||||||
Bukkit.getScheduler().runTask(getPlugin(), new Runnable() {
|
Via.getPlatform().runSync(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PacketWrapper wrapper = new PacketWrapper(0x2C, null, getUserConnection(p));
|
PacketWrapper wrapper = new PacketWrapper(0x2C, null, getUserConnection(p));
|
||||||
|
@ -6,10 +6,10 @@ import org.bukkit.block.BlockFace;
|
|||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||||
import us.myles.ViaVersion.api.ViaListener;
|
import us.myles.ViaVersion.listeners.ViaBukkitListener;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
||||||
|
|
||||||
public class PaperPatch extends ViaListener {
|
public class PaperPatch extends ViaBukkitListener {
|
||||||
|
|
||||||
public PaperPatch(ViaVersionPlugin plugin) {
|
public PaperPatch(ViaVersionPlugin plugin) {
|
||||||
super(plugin, Protocol1_9TO1_8.class);
|
super(plugin, Protocol1_9TO1_8.class);
|
||||||
|
@ -11,11 +11,11 @@ import us.myles.ViaVersion.api.ViaVersionConfig;
|
|||||||
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||||
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
|
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
|
||||||
import us.myles.ViaVersion.api.platform.ViaPlatform;
|
import us.myles.ViaVersion.api.platform.ViaPlatform;
|
||||||
import us.myles.ViaVersion.bungee.command.BungeeCommand;
|
|
||||||
import us.myles.ViaVersion.bungee.command.BungeeCommandHandler;
|
|
||||||
import us.myles.ViaVersion.bungee.BungeeViaAPI;
|
import us.myles.ViaVersion.bungee.BungeeViaAPI;
|
||||||
import us.myles.ViaVersion.bungee.BungeeViaInjector;
|
import us.myles.ViaVersion.bungee.BungeeViaInjector;
|
||||||
import us.myles.ViaVersion.bungee.BungeeViaLoader;
|
import us.myles.ViaVersion.bungee.BungeeViaLoader;
|
||||||
|
import us.myles.ViaVersion.bungee.command.BungeeCommand;
|
||||||
|
import us.myles.ViaVersion.bungee.command.BungeeCommandHandler;
|
||||||
import us.myles.ViaVersion.bungee.command.BungeeCommandSender;
|
import us.myles.ViaVersion.bungee.command.BungeeCommandSender;
|
||||||
import us.myles.ViaVersion.bungee.config.BungeeConfigAPI;
|
import us.myles.ViaVersion.bungee.config.BungeeConfigAPI;
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ public class BungeeViaInjector implements ViaInjector {
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void uninject() {
|
public void uninject() {
|
||||||
// TODO: Uninject from players currently online
|
// TODO: Uninject from players currently online
|
||||||
|
@ -2,8 +2,6 @@ package us.myles.ViaVersion.bungee.handlers;
|
|||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
|
||||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.protocol.MinecraftDecoder;
|
import net.md_5.bungee.protocol.MinecraftDecoder;
|
||||||
import net.md_5.bungee.protocol.Protocol;
|
import net.md_5.bungee.protocol.Protocol;
|
||||||
|
@ -2,7 +2,6 @@ package us.myles.ViaVersion.bungee.handlers;
|
|||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.MessageToByteEncoder;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.protocol.DefinedPacket;
|
import net.md_5.bungee.protocol.DefinedPacket;
|
||||||
import net.md_5.bungee.protocol.MinecraftEncoder;
|
import net.md_5.bungee.protocol.MinecraftEncoder;
|
||||||
|
@ -3,9 +3,6 @@ package us.myles.ViaVersion.bungee.handlers;
|
|||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.socket.SocketChannel;
|
import io.netty.channel.socket.SocketChannel;
|
||||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
|
||||||
import io.netty.handler.codec.MessageToByteEncoder;
|
|
||||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
|
||||||
import net.md_5.bungee.protocol.MinecraftDecoder;
|
import net.md_5.bungee.protocol.MinecraftDecoder;
|
||||||
import net.md_5.bungee.protocol.MinecraftEncoder;
|
import net.md_5.bungee.protocol.MinecraftEncoder;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
|
@ -2,14 +2,11 @@ package us.myles.ViaVersion.bungee.util;
|
|||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
|
||||||
import io.netty.handler.codec.MessageToByteEncoder;
|
import io.netty.handler.codec.MessageToByteEncoder;
|
||||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||||
import net.md_5.bungee.protocol.DefinedPacket;
|
import net.md_5.bungee.protocol.DefinedPacket;
|
||||||
import net.md_5.bungee.protocol.MinecraftDecoder;
|
import net.md_5.bungee.protocol.MinecraftDecoder;
|
||||||
import net.md_5.bungee.protocol.MinecraftEncoder;
|
import net.md_5.bungee.protocol.MinecraftEncoder;
|
||||||
import us.myles.ViaVersion.Bungee;
|
|
||||||
import us.myles.ViaVersion.util.PipelineUtil;
|
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
@ -36,6 +33,7 @@ public class BungeePipelineUtil {
|
|||||||
System.out.println("Netty issue?");
|
System.out.println("Netty issue?");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Object> callDecode(MessageToMessageDecoder decoder, ChannelHandlerContext ctx, Object input) throws InvocationTargetException {
|
public static List<Object> callDecode(MessageToMessageDecoder decoder, ChannelHandlerContext ctx, Object input) throws InvocationTargetException {
|
||||||
List<Object> output = new ArrayList<>();
|
List<Object> output = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
|
@ -1,12 +1,6 @@
|
|||||||
package us.myles.ViaVersion.api;
|
package us.myles.ViaVersion.api;
|
||||||
|
|
||||||
import lombok.AccessLevel;
|
import lombok.*;
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NonNull;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||||
@ -14,22 +8,12 @@ import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Getter(AccessLevel.PROTECTED)
|
@Getter(AccessLevel.PROTECTED)
|
||||||
|
@Setter(AccessLevel.PROTECTED)
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public abstract class ViaListener implements Listener {
|
public abstract class ViaListener {
|
||||||
private final ViaVersionPlugin plugin;
|
|
||||||
private final Class<? extends Protocol> requiredPipeline;
|
private final Class<? extends Protocol> requiredPipeline;
|
||||||
private boolean registered = false;
|
private boolean registered = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the UserConnection from a player
|
|
||||||
*
|
|
||||||
* @param player Player object
|
|
||||||
* @return The UserConnection
|
|
||||||
*/
|
|
||||||
protected UserConnection getUserConnection(@NonNull Player player) {
|
|
||||||
return getUserConnection(player.getUniqueId());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the UserConnection from an UUID
|
* Get the UserConnection from an UUID
|
||||||
*
|
*
|
||||||
@ -41,16 +25,6 @@ public abstract class ViaListener implements Listener {
|
|||||||
return Via.getManager().getConnection(uuid);
|
return Via.getManager().getConnection(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the player is on the selected pipe
|
|
||||||
*
|
|
||||||
* @param player Player Object
|
|
||||||
* @return True if on pipe
|
|
||||||
*/
|
|
||||||
protected boolean isOnPipe(Player player) {
|
|
||||||
return isOnPipe(player.getUniqueId());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the UUID is on the selected pipe
|
* Checks if the UUID is on the selected pipe
|
||||||
*
|
*
|
||||||
@ -64,12 +38,7 @@ public abstract class ViaListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register as Bukkit event
|
* Register the event
|
||||||
*/
|
*/
|
||||||
public void register() {
|
public abstract void register();
|
||||||
if (registered) return;
|
|
||||||
|
|
||||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
|
||||||
registered = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -9,27 +9,27 @@ import java.util.HashMap;
|
|||||||
@Getter
|
@Getter
|
||||||
public enum ArmorType {
|
public enum ArmorType {
|
||||||
|
|
||||||
LEATHER_HELMET(1, 298),
|
LEATHER_HELMET(1, 298, "minecraft:leather_helmet"),
|
||||||
LEATHER_CHESTPLATE(3, 299),
|
LEATHER_CHESTPLATE(3, 299, "minecraft:leather_chestplate"),
|
||||||
LEATHER_LEGGINGS(2, 300),
|
LEATHER_LEGGINGS(2, 300, "minecraft:leather_leggings"),
|
||||||
LEATHER_BOOTS(1, 301),
|
LEATHER_BOOTS(1, 301, "minecraft:leather_boots"),
|
||||||
CHAINMAIL_HELMET(2, 302),
|
CHAINMAIL_HELMET(2, 302, "minecraft:chainmail_helmet"),
|
||||||
CHAINMAIL_CHESTPLATE(5, 303),
|
CHAINMAIL_CHESTPLATE(5, 303, "minecraft:chainmail_chestplate"),
|
||||||
CHAINMAIL_LEGGINGS(4, 304),
|
CHAINMAIL_LEGGINGS(4, 304, "minecraft:chainmail_leggings"),
|
||||||
CHAINMAIL_BOOTS(1, 305),
|
CHAINMAIL_BOOTS(1, 305, "minecraft:chainmail_boots"),
|
||||||
IRON_HELMET(2, 306),
|
IRON_HELMET(2, 306, "minecraft:iron_helmet"),
|
||||||
IRON_CHESTPLATE(6, 307),
|
IRON_CHESTPLATE(6, 307, "minecraft:iron_chestplate"),
|
||||||
IRON_LEGGINGS(5, 308),
|
IRON_LEGGINGS(5, 308, "minecraft:iron_leggings"),
|
||||||
IRON_BOOTS(2, 309),
|
IRON_BOOTS(2, 309, "minecraft:iron_boots"),
|
||||||
DIAMOND_HELMET(3, 310),
|
DIAMOND_HELMET(3, 310, "minecraft:diamond_helmet"),
|
||||||
DIAMOND_CHESTPLATE(8, 311),
|
DIAMOND_CHESTPLATE(8, 311, "minecraft:diamond_chestplate"),
|
||||||
DIAMOND_LEGGINGS(6, 312),
|
DIAMOND_LEGGINGS(6, 312, "minecraft:diamond_leggings"),
|
||||||
DIAMOND_BOOTS(3, 313),
|
DIAMOND_BOOTS(3, 313, "minecraft:diamond_boots"),
|
||||||
GOLD_HELMET(2, 314),
|
GOLD_HELMET(2, 314, "minecraft:gold_helmet"),
|
||||||
GOLD_CHESTPLATE(5, 315),
|
GOLD_CHESTPLATE(5, 315, "minecraft:gold_chestplate"),
|
||||||
GOLD_LEGGINGS(3, 316),
|
GOLD_LEGGINGS(3, 316, "minecraft:gold_leggings"),
|
||||||
GOLD_BOOTS(1, 317),
|
GOLD_BOOTS(1, 317, "minecraft:gold_boots"),
|
||||||
NONE(0, 0);
|
NONE(0, 0, "none");
|
||||||
|
|
||||||
private static HashMap<Integer, ArmorType> armor;
|
private static HashMap<Integer, ArmorType> armor;
|
||||||
|
|
||||||
@ -42,6 +42,7 @@ public enum ArmorType {
|
|||||||
|
|
||||||
private final int armorPoints;
|
private final int armorPoints;
|
||||||
private final int id;
|
private final int id;
|
||||||
|
private final String type;
|
||||||
|
|
||||||
public static ArmorType findById(int id) {
|
public static ArmorType findById(int id) {
|
||||||
for (ArmorType a : ArmorType.values())
|
for (ArmorType a : ArmorType.values())
|
||||||
@ -50,6 +51,13 @@ public enum ArmorType {
|
|||||||
return ArmorType.NONE;
|
return ArmorType.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ArmorType findByType(String type) {
|
||||||
|
for (ArmorType a : ArmorType.values())
|
||||||
|
if (a.getType().equals(type))
|
||||||
|
return a;
|
||||||
|
return NONE;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isArmor(int id) {
|
public static boolean isArmor(int id) {
|
||||||
for (ArmorType a : ArmorType.values())
|
for (ArmorType a : ArmorType.values())
|
||||||
if (a.getId() == id)
|
if (a.getId() == id)
|
||||||
@ -57,13 +65,11 @@ public enum ArmorType {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int calculateArmorPoints(int[] armor) {
|
public static boolean isArmor(String type) {
|
||||||
int total = 0;
|
for (ArmorType a : ArmorType.values())
|
||||||
for (int anArmor : armor) {
|
if (a.getType().equals(type))
|
||||||
if (anArmor != -1)
|
return true;
|
||||||
total += findById(anArmor).getArmorPoints();
|
return false;
|
||||||
}
|
|
||||||
return total;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
|
@ -64,7 +64,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spongepowered</groupId>
|
<groupId>org.spongepowered</groupId>
|
||||||
<artifactId>spongeapi</artifactId>
|
<artifactId>spongeapi</artifactId>
|
||||||
<version>4.1.0</version>
|
<version>LATEST</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -3,15 +3,11 @@ package us.myles.ViaVersion;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
|
|
||||||
import ninja.leaping.configurate.loader.ConfigurationLoader;
|
|
||||||
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
|
|
||||||
import org.spongepowered.api.Game;
|
import org.spongepowered.api.Game;
|
||||||
import org.spongepowered.api.config.DefaultConfig;
|
import org.spongepowered.api.config.DefaultConfig;
|
||||||
import org.spongepowered.api.entity.living.player.Player;
|
import org.spongepowered.api.entity.living.player.Player;
|
||||||
import org.spongepowered.api.event.Listener;
|
import org.spongepowered.api.event.Listener;
|
||||||
import org.spongepowered.api.event.game.state.GameAboutToStartServerEvent;
|
import org.spongepowered.api.event.game.state.GameAboutToStartServerEvent;
|
||||||
import org.spongepowered.api.event.game.state.GameStartedServerEvent;
|
|
||||||
import org.spongepowered.api.plugin.Plugin;
|
import org.spongepowered.api.plugin.Plugin;
|
||||||
import org.spongepowered.api.plugin.PluginContainer;
|
import org.spongepowered.api.plugin.PluginContainer;
|
||||||
import org.spongepowered.api.scheduler.SpongeExecutorService;
|
import org.spongepowered.api.scheduler.SpongeExecutorService;
|
||||||
|
@ -3,7 +3,6 @@ package us.myles.ViaVersion.sponge;
|
|||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.spongepowered.api.command.CommandSource;
|
import org.spongepowered.api.command.CommandSource;
|
||||||
import org.spongepowered.api.entity.living.player.Player;
|
import org.spongepowered.api.entity.living.player.Player;
|
||||||
import org.spongepowered.api.text.serializer.TextSerializer;
|
|
||||||
import org.spongepowered.api.text.serializer.TextSerializers;
|
import org.spongepowered.api.text.serializer.TextSerializers;
|
||||||
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||||
|
|
||||||
|
@ -6,7 +6,10 @@ import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
|
|||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class SpongeConfigAPI implements ViaVersionConfig, ConfigurationProvider {
|
public class SpongeConfigAPI implements ViaVersionConfig, ConfigurationProvider {
|
||||||
private final File defaultConfig;
|
private final File defaultConfig;
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
package us.myles.ViaVersion.sponge;
|
package us.myles.ViaVersion.sponge;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import org.spongepowered.api.entity.living.player.Player;
|
import org.spongepowered.api.entity.living.player.Player;
|
||||||
import us.myles.ViaVersion.SpongePlugin;
|
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.ViaAPI;
|
import us.myles.ViaVersion.api.ViaAPI;
|
||||||
import us.myles.ViaVersion.api.boss.BossBar;
|
import us.myles.ViaVersion.api.boss.BossBar;
|
||||||
|
@ -10,8 +10,8 @@ import us.myles.ViaVersion.api.Pair;
|
|||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.platform.ViaInjector;
|
import us.myles.ViaVersion.api.platform.ViaInjector;
|
||||||
import us.myles.ViaVersion.sponge.handlers.ViaVersionInitializer;
|
import us.myles.ViaVersion.sponge.handlers.ViaVersionInitializer;
|
||||||
import us.myles.ViaVersion.util.ReflectionUtil;
|
|
||||||
import us.myles.ViaVersion.util.ListWrapper;
|
import us.myles.ViaVersion.util.ListWrapper;
|
||||||
|
import us.myles.ViaVersion.util.ReflectionUtil;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
@ -9,6 +9,10 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTransla
|
|||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
|
||||||
import us.myles.ViaVersion.sponge.listeners.ClientLeaveListener;
|
import us.myles.ViaVersion.sponge.listeners.ClientLeaveListener;
|
||||||
import us.myles.ViaVersion.sponge.listeners.UpdateListener;
|
import us.myles.ViaVersion.sponge.listeners.UpdateListener;
|
||||||
|
import us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.ArmorListener;
|
||||||
|
import us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.BlockListener;
|
||||||
|
import us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.CommandBlockListener;
|
||||||
|
import us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.DeathListener;
|
||||||
import us.myles.ViaVersion.sponge.providers.SpongeViaBulkChunkTranslator;
|
import us.myles.ViaVersion.sponge.providers.SpongeViaBulkChunkTranslator;
|
||||||
import us.myles.ViaVersion.sponge.providers.SpongeViaMovementTransmitter;
|
import us.myles.ViaVersion.sponge.providers.SpongeViaMovementTransmitter;
|
||||||
|
|
||||||
@ -25,15 +29,11 @@ public class SpongeViaLoader implements ViaPlatformLoader {
|
|||||||
Sponge.getEventManager().registerListeners(plugin, new ClientLeaveListener());
|
Sponge.getEventManager().registerListeners(plugin, new ClientLeaveListener());
|
||||||
// /* 1.9 client to 1.8 server */
|
// /* 1.9 client to 1.8 server */
|
||||||
//
|
//
|
||||||
// new ArmorListener(plugin).register();
|
new ArmorListener(plugin).register();
|
||||||
// new CommandBlockListener(plugin).register();
|
new CommandBlockListener(plugin).register();
|
||||||
// new DeathListener(plugin).register();
|
new DeathListener(plugin).register();
|
||||||
// new BlockListener(plugin).register();
|
new BlockListener(plugin).register();
|
||||||
//
|
|
||||||
// if (Bukkit.getVersion().toLowerCase().contains("paper") || Bukkit.getVersion().toLowerCase().contains("taco")) {
|
|
||||||
// plugin.getLogger().info("Enabling PaperSpigot/TacoSpigot patch: Fixes block placement.");
|
|
||||||
// new PaperPatch(plugin).register();
|
|
||||||
// }
|
|
||||||
// if (plugin.getConf().isItemCache()) {
|
// if (plugin.getConf().isItemCache()) {
|
||||||
// new HandItemCache().runTaskTimerAsynchronously(plugin, 2L, 2L); // Updates player's items :)
|
// new HandItemCache().runTaskTimerAsynchronously(plugin, 2L, 2L); // Updates player's items :)
|
||||||
// HandItemCache.CACHE = true;
|
// HandItemCache.CACHE = true;
|
||||||
|
@ -4,7 +4,6 @@ import io.netty.buffer.ByteBuf;
|
|||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.Via;
|
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.exception.CancelException;
|
import us.myles.ViaVersion.exception.CancelException;
|
||||||
|
@ -4,7 +4,6 @@ import io.netty.buffer.ByteBuf;
|
|||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.MessageToByteEncoder;
|
import io.netty.handler.codec.MessageToByteEncoder;
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.Via;
|
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.exception.CancelException;
|
import us.myles.ViaVersion.exception.CancelException;
|
||||||
@ -12,7 +11,6 @@ import us.myles.ViaVersion.packets.Direction;
|
|||||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||||
import us.myles.ViaVersion.util.PipelineUtil;
|
import us.myles.ViaVersion.util.PipelineUtil;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
public class ViaEncodeHandler extends MessageToByteEncoder {
|
public class ViaEncodeHandler extends MessageToByteEncoder {
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
package us.myles.ViaVersion.sponge.listeners;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.spongepowered.api.Sponge;
|
||||||
|
import org.spongepowered.api.entity.living.player.Player;
|
||||||
|
import us.myles.ViaVersion.SpongePlugin;
|
||||||
|
import us.myles.ViaVersion.api.Via;
|
||||||
|
import us.myles.ViaVersion.api.ViaListener;
|
||||||
|
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
public class ViaSpongeListener extends ViaListener {
|
||||||
|
private static Field entityIdField;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final SpongePlugin plugin;
|
||||||
|
|
||||||
|
public ViaSpongeListener(SpongePlugin plugin, Class<? extends Protocol> requiredPipeline) {
|
||||||
|
super(requiredPipeline);
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void register() {
|
||||||
|
if (isRegistered()) return;
|
||||||
|
|
||||||
|
Sponge.getEventManager().registerListeners(plugin, this);
|
||||||
|
setRegistered(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hey sponge, please create a getEntityId method :'(
|
||||||
|
protected int getEntityId(Player p) {
|
||||||
|
try {
|
||||||
|
if (entityIdField == null) {
|
||||||
|
entityIdField = p.getClass().getSuperclass().getSuperclass().getSuperclass().getDeclaredField("field_145783_c");
|
||||||
|
entityIdField.setAccessible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return entityIdField.getInt(p);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Via.getPlatform().getLogger().severe("Could not get the entity id, please report this on our Github");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
Via.getPlatform().getLogger().severe("Could not get the entity id, please report this on our Github");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,114 @@
|
|||||||
|
package us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8;
|
||||||
|
|
||||||
|
import org.spongepowered.api.entity.living.player.Player;
|
||||||
|
import org.spongepowered.api.event.Listener;
|
||||||
|
import org.spongepowered.api.event.action.InteractEvent;
|
||||||
|
import org.spongepowered.api.event.entity.living.humanoid.player.RespawnPlayerEvent;
|
||||||
|
import org.spongepowered.api.event.filter.cause.Root;
|
||||||
|
import org.spongepowered.api.event.item.inventory.ClickInventoryEvent;
|
||||||
|
import org.spongepowered.api.event.network.ClientConnectionEvent;
|
||||||
|
import org.spongepowered.api.item.inventory.ItemStack;
|
||||||
|
import org.spongepowered.api.item.inventory.transaction.SlotTransaction;
|
||||||
|
import us.myles.ViaVersion.SpongePlugin;
|
||||||
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
|
import us.myles.ViaVersion.api.Via;
|
||||||
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ArmorType;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
||||||
|
import us.myles.ViaVersion.sponge.listeners.ViaSpongeListener;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class ArmorListener extends ViaSpongeListener {
|
||||||
|
private static final UUID ARMOR_ATTRIBUTE = UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150");
|
||||||
|
|
||||||
|
public ArmorListener(SpongePlugin plugin) {
|
||||||
|
super(plugin, Protocol1_9TO1_8.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
public void sendArmorUpdate(Player player) {
|
||||||
|
// Ensure that the player is on our pipe
|
||||||
|
if (!isOnPipe(player.getUniqueId())) return;
|
||||||
|
|
||||||
|
|
||||||
|
int armor = 0;
|
||||||
|
|
||||||
|
// TODO is there a method like getArmorContents?
|
||||||
|
armor += calculate(player.getHelmet());
|
||||||
|
armor += calculate(player.getChestplate());
|
||||||
|
armor += calculate(player.getLeggings());
|
||||||
|
armor += calculate(player.getBoots());
|
||||||
|
|
||||||
|
PacketWrapper wrapper = new PacketWrapper(0x4B, null, getUserConnection(player.getUniqueId()));
|
||||||
|
try {
|
||||||
|
wrapper.write(Type.VAR_INT, getEntityId(player)); // Player ID
|
||||||
|
wrapper.write(Type.INT, 1); // only 1 property
|
||||||
|
wrapper.write(Type.STRING, "generic.armor");
|
||||||
|
wrapper.write(Type.DOUBLE, 0D); //default 0 armor
|
||||||
|
wrapper.write(Type.VAR_INT, 1); // 1 modifier
|
||||||
|
wrapper.write(Type.UUID, ARMOR_ATTRIBUTE); // armor modifier uuid
|
||||||
|
wrapper.write(Type.DOUBLE, (double) armor); // the modifier value
|
||||||
|
wrapper.write(Type.BYTE, (byte) 0);// the modifier operation, 0 is add number
|
||||||
|
|
||||||
|
wrapper.send(Protocol1_9TO1_8.class);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int calculate(Optional<ItemStack> itemStack) {
|
||||||
|
if (itemStack.isPresent())
|
||||||
|
return ArmorType.findByType(itemStack.get().getItem().getType().getId()).getArmorPoints();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Listener
|
||||||
|
public void onInventoryClick(ClickInventoryEvent e, @Root Player player) {
|
||||||
|
for (SlotTransaction transaction : e.getTransactions()) {
|
||||||
|
if (ArmorType.isArmor(transaction.getFinal().getType().getId()) ||
|
||||||
|
ArmorType.isArmor(e.getCursorTransaction().getFinal().getType().getId())) {
|
||||||
|
sendDelayedArmorUpdate(player);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Listener
|
||||||
|
public void onInteract(InteractEvent event, @Root Player player) {
|
||||||
|
if (player.getItemInHand().isPresent()) {
|
||||||
|
if (ArmorType.isArmor(player.getItemInHand().get().getItem().getId()))
|
||||||
|
sendDelayedArmorUpdate(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Listener
|
||||||
|
public void onJoin(ClientConnectionEvent.Join e) {
|
||||||
|
sendArmorUpdate(e.getTargetEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Listener
|
||||||
|
public void onRespawn(RespawnPlayerEvent e) {
|
||||||
|
if (!isOnPipe(e.getTargetEntity().getUniqueId())) return;
|
||||||
|
|
||||||
|
sendDelayedArmorUpdate(e.getTargetEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO find world change event
|
||||||
|
// @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
|
// public void onWorldChange(PlayerChangedWorldEvent e) {
|
||||||
|
// sendArmorUpdate(e.getPlayer());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
public void sendDelayedArmorUpdate(final Player player) {
|
||||||
|
if (!isOnPipe(player.getUniqueId())) return; // Don't start a task if the player is not on the pipe
|
||||||
|
Via.getPlatform().runSync(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
sendArmorUpdate(player);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8;
|
||||||
|
|
||||||
|
import org.spongepowered.api.entity.living.player.Player;
|
||||||
|
import org.spongepowered.api.event.Listener;
|
||||||
|
import org.spongepowered.api.event.block.ChangeBlockEvent;
|
||||||
|
import org.spongepowered.api.event.filter.cause.Root;
|
||||||
|
import org.spongepowered.api.world.Location;
|
||||||
|
import us.myles.ViaVersion.SpongePlugin;
|
||||||
|
import us.myles.ViaVersion.api.minecraft.Position;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
|
||||||
|
import us.myles.ViaVersion.sponge.listeners.ViaSpongeListener;
|
||||||
|
|
||||||
|
public class BlockListener extends ViaSpongeListener {
|
||||||
|
|
||||||
|
public BlockListener(SpongePlugin plugin) {
|
||||||
|
super(plugin, Protocol1_9TO1_8.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Listener // TODO is there better way to do this?
|
||||||
|
public void placeBlock(ChangeBlockEvent.Place e, @Root Player player) {
|
||||||
|
if (isOnPipe(player.getUniqueId())) {
|
||||||
|
Location loc = e.getTransactions().get(0).getFinal().getLocation().get();
|
||||||
|
getUserConnection(player.getUniqueId())
|
||||||
|
.get(EntityTracker.class)
|
||||||
|
.addBlockInteraction(new Position((long) loc.getX(), (long) loc.getY(), (long) loc.getZ()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,156 @@
|
|||||||
|
package us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.ByteBufOutputStream;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
import org.spacehq.opennbt.tag.builtin.ByteTag;
|
||||||
|
import org.spacehq.opennbt.tag.builtin.CompoundTag;
|
||||||
|
import org.spongepowered.api.Sponge;
|
||||||
|
import org.spongepowered.api.block.tileentity.CommandBlock;
|
||||||
|
import org.spongepowered.api.block.tileentity.TileEntity;
|
||||||
|
import org.spongepowered.api.entity.living.player.Player;
|
||||||
|
import org.spongepowered.api.event.Listener;
|
||||||
|
import org.spongepowered.api.event.block.InteractBlockEvent;
|
||||||
|
import org.spongepowered.api.event.entity.living.humanoid.player.RespawnPlayerEvent;
|
||||||
|
import org.spongepowered.api.event.filter.cause.Root;
|
||||||
|
import org.spongepowered.api.event.network.ClientConnectionEvent;
|
||||||
|
import org.spongepowered.api.world.Location;
|
||||||
|
import org.spongepowered.api.world.World;
|
||||||
|
import us.myles.ViaVersion.SpongePlugin;
|
||||||
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
|
import us.myles.ViaVersion.api.minecraft.Position;
|
||||||
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
||||||
|
import us.myles.ViaVersion.sponge.listeners.ViaSpongeListener;
|
||||||
|
import us.myles.ViaVersion.util.ReflectionUtil;
|
||||||
|
|
||||||
|
import java.io.DataOutput;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
// TODO Change to bytebuf to not use reflection bullshit?
|
||||||
|
public class CommandBlockListener extends ViaSpongeListener {
|
||||||
|
public CommandBlockListener(SpongePlugin plugin) {
|
||||||
|
super(plugin, Protocol1_9TO1_8.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Listener
|
||||||
|
public void onJoin(ClientConnectionEvent.Join e) {
|
||||||
|
sendOp(e.getTargetEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Listener
|
||||||
|
public void onRespawn(RespawnPlayerEvent e) {
|
||||||
|
if (!isOnPipe(e.getTargetEntity().getUniqueId())) return;
|
||||||
|
|
||||||
|
Sponge.getScheduler().createTaskBuilder().delayTicks(1).execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
sendOp(e.getTargetEntity());
|
||||||
|
}
|
||||||
|
}).submit(getPlugin());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Listener
|
||||||
|
public void onInteract(InteractBlockEvent e, @Root Player player) {
|
||||||
|
Optional<Location<World>> location = e.getTargetBlock().getLocation();
|
||||||
|
if (!location.isPresent()) return;
|
||||||
|
Optional<TileEntity> optTile = location.get().getTileEntity();
|
||||||
|
if (!optTile.isPresent()) return;
|
||||||
|
TileEntity block = optTile.get();
|
||||||
|
if (block instanceof CommandBlock) {
|
||||||
|
CommandBlock cmd = (CommandBlock) block;
|
||||||
|
try {
|
||||||
|
sendCommandBlockPacket(cmd, player);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO Change world
|
||||||
|
// @EventHandler(priority = EventPriority.MONITOR)
|
||||||
|
// public void onWorldChange(PlayerChangedWorldEvent e) {
|
||||||
|
// sendOp(e.getPlayer());
|
||||||
|
// }
|
||||||
|
|
||||||
|
// @EventHandler(ignoreCancelled = true)
|
||||||
|
// public void onInteract(PlayerInteractEvent e) {
|
||||||
|
// if (e.getAction() == Action.RIGHT_CLICK_BLOCK && isOnPipe(e.getPlayer()) && e.getPlayer().isOp()) {
|
||||||
|
// try {
|
||||||
|
// sendCommandBlockPacket(e.getClickedBlock(), e.getPlayer());
|
||||||
|
// } catch (Exception ex) {
|
||||||
|
// ex.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
private void sendOp(Player p) {
|
||||||
|
// TODO Is there an isOp check?
|
||||||
|
if (p.hasPermission("viaversion.commandblocks") && isOnPipe(p.getUniqueId())) {
|
||||||
|
try {
|
||||||
|
PacketWrapper wrapper = new PacketWrapper(0x1B, null, getUserConnection(p.getUniqueId())); // Entity status
|
||||||
|
|
||||||
|
wrapper.write(Type.INT, getEntityId(p)); // Entity ID
|
||||||
|
wrapper.write(Type.BYTE, (byte) 26); //Hardcoded op permission level
|
||||||
|
|
||||||
|
wrapper.send(Protocol1_9TO1_8.class);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendCommandBlockPacket(CommandBlock b, Player player) throws Exception {
|
||||||
|
Method m = b.getClass().getDeclaredMethod("func_145844_m");
|
||||||
|
m.setAccessible(true);
|
||||||
|
|
||||||
|
Object updatePacket = m.invoke(b);
|
||||||
|
|
||||||
|
PacketWrapper wrapper = generatePacket(updatePacket, getUserConnection(player.getUniqueId()));
|
||||||
|
wrapper.send(Protocol1_9TO1_8.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
private PacketWrapper generatePacket(Object updatePacket, UserConnection usr) throws Exception {
|
||||||
|
PacketWrapper wrapper = new PacketWrapper(0x09, null, usr); // Update block entity
|
||||||
|
|
||||||
|
long[] pos = getPosition(ReflectionUtil.get(updatePacket, "field_179824_a", Class.forName("net.minecraft.util.BlockPos")));
|
||||||
|
|
||||||
|
wrapper.write(Type.POSITION, new Position(pos[0], pos[1], pos[2])); //Block position
|
||||||
|
wrapper.write(Type.BYTE, (byte) 2); // Action id always 2
|
||||||
|
|
||||||
|
CompoundTag nbt = getNBT(ReflectionUtil.get(updatePacket, "field_148860_e", Class.forName("net.minecraft.nbt.NBTTagCompound")));
|
||||||
|
if (nbt == null) {
|
||||||
|
wrapper.write(Type.BYTE, (byte) 0); //If nbt is null. Use 0 as nbt
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
nbt.put(new ByteTag("powered", (byte) 0));
|
||||||
|
nbt.put(new ByteTag("auto", (byte) 0));
|
||||||
|
nbt.put(new ByteTag("conditionMet", (byte) 0));
|
||||||
|
|
||||||
|
wrapper.write(Type.NBT, nbt); // NBT TAG
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
private long[] getPosition(Object obj) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
|
||||||
|
return new long[]{
|
||||||
|
(long) ReflectionUtil.getSuper(obj, "field_177962_a", int.class), //X
|
||||||
|
(long) ReflectionUtil.getSuper(obj, "field_177960_b", int.class), //Y
|
||||||
|
(long) ReflectionUtil.getSuper(obj, "field_177961_c", int.class) //Z
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private CompoundTag getNBT(Object obj) throws Exception {
|
||||||
|
ByteBuf buf = Unpooled.buffer();
|
||||||
|
Method m = Class.forName("net.minecraft.nbt.CompressedStreamTools").getMethod("func_74800_a", Class.forName("net.minecraft.nbt.NBTTagCompound"), DataOutput.class);
|
||||||
|
m.invoke(null, obj, new DataOutputStream(new ByteBufOutputStream(buf)));
|
||||||
|
try {
|
||||||
|
return Type.NBT.read(buf);
|
||||||
|
} finally {
|
||||||
|
buf.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
package us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8;
|
||||||
|
|
||||||
|
import org.spongepowered.api.entity.living.player.Player;
|
||||||
|
import org.spongepowered.api.event.Listener;
|
||||||
|
import org.spongepowered.api.event.Order;
|
||||||
|
import org.spongepowered.api.event.entity.DestructEntityEvent;
|
||||||
|
import org.spongepowered.api.world.World;
|
||||||
|
import us.myles.ViaVersion.SpongePlugin;
|
||||||
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
|
import us.myles.ViaVersion.api.Via;
|
||||||
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
||||||
|
import us.myles.ViaVersion.sponge.listeners.ViaSpongeListener;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class DeathListener extends ViaSpongeListener {
|
||||||
|
public DeathListener(SpongePlugin plugin) {
|
||||||
|
super(plugin, Protocol1_9TO1_8.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Listener(order = Order.LAST)
|
||||||
|
public void onDeath(DestructEntityEvent.Death e) {
|
||||||
|
if (!(e.getTargetEntity() instanceof Player))
|
||||||
|
return;
|
||||||
|
|
||||||
|
Player p = (Player) e.getTargetEntity();
|
||||||
|
if (isOnPipe(p.getUniqueId()) && Via.getConfig().isShowNewDeathMessages() && checkGamerule(p.getWorld())) {
|
||||||
|
sendPacket(p, e.getMessage().toPlain());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean checkGamerule(World w) {
|
||||||
|
Optional<String> gamerule = w.getGameRule("showDeathMessages");
|
||||||
|
|
||||||
|
if (gamerule.isPresent()) {
|
||||||
|
try {
|
||||||
|
return Boolean.parseBoolean(gamerule.get());
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendPacket(final Player p, final String msg) {
|
||||||
|
Via.getPlatform().runSync(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
PacketWrapper wrapper = new PacketWrapper(0x2C, null, getUserConnection(p.getUniqueId()));
|
||||||
|
try {
|
||||||
|
int entityId = getEntityId(p);
|
||||||
|
wrapper.write(Type.VAR_INT, 2); // Event - Entity dead
|
||||||
|
wrapper.write(Type.VAR_INT, entityId); // Player ID
|
||||||
|
wrapper.write(Type.INT, entityId); // Entity ID
|
||||||
|
Protocol1_9TO1_8.FIX_JSON.write(wrapper, msg); // Message
|
||||||
|
|
||||||
|
wrapper.send(Protocol1_9TO1_8.class);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren