diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Recording.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Recording.java index fcefb2f..9a414ba 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Recording.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Recording.java @@ -19,6 +19,12 @@ package de.steamwar.fightsystem.listener; +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.events.PacketAdapter; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.events.PacketEvent; +import com.comphenix.protocol.wrappers.EnumWrappers; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; @@ -36,10 +42,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockPhysicsEvent; -import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.event.entity.EntitySpawnEvent; -import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.entity.ProjectileLaunchEvent; +import org.bukkit.event.entity.*; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.player.*; @@ -52,6 +55,30 @@ public class Recording implements Listener { private static final int AIR = 0; private static final Random random = new Random(); + private static final PacketAdapter BOW_PACKET_PROCESSOR = new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Client.BLOCK_PLACE) { + @Override + public void onPacketReceiving(PacketEvent event) { + PacketContainer packet = event.getPacket(); + EnumWrappers.Hand hand = packet.getHands().read(0); + Player p = event.getPlayer(); + + if(!((hand == EnumWrappers.Hand.MAIN_HAND && p.getInventory().getItemInMainHand().getType() == Material.BOW) || + (hand == EnumWrappers.Hand.OFF_HAND && p.getInventory().getItemInOffHand().getType() == Material.BOW))) + return; + + RecordSystem.bowSpan(p, true, hand != EnumWrappers.Hand.MAIN_HAND); + } + }; + + private static final PacketAdapter BOW_PACKET_DEDRAW_PROCESSOR = new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Client.BLOCK_DIG) { + @Override + public void onPacketReceiving(PacketEvent e) { + PacketContainer packetDig = e.getPacket(); + if(packetDig.getPlayerDigTypes().read(0) == EnumWrappers.PlayerDigType.RELEASE_USE_ITEM) { + RecordSystem.bowSpan(e.getPlayer(), false, false); + } + } + }; public Recording() { new StateDependentListener(Config.recording(), FightState.All, this); @@ -71,6 +98,19 @@ public class Recording implements Listener { despawnTNT(); } }.register(); + new StateDependent(Config.recording(), FightState.Ingame) { + @Override + public void enable() { + ProtocolLibrary.getProtocolManager().addPacketListener(BOW_PACKET_PROCESSOR); + ProtocolLibrary.getProtocolManager().addPacketListener(BOW_PACKET_DEDRAW_PROCESSOR); + } + + @Override + public void disable() { + ProtocolLibrary.getProtocolManager().removePacketListener(BOW_PACKET_PROCESSOR); + ProtocolLibrary.getProtocolManager().removePacketListener(BOW_PACKET_DEDRAW_PROCESSOR); + } + }.register(); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @@ -111,6 +151,33 @@ public class Recording implements Listener { RecordSystem.entityAnimation(e.getPlayer(), AIR); } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onEntityDamage(EntityDamageEvent e) { + if(e.getEntityType() != EntityType.PLAYER) + return; + + Player p = (Player) e.getEntity(); + if(isNotSent(p)) + return; + + RecordSystem.damageAnimation(p); + + if(e.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK || e.getCause() == EntityDamageEvent.DamageCause.FIRE) + RecordSystem.setOnFire(p, false); + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onEntityCombust(EntityCombustEvent e) { + if(e.getEntityType() != EntityType.PLAYER) + return; + + Player p = (Player) e.getEntity(); + if(isNotSent(p)) + return; + + RecordSystem.setOnFire(p, false); + } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onTNTSpawn(EntitySpawnEvent e){ //TODO: Falling block diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java index f0282ff..52e31ba 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java @@ -64,8 +64,9 @@ public class RecordSystem { * PlayerItemPacket (0x07) + int EntityId + String item + boolean enchanted + String slot * ArrowSpawnPacket (0x08) + int EntityId * FireballSpawnPacket (0x09) + int EntityId - * TODO Bow spanning - * + * BowSpanPacket (0x0A) + int EntityId + boolean start + hand + * PlayerDamagePacket (0x0B) + int EntityId + * SetOnFire (0x0C) + int EntityId + boolean perma * * * BlockPacket (0x30) + pos int, byte, int + int BlockState @@ -165,6 +166,8 @@ public class RecordSystem { public static synchronized void arrowSpawn(Entity e){ Recorder.rByte(0x08); spawnEntity(e); + if(e.getFireTicks() > 0) + setOnFire(e, true); } public static synchronized void fireballSpawn(Entity e){ @@ -172,6 +175,27 @@ public class RecordSystem { spawnEntity(e); } + public static synchronized void bowSpan(Entity e, boolean start, boolean offHand) { + Recorder.rByte(0x0A); + Recorder.rInt(e.getEntityId()); + Recorder.rBoolean(start); + Recorder.rBoolean(offHand); + Recorder.flush(); + } + + public static synchronized void damageAnimation(Player p) { + Recorder.rByte(0x0B); + Recorder.rInt(p.getEntityId()); + Recorder.flush(); + } + + public static synchronized void setOnFire(Entity e, boolean perma) { + Recorder.rByte(0x0C); + Recorder.rInt(e.getEntityId()); + Recorder.rBoolean(perma); + Recorder.flush(); + } + public static synchronized void blockChange(Block block){ int blockState = blockToId(block);