3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-03 14:50:30 +01:00

Migrate to our own types + use ids instead of materials

Dieser Commit ist enthalten in:
Myles 2016-09-25 15:40:30 +01:00
Ursprung 49b602994a
Commit c4ffdc1b7c
21 geänderte Dateien mit 130 neuen und 129 gelöschten Zeilen

Datei anzeigen

@ -1,8 +1,6 @@
Migrate EntityUtil to be cool Migrate EntityUtil to be cool
Fix 1.9to1.8 Fix 1.9to1.8
Fix 1.9.3to1.9.1/2 Migrate listeners in BaseProtocol
Fix snapshot to 1.10
Fix BaseProtocol
Fix BossBar to use Generics Fix BossBar to use Generics
Register Listeners Properly Register Listeners Properly
Fix commands Fix commands

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -1,7 +1,6 @@
package us.myles.ViaVersion.api.minecraft.item; package us.myles.ViaVersion.api.minecraft.item;
import lombok.*; import lombok.*;
import org.bukkit.inventory.ItemStack;
import org.spacehq.opennbt.tag.builtin.CompoundTag; import org.spacehq.opennbt.tag.builtin.CompoundTag;
@Getter @Getter
@ -14,15 +13,4 @@ public class Item {
private byte amount; private byte amount;
private short data; private short data;
private CompoundTag tag; 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);
}
} }

Datei anzeigen

@ -2,10 +2,10 @@ package us.myles.ViaVersion.api.type;
import lombok.Getter; import lombok.Getter;
import org.bukkit.util.EulerAngle;
import org.bukkit.util.Vector;
import org.spacehq.opennbt.tag.builtin.CompoundTag; 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.Position;
import us.myles.ViaVersion.api.minecraft.Vector;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.type.types.*; import us.myles.ViaVersion.api.type.types.*;
import us.myles.ViaVersion.api.type.types.minecraft.*; import us.myles.ViaVersion.api.type.types.minecraft.*;

Datei anzeigen

