SteamWar/FightSystem
Archiviert
13
1

Merge branch 'master' into standalone
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
Lixfel 2022-03-03 14:39:15 +01:00
Commit badf96cd05
15 geänderte Dateien mit 92 neuen und 89 gelöschten Zeilen

Datei anzeigen

@ -72,7 +72,7 @@ public class FlatteningWrapper8 implements FlatteningWrapper.IFlatteningWrapper
@Override @Override
public void forceLoadChunk(World world, int cX, int cZ) { public void forceLoadChunk(World world, int cX, int cZ) {
// not possible in 1.8 world.setKeepSpawnInMemory(true);
} }
@Override @Override

Datei anzeigen

@ -100,7 +100,7 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper {
@Override @Override
public Listener newHandSwapRecorder() { public Listener newHandSwapRecorder() {
return new Listener() { return new Listener() {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onItemSwap(PlayerSwapHandItemsEvent e){ public void onItemSwap(PlayerSwapHandItemsEvent e){
if(Recording.isNotSent(e.getPlayer())) if(Recording.isNotSent(e.getPlayer()))
return; return;

Datei anzeigen

@ -40,7 +40,7 @@ public enum ArenaMode {
public static final Set<ArenaMode> Test = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK)); public static final Set<ArenaMode> Test = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK));
public static final Set<ArenaMode> Ranked = Collections.unmodifiableSet(EnumSet.of(RANKED)); public static final Set<ArenaMode> Ranked = Collections.unmodifiableSet(EnumSet.of(RANKED));
public static final Set<ArenaMode> Prepare = Collections.unmodifiableSet(EnumSet.of(PREPARE)); public static final Set<ArenaMode> Prepare = Collections.unmodifiableSet(EnumSet.of(PREPARE));
public static final Set<ArenaMode> Replay = Collections.unmodifiableSet(EnumSet.of(REPLAY)); public static final Set<ArenaMode> Replay = Collections.unmodifiableSet(EnumSet.of(REPLAY, TEST));
public static final Set<ArenaMode> AntiReplay = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(REPLAY))); public static final Set<ArenaMode> AntiReplay = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(REPLAY)));
public static final Set<ArenaMode> AntiTest = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK))); public static final Set<ArenaMode> AntiTest = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK)));

Datei anzeigen

@ -148,6 +148,7 @@ public class FightSystem extends JavaPlugin {
new FileRecorder(); new FileRecorder();
REntity.initWatchers(); REntity.initWatchers();
FileSource.startReplay();
if(Config.mode == ArenaMode.EVENT) { if(Config.mode == ArenaMode.EVENT) {
setPreSchemState(); setPreSchemState();
@ -155,9 +156,6 @@ public class FightSystem extends JavaPlugin {
Fight.getBlueTeam().setSchem(SchematicNode.getSchematicNode(Config.CheckSchemID)); Fight.getBlueTeam().setSchem(SchematicNode.getSchematicNode(Config.CheckSchemID));
}else if(Config.mode == ArenaMode.PREPARE) { }else if(Config.mode == ArenaMode.PREPARE) {
Fight.getUnrotated().setSchem(SchematicNode.getSchematicNode(Config.PrepareSchemID)); Fight.getUnrotated().setSchem(SchematicNode.getSchematicNode(Config.PrepareSchemID));
}else if(Config.mode == ArenaMode.REPLAY) {
FightWorld.forceLoad();
FileSource.startReplay();
} }
} }

Datei anzeigen

