Add Bow Damge and Fire #261
@ -19,6 +19,12 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.listener;
|
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.Config;
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
import de.steamwar.fightsystem.fight.Fight;
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
@ -36,10 +42,7 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
import org.bukkit.event.entity.*;
|
||||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
|
||||||
import org.bukkit.event.entity.ProjectileLaunchEvent;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.event.inventory.InventoryType;
|
import org.bukkit.event.inventory.InventoryType;
|
||||||
import org.bukkit.event.player.*;
|
import org.bukkit.event.player.*;
|
||||||
@ -52,6 +55,30 @@ public class Recording implements Listener {
|
|||||||
|
|
||||||
private static final int AIR = 0;
|
private static final int AIR = 0;
|
||||||
private static final Random random = new Random();
|
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() {
|
public Recording() {
|
||||||
new StateDependentListener(Config.recording(), FightState.All, this);
|
new StateDependentListener(Config.recording(), FightState.All, this);
|
||||||
@ -71,6 +98,19 @@ public class Recording implements Listener {
|
|||||||
despawnTNT();
|
despawnTNT();
|
||||||
}
|
}
|
||||||
}.register();
|
}.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)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
@ -111,6 +151,33 @@ public class Recording implements Listener {
|
|||||||
RecordSystem.entityAnimation(e.getPlayer(), AIR);
|
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)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onTNTSpawn(EntitySpawnEvent e){
|
public void onTNTSpawn(EntitySpawnEvent e){
|
||||||
//TODO: Falling block
|
//TODO: Falling block
|
||||||
|
@ -64,8 +64,9 @@ public class RecordSystem {
|
|||||||
* PlayerItemPacket (0x07) + int EntityId + String item + boolean enchanted + String slot
|
* PlayerItemPacket (0x07) + int EntityId + String item + boolean enchanted + String slot
|
||||||
* ArrowSpawnPacket (0x08) + int EntityId
|
* ArrowSpawnPacket (0x08) + int EntityId
|
||||||
* FireballSpawnPacket (0x09) + 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
|
||||||
Lixfel markierte diese Unterhaltung als gelöst
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* BlockPacket (0x30) + pos int, byte, int + int BlockState
|
* BlockPacket (0x30) + pos int, byte, int + int BlockState
|
||||||
@ -165,6 +166,8 @@ public class RecordSystem {
|
|||||||
public static synchronized void arrowSpawn(Entity e){
|
public static synchronized void arrowSpawn(Entity e){
|
||||||
Recorder.rByte(0x08);
|
Recorder.rByte(0x08);
|
||||||
spawnEntity(e);
|
spawnEntity(e);
|
||||||
|
if(e.getFireTicks() > 0)
|
||||||
|
setOnFire(e, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void fireballSpawn(Entity e){
|
public static synchronized void fireballSpawn(Entity e){
|
||||||
@ -172,6 +175,27 @@ public class RecordSystem {
|
|||||||
spawnEntity(e);
|
spawnEntity(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static synchronized void bowSpan(Entity e, boolean start, boolean offHand) {
|
||||||
Chaoscaot markierte diese Unterhaltung als gelöst
Lixfel
hat
Bögen kann man nur in der MainHand spannen? (Meines wissens nach?) Bögen kann man nur in der MainHand spannen? (Meines wissens nach?)
|
|||||||
|
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) {
|
||||||
Chaoscaot markierte diese Unterhaltung als gelöst
Lixfel
hat
Gibt es überhaupt permafeuer, wenn ja, wo? Gibt es überhaupt permafeuer, wenn ja, wo?
|
|||||||
|
Recorder.rByte(0x0C);
|
||||||
|
Recorder.rInt(e.getEntityId());
|
||||||
|
Recorder.rBoolean(perma);
|
||||||
|
Recorder.flush();
|
||||||
|
}
|
||||||
|
|
||||||
public static synchronized void blockChange(Block block){
|
public static synchronized void blockChange(Block block){
|
||||||
int blockState = blockToId(block);
|
int blockState = blockToId(block);
|
||||||
|
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Dieses Packet kommt mir nicht ganz richtig vor, FireTick ist doch eine sache, welche zufällig weggeht, somit ist es nicht deterministisch, also weiß ich nicht, ob das abspielen dieser nicht dann mal länger und mal kürzer ist, was nicht im Sinne des Packets sein dürfte.
Deshalb wird der FireTick auch, wenn die perma flag auf false ist, nur für 21 Ticks abgespielt, somit ist relativ genau, kann aber noch max. 1 Sekunde off sein.