Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-26 00:00:28 +01:00
Add armour, based on HugoDaBoss code but modified to work correctly with shift click. Also fix small issue from last commit.
Dieser Commit ist enthalten in:
Ursprung
f71e51c85e
Commit
fb5dace6a6
@ -78,8 +78,13 @@ public class ConnectionInfo {
|
|||||||
this.active = active;
|
this.active = active;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendRawPacket(ByteBuf packet) {
|
public void sendRawPacket(final ByteBuf packet) {
|
||||||
ChannelHandler handler = channel.pipeline().get("encoder");
|
final ChannelHandler handler = channel.pipeline().get("encoder");
|
||||||
channel.pipeline().context(handler).writeAndFlush(packet);
|
channel.eventLoop().submit(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
channel.pipeline().context(handler).writeAndFlush(packet);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,9 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import us.myles.ViaVersion.api.ViaVersion;
|
import us.myles.ViaVersion.api.ViaVersion;
|
||||||
import us.myles.ViaVersion.api.ViaVersionAPI;
|
import us.myles.ViaVersion.api.ViaVersionAPI;
|
||||||
|
import us.myles.ViaVersion.armor.ArmorListener;
|
||||||
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;
|
||||||
@ -48,13 +48,16 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI {
|
|||||||
getLogger().severe("Unable to inject handlers, are you on 1.8? ");
|
getLogger().severe("Unable to inject handlers, are you on 1.8? ");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getPluginManager().registerEvents(new Listener() {
|
Bukkit.getPluginManager().registerEvents(new Listener() {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerQuit(PlayerQuitEvent e) {
|
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||||
removePortedClient(e.getPlayer().getUniqueId());
|
removePortedClient(e.getPlayer().getUniqueId());
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
Bukkit.getPluginManager().registerEvents(new ArmorFix(), this);
|
|
||||||
|
Bukkit.getPluginManager().registerEvents(new ArmorListener(this), this);
|
||||||
|
|
||||||
getCommand("viaversion").setExecutor(new ViaVersionCommand());
|
getCommand("viaversion").setExecutor(new ViaVersionCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
106
src/main/java/us/myles/ViaVersion/armor/ArmorListener.java
Normale Datei
106
src/main/java/us/myles/ViaVersion/armor/ArmorListener.java
Normale Datei
@ -0,0 +1,106 @@
|
|||||||
|
package us.myles.ViaVersion.armor;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.Action;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.inventory.CraftingInventory;
|
||||||
|
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||||
|
import us.myles.ViaVersion.api.ViaVersion;
|
||||||
|
import us.myles.ViaVersion.packets.PacketType;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static us.myles.ViaVersion.util.PacketUtil.*;
|
||||||
|
|
||||||
|
public class ArmorListener implements Listener {
|
||||||
|
|
||||||
|
private final ViaVersionPlugin plugin;
|
||||||
|
|
||||||
|
private static UUID armorAttribute = UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150");
|
||||||
|
|
||||||
|
public ArmorListener(ViaVersionPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
|
public void onInventoryClick(InventoryClickEvent e) {
|
||||||
|
HumanEntity human = e.getWhoClicked();
|
||||||
|
if (human instanceof Player && e.getInventory() instanceof CraftingInventory) {
|
||||||
|
final Player player = (Player) human;
|
||||||
|
if (ViaVersion.getInstance().isPorted(player)) {
|
||||||
|
if (e.getCurrentItem() != null) {
|
||||||
|
if (ArmorType.isArmor(e.getCurrentItem().getType())) {
|
||||||
|
sendDelayedArmorUpdate(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (e.getRawSlot() >= 5 && e.getRawSlot() <= 8) {
|
||||||
|
sendDelayedArmorUpdate(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
|
public void onInteract(PlayerInteractEvent e) {
|
||||||
|
if (e.getItem() != null) {
|
||||||
|
if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||||
|
if (ArmorType.isArmor(e.getMaterial())) {
|
||||||
|
final Player player = e.getPlayer();
|
||||||
|
// Due to odd bugs it's 3 ticks later
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (ViaVersion.getInstance().isPorted(player)) {
|
||||||
|
sendArmorUpdate(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 3L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
|
public void onJoin(PlayerJoinEvent e) {
|
||||||
|
sendDelayedArmorUpdate(e.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendDelayedArmorUpdate(final Player player) {
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (ViaVersion.getInstance().isPorted(player)) {
|
||||||
|
sendArmorUpdate(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendArmorUpdate(Player player) {
|
||||||
|
int armor = ArmorType.calculateArmorPoints(player.getInventory().getArmorContents());
|
||||||
|
|
||||||
|
ByteBuf buf = Unpooled.buffer();
|
||||||
|
writeVarInt(PacketType.PLAY_ENTITY_PROPERTIES.getNewPacketID(), buf);
|
||||||
|
writeVarInt(player.getEntityId(), buf);
|
||||||
|
buf.writeInt(1); // only 1 property
|
||||||
|
writeString("generic.armor", buf);
|
||||||
|
buf.writeDouble(0); //default 0 armor
|
||||||
|
writeVarInt(1, buf); // 1 modifier
|
||||||
|
writeUUID(armorAttribute, buf); // armor modifier uuid
|
||||||
|
buf.writeDouble((double) armor); // the modifier value
|
||||||
|
buf.writeByte(0); // the modifier operation, 0 is add number
|
||||||
|
|
||||||
|
ViaVersion.getInstance().sendRawPacket(player, buf);
|
||||||
|
}
|
||||||
|
}
|
91
src/main/java/us/myles/ViaVersion/armor/ArmorType.java
Normale Datei
91
src/main/java/us/myles/ViaVersion/armor/ArmorType.java
Normale Datei
@ -0,0 +1,91 @@
|
|||||||
|
package us.myles.ViaVersion.armor;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public enum ArmorType {
|
||||||
|
|
||||||
|
LEATHER_HELMET(1, 298, Material.LEATHER_HELMET),
|
||||||
|
LEATHER_CHESTPLATE(3, 299, Material.LEATHER_CHESTPLATE),
|
||||||
|
LEATHER_LEGGINGS(2, 300, Material.LEATHER_LEGGINGS),
|
||||||
|
LEATHER_BOOTS(1, 301, Material.LEATHER_BOOTS),
|
||||||
|
CHAINMAIL_HELMET(2, 302, Material.CHAINMAIL_HELMET),
|
||||||
|
CHAINMAIL_CHESTPLATE(5, 303, Material.CHAINMAIL_CHESTPLATE),
|
||||||
|
CHAINMAIL_LEGGINGS(4, 304, Material.CHAINMAIL_LEGGINGS),
|
||||||
|
CHAINMAIL_BOOTS(1, 305, Material.CHAINMAIL_BOOTS),
|
||||||
|
IRON_HELMET(2, 306, Material.IRON_HELMET),
|
||||||
|
IRON_CHESTPLATE(6, 307, Material.IRON_CHESTPLATE),
|
||||||
|
IRON_LEGGINGS(5, 308, Material.IRON_LEGGINGS),
|
||||||
|
IRON_BOOTS(2, 309, Material.IRON_BOOTS),
|
||||||
|
DIAMOND_HELMET(3, 310, Material.DIAMOND_HELMET),
|
||||||
|
DIAMOND_CHESTPLATE(8, 311, Material.DIAMOND_CHESTPLATE),
|
||||||
|
DIAMOND_LEGGINGS(6, 312, Material.DIAMOND_LEGGINGS),
|
||||||
|
DIAMOND_BOOTS(3, 313, Material.DIAMOND_BOOTS),
|
||||||
|
GOLD_HELMET(2, 314, Material.GOLD_HELMET),
|
||||||
|
GOLD_CHESTPLATE(5, 315, Material.GOLD_CHESTPLATE),
|
||||||
|
GOLD_LEGGINGS(3, 316, Material.GOLD_LEGGINGS),
|
||||||
|
GOLD_BOOTS(1, 317, Material.GOLD_BOOTS),
|
||||||
|
NONE(0, 0, Material.AIR);
|
||||||
|
|
||||||
|
private int armorpoints;
|
||||||
|
private int id;
|
||||||
|
private Material type;
|
||||||
|
|
||||||
|
ArmorType(int armor, int id, Material type) {
|
||||||
|
this.armorpoints = armor;
|
||||||
|
this.id = id;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getArmorPoints() {
|
||||||
|
return this.armorpoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Material getType() {
|
||||||
|
return this.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArmorType findByType(Material type) {
|
||||||
|
for(ArmorType a : ArmorType.values())
|
||||||
|
if(a.getType() == type)
|
||||||
|
return a;
|
||||||
|
return ArmorType.NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int calculateArmorPoints(ItemStack[] armor) {
|
||||||
|
int total = 0;
|
||||||
|
for(int i = 0; i < armor.length; i++) {
|
||||||
|
if(armor[i] != null)
|
||||||
|
total += findByType(armor[i].getType()).getArmorPoints();
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArmorType findById(int id) {
|
||||||
|
for(ArmorType a : ArmorType.values())
|
||||||
|
if(a.getId() == id)
|
||||||
|
return a;
|
||||||
|
return ArmorType.NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isArmor(Material material){
|
||||||
|
for(ArmorType a : ArmorType.values())
|
||||||
|
if(a.getType() == material)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int calculateArmorPoints(int[] armor) {
|
||||||
|
int total = 0;
|
||||||
|
for(int i = 0; i < armor.length; i++) {
|
||||||
|
if(armor[i] != -1)
|
||||||
|
total += findById(armor[i]).getArmorPoints();
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,26 +1,21 @@
|
|||||||
package us.myles.ViaVersion.transformers;
|
package us.myles.ViaVersion.transformers;
|
||||||
|
|
||||||
import com.avaje.ebeaninternal.server.cluster.Packet;
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.spacehq.opennbt.tag.builtin.ListTag;
|
|
||||||
import org.spacehq.opennbt.tag.builtin.StringTag;
|
|
||||||
import org.spacehq.opennbt.tag.builtin.Tag;
|
|
||||||
import us.myles.ViaVersion.CancelException;
|
import us.myles.ViaVersion.CancelException;
|
||||||
import us.myles.ViaVersion.ConnectionInfo;
|
import us.myles.ViaVersion.ConnectionInfo;
|
||||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||||
import us.myles.ViaVersion.slot.ItemSlotRewriter;
|
|
||||||
import us.myles.ViaVersion.packets.PacketType;
|
import us.myles.ViaVersion.packets.PacketType;
|
||||||
import us.myles.ViaVersion.packets.State;
|
import us.myles.ViaVersion.packets.State;
|
||||||
|
import us.myles.ViaVersion.slot.ItemSlotRewriter;
|
||||||
import us.myles.ViaVersion.util.PacketUtil;
|
import us.myles.ViaVersion.util.PacketUtil;
|
||||||
import us.myles.ViaVersion.util.ReflectionUtil;
|
import us.myles.ViaVersion.util.ReflectionUtil;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.nio.charset.Charset;
|
|
||||||
|
|
||||||
public class IncomingTransformer {
|
public class IncomingTransformer {
|
||||||
private final ConnectionInfo info;
|
private final ConnectionInfo info;
|
||||||
@ -108,6 +103,7 @@ public class IncomingTransformer {
|
|||||||
byte button = input.readByte();
|
byte button = input.readByte();
|
||||||
short action = input.readShort();
|
short action = input.readShort();
|
||||||
byte mode = input.readByte();
|
byte mode = input.readByte();
|
||||||
|
// if the action is on an elytra armour slot
|
||||||
if (slot == 45 && windowID == 0) {
|
if (slot == 45 && windowID == 0) {
|
||||||
try {
|
try {
|
||||||
Class<?> setSlot = ReflectionUtil.nms("PacketPlayOutSetSlot");
|
Class<?> setSlot = ReflectionUtil.nms("PacketPlayOutSetSlot");
|
||||||
|
@ -1,17 +1,12 @@
|
|||||||
package us.myles.ViaVersion.transformers;
|
package us.myles.ViaVersion.transformers;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.parser.JSONParser;
|
||||||
import org.json.simple.parser.ParseException;
|
import org.json.simple.parser.ParseException;
|
||||||
import org.spacehq.mc.protocol.data.game.chunk.Column;
|
import org.spacehq.mc.protocol.data.game.chunk.Column;
|
||||||
import org.spacehq.mc.protocol.util.NetUtil;
|
import org.spacehq.mc.protocol.util.NetUtil;
|
||||||
import org.spacehq.opennbt.tag.builtin.ListTag;
|
|
||||||
import org.spacehq.opennbt.tag.builtin.StringTag;
|
|
||||||
import org.spacehq.opennbt.tag.builtin.Tag;
|
|
||||||
import us.myles.ViaVersion.CancelException;
|
import us.myles.ViaVersion.CancelException;
|
||||||
import us.myles.ViaVersion.ConnectionInfo;
|
import us.myles.ViaVersion.ConnectionInfo;
|
||||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||||
@ -34,6 +29,7 @@ public class OutgoingTransformer {
|
|||||||
private final ConnectionInfo info;
|
private final ConnectionInfo info;
|
||||||
private final ViaVersionPlugin plugin = (ViaVersionPlugin) ViaVersion.getInstance();
|
private final ViaVersionPlugin plugin = (ViaVersionPlugin) ViaVersion.getInstance();
|
||||||
private boolean cancel = false;
|
private boolean cancel = false;
|
||||||
|
|
||||||
private Map<Integer, UUID> uuidMap = new HashMap<Integer, UUID>();
|
private Map<Integer, UUID> uuidMap = new HashMap<Integer, UUID>();
|
||||||
private Map<Integer, EntityType> clientEntityTypes = new HashMap<Integer, EntityType>();
|
private Map<Integer, EntityType> clientEntityTypes = new HashMap<Integer, EntityType>();
|
||||||
private Map<Integer, Integer> vehicleMap = new HashMap<>();
|
private Map<Integer, Integer> vehicleMap = new HashMap<>();
|
||||||
@ -268,7 +264,7 @@ public class OutgoingTransformer {
|
|||||||
PacketUtil.writeString(uu, output);
|
PacketUtil.writeString(uu, output);
|
||||||
UUID uniqueId = UUID.fromString(uu);
|
UUID uniqueId = UUID.fromString(uu);
|
||||||
info.setUUID(uniqueId);
|
info.setUUID(uniqueId);
|
||||||
plugin.setPorted(uniqueId, true);
|
plugin.addPortedClient(info);
|
||||||
output.writeBytes(input);
|
output.writeBytes(input);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -412,7 +408,6 @@ public class OutgoingTransformer {
|
|||||||
|
|
||||||
short slot = input.readShort();
|
short slot = input.readShort();
|
||||||
output.writeShort(slot);
|
output.writeShort(slot);
|
||||||
|
|
||||||
ItemSlotRewriter.rewrite1_8To1_9(input, output);
|
ItemSlotRewriter.rewrite1_8To1_9(input, output);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren