SteamWar/FightSystem
Archiviert
13
1

TinyProtocol Recording
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2021-09-18 14:30:32 +02:00
Ursprung a4148c8e6d
Commit 56096d5070
5 geänderte Dateien mit 47 neuen und 48 gelöschten Zeilen

Datei anzeigen

@ -19,7 +19,6 @@
package de.steamwar.fightsystem.utils;
import com.comphenix.protocol.wrappers.EnumWrappers;
import de.steamwar.fightsystem.listener.Recording;
import de.steamwar.fightsystem.record.GlobalRecorder;
import net.md_5.bungee.api.chat.BaseComponent;
@ -35,8 +34,14 @@ import org.bukkit.event.Listener;
import org.bukkit.scoreboard.Team;
public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper {
@Override
public boolean bowInHand(EnumWrappers.Hand hand, Player p) {
public boolean mainHand(Object packet) {
return true;
}
@Override
public boolean bowInHand(boolean mainHand, Player p) {
return p.getInventory().getItemInHand().getType() == Material.BOW;
}

Datei anzeigen

@ -19,7 +19,7 @@
package de.steamwar.fightsystem.utils;
import com.comphenix.protocol.wrappers.EnumWrappers;
import com.comphenix.tinyprotocol.Reflection;
import de.steamwar.fightsystem.listener.Recording;
import de.steamwar.fightsystem.record.GlobalRecorder;
import net.md_5.bungee.api.ChatMessageType;
@ -38,10 +38,19 @@ import org.bukkit.event.player.PlayerSwapHandItemsEvent;
import org.bukkit.scoreboard.Team;
public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper {
private static final Class<?> enumHand = Reflection.getClass("{nms}.EnumHand");
private static final Object mainHand = enumHand.getEnumConstants()[0];
private static final Reflection.FieldAccessor<?> blockPlaceHand = Reflection.getField(Recording.blockPlacePacket, enumHand, 0);
@Override
public boolean bowInHand(EnumWrappers.Hand hand, Player p) {
return (hand == EnumWrappers.Hand.MAIN_HAND && p.getInventory().getItemInMainHand().getType() == Material.BOW) ||
(hand == EnumWrappers.Hand.OFF_HAND && p.getInventory().getItemInOffHand().getType() == Material.BOW);
public boolean mainHand(Object packet) {
return blockPlaceHand.get(packet) == mainHand;
}
@Override
public boolean bowInHand(boolean mainHand, Player p) {
return (mainHand ? p.getInventory().getItemInMainHand() : p.getInventory().getItemInOffHand()).getType() == Material.BOW;
}
@Override

Datei anzeigen

@ -19,12 +19,7 @@
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 com.comphenix.tinyprotocol.Reflection;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
@ -37,6 +32,7 @@ import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.states.StateDependentTask;
import de.steamwar.fightsystem.utils.BountifulWrapper;
import de.steamwar.fightsystem.utils.FlatteningWrapper;
import de.steamwar.fightsystem.utils.ProtocolAPI;
import de.steamwar.fightsystem.utils.SWSound;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@ -62,28 +58,6 @@ public class Recording implements Listener {
private static final int AIR = 0;
private static final Random random = new Random();
private static final World world = Bukkit.getWorlds().get(0);
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(!BountifulWrapper.impl.bowInHand(hand, p))
return;
GlobalRecorder.getInstance().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) {
GlobalRecorder.getInstance().bowSpan(e.getPlayer(), false, false);
}
}
};
public static ItemStack disarmNull(ItemStack stack){
if(stack == null)
@ -118,14 +92,14 @@ public class Recording implements Listener {
new StateDependent(ArenaMode.AntiReplay, FightState.Ingame) {
@Override
public void enable() {
ProtocolLibrary.getProtocolManager().addPacketListener(BOW_PACKET_PROCESSOR);
ProtocolLibrary.getProtocolManager().addPacketListener(BOW_PACKET_DEDRAW_PROCESSOR);
ProtocolAPI.setIncomingHandler(blockPlacePacket, Recording.this::blockPlace);
ProtocolAPI.setIncomingHandler(blockDigPacket, Recording.this::blockDig);
}
@Override
public void disable() {
ProtocolLibrary.getProtocolManager().removePacketListener(BOW_PACKET_PROCESSOR);
ProtocolLibrary.getProtocolManager().removePacketListener(BOW_PACKET_DEDRAW_PROCESSOR);
ProtocolAPI.removeIncomingHandler(blockPlacePacket);
ProtocolAPI.removeIncomingHandler(blockDigPacket);
}
}.register();
new StateDependentTask(ArenaMode.AntiReplay, FightState.All, () -> {
@ -141,6 +115,24 @@ public class Recording implements Listener {
}, 1, 1);
}
private static final Class<?> blockDigPacket = Reflection.getClass("{nms}.PacketPlayInBlockDig");
private static final Class<?> playerDigType = blockDigPacket.getDeclaredClasses()[0];
private static final Reflection.FieldAccessor<?> blockDigType = Reflection.getField(blockDigPacket, playerDigType, 0);
private static final Object releaseUseItem = playerDigType.getEnumConstants()[5];
private Object blockDig(Player p, Object packet) {
if(blockDigType.get(packet) == releaseUseItem)
GlobalRecorder.getInstance().bowSpan(p, false, false);
return packet;
}
public static final Class<?> blockPlacePacket = Reflection.getClass("{nms}.PacketPlayInBlockPlace");
private Object blockPlace(Player p, Object packet) {
boolean mainHand = BountifulWrapper.impl.mainHand(packet);
if(BountifulWrapper.impl.bowInHand(mainHand, p))
GlobalRecorder.getInstance().bowSpan(p, true, !mainHand);
return packet;
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent e){
if(isNotSent(e.getPlayer()))
@ -223,7 +215,7 @@ public class Recording implements Listener {
Location loc = e.getLocation();
GlobalRecorder.getInstance().entityDespawns(e.getEntity());
GlobalRecorder.getInstance().particle(loc.getX(), loc.getY(), loc.getZ(), "EXPLOSION_HUGE");
GlobalRecorder.getInstance().sound(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), SWSound.ENTITY_GENERIC_EXPLODE, EnumWrappers.SoundCategory.BLOCKS.name(), 4.0F, (1.0F + (random.nextFloat() - random.nextFloat()) * 0.2F) * 0.7F);
GlobalRecorder.getInstance().sound(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), SWSound.ENTITY_GENERIC_EXPLODE, "BLOCKS", 4.0F, (1.0F + (random.nextFloat() - random.nextFloat()) * 0.2F) * 0.7F);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)

Datei anzeigen

@ -19,7 +19,6 @@
package de.steamwar.fightsystem.utils;
import com.comphenix.protocol.wrappers.EnumWrappers;
import de.steamwar.fightsystem.VersionDependent;
import net.md_5.bungee.api.chat.BaseComponent;
import org.bukkit.World;
@ -33,7 +32,8 @@ public class BountifulWrapper {
public static final IBountifulWrapper impl = VersionDependent.getVersionImpl(BountifulWrapper.class.getName());
public interface IBountifulWrapper {
boolean bowInHand(EnumWrappers.Hand hand, Player p);
boolean mainHand(Object packet);
boolean bowInHand(boolean mainHand, Player p);
void toActionbar(Player player, BaseComponent... components);
void toChat(Player player, BaseComponent... components);

Datei anzeigen

@ -68,13 +68,6 @@
<scope>system</scope>
<systemPath>${main.basedir}/lib/SpigotCore.jar</systemPath>
</dependency>
<dependency>
<groupId>steamwar</groupId>
<artifactId>ProtocolLib</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${main.basedir}/lib/ProtocolLib.jar</systemPath>
</dependency>
</dependencies>
</project>