mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-12-23 17:08:15 +01:00
Migrate to our own types + use ids instead of materials
This commit is contained in:
parent
49b602994a
commit
c4ffdc1b7c
4
TODOLIST
4
TODOLIST
@ -1,8 +1,6 @@
|
||||
Migrate EntityUtil to be cool
|
||||
Fix 1.9to1.8
|
||||
Fix 1.9.3to1.9.1/2
|
||||
Fix snapshot to 1.10
|
||||
Fix BaseProtocol
|
||||
Migrate listeners in BaseProtocol
|
||||
Fix BossBar to use Generics
|
||||
Register Listeners Properly
|
||||
Fix commands
|
||||
|
@ -0,0 +1,12 @@
|
||||
package us.myles.ViaVersion.api.minecraft;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class EulerAngle {
|
||||
private float x;
|
||||
private float y;
|
||||
private float z;
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package us.myles.ViaVersion.api.minecraft;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Vector {
|
||||
private int blockX;
|
||||
private int blockY;
|
||||
private int blockZ;
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package us.myles.ViaVersion.api.minecraft.item;
|
||||
|
||||
import lombok.*;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.spacehq.opennbt.tag.builtin.CompoundTag;
|
||||
|
||||
@Getter
|
||||
@ -14,15 +13,4 @@ public class Item {
|
||||
private byte amount;
|
||||
private short data;
|
||||
private CompoundTag tag;
|
||||
|
||||
/**
|
||||
* Create an item from a bukkit stack (doesn't save NBT)
|
||||
*
|
||||
* @param stack The stack to convert from
|
||||
* @return The output stack
|
||||
*/
|
||||
public static Item getItem(ItemStack stack) {
|
||||
if (stack == null) return null;
|
||||
return new Item((short) stack.getTypeId(), (byte) stack.getAmount(), stack.getDurability(), null);
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,10 @@ package us.myles.ViaVersion.api.type;
|
||||
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.util.EulerAngle;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.spacehq.opennbt.tag.builtin.CompoundTag;
|
||||
import us.myles.ViaVersion.api.minecraft.EulerAngle;
|
||||
import us.myles.ViaVersion.api.minecraft.Position;
|
||||
import us.myles.ViaVersion.api.minecraft.Vector;
|
||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
import us.myles.ViaVersion.api.type.types.*;
|
||||
import us.myles.ViaVersion.api.type.types.minecraft.*;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package us.myles.ViaVersion.api.type.types.minecraft;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.bukkit.util.EulerAngle;
|
||||
import us.myles.ViaVersion.api.minecraft.EulerAngle;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
|
||||
public class EulerAngleType extends Type<EulerAngle> {
|
||||
@ -20,8 +20,8 @@ public class EulerAngleType extends Type<EulerAngle> {
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, EulerAngle object) throws Exception {
|
||||
Type.FLOAT.write(buffer, (float) object.getX());
|
||||
Type.FLOAT.write(buffer, (float) object.getY());
|
||||
Type.FLOAT.write(buffer, (float) object.getZ());
|
||||
Type.FLOAT.write(buffer, object.getX());
|
||||
Type.FLOAT.write(buffer, object.getY());
|
||||
Type.FLOAT.write(buffer, object.getZ());
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package us.myles.ViaVersion.api.type.types.minecraft;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.bukkit.util.Vector;
|
||||
import us.myles.ViaVersion.api.minecraft.Vector;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
|
||||
public class VectorType extends Type<Vector> {
|
||||
|
@ -6,7 +6,7 @@ import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import us.myles.ViaVersion.api.ViaVersion;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.boss.BossBar;
|
||||
import us.myles.ViaVersion.api.boss.BossColor;
|
||||
import us.myles.ViaVersion.api.boss.BossFlag;
|
||||
@ -45,7 +45,7 @@ public abstract class CommonBoss extends BossBar {
|
||||
@Override
|
||||
public BossBar setTitle(@NonNull String title) {
|
||||
this.title = title;
|
||||
sendPacket(ViaBossBar.UpdateAction.UPDATE_TITLE);
|
||||
sendPacket(CommonBoss.UpdateAction.UPDATE_TITLE);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ public abstract class CommonBoss extends BossBar {
|
||||
public BossBar setHealth(float health) {
|
||||
Validate.isTrue((health >= 0 && health <= 1), "Health must be between 0 and 1");
|
||||
this.health = health;
|
||||
sendPacket(ViaBossBar.UpdateAction.UPDATE_HEALTH);
|
||||
sendPacket(CommonBoss.UpdateAction.UPDATE_HEALTH);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -65,14 +65,14 @@ public abstract class CommonBoss extends BossBar {
|
||||
@Override
|
||||
public BossBar setColor(@NonNull BossColor color) {
|
||||
this.color = color;
|
||||
sendPacket(ViaBossBar.UpdateAction.UPDATE_STYLE);
|
||||
sendPacket(CommonBoss.UpdateAction.UPDATE_STYLE);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar setStyle(@NonNull BossStyle style) {
|
||||
this.style = style;
|
||||
sendPacket(ViaBossBar.UpdateAction.UPDATE_STYLE);
|
||||
sendPacket(CommonBoss.UpdateAction.UPDATE_STYLE);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ public abstract class CommonBoss extends BossBar {
|
||||
if (!players.contains(player)) {
|
||||
players.add(player);
|
||||
if (visible)
|
||||
sendPacket(player, getPacket(ViaBossBar.UpdateAction.ADD));
|
||||
sendPacket(player, getPacket(CommonBoss.UpdateAction.ADD));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@ -99,7 +99,7 @@ public abstract class CommonBoss extends BossBar {
|
||||
public BossBar addFlag(@NonNull BossFlag flag) {
|
||||
if (!hasFlag(flag))
|
||||
flags.add(flag);
|
||||
sendPacket(ViaBossBar.UpdateAction.UPDATE_FLAGS);
|
||||
sendPacket(CommonBoss.UpdateAction.UPDATE_FLAGS);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -107,7 +107,7 @@ public abstract class CommonBoss extends BossBar {
|
||||
public BossBar removeFlag(@NonNull BossFlag flag) {
|
||||
if (hasFlag(flag))
|
||||
flags.remove(flag);
|
||||
sendPacket(ViaBossBar.UpdateAction.UPDATE_FLAGS);
|
||||
sendPacket(CommonBoss.UpdateAction.UPDATE_FLAGS);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -141,7 +141,7 @@ public abstract class CommonBoss extends BossBar {
|
||||
private void setVisible(boolean value) {
|
||||
if (visible != value) {
|
||||
visible = value;
|
||||
sendPacket(value ? ViaBossBar.UpdateAction.ADD : ViaBossBar.UpdateAction.REMOVE);
|
||||
sendPacket(value ? CommonBoss.UpdateAction.ADD : CommonBoss.UpdateAction.REMOVE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -153,12 +153,12 @@ public abstract class CommonBoss extends BossBar {
|
||||
}
|
||||
|
||||
private void sendPacket(UUID uuid, ByteBuf buf) {
|
||||
if (!ViaVersion.getInstance().isPorted(uuid) || !(ViaVersion.getInstance().getPlayerVersion(uuid) >= ProtocolVersion.v1_9.getId())) {
|
||||
if (!Via.getAPI().isPorted(uuid) || !(Via.getAPI().getPlayerVersion(uuid) >= ProtocolVersion.v1_9.getId())) {
|
||||
players.remove(uuid);
|
||||
buf.release();
|
||||
return;
|
||||
}
|
||||
ViaVersion.getInstance().sendRawPacket(uuid, buf);
|
||||
Via.getAPI().sendRawPacket(uuid, buf);
|
||||
}
|
||||
|
||||
private ByteBuf getPacket(UpdateAction action) {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.chunks;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.spacehq.opennbt.tag.builtin.CompoundTag;
|
||||
import org.spacehq.opennbt.tag.builtin.IntTag;
|
||||
import org.spacehq.opennbt.tag.builtin.StringTag;
|
||||
@ -18,28 +17,28 @@ public class FakeTileEntity {
|
||||
private static Map<Integer, CompoundTag> tileEntities = new ConcurrentHashMap<>();
|
||||
|
||||
static {
|
||||
register(Material.FURNACE, "Furnace");
|
||||
register(Arrays.asList(Material.CHEST, Material.TRAPPED_CHEST), "Chest");
|
||||
register(Material.ENDER_CHEST, "EnderChest");
|
||||
register(Material.JUKEBOX, "RecordPlayer");
|
||||
register(Material.DISPENSER, "Trap");
|
||||
register(Material.DROPPER, "Dropper");
|
||||
register(Arrays.asList(Material.SIGN_POST, Material.WALL_SIGN), "Sign");
|
||||
register(Material.MOB_SPAWNER, "MobSpawner");
|
||||
register(Material.NOTE_BLOCK, "Music");
|
||||
register(Arrays.asList(Material.PISTON_BASE, Material.PISTON_EXTENSION, Material.PISTON_STICKY_BASE, Material.PISTON_MOVING_PIECE), "Piston");
|
||||
register(Arrays.asList(Material.BREWING_STAND, Material.CAULDRON), "Cauldron");
|
||||
register(Material.ENCHANTMENT_TABLE, "EnchantTable");
|
||||
register(Arrays.asList(Material.ENDER_PORTAL, Material.ENDER_PORTAL_FRAME), "Airportal");
|
||||
register(Material.BEACON, "Beacon");
|
||||
register(Arrays.asList(Material.SKULL, Material.SKULL_ITEM), "Skull");
|
||||
register(Arrays.asList(Material.DAYLIGHT_DETECTOR, Material.DAYLIGHT_DETECTOR_INVERTED), "DLDetector");
|
||||
register(Material.HOPPER, "Hopper");
|
||||
register(Arrays.asList(Material.REDSTONE_COMPARATOR, Material.REDSTONE_COMPARATOR_OFF, Material.REDSTONE_COMPARATOR_ON), "Comparator");
|
||||
register(Material.FLOWER_POT, "FlowerPot");
|
||||
register(Arrays.asList(Material.STANDING_BANNER, Material.WALL_BANNER, Material.BANNER), "Banner");
|
||||
register(Arrays.asList(61, 62), "Furnace");
|
||||
register(Arrays.asList(54, 146), "Chest");
|
||||
register(130, "EnderChest");
|
||||
register(84, "RecordPlayer");
|
||||
register(23, "Trap"); // Dispenser
|
||||
register(158, "Dropper");
|
||||
register(Arrays.asList(63, 68), "Sign");
|
||||
register(52, "MobSpawner");
|
||||
register(25, "Music"); // Note Block
|
||||
register(Arrays.asList(33, 34, 29, 36), "Piston");
|
||||
register(117, "Cauldron"); // Brewing stand
|
||||
register(116, "EnchantTable");
|
||||
register(Arrays.asList(119, 120), "Airportal"); // End portal
|
||||
register(138, "Beacon");
|
||||
register(144, "Skull");
|
||||
register(Arrays.asList(178, 151), "DLDetector");
|
||||
register(154, "Hopper");
|
||||
register(Arrays.asList(149, 150), "Comparator");
|
||||
register(140, "FlowerPot");
|
||||
register(Arrays.asList(176, 177), "Banner");
|
||||
register(209, "EndGateway");
|
||||
register(Material.COMMAND.getId(), "Control");
|
||||
register(137, "Control");
|
||||
}
|
||||
|
||||
private static void register(Integer material, String name) {
|
||||
@ -48,13 +47,9 @@ public class FakeTileEntity {
|
||||
tileEntities.put(material, comp);
|
||||
}
|
||||
|
||||
private static void register(Material material, String name) {
|
||||
register(material.getId(), name);
|
||||
}
|
||||
|
||||
private static void register(List<Material> materials, String name) {
|
||||
for (Material m : materials)
|
||||
register(m.getId(), name);
|
||||
private static void register(List<Integer> materials, String name) {
|
||||
for (int m : materials)
|
||||
register(m, name);
|
||||
}
|
||||
|
||||
public static boolean hasBlock(int block) {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_9to1_8;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.spacehq.opennbt.tag.builtin.CompoundTag;
|
||||
import org.spacehq.opennbt.tag.builtin.ListTag;
|
||||
import org.spacehq.opennbt.tag.builtin.StringTag;
|
||||
@ -140,7 +139,7 @@ public class ItemRewriter {
|
||||
|
||||
public static void toServer(Item item) {
|
||||
if (item != null) {
|
||||
if (item.getId() == Material.MONSTER_EGG.getId() && item.getData() == 0) {
|
||||
if (item.getId() == 383 && item.getData() == 0) { // Monster Egg
|
||||
CompoundTag tag = item.getTag();
|
||||
int data = 0;
|
||||
if (tag != null && tag.get("EntityTag") instanceof CompoundTag) {
|
||||
@ -155,7 +154,7 @@ public class ItemRewriter {
|
||||
item.setTag(tag);
|
||||
item.setData((short) data);
|
||||
}
|
||||
if (item.getId() == Material.POTION.getId()) {
|
||||
if (item.getId() == 373) { // Potion
|
||||
CompoundTag tag = item.getTag();
|
||||
int data = 0;
|
||||
if (tag != null && tag.get("Potion") instanceof StringTag) {
|
||||
@ -169,11 +168,11 @@ public class ItemRewriter {
|
||||
item.setTag(tag);
|
||||
item.setData((short) data);
|
||||
}
|
||||
//Splash potion
|
||||
// Splash potion
|
||||
if (item.getId() == 438) {
|
||||
CompoundTag tag = item.getTag();
|
||||
int data = 0;
|
||||
item.setId((short) Material.POTION.getId());
|
||||
item.setId((short) 373); // Potion
|
||||
if (tag != null && tag.get("Potion") instanceof StringTag) {
|
||||
StringTag potion = tag.get("Potion");
|
||||
String potionName = potion.getValue().replace("minecraft:", "");
|
||||
@ -190,7 +189,7 @@ public class ItemRewriter {
|
||||
|
||||
public static void toClient(Item item) {
|
||||
if (item != null) {
|
||||
if (item.getId() == Material.MONSTER_EGG.getId() && item.getData() != 0) {
|
||||
if (item.getId() == 383 && item.getData() != 0) { // Monster Egg
|
||||
CompoundTag tag = item.getTag();
|
||||
if (tag == null) {
|
||||
tag = new CompoundTag("tag");
|
||||
@ -204,7 +203,7 @@ public class ItemRewriter {
|
||||
item.setTag(tag);
|
||||
item.setData((short) 0);
|
||||
}
|
||||
if (item.getId() == Material.POTION.getId()) {
|
||||
if (item.getId() == 373) { // Potion
|
||||
CompoundTag tag = item.getTag();
|
||||
if (tag == null) {
|
||||
tag = new CompoundTag("tag");
|
||||
@ -219,7 +218,7 @@ public class ItemRewriter {
|
||||
item.setTag(tag);
|
||||
item.setData((short) 0);
|
||||
}
|
||||
if (item.getId() == Material.WRITTEN_BOOK.getId()) {
|
||||
if (item.getId() == 387) { // WRITTEN_BOOK
|
||||
CompoundTag tag = item.getTag();
|
||||
if (tag == null) {
|
||||
tag = new CompoundTag("tag");
|
||||
|
@ -6,7 +6,7 @@ import com.google.gson.JsonObject;
|
||||
import org.bukkit.Bukkit;
|
||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.ViaVersion;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
@ -15,7 +15,6 @@ import us.myles.ViaVersion.api.remapper.ValueTransformer;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.api.type.types.version.Metadata1_8Type;
|
||||
import us.myles.ViaVersion.api.type.types.version.MetadataList1_8Type;
|
||||
import us.myles.ViaVersion.listeners.protocol1_9to1_8.*;
|
||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.packets.*;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.*;
|
||||
@ -53,7 +52,7 @@ public class Protocol1_9TO1_8 extends Protocol {
|
||||
try {
|
||||
gson.fromJson(line, JsonObject.class);
|
||||
} catch (Exception e) {
|
||||
if (ViaVersion.getConfig().isForceJsonTransform()) {
|
||||
if (Via.getConfig().isForceJsonTransform()) {
|
||||
return constructJson(line);
|
||||
} else {
|
||||
System.out.println("Invalid JSON String: \"" + line + "\" Please report this issue to the ViaVersion Github: " + e.getMessage());
|
||||
@ -86,7 +85,7 @@ public class Protocol1_9TO1_8 extends Protocol {
|
||||
}).get(10, TimeUnit.SECONDS);
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error fetching hand item: " + e.getClass().getName());
|
||||
if (ViaVersion.getInstance().isDebug())
|
||||
if (Via.getManager().isDebug())
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
@ -146,4 +145,14 @@ public class Protocol1_9TO1_8 extends Protocol {
|
||||
// Place block tracker
|
||||
userConnection.put(new PlaceBlockTracker(userConnection));
|
||||
}
|
||||
|
||||
public static boolean isSword(int id) {
|
||||
if (id == 267) return true; // Iron
|
||||
if (id == 268) return true; // Wood
|
||||
if (id == 272) return true; // Stone
|
||||
if (id == 276) return true; // Diamond
|
||||
if (id == 283) return true; // Gold
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import io.netty.channel.ChannelHandlerContext;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.ViaVersion;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
@ -29,7 +30,7 @@ public class ViaIdleThread extends BukkitRunnable {
|
||||
private Method handleFlying;
|
||||
|
||||
public ViaIdleThread(Map<UUID, UserConnection> portedPlayers) {
|
||||
USE_NMS = ViaVersion.getConfig().isNMSPlayerTicking();
|
||||
USE_NMS = Via.getConfig().isNMSPlayerTicking();
|
||||
|
||||
this.portedPlayers = portedPlayers;
|
||||
Class<?> idlePacketClass;
|
||||
|
@ -1,10 +1,9 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata;
|
||||
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.util.EulerAngle;
|
||||
import org.bukkit.util.Vector;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.ViaVersion;
|
||||
import us.myles.ViaVersion.api.minecraft.EulerAngle;
|
||||
import us.myles.ViaVersion.api.minecraft.Vector;
|
||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter;
|
||||
|
@ -1,8 +1,7 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.ViaVersion;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||
@ -85,11 +84,11 @@ public class EntityPackets {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityID = wrapper.get(Type.VAR_INT, 0);
|
||||
if (ViaVersion.getConfig().isHologramPatch()) {
|
||||
if (Via.getConfig().isHologramPatch()) {
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
if (tracker.getKnownHolograms().contains(entityID)) {
|
||||
Double newValue = wrapper.get(Type.DOUBLE, 1);
|
||||
newValue += (ViaVersion.getConfig().getHologramYOffset());
|
||||
newValue += (Via.getConfig().getHologramYOffset());
|
||||
wrapper.set(Type.DOUBLE, 1, newValue);
|
||||
}
|
||||
}
|
||||
@ -159,11 +158,9 @@ public class EntityPackets {
|
||||
Item stack = wrapper.get(Type.ITEM, 0);
|
||||
|
||||
if (stack != null) {
|
||||
if (Material.getMaterial(stack.getId()) != null) {
|
||||
if (Material.getMaterial(stack.getId()).name().endsWith("SWORD")) {
|
||||
entityTracker.getValidBlocking().add(entityID);
|
||||
return;
|
||||
}
|
||||
if (Protocol1_9TO1_8.isSword(stack.getId())) {
|
||||
entityTracker.getValidBlocking().add(entityID);
|
||||
return;
|
||||
}
|
||||
}
|
||||
entityTracker.getValidBlocking().remove(entityID);
|
||||
@ -231,7 +228,7 @@ public class EntityPackets {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
boolean showParticles = wrapper.read(Type.BOOLEAN); //In 1.8 = true->Show particles : false->Hide particles
|
||||
boolean newEffect = ViaVersion.getConfig().isNewEffectIndicator();
|
||||
boolean newEffect = Via.getConfig().isNewEffectIndicator();
|
||||
//0: hide, 1: shown without indictator, 2: shown with indicator, 3: hide with beacon indicator but we don't use it.
|
||||
wrapper.write(Type.BYTE, (byte) (showParticles ? newEffect ? 2 : 1 : 0));
|
||||
}
|
||||
|
@ -2,11 +2,9 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.ViaVersion;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||
@ -124,7 +122,7 @@ public class PlayerPackets {
|
||||
|
||||
wrapper.passthrough(Type.STRING); // Name tag visibility
|
||||
|
||||
wrapper.write(Type.STRING, ViaVersion.getConfig().isPreventCollision() ? "never" : "");
|
||||
wrapper.write(Type.STRING, Via.getConfig().isPreventCollision() ? "never" : "");
|
||||
|
||||
wrapper.passthrough(Type.BYTE); // Colour
|
||||
}
|
||||
@ -137,12 +135,12 @@ public class PlayerPackets {
|
||||
if (entityTracker.isAutoTeam() && player.equalsIgnoreCase(myName)) {
|
||||
if (mode == 4) {
|
||||
// since removing add to auto team
|
||||
((ViaVersionPlugin) ViaVersion.getInstance()).run(new Runnable() {
|
||||
Via.getPlatform().runSync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
entityTracker.sendTeamPacket(true);
|
||||
}
|
||||
}, false);
|
||||
});
|
||||
} else {
|
||||
// since adding remove from auto team
|
||||
entityTracker.sendTeamPacket(false);
|
||||
@ -477,7 +475,7 @@ public class PlayerPackets {
|
||||
if (name.equalsIgnoreCase("MC|BSign")) {
|
||||
Item item = wrapper.passthrough(Type.ITEM);
|
||||
if (item != null) {
|
||||
item.setId((short) Material.WRITTEN_BOOK.getId());
|
||||
item.setId((short) 387); // Written Book
|
||||
}
|
||||
}
|
||||
if (name.equalsIgnoreCase("MC|AutoCmd")) {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
@ -104,7 +103,7 @@ public class SpawnPackets {
|
||||
public void write(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.write(Type.VAR_INT, entityID);
|
||||
List<Metadata> meta = new ArrayList<>();
|
||||
Item item = new Item((short) Material.POTION.getId(), (byte) 1, (short) data, null);
|
||||
Item item = new Item((short) 373, (byte) 1, (short) data, null); // Potion
|
||||
ItemRewriter.toClient(item); // Rewrite so that it gets the right nbt
|
||||
// TEMP FIX FOR POTIONS UNTIL WE FIGURE OUT HOW TO TRANSFORM SENT PACKETS
|
||||
Metadata potion = new Metadata(5, NewType.Slot.getTypeID(), Type.ITEM, item);
|
||||
|
@ -1,10 +1,9 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.spacehq.opennbt.tag.builtin.CompoundTag;
|
||||
import org.spacehq.opennbt.tag.builtin.StringTag;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.ViaVersion;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.minecraft.Position;
|
||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||
@ -168,7 +167,7 @@ public class WorldPackets {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
if (ViaVersion.getConfig().isAutoTeam()) {
|
||||
if (Via.getConfig().isAutoTeam()) {
|
||||
EntityTracker entityTracker = wrapper.user().get(EntityTracker.class);
|
||||
entityTracker.setAutoTeam(true);
|
||||
entityTracker.sendTeamPacket(true);
|
||||
@ -259,19 +258,17 @@ public class WorldPackets {
|
||||
// Write item in hand
|
||||
Item item = Protocol1_9TO1_8.getHandItem(wrapper.user());
|
||||
// Blocking patch
|
||||
if (ViaVersion.getConfig().isShieldBlocking()) {
|
||||
if (Via.getConfig().isShieldBlocking()) {
|
||||
if (item != null) {
|
||||
if (Material.getMaterial(item.getId()) != null) {
|
||||
if (Material.getMaterial(item.getId()).name().endsWith("SWORD")) {
|
||||
if (hand == 0) {
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
if (!tracker.isBlocking()) {
|
||||
tracker.setBlocking(true);
|
||||
Item shield = new Item((short) 442, (byte) 1, (short) 0, null);
|
||||
tracker.setSecondHand(shield);
|
||||
}
|
||||
wrapper.cancel();
|
||||
if (Protocol1_9TO1_8.isSword(item.getId())) {
|
||||
if (hand == 0) {
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
if (!tracker.isBlocking()) {
|
||||
tracker.setBlocking(true);
|
||||
Item shield = new Item((short) 442, (byte) 1, (short) 0, null);
|
||||
tracker.setSecondHand(shield);
|
||||
}
|
||||
wrapper.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ public class ClientChunks extends StoredObject {
|
||||
int[] zcoords = mapChunkBulkRef.getFieldValue("b", packet, int[].class);
|
||||
Object[] chunkMaps = mapChunkBulkRef.getFieldValue("c", packet, Object[].class);
|
||||
|
||||
if (ViaVersion.getConfig().isAntiXRay() && ViaVersion.getInstance().isSpigot()) { //Spigot anti-xray patch
|
||||
if (Via.getConfig().isAntiXRay() && Via.getInstance().isSpigot()) { //Spigot anti-xray patch
|
||||
try {
|
||||
Object world = mapChunkBulkRef.getFieldValue("world", packet, Object.class);
|
||||
|
||||
|
@ -6,10 +6,9 @@ import com.google.common.collect.Sets;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.ViaVersion;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.boss.BossBar;
|
||||
import us.myles.ViaVersion.api.boss.BossColor;
|
||||
import us.myles.ViaVersion.api.boss.BossStyle;
|
||||
@ -39,7 +38,7 @@ public class EntityTracker extends StoredObject {
|
||||
private final Map<Integer, BossBar> bossBarMap = new ConcurrentHashMap<>();
|
||||
private final Set<Integer> validBlocking = Sets.newConcurrentHashSet();
|
||||
private final Set<Integer> knownHolograms = Sets.newConcurrentHashSet();
|
||||
private final Cache<Position, Material> blockInteractions = CacheBuilder.newBuilder().maximumSize(10).expireAfterAccess(250, TimeUnit.MILLISECONDS).build();
|
||||
private final Cache<Position, Integer> blockInteractions = CacheBuilder.newBuilder().maximumSize(10).expireAfterAccess(250, TimeUnit.MILLISECONDS).build();
|
||||
@Setter
|
||||
private boolean blocking = false;
|
||||
@Setter
|
||||
@ -111,7 +110,7 @@ public class EntityTracker extends StoredObject {
|
||||
}
|
||||
|
||||
public void addBlockInteraction(Position p) {
|
||||
blockInteractions.put(p, Material.AIR);
|
||||
blockInteractions.put(p, 0);
|
||||
}
|
||||
|
||||
public void handleMetadata(int entityID, List<Metadata> metadataList) {
|
||||
@ -153,7 +152,7 @@ public class EntityTracker extends StoredObject {
|
||||
if (metadata.getId() == 0) {
|
||||
// Byte
|
||||
byte data = (byte) metadata.getValue();
|
||||
if (entityID != getEntityID() && ViaVersion.getConfig().isShieldBlocking()) {
|
||||
if (entityID != getEntityID() && Via.getConfig().isShieldBlocking()) {
|
||||
if ((data & 0x10) == 0x10) {
|
||||
if (validBlocking.contains(entityID)) {
|
||||
Item shield = new Item((short) 442, (byte) 1, (short) 0, null);
|
||||
@ -180,7 +179,7 @@ public class EntityTracker extends StoredObject {
|
||||
Type.VAR_INT.write(buf, 0x25); // Relative Move Packet
|
||||
Type.VAR_INT.write(buf, entityID);
|
||||
buf.writeShort(0);
|
||||
buf.writeShort((short) (128D * (ViaVersion.getConfig().getHologramYOffset() * 32D)));
|
||||
buf.writeShort((short) (128D * (Via.getConfig().getHologramYOffset() * 32D)));
|
||||
buf.writeShort(0);
|
||||
buf.writeBoolean(true);
|
||||
getUser().sendRawPacket(buf, false);
|
||||
@ -192,28 +191,28 @@ public class EntityTracker extends StoredObject {
|
||||
}
|
||||
UUID uuid = getUser().get(ProtocolInfo.class).getUuid();
|
||||
// Boss bar
|
||||
if (ViaVersion.getConfig().isBossbarPatch()) {
|
||||
if (Via.getConfig().isBossbarPatch()) {
|
||||
if (type == EntityType.ENDER_DRAGON || type == EntityType.WITHER) {
|
||||
if (metadata.getId() == 2) {
|
||||
BossBar bar = bossBarMap.get(entityID);
|
||||
String title = (String) metadata.getValue();
|
||||
title = title.isEmpty() ? (type == EntityType.ENDER_DRAGON ? "Ender Dragon" : "Wither") : title;
|
||||
if (bar == null) {
|
||||
bar = ViaVersion.getInstance().createBossBar(title, BossColor.PINK, BossStyle.SOLID);
|
||||
bar = Via.getAPI().createBossBar(title, BossColor.PINK, BossStyle.SOLID);
|
||||
bossBarMap.put(entityID, bar);
|
||||
bar.addPlayer(uuid);
|
||||
bar.show();
|
||||
} else {
|
||||
bar.setTitle(title);
|
||||
}
|
||||
} else if (metadata.getId() == 6 && !ViaVersion.getConfig().isBossbarAntiflicker()) { // If anti flicker is enabled, don't update health
|
||||
} else if (metadata.getId() == 6 && !Via.getConfig().isBossbarAntiflicker()) { // If anti flicker is enabled, don't update health
|
||||
BossBar bar = bossBarMap.get(entityID);
|
||||
// Make health range between 0 and 1
|
||||
float maxHealth = type == EntityType.ENDER_DRAGON ? 200.0f : 300.0f;
|
||||
float health = Math.max(0.0f, Math.min(((float) metadata.getValue()) / maxHealth, 1.0f));
|
||||
if (bar == null) {
|
||||
String title = type == EntityType.ENDER_DRAGON ? "Ender Dragon" : "Wither";
|
||||
bar = ViaVersion.getInstance().createBossBar(title, health, BossColor.PINK, BossStyle.SOLID);
|
||||
bar = Via.getAPI().createBossBar(title, health, BossColor.PINK, BossStyle.SOLID);
|
||||
bossBarMap.put(entityID, bar);
|
||||
bar.addPlayer(uuid);
|
||||
bar.show();
|
||||
|
@ -3,7 +3,6 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.types;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.ViaVersion;
|
||||
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
|
||||
import us.myles.ViaVersion.api.type.PartialType;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
@ -49,8 +48,8 @@ public class ChunkType extends PartialType<Chunk, ClientChunks> {
|
||||
|
||||
@Override
|
||||
public Chunk read(ByteBuf input, ClientChunks param) throws Exception {
|
||||
boolean replacePistons = param.getUser().get(ProtocolInfo.class).getPipeline().contains(Protocol1_10To1_9_3_4.class) && ViaVersion.getConfig().isReplacePistons();
|
||||
int replacementId = ViaVersion.getConfig().getPistonReplacementId();
|
||||
boolean replacePistons = param.getUser().get(ProtocolInfo.class).getPipeline().contains(Protocol1_10To1_9_3_4.class) && Via.getConfig().isReplacePistons();
|
||||
int replacementId = Via.getConfig().getPistonReplacementId();
|
||||
|
||||
int chunkX = input.readInt();
|
||||
int chunkZ = input.readInt();
|
||||
|
@ -1,7 +1,7 @@
|
||||
package us.myles.ViaVersion.protocols.protocolsnapshotto1_10;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import us.myles.ViaVersion.api.ViaVersion;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.NewType;
|
||||
@ -75,8 +75,7 @@ public class MetadataRewriter {
|
||||
}
|
||||
return currentType;
|
||||
} catch (Exception e) {
|
||||
;
|
||||
if (!ViaVersion.getConfig().isSuppressMetadataErrors() || ViaVersion.getInstance().isDebug()) {
|
||||
if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) {
|
||||
System.out.println("An error occurred with entity type rewriter");
|
||||
System.out.println("Metadata: " + metadata);
|
||||
e.printStackTrace();
|
||||
@ -154,7 +153,7 @@ public class MetadataRewriter {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
metadatas.remove(metadata);
|
||||
if (!ViaVersion.getConfig().isSuppressMetadataErrors() || ViaVersion.getInstance().isDebug()) {
|
||||
if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) {
|
||||
System.out.println("An error occurred with entity metadata handler");
|
||||
System.out.println("Metadata: " + metadata);
|
||||
e.printStackTrace();
|
||||
|
Loading…
Reference in New Issue
Block a user