SteamWar/FightSystem
Archiviert
13
1

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

Dieser Commit ist enthalten in:
Lixfel 2023-01-20 12:02:07 +01:00
Commit 14753ebe99
22 geänderte Dateien mit 132 neuen und 853 gelöschten Zeilen

Datei anzeigen

@ -94,9 +94,4 @@ public class FlatteningWrapper14 implements FlatteningWrapper {
public boolean checkPistonMoving(Block block) {
return block.getType() == Material.MOVING_PISTON;
}
@Override
public void setNamedSpawnPacketDataWatcher(Object packet) {
// field not present
}
}

Datei anzeigen

@ -42,6 +42,7 @@ import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockTypes;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.sql.SchematicData;
import de.steamwar.sql.SchematicNode;
import org.bukkit.DyeColor;
import org.bukkit.Location;
@ -143,6 +144,6 @@ public class WorldeditWrapper14 implements WorldeditWrapper {
throw new SecurityException(e);
}
schem.saveFromBytes(outputStream.toByteArray(), true);
new SchematicData(schem).saveFromBytes(outputStream.toByteArray(), true);
}
}

Datei anzeigen

@ -1,82 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2021 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.fightsystem.utils;
import com.comphenix.tinyprotocol.Reflection;
import com.mojang.authlib.GameProfile;
import com.mojang.datafixers.util.Pair;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.record.REntity;
import net.minecraft.world.entity.EntityTypes;
import org.bukkit.entity.EntityType;
import java.util.Collections;
import java.util.List;
public class ProtocolWrapper18 implements ProtocolWrapper {
private static final Reflection.FieldAccessor<List> equipmentStack = Reflection.getField(REntity.equipmentPacket, List.class, 0);
@Override
public void setEquipmentPacketStack(Object packet, String slot, Object stack) {
equipmentStack.set(packet, Collections.singletonList(new Pair<>(getSlot(slot), stack)));
}
private static final Reflection.FieldAccessor<?> spawnType = Reflection.getField(REntity.spawnPacket, EntityTypes.class, 0);
@Override
public void setSpawnPacketType(Object packet, EntityType type) {
switch(type) {
case PRIMED_TNT:
spawnType.set(packet, EntityTypes.as);
break;
case ARROW:
spawnType.set(packet, EntityTypes.d);
break;
case FIREBALL:
spawnType.set(packet, EntityTypes.S);
break;
}
}
private static final Class<?> enumItemSlot = Reflection.getClass("{nms.world.entity}.EnumItemSlot");
private static final Object[] itemSlots = enumItemSlot.getEnumConstants();
private static Object getSlot(String slot) {
switch(slot){
case "HEAD":
return itemSlots[5];
case "CHEST":
return itemSlots[4];
case "LEGS":
return itemSlots[3];
case "FEET":
return itemSlots[2];
case "OFFHAND":
return itemSlots[1];
case "MAINHAND":
default:
return itemSlots[0];
}
}
private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(Fight.playerInfoDataClass, GameProfile.class, int.class, Fight.enumGamemode, Fight.iChatBaseComponent);
@Override
public Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode) {
return playerInfoDataConstructor.invoke(profile, 0, mode, null);
}
}

Datei anzeigen

@ -1,82 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2021 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.fightsystem.utils;
import com.comphenix.tinyprotocol.Reflection;
import com.mojang.authlib.GameProfile;
import com.mojang.datafixers.util.Pair;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.record.REntity;
import net.minecraft.world.entity.EntityTypes;
import org.bukkit.entity.EntityType;
import java.util.Collections;
import java.util.List;
public class ProtocolWrapper19 implements ProtocolWrapper {
private static final Reflection.FieldAccessor<List> equipmentStack = Reflection.getField(REntity.equipmentPacket, List.class, 0);
@Override
public void setEquipmentPacketStack(Object packet, String slot, Object stack) {
equipmentStack.set(packet, Collections.singletonList(new Pair<>(getSlot(slot), stack)));
}
private static final Reflection.FieldAccessor<?> spawnType = Reflection.getField(REntity.spawnPacket, EntityTypes.class, 0);
@Override
public void setSpawnPacketType(Object packet, EntityType type) {
switch(type) {
case PRIMED_TNT:
spawnType.set(packet, EntityTypes.av);
break;
case ARROW:
spawnType.set(packet, EntityTypes.e);
break;
case FIREBALL:
spawnType.set(packet, EntityTypes.V);
break;
}
}
private static final Class<?> enumItemSlot = Reflection.getClass("{nms.world.entity}.EnumItemSlot");
private static final Object[] itemSlots = enumItemSlot.getEnumConstants();
private static Object getSlot(String slot) {
switch(slot){
case "HEAD":
return itemSlots[5];
case "CHEST":
return itemSlots[4];
case "LEGS":
return itemSlots[3];
case "FEET":
return itemSlots[2];
case "OFFHAND":
return itemSlots[1];
case "MAINHAND":
default:
return itemSlots[0];
}
}
private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(Fight.playerInfoDataClass, GameProfile.class, int.class, Fight.enumGamemode, Fight.iChatBaseComponent, Reflection.getClass("net.minecraft.world.entity.player.ProfilePublicKey$a"));
@Override
public Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode) {
return playerInfoDataConstructor.invoke(profile, 0, mode, null, null);
}
}

Datei anzeigen