@ -1,7 +1,7 @@
package us.myles.ViaVersion.api.type.types.minecraft; package us.myles.ViaVersion.api.type.types.minecraft;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.bukkit.util.EulerAngle; import us.myles.ViaVersion.api.minecraft.EulerAngle;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
public class EulerAngleType extends Type<EulerAngle> { public class EulerAngleType extends Type<EulerAngle> {
@ -20,8 +20,8 @@ public class EulerAngleType extends Type<EulerAngle> {
@Override @Override
public void write(ByteBuf buffer, EulerAngle object) throws Exception { public void write(ByteBuf buffer, EulerAngle object) throws Exception {
Type.FLOAT.write(buffer, (float) object.getX()); Type.FLOAT.write(buffer, object.getX());
Type.FLOAT.write(buffer, (float) object.getY()); Type.FLOAT.write(buffer, object.getY());
Type.FLOAT.write(buffer, (float) object.getZ()); Type.FLOAT.write(buffer, object.getZ());
} }
} }

Datei anzeigen

@ -1,7 +1,7 @@
package us.myles.ViaVersion.api.type.types.minecraft; package us.myles.ViaVersion.api.type.types.minecraft;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.bukkit.util.Vector; import us.myles.ViaVersion.api.minecraft.Vector;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
public class VectorType extends Type<Vector> { public class VectorType extends Type<Vector> {

Datei anzeigen

@ -6,7 +6,7 @@ import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.Validate; 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.BossBar;
import us.myles.ViaVersion.api.boss.BossColor; import us.myles.ViaVersion.api.boss.BossColor;
import us.myles.ViaVersion.api.boss.BossFlag; import us.myles.ViaVersion.api.boss.BossFlag;
@ -45,7 +45,7 @@ public abstract class CommonBoss extends BossBar {
@Override @Override
public BossBar setTitle(@NonNull String title) { public BossBar setTitle(@NonNull String title) {
this.title = title; this.title = title;
sendPacket(ViaBossBar.UpdateAction.UPDATE_TITLE); sendPacket(CommonBoss.UpdateAction.UPDATE_TITLE);
return this; return this;
} }
@ -53,7 +53,7 @@ public abstract class CommonBoss extends BossBar {
public BossBar setHealth(float health) { public BossBar setHealth(float health) {
Validate.isTrue((health >= 0 && health <= 1), "Health must be between 0 and 1"); Validate.isTrue((health >= 0 && health <= 1), "Health must be between 0 and 1");
this.health = health; this.health = health;
sendPacket(ViaBossBar.UpdateAction.UPDATE_HEALTH); sendPacket(CommonBoss.UpdateAction.UPDATE_HEALTH);
return this; return this;
} }
@ -65,14 +65,14 @@ public abstract class CommonBoss extends BossBar {
@Override @Override
public BossBar setColor(@NonNull BossColor color) { public BossBar setColor(@NonNull BossColor color) {
this.color = color; this.color = color;
sendPacket(ViaBossBar.UpdateAction.UPDATE_STYLE); sendPacket(CommonBoss.UpdateAction.UPDATE_STYLE);
return this; return this;
} }
@Override @Override
public BossBar setStyle(@NonNull BossStyle style) { public BossBar setStyle(@NonNull BossStyle style) {
this.style = style; this.style = style;
sendPacket(ViaBossBar.UpdateAction.UPDATE_STYLE); sendPacket(CommonBoss.UpdateAction.UPDATE_STYLE);
return this; return this;
} }
@ -81,7 +81,7 @@ public abstract class CommonBoss extends BossBar {
if (!players.contains(player)) { if (!players.contains(player)) {
players.add(player); players.add(player);
if (visible) if (visible)
sendPacket(player, getPacket(ViaBossBar.UpdateAction.ADD)); sendPacket(player, getPacket(CommonBoss.UpdateAction.ADD));
} }
return this; return this;
} }
@ -99,7 +99,7 @@ public abstract class CommonBoss extends BossBar {
public BossBar addFlag(@NonNull BossFlag flag) { public BossBar addFlag(@NonNull BossFlag flag) {
if (!hasFlag(flag)) if (!hasFlag(flag))
flags.add(flag); flags.add(flag);
sendPacket(ViaBossBar.UpdateAction.UPDATE_FLAGS); sendPacket(CommonBoss.UpdateAction.UPDATE_FLAGS);
return this; return this;
} }
@ -107,7 +107,7 @@ public abstract class CommonBoss extends BossBar {
public BossBar removeFlag(@NonNull BossFlag flag) { public BossBar removeFlag(@NonNull BossFlag flag) {
if (hasFlag(flag)) if (hasFlag(flag))
flags.remove(flag); flags.remove(flag);
sendPacket(ViaBossBar.UpdateAction.UPDATE_FLAGS); sendPacket(CommonBoss.UpdateAction.UPDATE_FLAGS);
return this; return this;
} }
@ -141,7 +141,7 @@ public abstract class CommonBoss extends BossBar {
private void setVisible(boolean value) { private void setVisible(boolean value) {
if (visible != value) { if (visible != value) {
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) { 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); players.remove(uuid);
buf.release(); buf.release();
return; return;
} }
ViaVersion.getInstance().sendRawPacket(uuid, buf); Via.getAPI().sendRawPacket(uuid, buf);
} }
private ByteBuf getPacket(UpdateAction action) { private ByteBuf getPacket(UpdateAction action) {

Datei anzeigen

@ -1,6 +1,5 @@
package us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.chunks; 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.CompoundTag;
import org.spacehq.opennbt.tag.builtin.IntTag; import org.spacehq.opennbt.tag.builtin.IntTag;
import org.spacehq.opennbt.tag.builtin.StringTag; import org.spacehq.opennbt.tag.builtin.StringTag;
@ -18,28 +17,28 @@ public class FakeTileEntity {
private static Map<Integer, CompoundTag> tileEntities = new ConcurrentHashMap<>(); private static Map<Integer, CompoundTag> tileEntities = new ConcurrentHashMap<>();
static { static {
register(Material.FURNACE, "Furnace"); register(Arrays.asList(61, 62), "Furnace");
register(Arrays.asList(Material.CHEST, Material.TRAPPED_CHEST), "Chest"); register(Arrays.asList(54, 146), "Chest");
register(Material.ENDER_CHEST, "EnderChest"); register(130, "EnderChest");
register(Material.JUKEBOX, "RecordPlayer"); register(84, "RecordPlayer");
register(Material.DISPENSER, "Trap"); register(23, "Trap"); // Dispenser
register(Material.DROPPER, "Dropper"); register(158, "Dropper");
register(Arrays.asList(Material.SIGN_POST, Material.WALL_SIGN), "Sign"); register(Arrays.asList(63, 68), "Sign");
register(Material.MOB_SPAWNER, "MobSpawner"); register(52, "MobSpawner");
register(Material.NOTE_BLOCK, "Music"); register(25, "Music"); // Note Block
register(Arrays.asList(Material.PISTON_BASE, Material.PISTON_EXTENSION, Material.PISTON_STICKY_BASE, Material.PISTON_MOVING_PIECE), "Piston"); register(Arrays.asList(33, 34, 29, 36), "Piston");
register(Arrays.asList(Material.BREWING_STAND, Material.CAULDRON), "Cauldron"); register(117, "Cauldron"); // Brewing stand
register(Material.ENCHANTMENT_TABLE, "EnchantTable"); register(116, "EnchantTable");
register(Arrays.asList(Material.ENDER_PORTAL, Material.ENDER_PORTAL_FRAME), "Airportal"); register(Arrays.asList(119, 120), "Airportal"); // End portal
register(Material.BEACON, "Beacon"); register(138, "Beacon");
register(Arrays.asList(Material.SKULL, Material.SKULL_ITEM), "Skull"); register(144, "Skull");
register(Arrays.asList(Material.DAYLIGHT_DETECTOR, Material.DAYLIGHT_DETECTOR_INVERTED), "DLDetector"); register(Arrays.asList(178, 151), "DLDetector");
register(Material.HOPPER, "Hopper"); register(154, "Hopper");
register(Arrays.asList(Material.REDSTONE_COMPARATOR, Material.REDSTONE_COMPARATOR_OFF, Material.REDSTONE_COMPARATOR_ON), "Comparator"); register(Arrays.asList(149, 150), "Comparator");
register(Material.FLOWER_POT, "FlowerPot"); register(140, "FlowerPot");
register(Arrays.asList(Material.STANDING_BANNER, Material.WALL_BANNER, Material.BANNER), "Banner"); register(Arrays.asList(176, 177), "Banner");
register(209, "EndGateway"); register(209, "EndGateway");
register(Material.COMMAND.getId(), "Control"); register(137, "Control");
} }
private static void register(Integer material, String name) { private static void register(Integer material, String name) {
@ -48,13 +47,9 @@ public class FakeTileEntity {
tileEntities.put(material, comp); tileEntities.put(material, comp);
} }
private static void register(Material material, String name) { private static void register(List<Integer> materials, String name) {
register(material.getId(), name); for (int m : materials)
} register(m, name);
private static void register(List<Material> materials, String name) {
for (Material m : materials)
register(m.getId(), name);
} }
public static boolean hasBlock(int block) { public static boolean hasBlock(int block) {

Datei anzeigen

@ -1,6 +1,5 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8; 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.CompoundTag;
import org.spacehq.opennbt.tag.builtin.ListTag; import org.spacehq.opennbt.tag.builtin.ListTag;
import org.spacehq.opennbt.tag.builtin.StringTag; import org.spacehq.opennbt.tag.builtin.StringTag;
@ -140,7 +139,7 @@ public class ItemRewriter {
public static void toServer(Item item) { public static void toServer(Item item) {
if (item != null) { 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(); CompoundTag tag = item.getTag();
int data = 0; int data = 0;
if (tag != null && tag.get("EntityTag") instanceof CompoundTag) { if (tag != null && tag.get("EntityTag") instanceof CompoundTag) {
@ -155,7 +154,7 @@ public class ItemRewriter {
item.setTag(tag); item.setTag(tag);
item.setData((short) data); item.setData((short) data);
} }
if (item.getId() == Material.POTION.getId()) { if (item.getId() == 373) { // Potion
CompoundTag tag = item.getTag(); CompoundTag tag = item.getTag();
int data = 0; int data = 0;
if (tag != null && tag.get("Potion") instanceof StringTag) { if (tag != null && tag.get("Potion") instanceof StringTag) {
@ -169,11 +168,11 @@ public class ItemRewriter {
item.setTag(tag); item.setTag(tag);
item.setData((short) data); item.setData((short) data);
} }
//Splash potion // Splash potion
if (item.getId() == 438) { if (item.getId() == 438) {
CompoundTag tag = item.getTag(); CompoundTag tag = item.getTag();
int data = 0; int data = 0;
item.setId((short) Material.POTION.getId()); item.setId((short) 373); // Potion
if (tag != null && tag.get("Potion") instanceof StringTag) { if (tag != null && tag.get("Potion") instanceof StringTag) {
StringTag potion = tag.get("Potion"); StringTag potion = tag.get("Potion");
String potionName = potion.getValue().replace("minecraft:", ""); String potionName = potion.getValue().replace("minecraft:", "");
@ -190,7 +189,7 @@ public class ItemRewriter {
public static void toClient(Item item) { public static void toClient(Item item) {
if (item != null) { 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(); CompoundTag tag = item.getTag();
if (tag == null) { if (tag == null) {
tag = new CompoundTag("tag"); tag = new CompoundTag("tag");
@ -204,7 +203,7 @@ public class ItemRewriter {
item.setTag(tag); item.setTag(tag);
item.setData((short) 0); item.setData((short) 0);
} }
if (item.getId() == Material.POTION.getId()) { if (item.getId() == 373) { // Potion
CompoundTag tag = item.getTag(); CompoundTag tag = item.getTag();
if (tag == null) { if (tag == null) {
tag = new CompoundTag("tag"); tag = new CompoundTag("tag");
@ -219,7 +218,7 @@ public class ItemRewriter {
item.setTag(tag); item.setTag(tag);
item.setData((short) 0); item.setData((short) 0);
} }
if (item.getId() == Material.WRITTEN_BOOK.getId()) { if (item.getId() == 387) { // WRITTEN_BOOK
CompoundTag tag = item.getTag(); CompoundTag tag = item.getTag();
if (tag == null) { if (tag == null) {
tag = new CompoundTag("tag"); tag = new CompoundTag("tag");

Datei anzeigen

@ -6,7 +6,7 @@ import com.google.gson.JsonObject;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
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.ViaVersion; 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.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata; 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.Type;
import us.myles.ViaVersion.api.type.types.version.Metadata1_8Type; import us.myles.ViaVersion.api.type.types.version.Metadata1_8Type;
import us.myles.ViaVersion.api.type.types.version.MetadataList1_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.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.packets.*; import us.myles.ViaVersion.protocols.protocol1_9to1_8.packets.*;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.*; import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.*;
@ -53,7 +52,7 @@ public class Protocol1_9TO1_8 extends Protocol {
try { try {
gson.fromJson(line, JsonObject.class); gson.fromJson(line, JsonObject.class);
} catch (Exception e) { } catch (Exception e) {
if (ViaVersion.getConfig().isForceJsonTransform()) { if (Via.getConfig().isForceJsonTransform()) {
return constructJson(line); return constructJson(line);
} else { } else {
System.out.println("Invalid JSON String: \"" + line + "\" Please report this issue to the ViaVersion Github: " + e.getMessage()); 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); }).get(10, TimeUnit.SECONDS);
} catch (Exception e) { } catch (Exception e) {
System.out.println("Error fetching hand item: " + e.getClass().getName()); System.out.println("Error fetching hand item: " + e.getClass().getName());
if (ViaVersion.getInstance().isDebug()) if (Via.getManager().isDebug())
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
@ -146,4 +145,14 @@ public class Protocol1_9TO1_8 extends Protocol {
// Place block tracker // Place block tracker
userConnection.put(new PlaceBlockTracker(userConnection)); 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;
}
} }

Datei anzeigen

@ -4,6 +4,7 @@ import io.netty.channel.ChannelHandlerContext;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.ViaVersion; import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.base.ProtocolInfo;
@ -29,7 +30,7 @@ public class ViaIdleThread extends BukkitRunnable {
private Method handleFlying; private Method handleFlying;
public ViaIdleThread(Map<UUID, UserConnection> portedPlayers) { public ViaIdleThread(Map<UUID, UserConnection> portedPlayers) {
USE_NMS = ViaVersion.getConfig().isNMSPlayerTicking(); USE_NMS = Via.getConfig().isNMSPlayerTicking();
this.portedPlayers = portedPlayers; this.portedPlayers = portedPlayers;
Class<?> idlePacketClass; Class<?> idlePacketClass;

Datei anzeigen

@ -1,10 +1,9 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata; package us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata;
import org.bukkit.entity.EntityType; 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.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.item.Item;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter; import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter;

Datei anzeigen

@ -1,8 +1,7 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets; package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets;
import org.bukkit.Material;
import us.myles.ViaVersion.api.PacketWrapper; 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.item.Item;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.Protocol;
@ -85,11 +84,11 @@ public class EntityPackets {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int entityID = wrapper.get(Type.VAR_INT, 0); int entityID = wrapper.get(Type.VAR_INT, 0);
if (ViaVersion.getConfig().isHologramPatch()) { if (Via.getConfig().isHologramPatch()) {
EntityTracker tracker = wrapper.user().get(EntityTracker.class); EntityTracker tracker = wrapper.user().get(EntityTracker.class);
if (tracker.getKnownHolograms().contains(entityID)) { if (tracker.getKnownHolograms().contains(entityID)) {
Double newValue = wrapper.get(Type.DOUBLE, 1); Double newValue = wrapper.get(Type.DOUBLE, 1);
newValue += (ViaVersion.getConfig().getHologramYOffset()); newValue += (Via.getConfig().getHologramYOffset());
wrapper.set(Type.DOUBLE, 1, newValue); wrapper.set(Type.DOUBLE, 1, newValue);
} }
} }
@ -159,13 +158,11 @@ public class EntityPackets {
Item stack = wrapper.get(Type.ITEM, 0); Item stack = wrapper.get(Type.ITEM, 0);
if (stack != null) { if (stack != null) {
if (Material.getMaterial(stack.getId()) != null) { if (Protocol1_9TO1_8.isSword(stack.getId())) {
if (Material.getMaterial(stack.getId()).name().endsWith("SWORD")) {
entityTracker.getValidBlocking().add(entityID); entityTracker.getValidBlocking().add(entityID);
return; return;
} }
} }
}
entityTracker.getValidBlocking().remove(entityID); entityTracker.getValidBlocking().remove(entityID);
} }
}); });
@ -231,7 +228,7 @@ public class EntityPackets {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
boolean showParticles = wrapper.read(Type.BOOLEAN); //In 1.8 = true->Show particles : false->Hide particles 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. //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)); wrapper.write(Type.BYTE, (byte) (showParticles ? newEffect ? 2 : 1 : 0));
} }

Datei anzeigen

@ -2,11 +2,9 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.PacketWrapper; 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.item.Item;
import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketHandler;
@ -124,7 +122,7 @@ public class PlayerPackets {
wrapper.passthrough(Type.STRING); // Name tag visibility 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 wrapper.passthrough(Type.BYTE); // Colour
} }
@ -137,12 +135,12 @@ public class PlayerPackets {
if (entityTracker.isAutoTeam() && player.equalsIgnoreCase(myName)) { if (entityTracker.isAutoTeam() && player.equalsIgnoreCase(myName)) {
if (mode == 4) { if (mode == 4) {
// since removing add to auto team // since removing add to auto team
((ViaVersionPlugin) ViaVersion.getInstance()).run(new Runnable() { Via.getPlatform().runSync(new Runnable() {
@Override @Override
public void run() { public void run() {
entityTracker.sendTeamPacket(true); entityTracker.sendTeamPacket(true);
} }
}, false); });
} else { } else {
// since adding remove from auto team // since adding remove from auto team
entityTracker.sendTeamPacket(false); entityTracker.sendTeamPacket(false);
@ -477,7 +475,7 @@ public class PlayerPackets {
if (name.equalsIgnoreCase("MC|BSign")) { if (name.equalsIgnoreCase("MC|BSign")) {
Item item = wrapper.passthrough(Type.ITEM); Item item = wrapper.passthrough(Type.ITEM);
if (item != null) { if (item != null) {
item.setId((short) Material.WRITTEN_BOOK.getId()); item.setId((short) 387); // Written Book
} }
} }
if (name.equalsIgnoreCase("MC|AutoCmd")) { if (name.equalsIgnoreCase("MC|AutoCmd")) {

Datei anzeigen

@ -1,6 +1,5 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets; package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets;
import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
@ -104,7 +103,7 @@ public class SpawnPackets {
public void write(PacketWrapper wrapper) throws Exception { public void write(PacketWrapper wrapper) throws Exception {
wrapper.write(Type.VAR_INT, entityID); wrapper.write(Type.VAR_INT, entityID);
List<Metadata> meta = new ArrayList<>(); 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 ItemRewriter.toClient(item); // Rewrite so that it gets the right nbt
// TEMP FIX FOR POTIONS UNTIL WE FIGURE OUT HOW TO TRANSFORM SENT PACKETS // TEMP FIX FOR POTIONS UNTIL WE FIGURE OUT HOW TO TRANSFORM SENT PACKETS
Metadata potion = new Metadata(5, NewType.Slot.getTypeID(), Type.ITEM, item); Metadata potion = new Metadata(5, NewType.Slot.getTypeID(), Type.ITEM, item);

Datei anzeigen

@ -1,10 +1,9 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets; 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.CompoundTag;
import org.spacehq.opennbt.tag.builtin.StringTag; import org.spacehq.opennbt.tag.builtin.StringTag;
import us.myles.ViaVersion.api.PacketWrapper; 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.Position;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.Protocol;
@ -168,7 +167,7 @@ public class WorldPackets {
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
if (ViaVersion.getConfig().isAutoTeam()) { if (Via.getConfig().isAutoTeam()) {
EntityTracker entityTracker = wrapper.user().get(EntityTracker.class); EntityTracker entityTracker = wrapper.user().get(EntityTracker.class);
entityTracker.setAutoTeam(true); entityTracker.setAutoTeam(true);
entityTracker.sendTeamPacket(true); entityTracker.sendTeamPacket(true);
@ -259,10 +258,9 @@ public class WorldPackets {
// Write item in hand // Write item in hand
Item item = Protocol1_9TO1_8.getHandItem(wrapper.user()); Item item = Protocol1_9TO1_8.getHandItem(wrapper.user());
// Blocking patch // Blocking patch
if (ViaVersion.getConfig().isShieldBlocking()) { if (Via.getConfig().isShieldBlocking()) {
if (item != null) { if (item != null) {
if (Material.getMaterial(item.getId()) != null) { if (Protocol1_9TO1_8.isSword(item.getId())) {
if (Material.getMaterial(item.getId()).name().endsWith("SWORD")) {
if (hand == 0) { if (hand == 0) {
EntityTracker tracker = wrapper.user().get(EntityTracker.class); EntityTracker tracker = wrapper.user().get(EntityTracker.class);
if (!tracker.isBlocking()) { if (!tracker.isBlocking()) {
@ -275,7 +273,6 @@ public class WorldPackets {
} }
} }
} }
}
wrapper.write(Type.ITEM, item); wrapper.write(Type.ITEM, item);
wrapper.write(Type.BYTE, (byte) 0); wrapper.write(Type.BYTE, (byte) 0);

Datei anzeigen

@ -54,7 +54,7 @@ public class ClientChunks extends StoredObject {
int[] zcoords = mapChunkBulkRef.getFieldValue("b", packet, int[].class); int[] zcoords = mapChunkBulkRef.getFieldValue("b", packet, int[].class);
Object[] chunkMaps = mapChunkBulkRef.getFieldValue("c", packet, Object[].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 { try {
Object world = mapChunkBulkRef.getFieldValue("world", packet, Object.class); Object world = mapChunkBulkRef.getFieldValue("world", packet, Object.class);

Datei anzeigen

@ -6,10 +6,9 @@ import com.google.common.collect.Sets;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import us.myles.ViaVersion.api.PacketWrapper; 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.BossBar;
import us.myles.ViaVersion.api.boss.BossColor; import us.myles.ViaVersion.api.boss.BossColor;
import us.myles.ViaVersion.api.boss.BossStyle; 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 Map<Integer, BossBar> bossBarMap = new ConcurrentHashMap<>();
private final Set<Integer> validBlocking = Sets.newConcurrentHashSet(); private final Set<Integer> validBlocking = Sets.newConcurrentHashSet();
private final Set<Integer> knownHolograms = 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 @Setter
private boolean blocking = false; private boolean blocking = false;
@Setter @Setter
@ -111,7 +110,7 @@ public class EntityTracker extends StoredObject {
} }
public void addBlockInteraction(Position p) { public void addBlockInteraction(Position p) {
blockInteractions.put(p, Material.AIR); blockInteractions.put(p, 0);
} }
public void handleMetadata(int entityID, List<Metadata> metadataList) { public void handleMetadata(int entityID, List<Metadata> metadataList) {
@ -153,7 +152,7 @@ public class EntityTracker extends StoredObject {
if (metadata.getId() == 0) { if (metadata.getId() == 0) {
// Byte // Byte
byte data = (byte) metadata.getValue(); byte data = (byte) metadata.getValue();
if (entityID != getEntityID() && ViaVersion.getConfig().isShieldBlocking()) { if (entityID != getEntityID() && Via.getConfig().isShieldBlocking()) {
if ((data & 0x10) == 0x10) { if ((data & 0x10) == 0x10) {
if (validBlocking.contains(entityID)) { if (validBlocking.contains(entityID)) {
Item shield = new Item((short) 442, (byte) 1, (short) 0, null); 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, 0x25); // Relative Move Packet
Type.VAR_INT.write(buf, entityID); Type.VAR_INT.write(buf, entityID);
buf.writeShort(0); buf.writeShort(0);
buf.writeShort((short) (128D * (ViaVersion.getConfig().getHologramYOffset() * 32D))); buf.writeShort((short) (128D * (Via.getConfig().getHologramYOffset() * 32D)));
buf.writeShort(0); buf.writeShort(0);
buf.writeBoolean(true); buf.writeBoolean(true);
getUser().sendRawPacket(buf, false); getUser().sendRawPacket(buf, false);
@ -192,28 +191,28 @@ public class EntityTracker extends StoredObject {
} }
UUID uuid = getUser().get(ProtocolInfo.class).getUuid(); UUID uuid = getUser().get(ProtocolInfo.class).getUuid();
// Boss bar // Boss bar
if (ViaVersion.getConfig().isBossbarPatch()) { if (Via.getConfig().isBossbarPatch()) {
if (type == EntityType.ENDER_DRAGON || type == EntityType.WITHER) { if (type == EntityType.ENDER_DRAGON || type == EntityType.WITHER) {
if (metadata.getId() == 2) { if (metadata.getId() == 2) {
BossBar bar = bossBarMap.get(entityID); BossBar bar = bossBarMap.get(entityID);
String title = (String) metadata.getValue(); String title = (String) metadata.getValue();
title = title.isEmpty() ? (type == EntityType.ENDER_DRAGON ? "Ender Dragon" : "Wither") : title; title = title.isEmpty() ? (type == EntityType.ENDER_DRAGON ? "Ender Dragon" : "Wither") : title;
if (bar == null) { 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); bossBarMap.put(entityID, bar);
bar.addPlayer(uuid); bar.addPlayer(uuid);
bar.show(); bar.show();
} else { } else {
bar.setTitle(title); 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); BossBar bar = bossBarMap.get(entityID);
// Make health range between 0 and 1 // Make health range between 0 and 1
float maxHealth = type == EntityType.ENDER_DRAGON ? 200.0f : 300.0f; float maxHealth = type == EntityType.ENDER_DRAGON ? 200.0f : 300.0f;
float health = Math.max(0.0f, Math.min(((float) metadata.getValue()) / maxHealth, 1.0f)); float health = Math.max(0.0f, Math.min(((float) metadata.getValue()) / maxHealth, 1.0f));
if (bar == null) { if (bar == null) {
String title = type == EntityType.ENDER_DRAGON ? "Ender Dragon" : "Wither"; 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); bossBarMap.put(entityID, bar);
bar.addPlayer(uuid); bar.addPlayer(uuid);
bar.show(); bar.show();

Datei anzeigen

@ -3,7 +3,6 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.types;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import us.myles.ViaVersion.api.Via; 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.minecraft.chunks.Chunk;
import us.myles.ViaVersion.api.type.PartialType; import us.myles.ViaVersion.api.type.PartialType;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
@ -49,8 +48,8 @@ public class ChunkType extends PartialType<Chunk, ClientChunks> {
@Override @Override
public Chunk read(ByteBuf input, ClientChunks param) throws Exception { 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(); boolean replacePistons = param.getUser().get(ProtocolInfo.class).getPipeline().contains(Protocol1_10To1_9_3_4.class) && Via.getConfig().isReplacePistons();
int replacementId = ViaVersion.getConfig().getPistonReplacementId(); int replacementId = Via.getConfig().getPistonReplacementId();
int chunkX = input.readInt(); int chunkX = input.readInt();
int chunkZ = input.readInt(); int chunkZ = input.readInt();

Datei anzeigen

@ -1,7 +1,7 @@
package us.myles.ViaVersion.protocols.protocolsnapshotto1_10; package us.myles.ViaVersion.protocols.protocolsnapshotto1_10;
import com.google.common.base.Optional; 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.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.NewType; import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.NewType;
@ -75,8 +75,7 @@ public class MetadataRewriter {
} }
return currentType; return currentType;
} catch (Exception e) { } catch (Exception e) {
; if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) {
if (!ViaVersion.getConfig().isSuppressMetadataErrors() || ViaVersion.getInstance().isDebug()) {
System.out.println("An error occurred with entity type rewriter"); System.out.println("An error occurred with entity type rewriter");
System.out.println("Metadata: " + metadata); System.out.println("Metadata: " + metadata);
e.printStackTrace(); e.printStackTrace();
@ -154,7 +153,7 @@ public class MetadataRewriter {
} }
} catch (Exception e) { } catch (Exception e) {
metadatas.remove(metadata); 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("An error occurred with entity metadata handler");
System.out.println("Metadata: " + metadata); System.out.println("Metadata: " + metadata);
e.printStackTrace(); e.printStackTrace();