diff --git a/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java b/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java index 1e83039..a3a5fee 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java @@ -49,7 +49,7 @@ public enum ArenaMode { public static final Set AntiPrepare = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(PREPARE))); public static final Set VariableTeams = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(RANKED, EVENT, REPLAY))); public static final Set RankedEvent = Collections.unmodifiableSet(EnumSet.of(RANKED, EVENT, REPLAY)); - public static final Set Restartable = Collections.unmodifiableSet(EnumSet.of(NORMAL, RANKED)); + public static final Set Restartable = Collections.unmodifiableSet(EnumSet.of(NORMAL, RANKED, REPLAY)); public static final Set SoloLeader = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK, PREPARE)); public static final Set NotOnBau = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK, PREPARE, REPLAY))); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/RemoveCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/RemoveCommand.java index b538532..29ba6d2 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/RemoveCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/RemoveCommand.java @@ -30,7 +30,7 @@ import org.bukkit.entity.Player; public class RemoveCommand implements CommandExecutor { public RemoveCommand() { - new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "die", this); + new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "remove", this); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java index 74d512f..21756a4 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -60,7 +60,7 @@ public class FightSchematic extends StateDependent { private int schematic = 0; public FightSchematic(FightTeam team, boolean rotate) { - super(ArenaMode.AntiReplay, FightState.PostSchemSetup); + super(ArenaMode.All, FightState.PostSchemSetup); this.team = team; this.region = team.getSchemRegion(); this.rotate = rotate; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index 7c4a8e2..78cdb11 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -170,7 +170,7 @@ public class FightTeam implements IFightTeam{ playerSet.forEach(this::addMember); - if(isLeaderless()){ + if(ArenaMode.VariableTeams.contains(Config.mode) && isLeaderless()){ for(Player player : Bukkit.getOnlinePlayers()){ if(Fight.getPlayerTeam(player) == null && canbeLeader(player)){ addMember(player); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Shutdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Shutdown.java index be3e243..e088314 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Shutdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Shutdown.java @@ -20,6 +20,7 @@ package de.steamwar.fightsystem.listener; import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; import org.bukkit.Bukkit; @@ -36,7 +37,10 @@ public class Shutdown implements Listener { @EventHandler(priority = EventPriority.HIGH) public void handlePlayerQuit(PlayerQuitEvent event) { - //Shutdown server if nobody online and its not an event server + if(Config.replayserver()) + return; + + //Shutdown server if nobody online if(Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(event.getPlayer()))) Bukkit.shutdown(); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java index d1d3ce4..f462a83 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java @@ -38,6 +38,7 @@ public class FileRecorder extends StateDependent implements Recorder { public FileRecorder(){ super(ArenaMode.AntiReplay, FightState.Recording); + register(); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileSource.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileSource.java index 3af2c12..0540a2e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileSource.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileSource.java @@ -20,12 +20,10 @@ package de.steamwar.fightsystem.record; import de.steamwar.fightsystem.Config; -import org.bukkit.Bukkit; import java.io.*; import java.nio.file.Files; import java.nio.file.StandardCopyOption; -import java.util.logging.Level; import java.util.zip.GZIPInputStream; public class FileSource extends PacketSource { @@ -56,7 +54,6 @@ public class FileSource extends PacketSource { try{ return inputStream.available() == 0; }catch (IOException e){ - Bukkit.getLogger().log(Level.WARNING, "On close test exception", e); return true; } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java index dd85b7c..0942347 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -101,7 +101,7 @@ public class PacketProcessor { int entityId = source.rInt(); int userId = source.rInt(); - execSync(() -> new REntity(entityId, userId)); + execSync(() -> new REntity(entityId, userId)); } private void entityMoves() throws IOException { @@ -289,13 +289,13 @@ public class PacketProcessor { private void endReplay(){ REntity.dieAll(); freezer.disable(); - replaying = false; if(Config.replayserver() || ArenaMode.AntiReplay.contains(Config.mode)) { FightSystem.setSpectateState(null, "Replay ends"); }else{ Bukkit.broadcastMessage(FightSystem.PREFIX + "§cReplay beendet"); new EventSpectateCountdown().enable(); } + replaying = false; } private void bow() throws IOException { @@ -421,7 +421,7 @@ public class PacketProcessor { } catch (EOFException e) { Bukkit.getLogger().log(Level.INFO, "The FightServer is offline"); source.close(); - } catch(IOException e){ + } catch(IOException e) { Bukkit.getLogger().log(Level.WARNING, "Could not recieve packet", e); source.close(); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java index ef768a8..6e2d067 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java @@ -24,6 +24,7 @@ import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.wrappers.*; +import com.mojang.authlib.GameProfile; import de.steamwar.core.Core; import de.steamwar.core.VersionedCallable; import de.steamwar.fightsystem.listener.FightScoreboard; @@ -55,14 +56,7 @@ public class REntity { if(entity.fireTick > 0) { entity.fireTick--; if(entity.fireTick == 0) { - /*DataWatcher dataWatcher = new DataWatcher(null); - DataWatcherObject dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a); - dataWatcher.register(dataWatcherObject, (byte) 0); - dataWatcher.markDirty(dataWatcherObject); - entity.sendDataWatcher(dataWatcher);*/ - WrappedDataWatcher watcher = new WrappedDataWatcher(); - watcher.setObject(0, (byte) 0, true); - ProtocolLibrary.getProtocolManager().broadcastServerPacket(entity.getDataWatcherPacket(watcher)); + ProtocolLibrary.getProtocolManager().broadcastServerPacket(entity.getDataWatcherPacket(0, (byte)0)); } } }); @@ -82,28 +76,14 @@ public class REntity { } //ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getTeleportPacket()); Sollte nicht nötig sein? if(entity.fireTick != 0) { - WrappedDataWatcher watcher = new WrappedDataWatcher(); - watcher.setObject(0, (byte) 1, true); - /*ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(watcher)); - DataWatcher dataWatcher = new DataWatcher(null); - DataWatcherObject dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a); - dataWatcher.register(dataWatcherObject, (byte) 1); - dataWatcher.markDirty(dataWatcherObject); - entity.sendDataWatcher(dataWatcher);*/ + ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(0, (byte) 1)); } if(entity.sneaks) { - WrappedDataWatcher watcher = new WrappedDataWatcher(); if(Core.getVersion() > 12){ - watcher.setObject(6, getPose(true), true); + ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(6, getPose(true))); }else{ - watcher.setObject(0, (byte) 2, true); + ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(0, (byte) 2)); } - ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(watcher)); - /*DataWatcher dataWatcher = new DataWatcher(null); - DataWatcherObject dataWatcherObject = new DataWatcherObject<>(6, DataWatcherRegistry.s); - dataWatcher.register(dataWatcherObject, EntityPose.CROUCHING); - dataWatcher.markDirty(dataWatcherObject); - entity.sendDataWatcher(dataWatcher);*/ } } }catch(InvocationTargetException e){ @@ -153,7 +133,7 @@ public class REntity { SteamwarUser user = SteamwarUser.get(userId); this.uuid = user.getUUID(); - this.playerInfoData = new PlayerInfoData(WrappedGameProfile.fromOfflinePlayer(Bukkit.getOfflinePlayer(uuid)), 0, EnumWrappers.NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(user.getUserName())); + this.playerInfoData = new PlayerInfoData(WrappedGameProfile.fromHandle(new GameProfile(uuid, user.getUserName())), 0, EnumWrappers.NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(user.getUserName())); entities.put(internalId, this); ProtocolLibrary.getProtocolManager().broadcastServerPacket(getPlayerInfoPacket()); @@ -211,18 +191,11 @@ public class REntity { public void sneak(boolean sneaking) { sneaks = sneaking; - /*DataWatcher dataWatcher = new DataWatcher(null); - DataWatcherObject dataWatcherObject = new DataWatcherObject<>(6, DataWatcherRegistry.s); - dataWatcher.register(dataWatcherObject, sneaking?EntityPose.CROUCHING:EntityPose.STANDING); - dataWatcher.markDirty(dataWatcherObject);*/ - - WrappedDataWatcher watcher = new WrappedDataWatcher(); if(Core.getVersion() > 12){ - watcher.setObject(6, getPose(sneaking), true); + ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(6, getPose(sneaking))); }else{ - watcher.setObject(0, sneaking ? (byte) 2 : (byte) 0, true); + ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(0, sneaking ? (byte) 2 : (byte) 0)); } - ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(watcher)); } public void setOnFire(boolean perma) { @@ -232,36 +205,21 @@ public class REntity { fireTick = -1; } - /*DataWatcher dataWatcher = new DataWatcher(null); - DataWatcherObject dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a); - dataWatcher.register(dataWatcherObject, (byte) 1); - dataWatcher.markDirty(dataWatcherObject);*/ - - WrappedDataWatcher watcher = new WrappedDataWatcher(); - watcher.setObject(0, (byte) 1, true); - ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(watcher)); + ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(0, (byte) 1)); } public void setBowDrawn(boolean drawn, boolean offHand) { - /*DataWatcher dataWatcher = new DataWatcher(null); - DataWatcherObject dataWatcherObject = new DataWatcherObject<>(7, DataWatcherRegistry.a); - dataWatcher.register(dataWatcherObject, (byte) ((drawn ? 1 : 0) + (offHand ? 2 : 0))); - dataWatcher.markDirty(dataWatcherObject); - */ - - WrappedDataWatcher watcher = new WrappedDataWatcher(); if(Core.getVersion() > 8){ - watcher.setObject(Core.getVersion() > 12 ? 7 : 6, (byte) ((drawn ? 1 : 0) + (offHand ? 2 : 0)), true); + ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(Core.getVersion() > 12 ? 7 : 6, (byte) ((drawn ? 1 : 0) + (offHand ? 2 : 0)))); }else{ - watcher.setObject(0, (byte)0x10, true); + ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(0, (byte)0x10)); } - ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(watcher)); } public void setItem(String item, boolean enchanted, String slot) { ItemStack stack = new ItemStack(Material.valueOf(item.replace("minecraft:", "").toUpperCase()), 1); if(enchanted) - stack.addEnchantment(Enchantment.DURABILITY, 1); + stack.addUnsafeEnchantment(Enchantment.DURABILITY, 1); itemSlots.put(slot, stack); ProtocolLibrary.getProtocolManager().broadcastServerPacket(getEquipmentPacket(slot, stack)); @@ -310,10 +268,12 @@ public class REntity { bytes.write(1, pitch); } - private PacketContainer getDataWatcherPacket(WrappedDataWatcher dataWatcher) { + private PacketContainer getDataWatcherPacket(int index, Object value) { PacketContainer metadataPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_METADATA); metadataPacket.getIntegers().write(0, entityId); - metadataPacket.getDataWatcherModifier().write(0, dataWatcher); + WrappedWatchableObject watchable = new WrappedWatchableObject(new WrappedDataWatcher.WrappedDataWatcherObject(index, WrappedDataWatcher.Registry.get(value.getClass())), value); + watchable.setDirtyState(true); + metadataPacket.getWatchableCollectionModifier().write(0, Collections.singletonList(watchable)); return metadataPacket; } @@ -327,7 +287,7 @@ public class REntity { private PacketContainer getHeadRotationPacket(){ PacketContainer headRotation = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_HEAD_ROTATION); headRotation.getIntegers().write(0, entityId); - headRotation.getBytes().write(1, headYaw); + headRotation.getBytes().write(0, headYaw); return headRotation; } @@ -366,7 +326,7 @@ public class REntity { PacketContainer equipmentPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_EQUIPMENT); StructureModifier ints = equipmentPacket.getIntegers(); ints.write(0, entityId); - if(Core.getVersion() > 8){ + if(Core.getVersion() == 8){ switch(slot){ case "MAINHAND": case "OFFHAND": diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java index 225a82e..577b870 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java @@ -122,7 +122,7 @@ public interface Recorder { default void entityMoves(Entity e){ Location location = e.getLocation(); - write(0x01, e.getEntityId(), location.getX(), location.getY(), location.getZ(), location.getPitch(), location.getYaw(), (int)(VersionedCallable.call( + write(0x01, e.getEntityId(), location.getX(), location.getY(), location.getZ(), location.getPitch(), location.getYaw(), (byte)(VersionedCallable.call( new VersionedCallable<>(() -> FightWorld_8.headRotation(e), 8), new VersionedCallable<>(() -> FightWorld_9.headRotation(e), 9), new VersionedCallable<>(() -> FightWorld_10.headRotation(e), 10), @@ -141,7 +141,7 @@ public interface Recorder { } default void entityAnimation(Entity e, int animation){ - write(0x04, e.getEntityId(), animation); + write(0x04, e.getEntityId(), (byte)animation); } default void tntSpawn(Entity e){ @@ -194,10 +194,10 @@ public interface Recorder { int shortZ = block.getZ() - Config.ArenaRegion.getMinZ(); if((short)blockState == blockState && shortX > 0 && shortX < 256 && shortZ > 0 && shortZ < 256){ //Short block packet - write(0x33, shortX, block.getY(), shortZ, (short)blockState); + write(0x33, (byte)shortX, (byte)block.getY(), (byte)shortZ, (short)blockState); }else{ //Block packet - write(0x30, block.getX(), block.getY(), block.getZ(), blockState); + write(0x30, block.getX(), (byte)block.getY(), block.getZ(), blockState); } } @@ -252,24 +252,28 @@ public interface Recorder { default void write(int id, Object... objects){ DataOutputStream stream = getStream(); try { - stream.writeByte(id); - for(Object o : objects){ - if(o instanceof Byte) - stream.writeByte((Byte)o); - else if(o instanceof Short) - stream.writeShort((Short)o); - else if(o instanceof Integer) - stream.writeInt((Integer)o); - else if(o instanceof Float) - stream.writeFloat((Float)o); - else if(o instanceof Double) - stream.writeDouble((Double)o); - else if(o instanceof String) - stream.writeUTF((String)o); - else - throw new SecurityException("Undefined write for: " + o.getClass().getName()); + synchronized (stream) { + stream.writeByte(id); + for(Object o : objects){ + if(o instanceof Boolean) + stream.writeBoolean((Boolean)o); + else if(o instanceof Byte) + stream.writeByte((Byte)o); + else if(o instanceof Short) + stream.writeShort((Short)o); + else if(o instanceof Integer) + stream.writeInt((Integer)o); + else if(o instanceof Float) + stream.writeFloat((Float)o); + else if(o instanceof Double) + stream.writeDouble((Double)o); + else if(o instanceof String) + stream.writeUTF((String)o); + else + throw new SecurityException("Undefined write for: " + o.getClass().getName()); + } + stream.flush(); } - stream.flush(); } catch (IOException e) { Bukkit.getLogger().log(Level.SEVERE, "Could not write", e); try {