@ -19,24 +19,25 @@
package de.steamwar.fightsystem.utils;
import com.comphenix.tinyprotocol.Reflection;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.listener.Recording;
import de.steamwar.fightsystem.record.GlobalRecorder;
import de.steamwar.fightsystem.record.REntity;
import net.minecraft.server.v1_8_R3.DataWatcher;
import net.minecraft.server.v1_8_R3.EntityEnderDragon;
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityMetadata;
import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
import net.royawesome.jlibnoise.MathHelper;
import org.bukkit.*;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.scoreboard.Team;
import java.util.*;
import java.util.HashSet;
import java.util.Set;
public class BountifulWrapper8 implements BountifulWrapper {
@ -92,47 +93,6 @@ public class BountifulWrapper8 implements BountifulWrapper {
world.playEffect(new Location(world, x, y, z), Effect.valueOf(particleName), 1);
}
@Override
public Object getDataWatcherObject(int index, Class<?> type) {
return index;
}
private static final Class<?> watchableObject = Reflection.getClass("{nms}.DataWatcher$WatchableObject");
private static final Reflection.ConstructorInvoker watchableObjectConstructor = Reflection.getConstructor(watchableObject, int.class, int.class, Object.class);
private static final Map<Class<?>, Integer> watchableDatatypes = new HashMap<>();
static {
watchableDatatypes.put(byte.class, 0);
watchableDatatypes.put(short.class, 1);
watchableDatatypes.put(int.class, 2);
watchableDatatypes.put(float.class, 3);
watchableDatatypes.put(String.class, 4);
}
@Override
public Object getDataWatcherItem(Object dwo, Object value) {
return watchableObjectConstructor.invoke(watchableDatatypes.get(value.getClass()), dwo, value);
}
private static final Reflection.FieldAccessor<Integer> teleportX = Reflection.getField(REntity.teleportPacket, int.class, 1);
private static final Reflection.FieldAccessor<Integer> teleportY = Reflection.getField(REntity.teleportPacket, int.class, 2);
private static final Reflection.FieldAccessor<Integer> teleportZ = Reflection.getField(REntity.teleportPacket, int.class, 3);
@Override
public void setTeleportPacketPosition(Object packet, double x, double y, double z) {
teleportX.set(packet, MathHelper.floor(x * 32));
teleportY.set(packet, MathHelper.floor(y * 32));
teleportZ.set(packet, MathHelper.floor(z * 32));
}
@Override
public void setSpawnPacketUUID(Object packet, UUID uuid) {
// field not present
}
@Override
public void setNamedSpawnPosition(Object packet, double x, double y, double z) {
//no implementation for 1.8
}
private final Set<Player> seesDragon = new HashSet<>();
private final PacketPlayOutSpawnEntityLiving spawnDragon;
private final int spawnDragonId;

Datei anzeigen

@ -19,8 +19,6 @@
package de.steamwar.fightsystem.utils;
import com.comphenix.tinyprotocol.Reflection;
import de.steamwar.fightsystem.record.REntity;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.World;
@ -74,13 +72,4 @@ public class FlatteningWrapper8 implements FlatteningWrapper {
public boolean checkPistonMoving(Block block) {
return block.getType() == Material.PISTON_MOVING_PIECE;
}
private static final Class<?> dataWatcher = Reflection.getClass("{nms}.DataWatcher");
private static final Reflection.FieldAccessor<?> namedSpawnDataWatcher = Reflection.getField(REntity.namedSpawnPacket, dataWatcher, 0);
private static final Class<?> entity = Reflection.getClass("{nms}.Entity");
private static final Reflection.ConstructorInvoker dataWatcherConstructor = Reflection.getConstructor(dataWatcher, entity);
@Override
public void setNamedSpawnPacketDataWatcher(Object packet) {
namedSpawnDataWatcher.set(packet, dataWatcherConstructor.invoke((Object) null));
}
}

Datei anzeigen

@ -1,108 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2021 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.fightsystem.utils;
import com.comphenix.tinyprotocol.Reflection;
import com.mojang.authlib.GameProfile;
import de.steamwar.core.Core;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.record.REntity;
import org.bukkit.entity.EntityType;
public class ProtocolWrapper8 implements ProtocolWrapper {
private static final Reflection.FieldAccessor<?> equipmentSlot;
private static final Object[] itemSlots;
static {
if(Core.getVersion() == 8) {
equipmentSlot = Reflection.getField(REntity.equipmentPacket, int.class, 1);
itemSlots = new Integer[]{0, 0, 1, 2, 3, 4};
} else {
Class<?> enumItemSlot = Reflection.getClass("{nms.world.entity}.EnumItemSlot");
equipmentSlot = Reflection.getField(REntity.equipmentPacket, enumItemSlot, 0);
itemSlots = enumItemSlot.getEnumConstants();
}
}
private static final Reflection.FieldAccessor<?> equipmentStack = Reflection.getField(REntity.equipmentPacket, REntity.itemStack, 0);
@Override
public void setEquipmentPacketStack(Object packet, String slot, Object stack) {
switch(slot){
case "HEAD":
equipmentSlot.set(packet, itemSlots[5]);
break;
case "CHEST":
equipmentSlot.set(packet, itemSlots[4]);
break;
case "LEGS":
equipmentSlot.set(packet, itemSlots[3]);
break;
case "FEET":
equipmentSlot.set(packet, itemSlots[2]);
break;
case "OFFHAND":
equipmentSlot.set(packet, itemSlots[1]);
break;
case "MAINHAND":
default:
equipmentSlot.set(packet, itemSlots[0]);
}
equipmentStack.set(packet, stack);
}
private static final Reflection.FieldAccessor<?> spawnType;
private static final Object tnt;
private static final Object arrow;
private static final Object fireball;
static {
if(Core.getVersion() < 14) {
spawnType = Reflection.getField(REntity.spawnPacket, int.class, Core.getVersion() > 8 ? 6 : 9);
tnt = 50;
arrow = 60;
fireball = 63;
} else {
Class<?> entityTypes = Reflection.getClass("{nms.world.entity}.EntityTypes");
spawnType = Reflection.getField(REntity.spawnPacket, entityTypes, 0);
tnt = Reflection.getField(entityTypes, "TNT", entityTypes).get(null);
arrow = Reflection.getField(entityTypes, "ARROW", entityTypes).get(null);
fireball = Reflection.getField(entityTypes, "FIREBALL", entityTypes).get(null);
}
}
@Override
public void setSpawnPacketType(Object packet, EntityType type) {
switch(type) {
case PRIMED_TNT:
spawnType.set(packet, tnt);
break;
case ARROW:
spawnType.set(packet, arrow);
break;
case FIREBALL:
spawnType.set(packet, fireball);
break;
}
}
private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(Fight.playerInfoDataClass, Fight.playerInfoPacket, GameProfile.class, int.class, Fight.enumGamemode, Fight.iChatBaseComponent);
@Override
public Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode) {
return playerInfoDataConstructor.invoke(packet, profile, 0, mode, null);
}
}