@ -27,7 +27,6 @@ import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.record.GlobalRecorder; import de.steamwar.fightsystem.record.GlobalRecorder;
import de.steamwar.fightsystem.utils.ProtocolAPI;
import de.steamwar.fightsystem.utils.ProtocolWrapper; import de.steamwar.fightsystem.utils.ProtocolWrapper;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@ -150,7 +149,7 @@ public class Fight {
} }
public static Object playerInfoPacket(Object action, GameProfile profile, Object mode) { public static Object playerInfoPacket(Object action, GameProfile profile, Object mode) {
Object packet = ProtocolAPI.construct(playerInfoPacket); Object packet = Reflection.newInstance(playerInfoPacket);
playerInfoAction.set(packet, action); playerInfoAction.set(packet, action);
playerInfoData.set(packet, Collections.singletonList(ProtocolWrapper.impl.playerInfoDataConstructor(packet, profile, mode))); playerInfoData.set(packet, Collections.singletonList(ProtocolWrapper.impl.playerInfoDataConstructor(packet, profile, mode)));
return packet; return packet;

Datei anzeigen

@ -61,7 +61,6 @@ public class FightWorld extends StateDependent {
world.loadChunk(cX, cZ); world.loadChunk(cX, cZ);
FlatteningWrapper.impl.forceLoadChunk(world, cX, cZ); FlatteningWrapper.impl.forceLoadChunk(world, cX, cZ);
}); });
world.setKeepSpawnInMemory(true);
} }
public static void resetWorld(){ public static void resetWorld(){

Datei anzeigen

@ -20,15 +20,12 @@
package de.steamwar.fightsystem.listener; package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.utils.FightUI; import de.steamwar.fightsystem.utils.FightUI;
import de.steamwar.fightsystem.utils.SWSound; import de.steamwar.fightsystem.utils.SWSound;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@ -36,41 +33,42 @@ import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import java.util.function.Consumer;
public class IngameDeath implements Listener { public class IngameDeath implements Listener {
public IngameDeath() { public IngameDeath() {
new StateDependentListener(ArenaMode.AntiReplay, FightState.Ingame, this); new StateDependentListener(ArenaMode.AntiReplay, FightState.Ingame, this);
} }
@EventHandler(priority = EventPriority.HIGH) @EventHandler
public void handlePlayerDeath(PlayerDeathEvent event) { public void broadcastDeath(PlayerDeathEvent event) {
event.setDeathMessage(null); onPlayerEnd(event.getEntity(), fightPlayer -> {
FightUI.addSubtitle("UI_PLAYER_DEATH", fightPlayer.getTeam().getPrefix(), fightPlayer.getPlayer().getName());
Player player = event.getEntity();
FightTeam team = Fight.getPlayerTeam(player);
if(team == null)
return;
FightUI.addSubtitle("UI_PLAYER_DEATH", team.getPrefix(), player.getName());
Fight.playSound(SWSound.ENTITY_WITHER_DEATH.getSound(), 100.0F, 1.0F); Fight.playSound(SWSound.ENTITY_WITHER_DEATH.getSound(), 100.0F, 1.0F);
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> team.getFightPlayer(player).setOut()); });
} }
@EventHandler(priority = EventPriority.HIGH) @EventHandler
public void broadcastQuit(PlayerQuitEvent event) {
onPlayerEnd(event.getPlayer(), fightPlayer -> FightUI.addSubtitle("UI_PLAYER_LEAVE", fightPlayer.getTeam().getPrefix(), fightPlayer.getPlayer().getName()));
}
@EventHandler(priority = EventPriority.MONITOR)
public void handlePlayerDeath(PlayerDeathEvent event) {
onPlayerEnd(event.getEntity(), FightPlayer::setOut);
}
@EventHandler(priority = EventPriority.MONITOR)
public void handlePlayerQuit(PlayerQuitEvent event) { public void handlePlayerQuit(PlayerQuitEvent event) {
event.setQuitMessage(null); onPlayerEnd(event.getPlayer(), FightPlayer::setOut);
}
Player player = event.getPlayer(); private void onPlayerEnd(Player player, Consumer<FightPlayer> withLivingPlayer) {
FightTeam team = Fight.getPlayerTeam(player); FightPlayer fightPlayer = Fight.getFightPlayer(player);
if(team == null) if(fightPlayer == null || !fightPlayer.isLiving())
return; return;
FightPlayer fightPlayer = team.getFightPlayer(player); withLivingPlayer.accept(fightPlayer);
if(!fightPlayer.isLiving())
return;
FightUI.addSubtitle("UI_PLAYER_LEAVE", team.getPrefix(), player.getName());
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> team.getFightPlayer(player).setOut());
} }
} }

