diff --git a/pom.xml b/pom.xml index f1657460..728a1bdc 100644 --- a/pom.xml +++ b/pom.xml @@ -53,12 +53,12 @@ org.spigotmc spigot-api - 1.14-R0.1-SNAPSHOT + 1.15-R0.1-SNAPSHOT org.spigotmc spigot - 1.14-R0.1-SNAPSHOT + 1.15-R0.1-SNAPSHOT diff --git a/src/main/java/me/libraryaddict/disguise/LibsDisguises.java b/src/main/java/me/libraryaddict/disguise/LibsDisguises.java index 9831efa7..b3edb5c2 100644 --- a/src/main/java/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/main/java/me/libraryaddict/disguise/LibsDisguises.java @@ -60,7 +60,7 @@ public class LibsDisguises extends JavaPlugin { "Blocks, Admins)"); } - if (!ReflectionManager.getMinecraftVersion().startsWith("1.14.4")) { + if (!ReflectionManager.getMinecraftVersion().startsWith("1.15")) { getLogger().severe("You're using the wrong version of Lib's Disguises for your server! This is " + "intended for 1.14.4!"); getPluginLoader().disablePlugin(this); diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/DisguiseType.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/DisguiseType.java index 34a2afac..f64e737c 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/DisguiseType.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/DisguiseType.java @@ -4,6 +4,7 @@ import me.libraryaddict.disguise.utilities.translations.TranslateType; import org.apache.commons.lang.StringUtils; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; +import org.omg.CORBA.UNKNOWN; public enum DisguiseType { AREA_EFFECT_CLOUD(3, 0), @@ -14,6 +15,8 @@ public enum DisguiseType { BAT, + BEE, + BLAZE, BOAT(1), diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/MetaIndex.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/MetaIndex.java index f37a4bff..c6b3980a 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/MetaIndex.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/MetaIndex.java @@ -108,6 +108,10 @@ public class MetaIndex { */ public static MetaIndex BAT_HANGING = new MetaIndex<>(BatWatcher.class, 0, (byte) 1); + public static MetaIndex BEE_META = new MetaIndex<>(BeeWatcher.class, 0, (byte) 0); + + public static MetaIndex BEE_ANGER = new MetaIndex<>(BeeWatcher.class, 1, 0); + /** * If the blaze is ignited, false/true state */ @@ -195,6 +199,8 @@ public class MetaIndex { */ public static MetaIndex ENDERMAN_AGRESSIVE = new MetaIndex<>(EndermanWatcher.class, 1, false); + public static MetaIndex ENDERMAN_UNKNOWN = new MetaIndex<>(EndermanWatcher.class, 2, false); + /** * What block the enderman is holding */ @@ -342,7 +348,12 @@ public class MetaIndex { */ public static MetaIndex LIVING_POTIONS = new MetaIndex<>(LivingWatcher.class, 2, 0); - public static MetaIndex> LIVING_BED_POSITION = new MetaIndex<>(LivingWatcher.class, 5, + /** + * How many bee stings does the entity have + */ + public static MetaIndex LIVING_STINGS = new MetaIndex<>(LivingWatcher.class, 5, 0); + + public static MetaIndex> LIVING_BED_POSITION = new MetaIndex<>(LivingWatcher.class, 6, Optional.empty()); /** @@ -477,6 +488,8 @@ public class MetaIndex { public static MetaIndex TRIDENT_ENCHANTS = new MetaIndex<>(TridentWatcher.class, 0, (byte) 0); + public static MetaIndex TRIDENT_ENCHANTED = new MetaIndex<>(TridentWatcher.class, 1, false); + public static MetaIndex TROPICAL_FISH_VARIANT = new MetaIndex<>(TropicalFishWatcher.class, 0, 0); public static MetaIndex TURTLE_HOME_POSITION = new MetaIndex<>(TurtleWatcher.class, 0, @@ -512,11 +525,9 @@ public class MetaIndex { public static MetaIndex WITHER_SKULL_BLUE = new MetaIndex<>(WitherSkullWatcher.class, 0, false); - public static MetaIndex WOLF_BEGGING = new MetaIndex<>(WolfWatcher.class, 1, false); + public static MetaIndex WOLF_BEGGING = new MetaIndex<>(WolfWatcher.class, 0, false); - public static MetaIndex WOLF_COLLAR = new MetaIndex<>(WolfWatcher.class, 2, 14); - - public static MetaIndex WOLF_DAMAGE = new MetaIndex<>(WolfWatcher.class, 0, 1F); + public static MetaIndex WOLF_COLLAR = new MetaIndex<>(WolfWatcher.class, 1, 14); public static MetaIndex ZOMBIE_BABY = new MetaIndex<>(ZombieWatcher.class, 0, false); diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BeeWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BeeWatcher.java new file mode 100644 index 00000000..148ddbff --- /dev/null +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BeeWatcher.java @@ -0,0 +1,63 @@ +package me.libraryaddict.disguise.disguisetypes.watchers; + +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.MetaIndex; + +/** + * Created by libraryaddict on 14/12/2019. + */ +public class BeeWatcher extends AgeableWatcher { + public BeeWatcher(Disguise disguise) { + super(disguise); + } + + public void setBeeAnger(int beeAnger) { + setData(MetaIndex.BEE_ANGER, beeAnger); + sendData(MetaIndex.BEE_ANGER); + } + + public int getBeeAnger() { + return getData(MetaIndex.BEE_ANGER); + } + + public void setHasNectar(boolean hasNectar) { + setBeeFlag(8, hasNectar); + } + + public boolean hasNectar() { + return getBeeFlag(8); + } + + public void setHasStung(boolean hasStung) { + setBeeFlag(4, hasStung); + } + + public boolean hasStung() { + return getBeeFlag(4); + } + + public void setFlipped(boolean isFlipped) { + setBeeFlag(2, isFlipped); + } + + public boolean isFlipped() { + return getBeeFlag(2); + } + + private boolean getBeeFlag(int value) { + return (getData(MetaIndex.PANDA_META) & value) != 0; + } + + private void setBeeFlag(int no, boolean flag) { + byte b1 = getData(MetaIndex.BEE_META); + + if (flag) { + b1 = (byte) (b1 | no); + } else { + b1 = (byte) (b1 & ~no); + } + + setData(MetaIndex.BEE_META, b1); + sendData(MetaIndex.BEE_META); + } +} diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java index 58ca207e..70e3721c 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java @@ -55,4 +55,9 @@ public class EndermanWatcher extends InsentientWatcher { setData(MetaIndex.ENDERMAN_AGRESSIVE, isAggressive); sendData(MetaIndex.ENDERMAN_AGRESSIVE); } + + public void setUnknown(boolean bo) { + setData(MetaIndex.ENDERMAN_UNKNOWN, bo); + sendData(MetaIndex.ENDERMAN_UNKNOWN); + } } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/IllagerWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/IllagerWatcher.java index ffbd48ec..aff1a33f 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/IllagerWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/IllagerWatcher.java @@ -1,7 +1,6 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; -import net.minecraft.server.v1_14_R1.EntityRaider; /** * Created by libraryaddict on 9/06/2017. diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TridentWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TridentWatcher.java index f5d069ca..777d4306 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TridentWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TridentWatcher.java @@ -1,6 +1,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.MetaIndex; /** * Created by libraryaddict on 6/08/2018. @@ -9,4 +10,13 @@ public class TridentWatcher extends ArrowWatcher { public TridentWatcher(Disguise disguise) { super(disguise); } + + public void setEnchanted(boolean enchanted) { + setData(MetaIndex.TRIDENT_ENCHANTED, enchanted); + sendData(MetaIndex.TRIDENT_ENCHANTED); + } + + public boolean isEnchanted() { + return getData(MetaIndex.TRIDENT_ENCHANTED); + } } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java index a040035c..0641c950 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java @@ -15,25 +15,6 @@ public class WolfWatcher extends TameableWatcher { return AnimalColor.getColorByWool(getData(MetaIndex.WOLF_COLLAR)); } - /** - * Used for tail rotation. - * - * @return - */ - public float getDamageTaken() { - return getData(MetaIndex.WOLF_DAMAGE); - } - - /** - * Used for tail rotation. - * - * @param damage - */ - public void setDamageTaken(float damage) { - setData(MetaIndex.WOLF_DAMAGE, damage); - sendData(MetaIndex.WOLF_DAMAGE); - } - public boolean isBegging() { return getData(MetaIndex.WOLF_BEGGING); } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseSound.java b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseSound.java index fee6bdfa..dbd77c10 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseSound.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseSound.java @@ -19,6 +19,9 @@ public enum DisguiseSound { BAT(Sound.ENTITY_BAT_HURT, null, Sound.ENTITY_BAT_DEATH, Sound.ENTITY_BAT_AMBIENT, Sound.ENTITY_PLAYER_SMALL_FALL, Sound.ENTITY_BAT_LOOP, Sound.ENTITY_PLAYER_BIG_FALL, Sound.ENTITY_BAT_TAKEOFF), + BEE(Sound.ENTITY_BEE_HURT, null, Sound.ENTITY_BEE_DEATH, null, Sound.ENTITY_BEE_LOOP, + Sound.ENTITY_BEE_LOOP_AGGRESSIVE, Sound.ENTITY_BEE_POLLINATE, Sound.ENTITY_BEE_STING), + BLAZE(Sound.ENTITY_BLAZE_HURT, null, Sound.ENTITY_BLAZE_DEATH, Sound.ENTITY_BLAZE_AMBIENT, Sound.ENTITY_PLAYER_SMALL_FALL, Sound.ENTITY_PLAYER_BIG_FALL, Sound.ENTITY_BLAZE_BURN, Sound.ENTITY_BLAZE_SHOOT), diff --git a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index cec90b14..c4098709 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -525,62 +525,6 @@ public class DisguiseUtilities { return cord; } - public static PacketContainer[] getBedChunkPacket(Location newLoc, Location oldLoc) { - int i = 0; - - PacketContainer[] packets = new PacketContainer[(newLoc != null ? 1 : 0) + (oldLoc != null ? 1 : 0)]; - - if (oldLoc != null) { - PacketContainer despawn = new PacketContainer(Server.UNLOAD_CHUNK); - - StructureModifier modifier = despawn.getModifier(); - - modifier.write(0, getChunkCord(oldLoc.getBlockX())); - modifier.write(1, getChunkCord(oldLoc.getBlockZ())); - - packets[i++] = despawn; - } - - if (newLoc != null) { - PacketContainer spawn = spawnChunk.shallowClone(); - - StructureModifier modifier = spawn.getModifier(); - - modifier.write(0, getChunkCord(newLoc.getBlockX())); - modifier.write(1, getChunkCord(newLoc.getBlockZ())); - - packets[i++] = spawn; - } - - return packets; - } - - public static PacketContainer[] getBedPackets(Location sleepingLocation, Location playerLocation, - PlayerDisguise disguise) { - int entity = disguise.getEntity().getEntityId(); - PlayerWatcher watcher = disguise.getWatcher(); - - //PacketContainer setBed = new PacketContainer(Server.BED); - - int bX = (getChunkCord(playerLocation.getBlockX()) * 16) + 1 + watcher.getSleepingDirection().getModX(); - int bZ = (getChunkCord(playerLocation.getBlockZ()) * 16) + 1 + watcher.getSleepingDirection().getModZ(); - - // setBed.getIntegers().write(0, entity); - // setBed.getBlockPositionModifier().write(0, new BlockPosition(bX, 0, bZ)); - - PacketContainer teleport = new PacketContainer(Server.ENTITY_TELEPORT); - - StructureModifier doubles = teleport.getDoubles(); - - teleport.getIntegers().write(0, entity); - - doubles.write(0, sleepingLocation.getX()); - doubles.write(1, DisguiseUtilities.getYModifier(disguise.getEntity(), disguise) + sleepingLocation.getY()); - doubles.write(2, sleepingLocation.getZ()); - - return new PacketContainer[]{teleport}; - } - public static Disguise getClonedDisguise(String key) { if (clonedDisguises.containsKey(key)) { return clonedDisguises.get(key).clone(); @@ -879,81 +823,6 @@ public class DisguiseUtilities { gson = gsonBuilder.create(); try { - Object world = ReflectionManager.getWorldServer(Bukkit.getWorlds().get(0)); - Class chunkClass = ReflectionManager.getNmsClass("Chunk"); - Object bedChunk = null; - Object[] biomes = (Object[]) Array.newInstance(ReflectionManager.getNmsClass("BiomeBase"), 256); - - Class registry = ReflectionManager.getNmsClass("IRegistry"); - Field biomeRegistry = ReflectionManager.getNmsField(registry, "BIOME"); - Iterator itel = ((Iterator) registry.getMethod("iterator").invoke(biomeRegistry.get(null))); - - for (int i = 0; i < biomes.length && itel.hasNext(); i++) { - while (itel.hasNext()) { - biomes[i] = itel.next(); - } - } - - for (Constructor constructor : chunkClass.getConstructors()) { - if (constructor.getParameterTypes().length != 9) - continue; - - Object cords = ReflectionManager.getNmsConstructor("ChunkCoordIntPair", int.class, int.class) - .newInstance(0, 0); - - bedChunk = constructor.newInstance(world, cords, biomes, null, null, null, 0L, null, null); - break; - } - - if (bedChunk == null) { - throw new IllegalStateException("[LibsDisguises] Cannot find constructor to create world chunk"); - } - - Field cSection = chunkClass.getDeclaredField("sections"); - cSection.setAccessible(true); - - Object chunkSection = ReflectionManager.getNmsClass("ChunkSection").getConstructor(int.class) - .newInstance(0); - - Class blockClass = ReflectionManager.getNmsClass("Block"); - Object REGISTRY = ReflectionManager.getNmsField("IRegistry", "BLOCK").get(null); - Object minecraftKey = ReflectionManager.createMinecraftKey("white_bed"); - - Object block = REGISTRY.getClass().getMethod("get", minecraftKey.getClass()).invoke(REGISTRY, minecraftKey); - Object blockData = ReflectionManager.getNmsMethod(blockClass, "getBlockData").invoke(block); - Method method = null; - - for (Method method1 : blockData.getClass().getMethods()) { - if (!method1.getName().equals("set") || method1.getParameterTypes().length != 2) - continue; - - method = method1; - break; - } - - Method setType = chunkSection.getClass() - .getMethod("setType", int.class, int.class, int.class, ReflectionManager.getNmsClass("IBlockData")); - - for (BlockFace face : new BlockFace[]{BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH}) { - int x = 1 + face.getModX(); - int z = 1 + face.getModZ(); - - Object data = method.invoke(blockData, block.getClass().getField("FACING").get(null), - ReflectionManager.getEnumDirection(face.ordinal())); - - setType.invoke(chunkSection, x, 0, z, data); - } - - Object[] array = (Object[]) Array.newInstance(chunkSection.getClass(), 16); - - array[0] = chunkSection; - - cSection.set(bedChunk, array); - - spawnChunk = ProtocolLibrary.getProtocolManager() - .createPacketConstructor(PacketType.Play.Server.MAP_CHUNK, bedChunk, 65535) - .createPacket(bedChunk, 65535); - Field threadField = ReflectionManager.getNmsField("MinecraftServer", "serverThread"); threadField.setAccessible(true); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java b/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java index 703db343..e5d01800 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java @@ -1,6 +1,7 @@ package me.libraryaddict.disguise.utilities.packets.packethandlers; import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLib; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.reflect.StructureModifier; @@ -209,14 +210,18 @@ public class PacketHandlerSpawn implements IPacketHandler { bytes.write(0, yaw); bytes.write(1, pitch); - spawnPlayer.getDataWatcherModifier().write(0, newWatcher); - // Make him invisible newWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(MetaIndex.ENTITY_META.getIndex(), WrappedDataWatcher.Registry.get(Byte.class)), (byte) 32); packets.addPacket(spawnPlayer); + PacketContainer metaPacket = ProtocolLibrary.getProtocolManager() + .createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, entityId, newWatcher, true) + .createPacket(entityId, newWatcher, true); + + packets.addPacket(metaPacket); + if (!selfDisguise) { // Teleport the player back to where he's supposed to be PacketContainer teleportPacket = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT); @@ -235,7 +240,7 @@ public class PacketHandlerSpawn implements IPacketHandler { packets.addDelayedPacket(teleportPacket, 3); // Send a metadata packet - PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA); + metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA); newWatcher = DisguiseUtilities .createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), @@ -302,9 +307,15 @@ public class PacketHandlerSpawn implements IPacketHandler { mods.write(10, pitch); mods.write(11, yaw); - spawnEntity.getDataWatcherModifier().write(0, DisguiseUtilities + WrappedDataWatcher newWatcher = DisguiseUtilities .createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), - disguise.getWatcher())); + disguise.getWatcher()); + + PacketContainer metaPacket = ProtocolLibrary.getProtocolManager() + .createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, disguisedEntity.getEntityId(), + newWatcher, true).createPacket(disguisedEntity.getEntityId(), newWatcher, true); + + packets.addPacket(metaPacket); } else if (disguise.getType().isMisc()) { int data = ((MiscDisguise) disguise).getData(); double x = loc.getX();