From 6941cc98f0b046da76975230a9dd7dee1e4962a3 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 25 Sep 2022 19:01:53 +0200 Subject: [PATCH 01/14] Fix Replay entities Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/utils/ProtocolWrapper19.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/FightSystem_19/src/de/steamwar/fightsystem/utils/ProtocolWrapper19.java b/FightSystem_19/src/de/steamwar/fightsystem/utils/ProtocolWrapper19.java index 64a8692..2a99a89 100644 --- a/FightSystem_19/src/de/steamwar/fightsystem/utils/ProtocolWrapper19.java +++ b/FightSystem_19/src/de/steamwar/fightsystem/utils/ProtocolWrapper19.java @@ -43,13 +43,13 @@ public class ProtocolWrapper19 implements ProtocolWrapper { public void setSpawnPacketType(Object packet, EntityType type) { switch(type) { case PRIMED_TNT: - spawnType.set(packet, EntityTypes.as); + spawnType.set(packet, EntityTypes.av); break; case ARROW: - spawnType.set(packet, EntityTypes.d); + spawnType.set(packet, EntityTypes.e); break; case FIREBALL: - spawnType.set(packet, EntityTypes.S); + spawnType.set(packet, EntityTypes.V); break; } } From 4531816792f6386d792d36326899c428874552a4 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 7 Oct 2022 16:58:01 +0200 Subject: [PATCH 02/14] Fix SGEU replay Signed-off-by: Lixfel --- .../fightsystem/utils/BlockIdWrapper8.java | 3 +++ .../fightsystem/record/PacketProcessor.java | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java index bb8bae2..06956c8 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java @@ -32,6 +32,9 @@ public class BlockIdWrapper8 implements BlockIdWrapper { @Override @SuppressWarnings("deprecation") public void setBlock(World world, int x, int y, int z, int blockState) { + if((blockState >> 4) > 256) // Illegal blockstate / corrupted replay + blockState = 0; + world.getBlockAt(x, y, z).setTypeIdAndData(blockState >> 4, (byte)(blockState & 0b1111), false); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index 734883e..6883199 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -45,6 +45,7 @@ import org.bukkit.entity.EntityType; import org.bukkit.scheduler.BukkitTask; import java.io.EOFException; +import java.io.FilterInputStream; import java.io.IOException; import java.util.*; import java.util.logging.Level; @@ -217,7 +218,11 @@ public class PacketProcessor { float yaw = source.readFloat() + (rotateZ ? 180 : 0); byte headYaw = (byte)((source.readByte() + (rotateZ ? 128 : 0)) % 256); - execSync(() -> REntity.getEntity(entityId).move(locX, locY, locZ, pitch, yaw, headYaw)); + execSync(() -> { + REntity entity = REntity.getEntity(entityId); + if(entity != null) + entity.move(locX, locY, locZ, pitch, yaw, headYaw); + }); } private void entityDespawns() throws IOException { @@ -410,7 +415,12 @@ public class PacketProcessor { private void pasteEmbeddedSchem(FightTeam team) throws IOException { int schemId = source.readInt(); - Clipboard clipboard = SchematicNode.clipboardFromStream(source, Core.getVersion() > 12); + Clipboard clipboard = SchematicNode.clipboardFromStream(new FilterInputStream(source) { + @Override + public void close() { + // FAWE 1.12 calls close... + } + }, Core.getVersion() > 12); execSync(() -> team.pasteSchem(schemId, clipboard)); } From 9d4df5b7152e10e103c95501697caa559411f63b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 7 Oct 2022 17:23:00 +0200 Subject: [PATCH 03/14] Support new world height in replays Signed-off-by: Lixfel --- .../fightsystem/record/PacketProcessor.java | 19 +++++++++++++++++-- .../steamwar/fightsystem/record/Recorder.java | 5 +++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index 6883199..a20608e 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -100,12 +100,13 @@ public class PacketProcessor { packetDecoder[0x0b] = this::damage; packetDecoder[0x0c] = this::fireTick; packetDecoder[0x20] = this::arenaInfo; - packetDecoder[0x30] = this::block; + packetDecoder[0x30] = this::byteWorldHeightBlock; packetDecoder[0x31] = this::particle; packetDecoder[0x32] = this::sound; packetDecoder[0x33] = this::shortBlock; packetDecoder[0x34] = this::soundAtPlayer; packetDecoder[0x35] = this::shortRelativeBlock; + packetDecoder[0x36] = this::block; packetDecoder[0xa0] = () -> send(ChatMessageType.CHAT); packetDecoder[0xa1] = () -> send(ChatMessageType.ACTION_BAR); packetDecoder[0xa2] = () -> send(ChatMessageType.SYSTEM); @@ -335,7 +336,7 @@ public class PacketProcessor { setBlock(x + Config.ArenaRegion.getMinX(), y + Config.BluePasteRegion.getMinY(), z + Config.ArenaRegion.getMinZ(), blockState); } - private void block() throws IOException { + private void byteWorldHeightBlock() throws IOException { int x = source.readInt() - arenaMinX; int y = Byte.toUnsignedInt(source.readByte()) - arenaMinY; int z = source.readInt() - arenaMinZ; @@ -349,6 +350,20 @@ public class PacketProcessor { setBlock(x + Config.ArenaRegion.getMinX(), y + Config.BluePasteRegion.getMinY(), z + Config.ArenaRegion.getMinZ(), blockState); } + private void block() throws IOException { + int x = source.readInt() - arenaMinX; + int y = source.readShort() - arenaMinY; + int z = source.readInt() - arenaMinZ; + int blockState = source.readInt(); + + if(rotateZ) { + x = Config.ArenaRegion.getSizeX() - x; + z = Config.ArenaRegion.getSizeZ() - z; + } + + setBlock(x + Config.ArenaRegion.getMinX(), y + Config.BluePasteRegion.getMinY(), z + Config.ArenaRegion.getMinZ(), blockState); + } + private void setBlock(int x, int y, int z, int blockState){ if(!Config.ArenaRegion.in2dRegion(x, z)) return; //Outside of the arena diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java index eb31336..7d571ae 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java @@ -99,12 +99,13 @@ public interface Recorder { * * ArenaInfo (0x20) + bool blueNegZ + byte arenaY + int arenaMinX + int arenaMinZ * - * BlockPacket (0x30) + pos int, byte, int + int BlockState + * DEPRECATED BlockPacket (0x30) + pos int, byte, int + int BlockState * ParticlePacket (0x31) + double x, y, z + string particleType * SoundPacket (0x32) + int x, y, z + string soundType + string soundCategory + float volume, pitch * DEPRECATED ShortBlockPacket (0x33) + pos relative to ArenaMinX,ArenaMinZ byte, byte, byte + short BlockState * SoundAtPlayerPacket (0x34) + string (soundType, soundCategory) + float volume, pitch * ShortBlockPacket (0x35) + pos relative to ArenaMinX,BluePasteY,ArenaMinZ byte, byte, byte + short BlockState + * BlockPacket (0x36) + pos int, short, int + int BlockState * * * DEPRECATED ChatPacket (0xa0) + String message @@ -226,7 +227,7 @@ public interface Recorder { write(0x35, (byte)shortX, (byte)shortY, (byte)shortZ, (short)blockState); }else{ //Block packet - write(0x30, block.getX(), (byte)block.getY(), block.getZ(), blockState); + write(0x36, block.getX(), (short)block.getY(), block.getZ(), blockState); } } From 83eb9bfa13cc1afbdbda2754de7d0cb69705efb8 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 7 Oct 2022 17:30:49 +0200 Subject: [PATCH 04/14] Fix ClickAnalyzer Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/FightSystem.java | 2 ++ .../fightsystem/listener/ClickAnalyzer.java | 13 +++++++++++-- .../de/steamwar/fightsystem/listener/Recording.java | 2 -- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index fb9ee97..1a94778 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -90,6 +90,7 @@ public class FightSystem extends JavaPlugin { new ArrowPickup(); new BlockFadeListener(); new LeaveableArena(); + new ClickAnalyzer(); new HotbarKit.HotbarKitListener(); new OneShotStateDependent(ArenaMode.All, FightState.PreSchemSetup, () -> Fight.playSound(SWSound.BLOCK_NOTE_PLING.getSound(), 100.0f, 2.0f)); @@ -161,6 +162,7 @@ public class FightSystem extends JavaPlugin { @Override public void onDisable() { GlobalRecorder.getInstance().close(); + ClickAnalyzer.close(); } public static void setSpectateState(FightTeam winFightTeam, String winreason, String subtitle, Object... params) { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java index dbc5b07..bf0ea32 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java @@ -19,6 +19,7 @@ package de.steamwar.fightsystem.listener; +import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.utils.CraftbukkitWrapper; import org.bukkit.entity.Player; @@ -26,7 +27,6 @@ import org.bukkit.entity.Player; import java.io.*; public class ClickAnalyzer { - private ClickAnalyzer() {} private static final PrintStream output; @@ -38,7 +38,16 @@ public class ClickAnalyzer { } } - public static void onBlockPlace(Player player) { + public ClickAnalyzer() { + TinyProtocol.instance.addFilter(Recording.blockPlacePacket, this::onBlockPlace); + } + + public Object onBlockPlace(Player player, Object packet) { output.println(player.getName() + "," + System.nanoTime() + "," + CraftbukkitWrapper.impl.headRotation(player) + "," + player.getLocation().getPitch()); + return packet; + } + + public static void close() { + output.close(); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java index 202b4fd..ca3c654 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java @@ -133,8 +133,6 @@ public class Recording implements Listener { public static final Class blockPlacePacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInBlockPlace"); private Object blockPlace(Player p, Object packet) { - ClickAnalyzer.onBlockPlace(p); - boolean mainHand = BountifulWrapper.impl.mainHand(packet); if(!isNotSent(p) && BountifulWrapper.impl.bowInHand(mainHand, p)) GlobalRecorder.getInstance().bowSpan(p, true, !mainHand); From c4116cba97f4c691fec38d975301e81dc28b4b5c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 8 Oct 2022 16:47:32 +0200 Subject: [PATCH 05/14] Update InFightDamage Add WinconditionAmongUs --- .../fightsystem/listener/InFightDamage.java | 4 ++- .../winconditions/WinconditionAmongUs.java | 33 +++++++++++++++++++ .../winconditions/Winconditions.java | 3 +- 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/InFightDamage.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/InFightDamage.java index 09ec33a..9be2167 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/InFightDamage.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/InFightDamage.java @@ -20,10 +20,12 @@ package de.steamwar.fightsystem.listener; import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; +import de.steamwar.fightsystem.winconditions.Winconditions; import net.md_5.bungee.api.ChatMessageType; import org.bukkit.entity.Arrow; import org.bukkit.entity.Player; @@ -36,7 +38,7 @@ import java.util.Objects; public class InFightDamage implements Listener { public InFightDamage() { - new StateDependentListener(ArenaMode.AntiReplay, FightState.Running, this); + new StateDependentListener(!Config.ActiveWinconditions.contains(Winconditions.AMONG_US), FightState.Running, this); } @EventHandler diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java new file mode 100644 index 0000000..927ed90 --- /dev/null +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java @@ -0,0 +1,33 @@ +/* + * 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 . + */ + +package de.steamwar.fightsystem.winconditions; + +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.OneShotStateDependent; + +public class WinconditionAmongUs extends Wincondition { + + public WinconditionAmongUs() { + super("AmongUs"); + new OneShotStateDependent(Winconditions.AMONG_US, FightState.Ingame, () -> { + // TODO: Select 1 imposter from each team + }); + } +} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java index 9d7ae2a..620a247 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java @@ -38,5 +38,6 @@ public enum Winconditions { PUMPKIN_TECH_KO, HELLS_BELLS, - METEOR + METEOR, + AMONG_US } From b750433f91c7c5c6035b572fbc3344c1d7c140d2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 8 Oct 2022 16:56:02 +0200 Subject: [PATCH 06/14] Add initial message --- .../de/steamwar/fightsystem/FightSystem.java | 1 + .../fightsystem/FightSystem.properties | 3 +++ .../fightsystem/FightSystem_de.properties | 3 +++ .../winconditions/WinconditionAmongUs.java | 21 ++++++++++++++++++- 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 1a94778..8d51340 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -118,6 +118,7 @@ public class FightSystem extends JavaPlugin { new HellsBells(); new Meteor(); + new WinconditionAmongUs(); new NoPlayersOnlineCountdown(); new PreSchemCountdown(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties index 126d650..82662c0 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties @@ -238,3 +238,6 @@ WIN_LESS_DAMAGE={0} §7less damaged WIN_POINTS={0} has more points WIN_POINTS_EQUAL=§7Equal points WIN_TECHKO={0} §7is tech K.O. +# WIN_AMONG_US={0} §7is tech K.O. + +AMONG_US_IMPOSTER_MESSAGE = §4You are the Imposter§8! §7Kill all your teammates to win the game! diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties index 082f69f..b5994e0 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties @@ -223,3 +223,6 @@ WIN_LESS_DAMAGE={0} §7weniger beschädigt WIN_POINTS={0} hat mehr Punkte WIN_POINTS_EQUAL=§7Gleicher Punktestand WIN_TECHKO={0} §7ist Tech K.O. +# WIN_AMONG_US={0} §7is tech K.O. + +AMONG_US_IMPOSTER_MESSAGE = §4Du bist ein Imposter§8! §7Du musst alle Teammates töten, um zu gewinnen. \ No newline at end of file diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java index 927ed90..720fec9 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java @@ -19,15 +19,34 @@ package de.steamwar.fightsystem.winconditions; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.OneShotStateDependent; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Random; + public class WinconditionAmongUs extends Wincondition { + private final Random random = new Random(); + public WinconditionAmongUs() { super("AmongUs"); new OneShotStateDependent(Winconditions.AMONG_US, FightState.Ingame, () -> { - // TODO: Select 1 imposter from each team + FightPlayer redPlayer = getRandomPlayer(Fight.getRedTeam().getPlayers()); + FightPlayer bluePlayer = getRandomPlayer(Fight.getBlueTeam().getPlayers()); + + FightSystem.getMessage().send("AMONG_US_IMPOSTER_MESSAGE", redPlayer.getPlayer()); + FightSystem.getMessage().send("AMONG_US_IMPOSTER_MESSAGE", bluePlayer.getPlayer()); }); } + + private FightPlayer getRandomPlayer(Collection fightPlayers) { + List fightPlayerList = new ArrayList<>(fightPlayers); + return fightPlayerList.get(random.nextInt(fightPlayerList.size())); + } } From b24e9a8b89839c5d5c56ebe689cfb39bb3a7b934 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 8 Oct 2022 17:00:44 +0200 Subject: [PATCH 07/14] Add message --- .../winconditions/WinconditionAmongUs.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java index 720fec9..3b1ece5 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java @@ -22,15 +22,22 @@ package de.steamwar.fightsystem.winconditions; 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.states.FightState; import de.steamwar.fightsystem.states.OneShotStateDependent; +import de.steamwar.fightsystem.states.StateDependentListener; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerQuitEvent; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Random; -public class WinconditionAmongUs extends Wincondition { +public class WinconditionAmongUs extends Wincondition implements Listener { private final Random random = new Random(); @@ -43,10 +50,35 @@ public class WinconditionAmongUs extends Wincondition { FightSystem.getMessage().send("AMONG_US_IMPOSTER_MESSAGE", redPlayer.getPlayer()); FightSystem.getMessage().send("AMONG_US_IMPOSTER_MESSAGE", bluePlayer.getPlayer()); }); + new StateDependentListener(Winconditions.AMONG_US, FightState.Ingame, this); } private FightPlayer getRandomPlayer(Collection fightPlayers) { List fightPlayerList = new ArrayList<>(fightPlayers); return fightPlayerList.get(random.nextInt(fightPlayerList.size())); } + + @EventHandler + public void handlePlayerDeath(PlayerDeathEvent event) { + handleDeath(event.getEntity().getPlayer()); + } + + @EventHandler + public void handlePlayerQuit(PlayerQuitEvent event) { + handleDeath(event.getPlayer()); + } + + private void handleDeath(Player player){ + // TODO: Adapt this + FightTeam team = isTarget(player); + if(team == null) + return; + + for(FightPlayer fp : team.getPlayers()) { + if(fp.isLiving() && fp.getPlayer() != player) + return; + } + + win(Fight.getOpposite(team), "WIN_ALL_DEAD", team.getPrefix()); + } } From f1e9dda0faad864368b9641dbc5a578eecc0f527 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 8 Oct 2022 17:07:05 +0200 Subject: [PATCH 08/14] Update handleDeath method --- .../winconditions/WinconditionAmongUs.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java index 3b1ece5..bbc9778 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java @@ -32,13 +32,12 @@ import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerQuitEvent; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Random; +import java.util.*; public class WinconditionAmongUs extends Wincondition implements Listener { + private Map imposter = new HashMap<>(); + private final Random random = new Random(); public WinconditionAmongUs() { @@ -47,6 +46,9 @@ public class WinconditionAmongUs extends Wincondition implements Listener { FightPlayer redPlayer = getRandomPlayer(Fight.getRedTeam().getPlayers()); FightPlayer bluePlayer = getRandomPlayer(Fight.getBlueTeam().getPlayers()); + imposter.put(Fight.getRedTeam(), redPlayer); + imposter.put(Fight.getBlueTeam(), bluePlayer); + FightSystem.getMessage().send("AMONG_US_IMPOSTER_MESSAGE", redPlayer.getPlayer()); FightSystem.getMessage().send("AMONG_US_IMPOSTER_MESSAGE", bluePlayer.getPlayer()); }); @@ -69,16 +71,15 @@ public class WinconditionAmongUs extends Wincondition implements Listener { } private void handleDeath(Player player){ - // TODO: Adapt this FightTeam team = isTarget(player); if(team == null) return; - for(FightPlayer fp : team.getPlayers()) { - if(fp.isLiving() && fp.getPlayer() != player) - return; + FightPlayer current = team.getFightPlayer(player); + if (current == imposter.get(team)) { + // TODO: Add message that the imposter is dead and the same team won! + } else if (team.getPlayers().contains(current) && team.getPlayers().contains(imposter.get(team))) { + // TODO: Add message that the all except the imposter are dead and the other team won! } - - win(Fight.getOpposite(team), "WIN_ALL_DEAD", team.getPrefix()); } } From 67a0d0f5e9be987f6586d2eb618b0a988178c8dc Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 8 Oct 2022 17:28:39 +0200 Subject: [PATCH 09/14] Add messages --- .../fightsystem/FightSystem.properties | 4 ++- .../fightsystem/FightSystem_de.properties | 6 +++-- .../winconditions/WinconditionAmongUs.java | 26 ++++++++++--------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties index 82662c0..0ba06f2 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties @@ -238,6 +238,8 @@ WIN_LESS_DAMAGE={0} §7less damaged WIN_POINTS={0} has more points WIN_POINTS_EQUAL=§7Equal points WIN_TECHKO={0} §7is tech K.O. -# WIN_AMONG_US={0} §7is tech K.O. +WIN_IMPOSTER_DEAD={0} §7killed the imposter +WIN_CREWMATE_DEAD={0} §7killed all creamates AMONG_US_IMPOSTER_MESSAGE = §4You are the Imposter§8! §7Kill all your teammates to win the game! +AMONG_US_IMPOSTER_AMONG_MESSAGE = §4There is an Imposter among us§8! §7Kill him to win the game! diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties index b5994e0..82036af 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties @@ -223,6 +223,8 @@ WIN_LESS_DAMAGE={0} §7weniger beschädigt WIN_POINTS={0} hat mehr Punkte WIN_POINTS_EQUAL=§7Gleicher Punktestand WIN_TECHKO={0} §7ist Tech K.O. -# WIN_AMONG_US={0} §7is tech K.O. +WIN_IMPOSTER_DEAD={0} §7 hat den Imposter getötet +WIN_CREWMATE_DEAD={0} §7 hat alle Crewmates getötet -AMONG_US_IMPOSTER_MESSAGE = §4Du bist ein Imposter§8! §7Du musst alle Teammates töten, um zu gewinnen. \ No newline at end of file +AMONG_US_IMPOSTER_MESSAGE = §4Du bist ein Imposter§8! §7Du musst alle Teammates töten, um zu gewinnen. +AMONG_US_IMPOSTER_AMONG_MESSAGE = §4Es ist ein Imposter unter uns§8! §7Tötet ihn, um das Spiel zu gewinnen! \ No newline at end of file diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java index bbc9778..7e040db 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java @@ -43,21 +43,23 @@ public class WinconditionAmongUs extends Wincondition implements Listener { public WinconditionAmongUs() { super("AmongUs"); new OneShotStateDependent(Winconditions.AMONG_US, FightState.Ingame, () -> { - FightPlayer redPlayer = getRandomPlayer(Fight.getRedTeam().getPlayers()); - FightPlayer bluePlayer = getRandomPlayer(Fight.getBlueTeam().getPlayers()); - - imposter.put(Fight.getRedTeam(), redPlayer); - imposter.put(Fight.getBlueTeam(), bluePlayer); - - FightSystem.getMessage().send("AMONG_US_IMPOSTER_MESSAGE", redPlayer.getPlayer()); - FightSystem.getMessage().send("AMONG_US_IMPOSTER_MESSAGE", bluePlayer.getPlayer()); + imposter.put(Fight.getRedTeam(), sendMessageAndReturnImposter(Fight.getRedTeam().getPlayers())); + imposter.put(Fight.getBlueTeam(), sendMessageAndReturnImposter(Fight.getBlueTeam().getPlayers())); }); new StateDependentListener(Winconditions.AMONG_US, FightState.Ingame, this); } - private FightPlayer getRandomPlayer(Collection fightPlayers) { + private FightPlayer sendMessageAndReturnImposter(Collection fightPlayers) { List fightPlayerList = new ArrayList<>(fightPlayers); - return fightPlayerList.get(random.nextInt(fightPlayerList.size())); + FightPlayer imposter = fightPlayerList.get(random.nextInt(fightPlayerList.size())); + for (FightPlayer fightPlayer : fightPlayerList) { + if (fightPlayer == imposter) { + FightSystem.getMessage().send("AMONG_US_IMPOSTER_MESSAGE", fightPlayer.getPlayer()); + } else { + FightSystem.getMessage().send("AMONG_US_IMPOSTER_AMONG_MESSAGE", fightPlayer.getPlayer()); + } + } + return imposter; } @EventHandler @@ -77,9 +79,9 @@ public class WinconditionAmongUs extends Wincondition implements Listener { FightPlayer current = team.getFightPlayer(player); if (current == imposter.get(team)) { - // TODO: Add message that the imposter is dead and the same team won! + win(team, "WIN_IMPOSTER_DEAD", team.getPrefix()); } else if (team.getPlayers().contains(current) && team.getPlayers().contains(imposter.get(team))) { - // TODO: Add message that the all except the imposter are dead and the other team won! + win(Fight.getOpposite(team), "WIN_CREWMATE_DEAD", Fight.getOpposite(team).getPrefix()); } } } From facee211dd665838d2c47765f3b4f2796fb5e722 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 8 Oct 2022 17:51:24 +0200 Subject: [PATCH 10/14] Update messages --- .../src/de/steamwar/fightsystem/FightSystem.properties | 4 ++-- .../src/de/steamwar/fightsystem/FightSystem_de.properties | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties index 0ba06f2..ef060ac 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties @@ -239,7 +239,7 @@ WIN_POINTS={0} has more points WIN_POINTS_EQUAL=§7Equal points WIN_TECHKO={0} §7is tech K.O. WIN_IMPOSTER_DEAD={0} §7killed the imposter -WIN_CREWMATE_DEAD={0} §7killed all creamates +WIN_CREWMATE_DEAD={0} §7killed all team mates -AMONG_US_IMPOSTER_MESSAGE = §4You are the Imposter§8! §7Kill all your teammates to win the game! +AMONG_US_IMPOSTER_MESSAGE = §4You are the Imposter§8! §7Kill all your team mates to win the game! AMONG_US_IMPOSTER_AMONG_MESSAGE = §4There is an Imposter among us§8! §7Kill him to win the game! diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties index 82036af..80bbee7 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties @@ -224,7 +224,7 @@ WIN_POINTS={0} hat mehr Punkte WIN_POINTS_EQUAL=§7Gleicher Punktestand WIN_TECHKO={0} §7ist Tech K.O. WIN_IMPOSTER_DEAD={0} §7 hat den Imposter getötet -WIN_CREWMATE_DEAD={0} §7 hat alle Crewmates getötet +WIN_CREWMATE_DEAD={0} §7 hat alle Kammeraden getötet -AMONG_US_IMPOSTER_MESSAGE = §4Du bist ein Imposter§8! §7Du musst alle Teammates töten, um zu gewinnen. +AMONG_US_IMPOSTER_MESSAGE = §4Du bist ein Imposter§8! §7Du musst alle Kammeraden töten, um zu gewinnen. AMONG_US_IMPOSTER_AMONG_MESSAGE = §4Es ist ein Imposter unter uns§8! §7Tötet ihn, um das Spiel zu gewinnen! \ No newline at end of file From d0a5e0c96fd9e346f65ea317b09b6ea8b2d735a6 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 8 Oct 2022 17:52:40 +0200 Subject: [PATCH 11/14] Update messages --- .../src/de/steamwar/fightsystem/FightSystem_de.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties index 80bbee7..2809513 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties @@ -224,7 +224,7 @@ WIN_POINTS={0} hat mehr Punkte WIN_POINTS_EQUAL=§7Gleicher Punktestand WIN_TECHKO={0} §7ist Tech K.O. WIN_IMPOSTER_DEAD={0} §7 hat den Imposter getötet -WIN_CREWMATE_DEAD={0} §7 hat alle Kammeraden getötet +WIN_CREWMATE_DEAD={0} §7 hat alle Kameraden getötet -AMONG_US_IMPOSTER_MESSAGE = §4Du bist ein Imposter§8! §7Du musst alle Kammeraden töten, um zu gewinnen. +AMONG_US_IMPOSTER_MESSAGE = §4Du bist ein Imposter§8! §7Du musst alle Kameraden töten, um zu gewinnen. AMONG_US_IMPOSTER_AMONG_MESSAGE = §4Es ist ein Imposter unter uns§8! §7Tötet ihn, um das Spiel zu gewinnen! \ No newline at end of file From 80a98a998a7ac82799ff2bb1919bd8e079fae3f0 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 8 Oct 2022 17:56:22 +0200 Subject: [PATCH 12/14] Update --- .../steamwar/fightsystem/winconditions/WinconditionAmongUs.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java index 7e040db..39ee800 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java @@ -80,7 +80,7 @@ public class WinconditionAmongUs extends Wincondition implements Listener { FightPlayer current = team.getFightPlayer(player); if (current == imposter.get(team)) { win(team, "WIN_IMPOSTER_DEAD", team.getPrefix()); - } else if (team.getPlayers().contains(current) && team.getPlayers().contains(imposter.get(team))) { + } else if (team.getAlivePlayers() <= 2 && team.getPlayers().contains(imposter.get(team))) { win(Fight.getOpposite(team), "WIN_CREWMATE_DEAD", Fight.getOpposite(team).getPrefix()); } } From 9b4eaa7a57c84bf22f07fdbbbf00fd723a3fcb1b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 8 Oct 2022 18:00:31 +0200 Subject: [PATCH 13/14] Fix WinconditionAmongUs --- .../steamwar/fightsystem/winconditions/WinconditionAmongUs.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java index 39ee800..0be9472 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java @@ -80,7 +80,7 @@ public class WinconditionAmongUs extends Wincondition implements Listener { FightPlayer current = team.getFightPlayer(player); if (current == imposter.get(team)) { win(team, "WIN_IMPOSTER_DEAD", team.getPrefix()); - } else if (team.getAlivePlayers() <= 2 && team.getPlayers().contains(imposter.get(team))) { + } else if (team.getAlivePlayers() <= 2 && imposter.get(team).isLiving()) { win(Fight.getOpposite(team), "WIN_CREWMATE_DEAD", Fight.getOpposite(team).getPrefix()); } } From 5b05fb1914ea515ec96bd88ee718e8888f7cbe79 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 8 Oct 2022 18:46:28 +0200 Subject: [PATCH 14/14] Hotfix FightTeam --- .../src/de/steamwar/fightsystem/fight/FightTeam.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 53486b5..47ba81f 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -32,6 +32,7 @@ import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.OneShotStateDependent; import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.utils.*; +import de.steamwar.fightsystem.winconditions.Winconditions; import de.steamwar.inventory.SWItem; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; @@ -128,7 +129,9 @@ public class FightTeam { WorldOfColorWrapper.impl.setTeamColor(team, color); BountifulWrapper.impl.setNametagVisibility(team); team.setNameTagVisibility(NameTagVisibility.HIDE_FOR_OTHER_TEAMS); - team.setAllowFriendlyFire(false); + if (!Config.ActiveWinconditions.contains(Winconditions.AMONG_US)) { + team.setAllowFriendlyFire(false); + } new OneShotStateDependent(ArenaMode.Restartable, FightState.PreLeaderSetup, () -> Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::reset)); new OneShotStateDependent(Config.replayserver(), FightState.PreLeaderSetup, () -> Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::reset));