Datei anzeigen

@ -34,6 +34,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.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.entity.SpawnerSpawnEvent; import org.bukkit.event.entity.SpawnerSpawnEvent;
import org.bukkit.event.inventory.CraftItemEvent; import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.FurnaceSmeltEvent; import org.bukkit.event.inventory.FurnaceSmeltEvent;
@ -81,7 +82,12 @@ public class Permanent implements Listener {
REntity.playerJoins(player); REntity.playerJoins(player);
} }
@EventHandler @EventHandler(priority = EventPriority.MONITOR)
public void handlePlayerDeath(PlayerDeathEvent event) {
event.setDeathMessage(null);
}
@EventHandler(priority = EventPriority.MONITOR)
public void handlePlayerLeave(PlayerQuitEvent event) { public void handlePlayerLeave(PlayerQuitEvent event) {
event.setQuitMessage(null); event.setQuitMessage(null);
} }

Datei anzeigen

@ -133,7 +133,7 @@ public class Recording implements Listener {
return packet; return packet;
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent e){ public void onPlayerMove(PlayerMoveEvent e){
if(isNotSent(e.getPlayer())) if(isNotSent(e.getPlayer()))
return; return;
@ -141,15 +141,12 @@ public class Recording implements Listener {
GlobalRecorder.getInstance().entityMoves(e.getPlayer()); GlobalRecorder.getInstance().entityMoves(e.getPlayer());
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler
public void onPlayerDeath(PlayerDeathEvent e) { public void onPlayerDeath(PlayerDeathEvent e) {
if(isNotSent(e.getEntity()))
return;
GlobalRecorder.getInstance().entityDespawns(e.getEntity()); GlobalRecorder.getInstance().entityDespawns(e.getEntity());
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler
public void onPlayerQuit(PlayerQuitEvent e){ public void onPlayerQuit(PlayerQuitEvent e){
if(isNotSent(e.getPlayer())) if(isNotSent(e.getPlayer()))
return; return;
@ -157,13 +154,13 @@ public class Recording implements Listener {
GlobalRecorder.getInstance().entityDespawns(e.getPlayer()); GlobalRecorder.getInstance().entityDespawns(e.getPlayer());
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockPhysics(BlockPhysicsEvent e){ public void onBlockPhysics(BlockPhysicsEvent e){
if(FlatteningWrapper.impl.doRecord(e)) if(FlatteningWrapper.impl.doRecord(e))
GlobalRecorder.getInstance().blockChange(e.getBlock()); GlobalRecorder.getInstance().blockChange(e.getBlock());
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onSneak(PlayerToggleSneakEvent e){ public void onSneak(PlayerToggleSneakEvent e){
if(isNotSent(e.getPlayer())) if(isNotSent(e.getPlayer()))
return; return;
@ -171,7 +168,7 @@ public class Recording implements Listener {
GlobalRecorder.getInstance().playerSneak(e.getPlayer(), e.isSneaking()); GlobalRecorder.getInstance().playerSneak(e.getPlayer(), e.isSneaking());
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onAnimation(PlayerAnimationEvent e){ public void onAnimation(PlayerAnimationEvent e){
if(isNotSent(e.getPlayer())) if(isNotSent(e.getPlayer()))
return; return;
@ -180,7 +177,7 @@ public class Recording implements Listener {
GlobalRecorder.getInstance().entityAnimation(e.getPlayer(), AIR); GlobalRecorder.getInstance().entityAnimation(e.getPlayer(), AIR);
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityDamage(EntityDamageEvent e) { public void onEntityDamage(EntityDamageEvent e) {
if(e.getEntityType() != EntityType.PLAYER) if(e.getEntityType() != EntityType.PLAYER)
return; return;
@ -195,7 +192,7 @@ public class Recording implements Listener {
GlobalRecorder.getInstance().setOnFire(p, false); GlobalRecorder.getInstance().setOnFire(p, false);
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityCombust(EntityCombustEvent e) { public void onEntityCombust(EntityCombustEvent e) {
if(e.getEntityType() != EntityType.PLAYER) if(e.getEntityType() != EntityType.PLAYER)
return; return;
@ -207,7 +204,7 @@ public class Recording implements Listener {
GlobalRecorder.getInstance().setOnFire(p, false); GlobalRecorder.getInstance().setOnFire(p, false);
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onTNTSpawn(EntitySpawnEvent e){ public void onTNTSpawn(EntitySpawnEvent e){
if(e.getEntityType() != EntityType.PRIMED_TNT) if(e.getEntityType() != EntityType.PRIMED_TNT)
return; return;
@ -215,7 +212,7 @@ public class Recording implements Listener {
GlobalRecorder.getInstance().tntSpawn(e.getEntity()); GlobalRecorder.getInstance().tntSpawn(e.getEntity());
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onExplosion(EntityExplodeEvent e){ public void onExplosion(EntityExplodeEvent e){
if(e.getEntityType() != EntityType.PRIMED_TNT) if(e.getEntityType() != EntityType.PRIMED_TNT)
return; return;
@ -226,7 +223,7 @@ public class Recording implements Listener {
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); 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) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onItem(PlayerItemHeldEvent e){ public void onItem(PlayerItemHeldEvent e){
if(isNotSent(e.getPlayer())) if(isNotSent(e.getPlayer()))
return; return;
@ -234,7 +231,7 @@ public class Recording implements Listener {
GlobalRecorder.getInstance().item(e.getPlayer(), disarmNull(e.getPlayer().getInventory().getItem(e.getNewSlot())), "MAINHAND"); GlobalRecorder.getInstance().item(e.getPlayer(), disarmNull(e.getPlayer().getInventory().getItem(e.getNewSlot())), "MAINHAND");
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onProjectileSpawn(ProjectileLaunchEvent e){ public void onProjectileSpawn(ProjectileLaunchEvent e){
if(e.getEntityType() == EntityType.FIREBALL) if(e.getEntityType() == EntityType.FIREBALL)
GlobalRecorder.getInstance().fireballSpawn(e.getEntity()); GlobalRecorder.getInstance().fireballSpawn(e.getEntity());
@ -242,7 +239,7 @@ public class Recording implements Listener {
GlobalRecorder.getInstance().arrowSpawn(e.getEntity()); GlobalRecorder.getInstance().arrowSpawn(e.getEntity());
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent e){ public void onInventoryClick(InventoryClickEvent e){
Player player = (Player) e.getWhoClicked(); Player player = (Player) e.getWhoClicked();
if(isNotSent(player)) if(isNotSent(player))

Datei anzeigen

@ -25,7 +25,6 @@ import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.states.StateDependentListener;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
@ -35,7 +34,7 @@ public class Shutdown implements Listener {
new StateDependentListener(ArenaMode.AntiEvent, FightState.All, this); new StateDependentListener(ArenaMode.AntiEvent, FightState.All, this);
} }
@EventHandler(priority = EventPriority.HIGH) @EventHandler
public void handlePlayerQuit(PlayerQuitEvent event) { public void handlePlayerQuit(PlayerQuitEvent event) {
if(Config.replayserver()) if(Config.replayserver())
return; return;

Datei anzeigen

@ -20,11 +20,13 @@
package de.steamwar.fightsystem.listener; package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.ArenaMode;
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;
import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -41,6 +43,12 @@ public class TestJoin implements Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
FightTeam fightTeam = Fight.getPlayerTeam(player); FightTeam fightTeam = Fight.getPlayerTeam(player);
if(Config.ReplayID != 0 && !SteamwarUser.get(player.getUniqueId()).getUserGroup().isAdminGroup()) {
FightSystem.getMessage().send("CHECK_JOIN_DENIED", player);
player.kickPlayer("");
return;
}
if (fightTeam == null && (Fight.getRedTeam().isLeaderless() || Fight.getBlueTeam().isLeaderless())) { if (fightTeam == null && (Fight.getRedTeam().isLeaderless() || Fight.getBlueTeam().isLeaderless())) {
FightSystem.getMessage().send("TEST_BECOME_LEADER", player); FightSystem.getMessage().send("TEST_BECOME_LEADER", player);
} }

Datei anzeigen

@ -38,6 +38,7 @@ public class FileSource extends PacketSource {
return; return;
} }
if(Config.ReplayID > 0) {
de.steamwar.sql.Fight.getReplay(Config.ReplayID, input -> { de.steamwar.sql.Fight.getReplay(Config.ReplayID, input -> {
try { try {
Files.copy( Files.copy(
@ -55,6 +56,7 @@ public class FileSource extends PacketSource {
throw new SecurityException("Could not start replay", e); throw new SecurityException("Could not start replay", e);
} }
} }
}
public FileSource(File fightFile) throws IOException { public FileSource(File fightFile) throws IOException {
super(new GZIPInputStream(new FileInputStream(fightFile))); super(new GZIPInputStream(new FileInputStream(fightFile)));

Datei anzeigen

@ -26,6 +26,7 @@ import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.countdown.Countdown; import de.steamwar.fightsystem.countdown.Countdown;
import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.fight.FightWorld;
import de.steamwar.fightsystem.fight.FreezeWorld; import de.steamwar.fightsystem.fight.FreezeWorld;
import de.steamwar.fightsystem.listener.FightScoreboard; import de.steamwar.fightsystem.listener.FightScoreboard;
import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.FightState;
@ -76,6 +77,7 @@ public class PacketProcessor {
private int arenaMinZ = Config.ArenaRegion.getMinZ(); private int arenaMinZ = Config.ArenaRegion.getMinZ();
private boolean tickFinished = false; private boolean tickFinished = false;
private int lastPacket = -1;
public PacketProcessor(PacketSource source){ public PacketProcessor(PacketSource source){
this.source = source; this.source = source;
@ -123,6 +125,8 @@ public class PacketProcessor {
packetDecoder[0xef] = source::readUTF; packetDecoder[0xef] = source::readUTF;
packetDecoder[0xff] = this::tick; packetDecoder[0xff] = this::tick;
FightWorld.forceLoad();
if(source.async()) { if(source.async()) {
Bukkit.getScheduler().runTaskAsynchronously(FightSystem.getPlugin(), this::process); Bukkit.getScheduler().runTaskAsynchronously(FightSystem.getPlugin(), this::process);
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::runSync, 1, 1); task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::runSync, 1, 1);
@ -507,15 +511,16 @@ public class PacketProcessor {
if(parser != null){ if(parser != null){
parser.process(); parser.process();
}else{ }else{
Bukkit.getLogger().log(Level.SEVERE, "Unknown packet " + packetType + " recieved, closing."); Bukkit.getLogger().log(Level.SEVERE, "Unknown packet " + packetType + " recieved, closing. LastPacket: " + lastPacket);
source.close(); source.close();
} }
lastPacket = packetType;
} }
} catch (EOFException e) { } catch (EOFException e) {
Bukkit.getLogger().log(Level.INFO, "The FightServer is offline"); Bukkit.getLogger().log(Level.INFO, "The FightServer is offline");
source.close(); source.close();
} catch(Exception e) { } catch(Exception e) {
Bukkit.getLogger().log(Level.WARNING, "Could not recieve packet", e); Bukkit.getLogger().log(Level.WARNING, "Could not recieve packet, LastPacket: " + lastPacket, e);
source.close(); source.close();
} }

Datei anzeigen

@ -177,7 +177,7 @@ public class REntity {
private static final Reflection.FieldAccessor<Integer> animationEntity = Reflection.getField(animationPacket, int.class, 0); private static final Reflection.FieldAccessor<Integer> animationEntity = Reflection.getField(animationPacket, int.class, 0);
private static final Reflection.FieldAccessor<Integer> animationAnimation = Reflection.getField(animationPacket, int.class, 1); private static final Reflection.FieldAccessor<Integer> animationAnimation = Reflection.getField(animationPacket, int.class, 1);
public void animation(byte animation) { public void animation(byte animation) {
Object packet = ProtocolAPI.construct(animationPacket); Object packet = Reflection.newInstance(animationPacket);
animationEntity.set(packet, entityId); animationEntity.set(packet, entityId);
animationAnimation.set(packet, (int) animation); animationAnimation.set(packet, (int) animation);
ProtocolAPI.broadcastPacket(packet); ProtocolAPI.broadcastPacket(packet);
@ -189,7 +189,7 @@ public class REntity {
private static final Reflection.FieldAccessor<Integer> velocityY = Reflection.getField(velocityPacket, int.class, 2); private static final Reflection.FieldAccessor<Integer> velocityY = Reflection.getField(velocityPacket, int.class, 2);
private static final Reflection.FieldAccessor<Integer> velocityZ = Reflection.getField(velocityPacket, int.class, 3); private static final Reflection.FieldAccessor<Integer> velocityZ = Reflection.getField(velocityPacket, int.class, 3);
public void setVelocity(double dX, double dY, double dZ) { public void setVelocity(double dX, double dY, double dZ) {
Object packet = ProtocolAPI.construct(velocityPacket); Object packet = Reflection.newInstance(velocityPacket);
velocityEntity.set(packet, entityId); velocityEntity.set(packet, entityId);
velocityX.set(packet, calcVelocity(dX)); velocityX.set(packet, calcVelocity(dX));
velocityY.set(packet, calcVelocity(dY)); velocityY.set(packet, calcVelocity(dY));
@ -201,7 +201,7 @@ public class REntity {
private static final Reflection.FieldAccessor<Integer> statusEntity = Reflection.getField(statusPacket, int.class, 0); private static final Reflection.FieldAccessor<Integer> statusEntity = Reflection.getField(statusPacket, int.class, 0);
private static final Reflection.FieldAccessor<Byte> statusStatus = Reflection.getField(statusPacket, byte.class, 0); private static final Reflection.FieldAccessor<Byte> statusStatus = Reflection.getField(statusPacket, byte.class, 0);
public void damage() { public void damage() {
Object packet = ProtocolAPI.construct(statusPacket); Object packet = Reflection.newInstance(statusPacket);
statusEntity.set(packet, entityId); statusEntity.set(packet, entityId);
statusStatus.set(packet, (byte) 2); statusStatus.set(packet, (byte) 2);
ProtocolAPI.broadcastPacket(packet); ProtocolAPI.broadcastPacket(packet);
@ -259,7 +259,7 @@ public class REntity {
team.removeEntry(name); team.removeEntry(name);
} }
Object packet = ProtocolAPI.construct(destroyPacket); Object packet = Reflection.newInstance(destroyPacket);
destroyEntities.set(packet, Core.getVersion() > 15 ? new IntArrayList(new int[]{entityId}) : new int[]{entityId}); destroyEntities.set(packet, Core.getVersion() > 15 ? new IntArrayList(new int[]{entityId}) : new int[]{entityId});
ProtocolAPI.broadcastPacket(packet); ProtocolAPI.broadcastPacket(packet);
} }
@ -272,7 +272,7 @@ public class REntity {
private static final Reflection.FieldAccessor<Integer> metadataEntity = Reflection.getField(metadataPacket, int.class, 0); private static final Reflection.FieldAccessor<Integer> metadataEntity = Reflection.getField(metadataPacket, int.class, 0);
private static final Reflection.FieldAccessor<List> metadataMetadata = Reflection.getField(metadataPacket, List.class, 0); private static final Reflection.FieldAccessor<List> metadataMetadata = Reflection.getField(metadataPacket, List.class, 0);
private Object getDataWatcherPacket(Object dataWatcherObject, Object value) { private Object getDataWatcherPacket(Object dataWatcherObject, Object value) {
Object packet = ProtocolAPI.construct(metadataPacket); Object packet = Reflection.newInstance(metadataPacket);
metadataEntity.set(packet, entityId); metadataEntity.set(packet, entityId);
metadataMetadata.set(packet, Collections.singletonList(BountifulWrapper.impl.getDataWatcherItem(dataWatcherObject, value))); metadataMetadata.set(packet, Collections.singletonList(BountifulWrapper.impl.getDataWatcherItem(dataWatcherObject, value)));
return packet; return packet;
@ -283,7 +283,7 @@ public class REntity {
private static final Reflection.FieldAccessor<Byte> teleportYaw = Reflection.getField(teleportPacket, byte.class, 0); private static final Reflection.FieldAccessor<Byte> teleportYaw = Reflection.getField(teleportPacket, byte.class, 0);
private static final Reflection.FieldAccessor<Byte> teleportPitch = Reflection.getField(teleportPacket, byte.class, 1); private static final Reflection.FieldAccessor<Byte> teleportPitch = Reflection.getField(teleportPacket, byte.class, 1);
private Object getTeleportPacket(){ private Object getTeleportPacket(){
Object packet = ProtocolAPI.construct(teleportPacket); Object packet = Reflection.newInstance(teleportPacket);
teleportEntity.set(packet, entityId); teleportEntity.set(packet, entityId);
BountifulWrapper.impl.setTeleportPacketPosition(packet, locX, locY, locZ); BountifulWrapper.impl.setTeleportPacketPosition(packet, locX, locY, locZ);
teleportYaw.set(packet, yaw); teleportYaw.set(packet, yaw);
@ -295,7 +295,7 @@ public class REntity {
private static final Reflection.FieldAccessor<Integer> headRotationEntity = Reflection.getField(headRotationPacket, int.class, 0); private static final Reflection.FieldAccessor<Integer> headRotationEntity = Reflection.getField(headRotationPacket, int.class, 0);
private static final Reflection.FieldAccessor<Byte> headRotationYaw = Reflection.getField(headRotationPacket, byte.class, 0); private static final Reflection.FieldAccessor<Byte> headRotationYaw = Reflection.getField(headRotationPacket, byte.class, 0);
private Object getHeadRotationPacket(){ private Object getHeadRotationPacket(){
Object packet = ProtocolAPI.construct(headRotationPacket); Object packet = Reflection.newInstance(headRotationPacket);
headRotationEntity.set(packet, entityId); headRotationEntity.set(packet, entityId);
headRotationYaw.set(packet, headYaw); headRotationYaw.set(packet, headYaw);
return packet; return packet;
@ -304,7 +304,7 @@ public class REntity {
public static final Class<?> spawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutSpawnEntity"); public static final Class<?> spawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutSpawnEntity");
private static final Reflection.FieldAccessor<Integer> spawnEntity = Reflection.getField(spawnPacket, int.class, 0); private static final Reflection.FieldAccessor<Integer> spawnEntity = Reflection.getField(spawnPacket, int.class, 0);
private Object getSpawnEntityPacket(){ private Object getSpawnEntityPacket(){
Object packet = ProtocolAPI.construct(spawnPacket); Object packet = Reflection.newInstance(spawnPacket);
spawnEntity.set(packet, entityId); spawnEntity.set(packet, entityId);
BountifulWrapper.impl.setSpawnPacketUUID(packet, uuid); BountifulWrapper.impl.setSpawnPacketUUID(packet, uuid);
ProtocolWrapper.impl.setSpawnPacketType(packet, entityType); ProtocolWrapper.impl.setSpawnPacketType(packet, entityType);
@ -318,7 +318,7 @@ public class REntity {
private static final Class<?> craftItemStack = Reflection.getClass("{obc}.inventory.CraftItemStack"); private static final Class<?> craftItemStack = Reflection.getClass("{obc}.inventory.CraftItemStack");
private static final Reflection.MethodInvoker asNMSCopy = Reflection.getTypedMethod(REntity.craftItemStack, "asNMSCopy", REntity.itemStack, ItemStack.class); private static final Reflection.MethodInvoker asNMSCopy = Reflection.getTypedMethod(REntity.craftItemStack, "asNMSCopy", REntity.itemStack, ItemStack.class);
private Object getEquipmentPacket(String slot, ItemStack stack){ private Object getEquipmentPacket(String slot, ItemStack stack){
Object packet = ProtocolAPI.construct(equipmentPacket); Object packet = Reflection.newInstance(equipmentPacket);
equipmentEntity.set(packet, entityId); equipmentEntity.set(packet, entityId);
ProtocolWrapper.impl.setEquipmentPacketStack(packet, slot, asNMSCopy.invoke(null, stack)); ProtocolWrapper.impl.setEquipmentPacketStack(packet, slot, asNMSCopy.invoke(null, stack));
return packet; return packet;
@ -332,7 +332,7 @@ public class REntity {
private static final Reflection.FieldAccessor<Integer> namedSpawnEntity = Reflection.getField(namedSpawnPacket, int.class, 0); private static final Reflection.FieldAccessor<Integer> namedSpawnEntity = Reflection.getField(namedSpawnPacket, int.class, 0);
private static final Reflection.FieldAccessor<UUID> namedSpawnUUID = Reflection.getField(namedSpawnPacket, UUID.class, 0); private static final Reflection.FieldAccessor<UUID> namedSpawnUUID = Reflection.getField(namedSpawnPacket, UUID.class, 0);
private Object getNamedSpawnPacket(){ private Object getNamedSpawnPacket(){
Object packet = ProtocolAPI.construct(namedSpawnPacket); Object packet = Reflection.newInstance(namedSpawnPacket);
namedSpawnEntity.set(packet, entityId); namedSpawnEntity.set(packet, entityId);
namedSpawnUUID.set(packet, uuid); namedSpawnUUID.set(packet, uuid);
FlatteningWrapper.impl.setNamedSpawnPacketDataWatcher(packet); FlatteningWrapper.impl.setNamedSpawnPacketDataWatcher(packet);

Datei anzeigen

@ -19,8 +19,8 @@
package de.steamwar.fightsystem.utils; package de.steamwar.fightsystem.utils;
import com.comphenix.tinyprotocol.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol; import com.comphenix.tinyprotocol.TinyProtocol;
import jdk.internal.misc.Unsafe;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -88,19 +88,11 @@ public class ProtocolAPI {
}; };
} }
public static <T> T construct(Class<T> clazz) {
try {
return (T) Unsafe.getUnsafe().allocateInstance(clazz);
} catch (InstantiationException e) {
throw new IllegalStateException(e);
}
}
public static UnaryOperator<Object> shallowCloneGenerator(Class<?> clazz) { public static UnaryOperator<Object> shallowCloneGenerator(Class<?> clazz) {
BiConsumer<Object, Object> filler = shallowFill(clazz); BiConsumer<Object, Object> filler = shallowFill(clazz);
return source -> { return source -> {
Object clone = construct(clazz); Object clone = Reflection.newInstance(clazz);
filler.accept(source, clone); filler.accept(source, clone);
return clone; return clone;
}; };