SteamWar/FightSystem
Archiviert
13
1

Add Bow, Damage and Fire

Dieser Commit ist enthalten in:
Chaoscaot 2021-04-12 23:32:28 +02:00
Ursprung 3f1706f40f
Commit d2799bfb87
3 geänderte Dateien mit 53 neuen und 11 gelöschten Zeilen

Datei anzeigen

@ -347,7 +347,7 @@ public class Config {
EventTeamRedID = 0; EventTeamRedID = 0;
BothTeamsPublic = true; BothTeamsPublic = true;
MaximumTeamMembers = Integer.MAX_VALUE; MaximumTeamMembers = Integer.MAX_VALUE;
SpectateSystem = true; SpectateSystem = false;
} }
String blueLeader = System.getProperty("blueLeader", null); String blueLeader = System.getProperty("blueLeader", null);
@ -384,6 +384,6 @@ public class Config {
return ArenaMode.Test.contains(mode); return ArenaMode.Test.contains(mode);
} }
public static boolean recording(){ public static boolean recording(){
return true;//mode == ArenaMode.EVENT; return mode == ArenaMode.EVENT;
} }
} }

Datei anzeigen

@ -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;
@ -28,6 +34,7 @@ import de.steamwar.fightsystem.record.RecordSystem;
import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.states.StateDependent;
import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.states.StateDependentListener;
import net.minecraft.server.v1_15_R1.PacketPlayInBlockDig;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -35,6 +42,7 @@ import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler; 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.Action;
import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.entity.*; import org.bukkit.event.entity.*;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
@ -68,6 +76,35 @@ public class Recording implements Listener {
despawnTNT(); despawnTNT();
} }
}.register(); }.register();
//Bow Listener
ProtocolLibrary.getProtocolManager().addPacketListener(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?1:0);
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Client.BLOCK_DIG) {
@Override
public void onPacketReceiving(PacketEvent e) {
if(e.getPlayer() != event.getPlayer())
return;
PacketContainer packetDig = e.getPacket();
if(packetDig.getPlayerDigTypes().read(0) == EnumWrappers.PlayerDigType.RELEASE_USE_ITEM) {
RecordSystem.bowSpan(e.getPlayer(), false, hand == EnumWrappers.Hand.MAIN_HAND?0:1);
ProtocolLibrary.getProtocolManager().removePacketListener(this);
}
}
});
}
});
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@ -110,6 +147,9 @@ public class Recording implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityDamage(EntityDamageEvent e) { public void onEntityDamage(EntityDamageEvent e) {
if(e.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK || e.getCause() == EntityDamageEvent.DamageCause.FIRE ||e.getEntity().getFireTicks() > 0)
RecordSystem.setOnFire(e.getEntity(), false);
if(e.getEntityType() != EntityType.PLAYER) if(e.getEntityType() != EntityType.PLAYER)
return; return;
@ -118,9 +158,6 @@ public class Recording implements Listener {
return; return;
RecordSystem.damageAnimation(p); RecordSystem.damageAnimation(p);
if(e.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK)
RecordSystem.setOnFire(p);
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)

Datei anzeigen

@ -64,9 +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
* BowSpanPacket (0x0A) + int EntityId + boolean hand * BowSpanPacket (0x0A) + int EntityId + boolean start + int hand
* PlayerDamagePacket (0x0B) + int EntityId * PlayerDamagePacket (0x0B) + int EntityId
* SetOnFire (0x0C) + int EntityId * SetOnFire (0x0C) + int EntityId + boolean perma
* *
* *
* BlockPacket (0x30) + pos int, byte, int + int BlockState * BlockPacket (0x30) + pos int, byte, int + int BlockState
@ -166,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){
@ -173,9 +175,11 @@ public class RecordSystem {
spawnEntity(e); spawnEntity(e);
} }
public static synchronized void bowSpan(Player p) { public static synchronized void bowSpan(Entity e, boolean start, int hand) {
Recorder.rByte(0x0A); Recorder.rByte(0x0A);
Recorder.rInt(p.getEntityId()); Recorder.rInt(e.getEntityId());
Recorder.rBoolean(start);
Recorder.rInt(hand);
Recorder.flush(); Recorder.flush();
} }
@ -185,9 +189,10 @@ public class RecordSystem {
Recorder.flush(); Recorder.flush();
} }
public static synchronized void setOnFire(Player p) { public static synchronized void setOnFire(Entity e, boolean perma) {
Recorder.rByte(0x0C); Recorder.rByte(0x0C);
Recorder.rInt(p.getEntityId()); Recorder.rInt(e.getEntityId());
Recorder.rBoolean(perma);
Recorder.flush(); Recorder.flush();
} }