Datei anzeigen

@ -39,6 +39,7 @@ import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.world.World;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.sql.SchematicData;
import de.steamwar.sql.SchematicNode;
import org.bukkit.DyeColor;
import org.bukkit.Location;
@ -141,6 +142,6 @@ public class WorldeditWrapper8 implements WorldeditWrapper {
throw new SecurityException(e);
}
schem.saveFromBytes(outputStream.toByteArray(), false);
new SchematicData(schem).saveFromBytes(outputStream.toByteArray(), false);
}
}

Datei anzeigen

@ -24,7 +24,6 @@ import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.listener.Recording;
import de.steamwar.fightsystem.record.GlobalRecorder;
import de.steamwar.fightsystem.record.REntity;
import org.bukkit.*;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
@ -39,11 +38,8 @@ import org.bukkit.event.player.PlayerPickupArrowEvent;
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
import org.bukkit.scoreboard.Team;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class BountifulWrapper9 implements BountifulWrapper {
@ -120,58 +116,6 @@ public class BountifulWrapper9 implements BountifulWrapper {
world.spawnParticle(Particle.valueOf(particleName), x, y, z, 1);
}
private static final Class<?> dataWatcherObject = Reflection.getClass("{nms.network.syncher}.DataWatcherObject");
private static final Class<?> dataWatcherRegistry = Reflection.getClass("{nms.network.syncher}.DataWatcherRegistry");
private static final Class<?> dataWatcherSerializer = Reflection.getClass("{nms.network.syncher}.DataWatcherSerializer");
private static final Reflection.ConstructorInvoker dataWatcherObjectConstructor = Reflection.getConstructor(dataWatcherObject, int.class, dataWatcherSerializer);
@Override
public Object getDataWatcherObject(int index, Class<?> type) {
for(Field field : dataWatcherRegistry.getFields()) {
if(dataWatcherSerializer.isAssignableFrom(field.getType()) && type.equals(((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0])) {
try {
return dataWatcherObjectConstructor.invoke(index, field.get(null));
} catch (IllegalAccessException e) {
throw new SecurityException("Could not get field", e);
}
}
}
throw new SecurityException("Could not find Serializer for " + type.getName());
}
private static final Class<?> item = Reflection.getClass("{nms.network.syncher}.DataWatcher$Item");
private static final Reflection.ConstructorInvoker itemConstructor = Reflection.getConstructor(item, dataWatcherObject, Object.class);
@Override
public Object getDataWatcherItem(Object dwo, Object value) {
return itemConstructor.invoke(dwo, value);
}
private static final Reflection.FieldAccessor<Double> teleportX = Reflection.getField(REntity.teleportPacket, double.class, 0);
private static final Reflection.FieldAccessor<Double> teleportY = Reflection.getField(REntity.teleportPacket, double.class, 1);
private static final Reflection.FieldAccessor<Double> teleportZ = Reflection.getField(REntity.teleportPacket, double.class, 2);
@Override
public void setTeleportPacketPosition(Object packet, double x, double y, double z) {
teleportX.set(packet, x);
teleportY.set(packet, y);
teleportZ.set(packet, z);
}
private static final Reflection.FieldAccessor<UUID> spawnUUID = Reflection.getField(REntity.spawnPacket, UUID.class, 0);
@Override
public void setSpawnPacketUUID(Object packet, UUID uuid) {
spawnUUID.set(packet, uuid);
}
private static final Reflection.FieldAccessor<Double> namedSpawnX = Reflection.getField(REntity.namedSpawnPacket, double.class, 0);
private static final Reflection.FieldAccessor<Double> namedSpawnY = Reflection.getField(REntity.namedSpawnPacket, double.class, 1);
private static final Reflection.FieldAccessor<Double> namedSpawnZ = Reflection.getField(REntity.namedSpawnPacket, double.class, 2);
@Override
public void setNamedSpawnPosition(Object packet, double x, double y, double z) {
namedSpawnX.set(packet, x);
namedSpawnY.set(packet, y);
namedSpawnZ.set(packet, z);
}
private final Map<Player, BossBar> barMap = new HashMap<>();
@Override
public void sendBar(Player player, FightTeam team, double progress, String text) {

Datei anzeigen

@ -148,7 +148,6 @@ public class FightSystem extends JavaPlugin {
new LiveRecorder();
new FileRecorder();
REntity.initWatchers();
FileSource.startReplay();
if(Config.mode == ArenaMode.EVENT) {

Datei anzeigen

@ -23,17 +23,20 @@ import com.comphenix.tinyprotocol.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol;
import com.mojang.authlib.GameProfile;
import de.steamwar.core.Core;
import de.steamwar.core.ProtocolWrapper;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.record.GlobalRecorder;
import de.steamwar.fightsystem.utils.ProtocolWrapper;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import java.util.*;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
public class Fight {
private Fight(){}
@ -143,25 +146,19 @@ public class Fight {
}
}
public static final Class<?> playerInfoPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo");
private static final Class<?> playerInfoActionClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$EnumPlayerInfoAction");
public static final Object addPlayer = playerInfoActionClass.getEnumConstants()[0];
private static final Reflection.FieldAccessor<?> playerInfoAction = Reflection.getField(playerInfoPacket, playerInfoActionClass, 0);
private static final Reflection.FieldAccessor<?> playerInfoAction = Reflection.getField(ProtocolWrapper.playerInfoPacket, playerInfoActionClass, 0);
private static final Object updateGamemode = playerInfoActionClass.getEnumConstants()[1];
public static final Object removePlayer = playerInfoActionClass.getEnumConstants()[4];
private static final Reflection.FieldAccessor<List> playerInfoData = Reflection.getField(playerInfoPacket, List.class, 0);
public static final Class<?> playerInfoDataClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$PlayerInfoData");
public static final Class<?> enumGamemode = Reflection.getClass(Core.getVersion() > 9 ? "{nms.world.level}.EnumGamemode" : "{nms}.WorldSettings$EnumGamemode");
public static final Object creative = enumGamemode.getEnumConstants()[Core.getVersion() > 15 ? 1 : 2];
private static final Object spectator = enumGamemode.getEnumConstants()[Core.getVersion() > 15 ? 3 : 4];
public static final Class<?> iChatBaseComponent = Reflection.getClass("{nms.network.chat}.IChatBaseComponent");
private static final Reflection.FieldAccessor<List> playerInfoData = Reflection.getField(ProtocolWrapper.playerInfoPacket, List.class, 0);
public static final Object creative = ProtocolWrapper.enumGamemode.getEnumConstants()[Core.getVersion() > 15 ? 1 : 2];
private static final Object spectator = ProtocolWrapper.enumGamemode.getEnumConstants()[Core.getVersion() > 15 ? 3 : 4];
public static void pseudoSpectator(Player player, boolean enable) {
TinyProtocol.instance.sendPacket(player, playerInfoPacket(updateGamemode, new GameProfile(player.getUniqueId(), player.getName()), enable ? creative : spectator));
}
public static Object playerInfoPacket(Object action, GameProfile profile, Object mode) {
Object packet = Reflection.newInstance(playerInfoPacket);
Object packet = Reflection.newInstance(ProtocolWrapper.playerInfoPacket);
playerInfoAction.set(packet, action);
playerInfoData.set(packet, Collections.singletonList(ProtocolWrapper.impl.playerInfoDataConstructor(packet, profile, mode)));
return packet;

Datei anzeigen

@ -31,6 +31,7 @@ import de.steamwar.fightsystem.states.StateDependent;
import de.steamwar.fightsystem.utils.ColorConverter;
import de.steamwar.fightsystem.utils.Region;
import de.steamwar.fightsystem.utils.WorldeditWrapper;
import de.steamwar.sql.SchematicData;
import de.steamwar.sql.SchematicNode;
import org.bukkit.*;
import org.bukkit.block.Block;
@ -70,7 +71,7 @@ public class FightSchematic extends StateDependent {
public void setSchematic(SchematicNode schem) {
schematic = schem.getId();
try {
clipboard = schem.load();
clipboard = new SchematicData(schem).load();
if(schem.replaceColor())
replaceTeamColor(clipboard);

Datei anzeigen

@ -25,7 +25,6 @@ import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.record.REntity;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import net.md_5.bungee.api.ChatMessageType;
@ -85,8 +84,6 @@ public class Permanent implements Listener {
Fight.setPlayerGamemode(player, GameMode.SPECTATOR);
player.teleport(Config.SpecSpawn);
}
REntity.playerJoins(player);
}
@EventHandler(priority = EventPriority.MONITOR)

Datei anzeigen

@ -20,10 +20,11 @@
package de.steamwar.fightsystem.record;
import de.steamwar.fightsystem.Config;
import de.steamwar.sql.Replay;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;
public class FileSource extends PacketSource {
@ -39,19 +40,8 @@ public class FileSource extends PacketSource {
}
if(Config.ReplayID > 0) {
de.steamwar.sql.Fight.getReplay(Config.ReplayID, input -> {
try {
Files.copy(
input,
FileRecorder.getFile().toPath(),
StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new SecurityException("Could not start replay", e);
}
});
try {
new FileSource(FileRecorder.getFile());
new FileSource(Replay.get(Config.ReplayID).getReplay());
} catch (IOException e) {
throw new SecurityException("Could not start replay", e);
}

Datei anzeigen

@ -21,6 +21,9 @@ package de.steamwar.fightsystem.record;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.core.Core;
import de.steamwar.entity.REntity;
import de.steamwar.entity.REntityServer;
import de.steamwar.entity.RPlayer;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.countdown.Countdown;
@ -31,7 +34,9 @@ import de.steamwar.fightsystem.fight.FreezeWorld;
import de.steamwar.fightsystem.listener.FightScoreboard;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.utils.*;
import de.steamwar.sql.SchematicData;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SteamwarUser;
import de.steamwar.sql.Team;
import de.steamwar.techhider.BlockIds;
import net.md_5.bungee.api.ChatMessageType;
@ -41,7 +46,15 @@ import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitTask;
import java.io.EOFException;
@ -51,7 +64,18 @@ import java.util.*;
import java.util.logging.Level;
import java.util.stream.Collectors;
public class PacketProcessor {
public class PacketProcessor implements Listener {
/*private static final String SCOREBOARD_TEAMNAME = "Replay";
private static final Team team;
static {
if(FightScoreboard.getBukkit().getTeam(SCOREBOARD_TEAMNAME) == null)
team = FightScoreboard.getBukkit().registerNewTeam(SCOREBOARD_TEAMNAME);
else
team = FightScoreboard.getBukkit().getTeam(SCOREBOARD_TEAMNAME);
team.setNameTagVisibility(NameTagVisibility.NEVER);
}*/
private static PacketProcessor currentProcessor = null;
@ -71,6 +95,8 @@ public class PacketProcessor {
private final Set<Integer> hiddenBlockIds = Config.HiddenBlocks.stream().map(String::toUpperCase).map(Material::getMaterial).flatMap(m -> BlockIds.impl.materialToAllIds(m).stream()).collect(Collectors.toSet());
private final int obfuscateWith = BlockIds.impl.materialToId(Material.getMaterial(Config.ObfuscateWith.toUpperCase()));
private final FreezeWorld freezer = new FreezeWorld();
private final REntityServer entityServer = new REntityServer();
private final Map<Integer, REntity> entities = new HashMap<>();
private boolean rotateZ = false;
private int arenaMinX = Config.ArenaRegion.getMinX();
@ -136,6 +162,15 @@ public class PacketProcessor {
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::runSync, 1, 1);
}else
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::process, 1, 1);
Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin());
for(Player player : Bukkit.getOnlinePlayers())
entityServer.addPlayer(player);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerJoin(PlayerJoinEvent e) {
entityServer.addPlayer(e.getPlayer());
}
public void skipToSubtitle() {
@ -201,7 +236,10 @@ public class PacketProcessor {
int entityId = source.readInt();
int userId = source.readInt();
execSync(() -> new REntity(entityId, userId));
execSync(() -> {
SteamwarUser user = SteamwarUser.get(userId);
entities.put(entityId, new RPlayer(entityServer, user.getUUID(), user.getUserName(), Config.SpecSpawn));
});
}
private void entityMoves() throws IOException {
@ -220,7 +258,7 @@ public class PacketProcessor {
byte headYaw = (byte)((source.readByte() + (rotateZ ? 128 : 0)) % 256);
execSync(() -> {
REntity entity = REntity.getEntity(entityId);
REntity entity = entities.get(entityId);
if(entity != null)
entity.move(locX, locY, locZ, pitch, yaw, headYaw);
});
@ -230,7 +268,7 @@ public class PacketProcessor {
int entityId = source.readInt();
execSync(() -> {
REntity entity = REntity.getEntity(entityId);
REntity entity = entities.remove(entityId);
if(entity != null)
entity.die();
});
@ -240,20 +278,20 @@ public class PacketProcessor {
int entityId = source.readInt();
boolean sneaking = source.readBoolean();
execSync(() -> REntity.getEntity(entityId).sneak(sneaking));
execSync(() -> entities.get(entityId).setPose(sneaking ? de.steamwar.core.FlatteningWrapper.EntityPose.SNEAKING : de.steamwar.core.FlatteningWrapper.EntityPose.NORMAL));
}
private void entityAnimation() throws IOException {
int entityId = source.readInt();
byte animation = source.readByte();
execSync(() -> REntity.getEntity(entityId).animation(animation));
execSync(() -> entities.get(entityId).showAnimation(animation));
}
private void tntSpawn() throws IOException {
int entityId = source.readInt();
execSync(() -> new REntity(entityId, EntityType.PRIMED_TNT));
execSync(() -> entities.put(entityId, new REntity(entityServer, EntityType.PRIMED_TNT, Config.SpecSpawn)));
}
private void entityVelocity() throws IOException {
@ -264,7 +302,7 @@ public class PacketProcessor {
double dZ = rotateZ ? -source.readDouble() : source.readDouble();
execSync(() -> {
REntity entity = REntity.getEntity(entityId);
REntity entity = entities.get(entityId);
if(entity != null)
entity.setVelocity(dX, dY, dZ);
});
@ -274,21 +312,47 @@ public class PacketProcessor {
int entityId = source.readInt();
String item = source.readUTF();
boolean enchanted = source.readBoolean();
String slot = source.readUTF();
String slotName = source.readUTF();
execSync(() -> REntity.getEntity(entityId).setItem(item, enchanted, slot));
ItemStack stack = new ItemStack(Material.valueOf(item.replace("minecraft:", "").toUpperCase()), 1);
if(enchanted)
stack.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
Object slot;
switch(slotName){
case "HEAD":
slot = de.steamwar.core.ProtocolWrapper.itemSlots[5];
break;
case "CHEST":
slot = de.steamwar.core.ProtocolWrapper.itemSlots[4];
break;
case "LEGS":
slot = de.steamwar.core.ProtocolWrapper.itemSlots[3];
break;
case "FEET":
slot = de.steamwar.core.ProtocolWrapper.itemSlots[2];
break;
case "OFFHAND":
slot = de.steamwar.core.ProtocolWrapper.itemSlots[1];
break;
case "MAINHAND":
default:
slot = de.steamwar.core.ProtocolWrapper.itemSlots[0];
}
execSync(() -> entities.get(entityId).setItem(slot, stack));
}
private void arrowSpawn() throws IOException {
int entityId = source.readInt();
execSync(() -> new REntity(entityId, EntityType.ARROW));
execSync(() -> entities.put(entityId, new REntity(entityServer, EntityType.ARROW, Config.SpecSpawn)));
}
private void fireballSpawn() throws IOException {
int entityId = source.readInt();
execSync(() -> new REntity(entityId, EntityType.FIREBALL));
execSync(() -> entities.put(entityId, new REntity(entityServer, EntityType.FIREBALL, Config.SpecSpawn)));
}
private void send(ChatMessageType type) throws IOException {
@ -424,13 +488,15 @@ public class PacketProcessor {
private void pasteSchem(FightTeam team) throws IOException {
int schemId = source.readInt();
if(schemId == 0)
return;
execSync(() -> team.pasteSchem(SchematicNode.getSchematicNode(schemId)));
}
private void pasteEmbeddedSchem(FightTeam team) throws IOException {
int schemId = source.readInt();
Clipboard clipboard = SchematicNode.clipboardFromStream(new FilterInputStream(source) {
Clipboard clipboard = SchematicData.clipboardFromStream(new FilterInputStream(source) {
@Override
public void close() {
// FAWE 1.12 calls close...
@ -505,7 +571,10 @@ public class PacketProcessor {
}
private void endReplay() {
REntity.dieAll();
HandlerList.unregisterAll(this);
entityServer.close();
entities.clear();
freezer.disable();
if(!Config.replayserver()) {
FightSystem.getMessage().broadcast("REPLAY_ENDS");
@ -521,6 +590,7 @@ public class PacketProcessor {
}
FightState.setFightState(FightState.SPECTATE);
currentProcessor = null;
task.cancel();
}
private void bow() throws IOException {
@ -528,24 +598,25 @@ public class PacketProcessor {
boolean drawn = source.readBoolean();
boolean offHand = source.readBoolean();
execSync(() -> REntity.getEntity(entityId).setBowDrawn(drawn, offHand));
execSync(() -> entities.get(entityId).setBowDrawn(drawn, offHand));
}
private void damage() throws IOException {
int entityId = source.readInt();
execSync(() -> REntity.getEntity(entityId).damage());
execSync(() -> entities.get(entityId).showDamage());
}
private void fireTick() throws IOException {
int entityId = source.readInt();
boolean perma = source.readBoolean();
execSync(() -> REntity.getEntity(entityId).setOnFire(perma));
execSync(() -> entities.get(entityId).setOnFire(perma));
}
private void tick(){
execSync(REntity::tickFire);
entityServer.tick();
if(!source.async() && !skipToSubtitle)
tickFinished = true;
}
@ -555,6 +626,11 @@ public class PacketProcessor {
try{
while(!source.isClosed() && !tickFinished){
int packetType = Byte.toUnsignedInt(source.readByte());
lastPackets.add(packetType);
if (lastPackets.size() > 10)
lastPackets.remove(0);
PacketParser parser = packetDecoder[packetType];
if(parser != null){
parser.process();
@ -562,9 +638,6 @@ public class PacketProcessor {
Bukkit.getLogger().log(Level.SEVERE, "Unknown packet " + packetType + " recieved, closing. LastPacket: " + Arrays.toString(lastPackets.toArray()));
source.close();
}
lastPackets.add(packetType);
if (lastPackets.size() > 10)
lastPackets.remove(0);
}
} catch (EOFException e) {
Bukkit.getLogger().log(Level.INFO, "The FightServer is offline");
@ -575,10 +648,7 @@ public class PacketProcessor {
}
if(source.isClosed()){
execSync(() -> {
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::endReplay);
task.cancel();
});
execSync(() -> Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::endReplay));
}
}

Datei anzeigen

@ -1,349 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.fightsystem.record;
import com.comphenix.tinyprotocol.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol;
import com.mojang.authlib.GameProfile;
import de.steamwar.core.Core;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.listener.FightScoreboard;
import de.steamwar.fightsystem.utils.*;
import de.steamwar.sql.SteamwarUser;
import de.steamwar.techhider.ProtocolUtils;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scoreboard.NameTagVisibility;
import org.bukkit.scoreboard.Team;
import java.util.*;
import java.util.logging.Level;
public class REntity {
private static final Map<Integer, REntity> entities = new HashMap<>();
public static REntity getEntity(int internalId){
return entities.get(internalId);
}
private static Object entityStatusWatcher;
private static Object sneakingDataWatcher;
private static Object bowDrawnWatcher;
public static void initWatchers() {
// not during <clinit> to prevent cyclic class init.
entityStatusWatcher = BountifulWrapper.impl.getDataWatcherObject(0, Byte.class);
sneakingDataWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() > 12 ? 6 : 0, BlockIdWrapper.impl.getPose(true).getClass());
bowDrawnWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() > 12 ? 7 : 6, Byte.class);
}
public static void tickFire() {
entities.forEach((integer, entity) -> {
if(entity.fireTick > 0) {
entity.fireTick--;
if(entity.fireTick == 0) {
ProtocolUtils.broadcastPacket(entity.getDataWatcherPacket(entityStatusWatcher, (byte)0));
}
}
});
}
public static void playerJoins(Player player) {
for(REntity entity : entities.values()){
if(entity.entityType == EntityType.PLAYER){
TinyProtocol.instance.sendPacket(player, entity.getPlayerInfoPacket());
TinyProtocol.instance.sendPacket(player, entity.getNamedSpawnPacket());
for (Map.Entry<String, ItemStack> entry : entity.itemSlots.entrySet()) {
TinyProtocol.instance.sendPacket(player, entity.getEquipmentPacket(entry.getKey(), entry.getValue()));
}
}else{
TinyProtocol.instance.sendPacket(player, entity.getSpawnEntityPacket());
}
TinyProtocol.instance.sendPacket(player, entity.getTeleportPacket());
TinyProtocol.instance.sendPacket(player, entity.getHeadRotationPacket());
if(entity.fireTick != 0) {
TinyProtocol.instance.sendPacket(player, entity.getDataWatcherPacket(entityStatusWatcher, (byte) 1));
}
if(entity.sneaks) {
TinyProtocol.instance.sendPacket(player, entity.getDataWatcherPacket(sneakingDataWatcher, BlockIdWrapper.impl.getPose(true)));
}
}
}
public static void dieAll(){
entities.forEach((id, entity) -> entity.broadcastDeath());
entities.clear();
}
private static final String SCOREBOARD_TEAMNAME = "Replay";
private static final Team team;
static {
if(FightScoreboard.getBukkit().getTeam(SCOREBOARD_TEAMNAME) == null)
team = FightScoreboard.getBukkit().registerNewTeam(SCOREBOARD_TEAMNAME);
else
team = FightScoreboard.getBukkit().getTeam(SCOREBOARD_TEAMNAME);
team.setNameTagVisibility(NameTagVisibility.NEVER);
}
private static int entityCount = Integer.MAX_VALUE;
private static final Random random = new Random();
private final int internalId;
private final int entityId;
private final UUID uuid;
private final EntityType entityType;
private final String name;
private final Map<String, ItemStack> itemSlots = new HashMap<>();
private double locX;
private double locY;
private double locZ;
private byte yaw;
private byte pitch;
private byte headYaw;
private int fireTick;
private boolean sneaks;
private boolean playerSpawned = false;
public REntity(int internalId, int userId){
this.internalId = internalId;
this.entityType = EntityType.PLAYER;
this.entityId = entityCount--;
SteamwarUser user;
try {
user = SteamwarUser.get(userId);
} catch (SecurityException e) {
FightSystem.getPlugin().getLogger().log(Level.SEVERE, "Could not load user " + userId);
throw e;
}
this.uuid = user.getUUID();
this.name = user.getUserName();
entities.put(internalId, this);
ProtocolUtils.broadcastPacket(getPlayerInfoPacket());
team.addEntry(name);
}
public REntity(int internalId, EntityType entityType){
this.internalId = internalId;
this.entityType = entityType;
this.entityId = entityCount--;
this.name = null;
this.uuid = new UUID(random.nextLong() & -61441L | 16384L, random.nextLong() & 4611686018427387903L | -9223372036854775808L);
entities.put(internalId, this);
ProtocolUtils.broadcastPacket(getSpawnEntityPacket());
}
public void move(double locX, double locY, double locZ, float pitch, float yaw, byte headYaw){
this.locX = locX;
this.locY = locY;
this.locZ = locZ;
if(entityType == EntityType.PLAYER && !playerSpawned) {
ProtocolUtils.broadcastPacket(getNamedSpawnPacket());
playerSpawned = true;
}
this.yaw = (byte)((int)(yaw * 256.0F / 360.0F));
this.pitch = (byte)((int)(pitch * 256.0F / 360.0F));
this.headYaw = headYaw;
ProtocolUtils.broadcastPacket(getTeleportPacket());
ProtocolUtils.broadcastPacket(getHeadRotationPacket());
}
private static final Class<?> animationPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutAnimation");
private static final Reflection.FieldAccessor<Integer> animationEntity = Reflection.getField(animationPacket, int.class, Core.getVersion() > 15 ? 6 : 0);
private static final Reflection.FieldAccessor<Integer> animationAnimation = Reflection.getField(animationPacket, int.class, Core.getVersion() > 15 ? 7 : 1);
public void animation(byte animation) {
Object packet = Reflection.newInstance(animationPacket);
animationEntity.set(packet, entityId);
animationAnimation.set(packet, (int) animation);
ProtocolUtils.broadcastPacket(packet);
}
private static final Class<?> velocityPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityVelocity");
private static final Reflection.FieldAccessor<Integer> velocityEntity = Reflection.getField(velocityPacket, int.class, 0);
private static final Reflection.FieldAccessor<Integer> velocityX = Reflection.getField(velocityPacket, int.class, 1);
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);
public void setVelocity(double dX, double dY, double dZ) {
Object packet = Reflection.newInstance(velocityPacket);
velocityEntity.set(packet, entityId);
velocityX.set(packet, calcVelocity(dX));
velocityY.set(packet, calcVelocity(dY));
velocityZ.set(packet, calcVelocity(dZ));
ProtocolUtils.broadcastPacket(packet);
}
private static final Class<?> statusPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityStatus");
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);
public void damage() {
Object packet = Reflection.newInstance(statusPacket);
statusEntity.set(packet, entityId);
statusStatus.set(packet, (byte) 2);
ProtocolUtils.broadcastPacket(packet);
}
public void sneak(boolean sneaking) {
sneaks = sneaking;
ProtocolUtils.broadcastPacket(getDataWatcherPacket(sneakingDataWatcher, BlockIdWrapper.impl.getPose(sneaking)));
}
public void setOnFire(boolean perma) {
if(!perma) {
fireTick = 21;
} else {
fireTick = -1;
}
ProtocolUtils.broadcastPacket(getDataWatcherPacket(entityStatusWatcher, (byte) 1));
}
public void setBowDrawn(boolean drawn, boolean offHand) {
if(Core.getVersion() > 8){
ProtocolUtils.broadcastPacket(getDataWatcherPacket(bowDrawnWatcher, (byte) ((drawn ? 1 : 0) + (offHand ? 2 : 0))));
}else{
ProtocolUtils.broadcastPacket(getDataWatcherPacket(entityStatusWatcher, (byte)0x10));
}
}
public void setItem(String item, boolean enchanted, String slot) {
ItemStack stack = new ItemStack(Material.valueOf(item.replace("minecraft:", "").toUpperCase()), 1);
if(enchanted)
stack.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
itemSlots.put(slot, stack);
ProtocolUtils.broadcastPacket(getEquipmentPacket(slot, stack));
}
public void die(){
broadcastDeath();
entities.remove(internalId);
}
private static final Class<?> destroyPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityDestroy");
private static final Reflection.FieldAccessor<?> destroyEntities;
static {
if(Core.getVersion() > 15)
destroyEntities = Reflection.getField(destroyPacket, IntList.class, 0);
else
destroyEntities = Reflection.getField(destroyPacket, int[].class, 0);
}
private void broadcastDeath(){
if(entityType == EntityType.PLAYER){
ProtocolUtils.broadcastPacket(Fight.playerInfoPacket(Fight.removePlayer, new GameProfile(uuid, name), Fight.creative));
team.removeEntry(name);
}
Object packet = Reflection.newInstance(destroyPacket);
destroyEntities.set(packet, Core.getVersion() > 15 ? new IntArrayList(new int[]{entityId}) : new int[]{entityId});
ProtocolUtils.broadcastPacket(packet);
}
private int calcVelocity(double value) {
return (int)(Math.max(-3.9, Math.min(value, 3.9)) * 8000);
}
private static final Class<?> metadataPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityMetadata");
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 Object getDataWatcherPacket(Object dataWatcherObject, Object value) {
Object packet = Reflection.newInstance(metadataPacket);
metadataEntity.set(packet, entityId);
metadataMetadata.set(packet, Collections.singletonList(BountifulWrapper.impl.getDataWatcherItem(dataWatcherObject, value)));
return packet;
}
public static final Class<?> teleportPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityTeleport");
private static final Reflection.FieldAccessor<Integer> teleportEntity = Reflection.getField(teleportPacket, int.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 Object getTeleportPacket(){
Object packet = Reflection.newInstance(teleportPacket);
teleportEntity.set(packet, entityId);
BountifulWrapper.impl.setTeleportPacketPosition(packet, locX, locY, locZ);
teleportYaw.set(packet, yaw);
teleportPitch.set(packet, pitch);
return packet;
}
private static final Class<?> headRotationPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityHeadRotation");
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 Object getHeadRotationPacket(){
Object packet = Reflection.newInstance(headRotationPacket);
headRotationEntity.set(packet, entityId);
headRotationYaw.set(packet, headYaw);
return packet;
}
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 Object getSpawnEntityPacket(){
Object packet = Reflection.newInstance(spawnPacket);
spawnEntity.set(packet, entityId);
BountifulWrapper.impl.setSpawnPacketUUID(packet, uuid);
ProtocolWrapper.impl.setSpawnPacketType(packet, entityType);
return packet;
}
public static final Class<?> equipmentPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityEquipment");
private static final Reflection.FieldAccessor<Integer> equipmentEntity = Reflection.getField(equipmentPacket, int.class, 0);
public static final Class<?> itemStack = Reflection.getClass("{nms.world.item}.ItemStack");
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 Object getEquipmentPacket(String slot, ItemStack stack){
Object packet = Reflection.newInstance(equipmentPacket);
equipmentEntity.set(packet, entityId);
ProtocolWrapper.impl.setEquipmentPacketStack(packet, slot, asNMSCopy.invoke(null, stack));
return packet;
}
private Object getPlayerInfoPacket(){
return Fight.playerInfoPacket(Fight.addPlayer, new GameProfile(uuid, name), Fight.creative);
}
public static final Class<?> namedSpawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutNamedEntitySpawn");
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 Object getNamedSpawnPacket(){
Object packet = Reflection.newInstance(namedSpawnPacket);
namedSpawnEntity.set(packet, entityId);
namedSpawnUUID.set(packet, uuid);
BountifulWrapper.impl.setNamedSpawnPosition(packet, locX, locY, locZ);
FlatteningWrapper.impl.setNamedSpawnPacketDataWatcher(packet);
return packet;
}
}

Datei anzeigen

@ -29,6 +29,7 @@ import de.steamwar.fightsystem.utils.BlockIdWrapper;
import de.steamwar.fightsystem.utils.CraftbukkitWrapper;
import de.steamwar.fightsystem.utils.Message;
import de.steamwar.fightsystem.utils.SWSound;
import de.steamwar.sql.SchematicData;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit;
@ -275,7 +276,7 @@ public interface Recorder {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
try{
copy(SchematicNode.getSchematicNode(schemId).schemData(), buffer);
copy(new SchematicData(SchematicNode.getSchematicNode(schemId)).schemData(), buffer);
}catch (EOFException e) {
Bukkit.getLogger().log(Level.INFO, "EOFException ignored");
} catch (IOException e) {

Datei anzeigen

@ -27,8 +27,6 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.scoreboard.Team;
import java.util.UUID;
public interface BountifulWrapper {
BountifulWrapper impl = VersionDependent.getVersionImpl(FightSystem.getPlugin());
@ -47,11 +45,5 @@ public interface BountifulWrapper {
void spawnParticle(World world, String particleName, double x, double y, double z);
Object getDataWatcherObject(int index, Class<?> type);
Object getDataWatcherItem(Object dataWatcherObject, Object value);
void setTeleportPacketPosition(Object packet, double x, double y, double z);
void setSpawnPacketUUID(Object packet, UUID uuid);
void setNamedSpawnPosition(Object packet, double x, double y, double z);
void sendBar(Player player, FightTeam team, double progress, String text);
}

Datei anzeigen

@ -32,18 +32,17 @@ import de.steamwar.fightsystem.states.OneShotStateDependent;
import de.steamwar.fightsystem.winconditions.Wincondition;
import de.steamwar.network.NetworkSender;
import de.steamwar.network.packets.common.FightEndsPacket;
import de.steamwar.sql.Replay;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit;
import java.io.FileInputStream;
import java.sql.Timestamp;
import java.time.Instant;
import java.util.logging.Level;
import java.util.stream.Collectors;
import static de.steamwar.sql.Fight.create;
import static de.steamwar.sql.Fight.setReplay;
public class FightStatistics {
@ -123,7 +122,7 @@ public class FightStatistics {
}
try {
setReplay(fightId, new FileInputStream(FileRecorder.getFile()));
Replay.save(fightId, FileRecorder.getFile());
} catch (Exception e) {
Bukkit.getLogger().log(Level.INFO, "Failed to save replay", e);
}
@ -132,7 +131,7 @@ public class FightStatistics {
}
if (!Bukkit.getOnlinePlayers().isEmpty() && !unranked) {
NetworkSender.send(new FightEndsPacket((byte) win, blueSchem == null ? 0 : blueSchem, redSchem == null ? 0 : redSchem, Fight.getBlueTeam().getPlayers().stream().map(FightPlayer::getPlayer).map(SteamwarUser::get).map(SteamwarUser::getId).collect(Collectors.toList()), Fight.getRedTeam().getPlayers().stream().map(FightPlayer::getPlayer).map(SteamwarUser::get).map(SteamwarUser::getId).collect(Collectors.toList()), gameMode));
NetworkSender.send(new FightEndsPacket((byte) win, blueSchem == null ? 0 : blueSchem, redSchem == null ? 0 : redSchem, Fight.getBlueTeam().getPlayers().stream().map(FightPlayer::getPlayer).map(p -> SteamwarUser.get(p.getUniqueId())).map(SteamwarUser::getId).collect(Collectors.toList()), Fight.getRedTeam().getPlayers().stream().map(FightPlayer::getPlayer).map(p -> SteamwarUser.get(p.getUniqueId())).map(SteamwarUser::getId).collect(Collectors.toList()), gameMode));
}
unranked = false;

Datei anzeigen

@ -44,6 +44,4 @@ public interface FlatteningWrapper {
void forceLoadChunk(World world, int cX, int cZ);
boolean checkPistonMoving(Block block);
void setNamedSpawnPacketDataWatcher(Object packet);
}

Datei anzeigen

@ -1,36 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2021 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.fightsystem.utils;
import com.mojang.authlib.GameProfile;
import de.steamwar.core.VersionDependent;
import de.steamwar.fightsystem.FightSystem;
import org.bukkit.entity.EntityType;
public interface ProtocolWrapper {
ProtocolWrapper impl = VersionDependent.getVersionImpl(FightSystem.getPlugin());
void setEquipmentPacketStack(Object packet, String slot, Object stack);
void setSpawnPacketType(Object packet, EntityType type);
Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode);
}

Datei anzeigen

@ -1,7 +1,9 @@
build:
setup:
- "ln -s /home/gitea/lib"
- "cp ~/gradle.properties ."
build:
- "./gradlew buildProject"
- "./gradlew --stop"
artifacts:
"/binarys/fightsystem.jar": "build/libs/fightsystem.jar"