From 868ba4073b10f0cc44047602480b6c8fdeb56c67 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 13 Jul 2025 16:46:11 +0200 Subject: [PATCH 1/7] Add Winconditions.TIMED_DAMAGE_TECH_KO and Winconditions.RANDOM_ROTATE --- .../src/de/steamwar/fightsystem/Config.java | 2 + .../fightsystem/FightSystem.properties | 1 + .../de/steamwar/fightsystem/fight/Fight.java | 9 +- .../fightsystem/fight/FightSchematic.java | 6 + .../fightsystem/record/PacketProcessor.java | 10 +- .../steamwar/fightsystem/record/Recorder.java | 7 ++ .../fightsystem/utils/RandomSeed.java | 45 +++++++ .../winconditions/WinconditionTimeTechKO.java | 11 +- .../WinconditionTimedDamageTechKO.java | 115 ++++++++++++++++++ .../winconditions/Winconditions.java | 4 +- 10 files changed, 196 insertions(+), 14 deletions(-) create mode 100644 FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java create mode 100644 FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimedDamageTechKO.java diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java index 3ecfa070..d7ce5f9e 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/Config.java @@ -108,6 +108,7 @@ public class Config { public static final boolean PercentEntern; public static final boolean PercentBlocksWhitelist; public static final Set PercentBlocks; + public static final int TechKoTime; //default kits public static final String MemberDefault; @@ -209,6 +210,7 @@ public class Config { PercentEntern = config.getBoolean("WinConditionParams.PercentEntern", true); PercentBlocksWhitelist = config.getBoolean("WinConditionParams.BlocksWhitelist", false); PercentBlocks = Collections.unmodifiableSet(config.getStringList("WinConditionParams.Blocks").stream().map(Material::valueOf).collect(Collectors.toSet())); + TechKoTime = config.getInt("WinConditionParams.TechKoTime", 90); EnterStages = Collections.unmodifiableList(config.getIntegerList("EnterStages")); AllowMissiles = config.getBoolean("Arena.AllowMissiles", !EnterStages.isEmpty()); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties index 455e0444..22babff0 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties @@ -191,6 +191,7 @@ BAR_POINTS_OF={0}§8/§7{1} §8Points BAR_PERCENT={0}§8% BAR_CANNONS={0} §8Cannons BAR_WATER={0} §8Water +BAR_SECONDS={0}§8s # Winconditions diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java index 1f205122..afd357e8 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java @@ -19,20 +19,15 @@ package de.steamwar.fightsystem.fight; -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.RandomSeed; import lombok.Getter; import org.bukkit.Bukkit; -import org.bukkit.GameMode; import org.bukkit.Sound; import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; import java.util.Collection; import java.util.HashSet; @@ -40,6 +35,8 @@ import java.util.HashSet; public class Fight { private Fight(){} + @Getter + private static final RandomSeed randomSeed = new RandomSeed(); @Getter private static final FightTeam redTeam = new FightTeam(Config.TeamRedName, Config.TeamRedColor, Config.TeamRedSpawn, Config.RedPasteRegion, Config.RedExtendRegion, Config.RedRotate, false, Config.RedLeader); @Getter diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index d566c022..0fe45c73 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -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.fightsystem.winconditions.Winconditions; import de.steamwar.sql.SchematicData; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicType; @@ -141,6 +142,11 @@ public class FightSchematic extends StateDependent { team.teleportToSpawn(); + boolean rotate = this.rotate; + if (Config.ActiveWinconditions.contains(Winconditions.RANDOM_ROTATE)) { + rotate = Fight.getRandomSeed().getRandom(schematic).nextBoolean(); + } + Vector dims = WorldeditWrapper.impl.getDimensions(clipboard); WorldeditWrapper.impl.pasteClipboard( clipboard, diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index 47efc09d..84906a7b 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -20,7 +20,6 @@ package de.steamwar.fightsystem.record; import com.sk89q.worldedit.extent.clipboard.Clipboard; -import de.steamwar.core.Core; import de.steamwar.core.TrickyTrialsWrapper; import de.steamwar.core.WorldEditWrapper; import de.steamwar.entity.REntity; @@ -153,6 +152,7 @@ public class PacketProcessor implements Listener { packetDecoder[0xc6] = this::winMessage; packetDecoder[0xc7] = this::bossBarMessage; packetDecoder[0xef] = source::readUTF; + packetDecoder[0xfd] = this::randomSeed; packetDecoder[0xff] = this::tick; execSync(FightWorld::forceLoad); @@ -638,6 +638,14 @@ public class PacketProcessor implements Listener { execSync(() -> entities.get(entityId).setOnFire(perma)); } + private void randomSeed() throws IOException { + long seed = source.readLong(); + + execSync(() -> { + Fight.getRandomSeed().setSeed(seed); + }); + } + private void tick(){ execSync(entityServer::tick); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java index 73821e6f..c6b899ef 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java @@ -133,6 +133,7 @@ public interface Recorder { * WinPacket (0xc6) + byte team + Message subtitle * BossBarPacket (0xc7) + double leftBlueProgress, leftRedProgress + Message leftBlueText, leftRedText * + * RandomSeed (0xfd) + long seed * CommentPacket (0xfe) + String comment * TickPacket (0xff) * @@ -310,6 +311,10 @@ public interface Recorder { write(0xc6, bTeam, new Message(subtitle, params)); } + default void seed(long seed) { + write(0xfd, seed); + } + default void tick(){ write(0xff); } @@ -339,6 +344,8 @@ public interface Recorder { stream.writeShort((Short)o); else if(o instanceof Integer) stream.writeInt((Integer)o); + else if(o instanceof Long) + stream.writeLong((Long)o); else if(o instanceof Float) stream.writeFloat((Float)o); else if(o instanceof Double) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java new file mode 100644 index 00000000..94db59dd --- /dev/null +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java @@ -0,0 +1,45 @@ +/* + * 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.utils; + +import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.record.GlobalRecorder; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.OneShotStateDependent; +import lombok.Setter; + +import java.util.Random; + +public class RandomSeed { + + @Setter + private long seed; + + public RandomSeed() { + new OneShotStateDependent(ArenaMode.AntiReplay, FightState.PreSchemSetup, () -> { + this.seed = System.nanoTime(); + GlobalRecorder.getInstance().seed(seed); + }); + } + + public Random getRandom(int derivation) { + return new Random(seed ^ new Random(derivation).nextLong()); + } +} diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java index f1177afa..df6e92ae 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java @@ -20,6 +20,7 @@ package de.steamwar.fightsystem.winconditions; import de.steamwar.core.TrickyTrialsWrapper; +import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.countdown.Countdown; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; @@ -30,7 +31,6 @@ import de.steamwar.fightsystem.states.StateDependentTask; import de.steamwar.fightsystem.utils.Message; import de.steamwar.fightsystem.utils.SWSound; import org.bukkit.Location; -import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityExplodeEvent; @@ -41,8 +41,7 @@ import java.util.Map; public class WinconditionTimeTechKO extends Wincondition implements Listener { - private static final int TECH_KO_TIME_IN_S = 90; - private static final int TECH_KO_HALF_TIME = TECH_KO_TIME_IN_S/2; + private static final int TECH_KO_HALF_TIME = Config.TechKoTime/2; private final Map spawnLocations = new HashMap<>(); private final Map countdowns = new HashMap<>(); @@ -51,9 +50,9 @@ public class WinconditionTimeTechKO extends Wincondition implements Listener { public WinconditionTimeTechKO(){ super("TechKO"); - new StateDependentListener(Winconditions.TIME_TECH_KO, FightState.Running, this); - new StateDependentTask(Winconditions.TIME_TECH_KO, FightState.Running, this::run, 20, 20); - new StateDependent(Winconditions.TIME_TECH_KO, FightState.Running) { + new StateDependentListener(Winconditions.TIMED_DAMAGE_TECH_KO, FightState.Running, this); + new StateDependentTask(Winconditions.TIMED_DAMAGE_TECH_KO, FightState.Running, this::run, 20, 20); + new StateDependent(Winconditions.TIMED_DAMAGE_TECH_KO, FightState.Running) { @Override public void enable() { Fight.teams().forEach(team -> currentTime.put(team, TECH_KO_HALF_TIME)); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimedDamageTechKO.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimedDamageTechKO.java new file mode 100644 index 00000000..c561400c --- /dev/null +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimedDamageTechKO.java @@ -0,0 +1,115 @@ +/* + * 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.core.TrickyTrialsWrapper; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.countdown.Countdown; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependent; +import de.steamwar.fightsystem.states.StateDependentListener; +import de.steamwar.fightsystem.utils.Message; +import de.steamwar.fightsystem.utils.SWSound; +import org.bukkit.Location; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityExplodeEvent; + +import java.util.HashMap; +import java.util.Map; + +public class WinconditionTimedDamageTechKO extends Wincondition implements PrintableWincondition, Listener { + + private final Map countdowns = new HashMap<>(); + + public WinconditionTimedDamageTechKO() { + super("TechKO"); + + new StateDependentListener(Winconditions.TIMED_DAMAGE_TECH_KO, FightState.Running, this); + new StateDependent(Winconditions.TIMED_DAMAGE_TECH_KO, FightState.Running) { + @Override + public void enable() { + Fight.teams().forEach(team -> { + TechKOCountdown countdown = new TechKOCountdown(team, Config.TechKoTime); + countdowns.put(team, countdown); + countdown.enable(); + }); + } + + @Override + public void disable() { + countdowns.values().forEach(Countdown::disable); + countdowns.clear(); + } + }.register(); + } + + @Override + public Message getDisplay(FightTeam team) { + return new Message("BAR_SECONDS", team.getPrefix() + countdowns.get(team).getTimeLeft()); + } + + @EventHandler + public void onExplode(EntityExplodeEvent e) { + if (e.getEntityType() != TrickyTrialsWrapper.impl.getTntEntityType()) + return; + + Location location = e.getLocation(); + TechKOCountdown countdown = null; + FightTeam fightTeam = null; + for (FightTeam team : Fight.teams()) { + FightTeam current = Fight.getOpposite(team); + if (current.getExtendRegion().inRegion(location)) { + fightTeam = current; + countdown = countdowns.get(team); + break; + } + } + if (fightTeam == null) { + return; + } + + FightTeam finalFightTeam = fightTeam; + TechKOCountdown finalCountdown = countdown; + e.blockList().forEach(block -> { + if (block.isEmpty()) return; + if (finalFightTeam.getExtendRegion().inRegion(block)) { + finalCountdown.disable(); + finalCountdown.enable(); + } + }); + } + + private class TechKOCountdown extends Countdown { + private final FightTeam team; + + public TechKOCountdown(FightTeam team, int countdownTime) { + super(countdownTime, new Message("TECHKO_COUNTDOWN", team.getColoredName()), SWSound.BLOCK_NOTE_PLING, false); + this.team = team; + } + + @Override + public void countdownFinished() { + win(Fight.getOpposite(team), "WIN_TECHKO", team.getColoredName()); + } + } +} diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java index 2aaecae6..81b75173 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java @@ -31,7 +31,8 @@ public enum Winconditions { POINTS, POINTS_AIRSHIP, - TIME_TECH_KO, + DAMAGE_TECH_KO, + TIMED_DAMAGE_TECH_KO, WATER_TECH_KO, PUMPKIN_TECH_KO, @@ -41,4 +42,5 @@ public enum Winconditions { PERSISTENT_DAMAGE, TNT_DISTRIBUTION, NO_GRAVITY, + RANDOM_ROTATE, } From 1e264a63a2d8bf3737081b8fff9c45fc72c127f5 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 13 Jul 2025 16:48:35 +0200 Subject: [PATCH 2/7] Add Winconditions.TIMED_DAMAGE_TECH_KO and Winconditions.RANDOM_ROTATE --- .../fightsystem/winconditions/WinconditionTimeTechKO.java | 6 +++--- .../steamwar/fightsystem/winconditions/Winconditions.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java index df6e92ae..789b130f 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java @@ -50,9 +50,9 @@ public class WinconditionTimeTechKO extends Wincondition implements Listener { public WinconditionTimeTechKO(){ super("TechKO"); - new StateDependentListener(Winconditions.TIMED_DAMAGE_TECH_KO, FightState.Running, this); - new StateDependentTask(Winconditions.TIMED_DAMAGE_TECH_KO, FightState.Running, this::run, 20, 20); - new StateDependent(Winconditions.TIMED_DAMAGE_TECH_KO, FightState.Running) { + new StateDependentListener(Winconditions.TIME_TECH_KO, FightState.Running, this); + new StateDependentTask(Winconditions.TIME_TECH_KO, FightState.Running, this::run, 20, 20); + new StateDependent(Winconditions.TIME_TECH_KO, FightState.Running) { @Override public void enable() { Fight.teams().forEach(team -> currentTime.put(team, TECH_KO_HALF_TIME)); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java index 81b75173..4ba66cf3 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java @@ -31,8 +31,8 @@ public enum Winconditions { POINTS, POINTS_AIRSHIP, - DAMAGE_TECH_KO, TIMED_DAMAGE_TECH_KO, + TIME_TECH_KO, WATER_TECH_KO, PUMPKIN_TECH_KO, From e9d107f0ed5331fbb77cb04ba15f73ac31ef703b Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 13 Jul 2025 17:54:06 +0200 Subject: [PATCH 3/7] Fix older replays --- .../de/steamwar/fightsystem/fight/FightSchematic.java | 2 +- .../src/de/steamwar/fightsystem/utils/RandomSeed.java | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index 0fe45c73..7c7b6e81 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -143,7 +143,7 @@ public class FightSchematic extends StateDependent { team.teleportToSpawn(); boolean rotate = this.rotate; - if (Config.ActiveWinconditions.contains(Winconditions.RANDOM_ROTATE)) { + if (Fight.getRandomSeed().isInitialized() && Config.ActiveWinconditions.contains(Winconditions.RANDOM_ROTATE)) { rotate = Fight.getRandomSeed().getRandom(schematic).nextBoolean(); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java index 94db59dd..49ac1cd4 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java @@ -23,13 +23,14 @@ import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.record.GlobalRecorder; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.OneShotStateDependent; -import lombok.Setter; +import lombok.Getter; import java.util.Random; public class RandomSeed { - @Setter + @Getter + private boolean initialized = false; private long seed; public RandomSeed() { @@ -39,6 +40,11 @@ public class RandomSeed { }); } + public void setSeed(long seed) { + initialized = true; + this.seed = seed; + } + public Random getRandom(int derivation) { return new Random(seed ^ new Random(derivation).nextLong()); } From b9b541957b3609fd3258267936bc98fea405ca11 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 13 Jul 2025 17:54:28 +0200 Subject: [PATCH 4/7] Fix older replays --- .../src/de/steamwar/fightsystem/utils/RandomSeed.java | 1 + 1 file changed, 1 insertion(+) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java index 49ac1cd4..397afcc8 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java @@ -35,6 +35,7 @@ public class RandomSeed { public RandomSeed() { new OneShotStateDependent(ArenaMode.AntiReplay, FightState.PreSchemSetup, () -> { + initialized = true; this.seed = System.nanoTime(); GlobalRecorder.getInstance().seed(seed); }); From 167b36b10cbb60674d045e22882d2cd29e232587 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 13 Jul 2025 18:10:53 +0200 Subject: [PATCH 5/7] Update RandomRotate --- .../fightsystem/fight/FightSchematic.java | 19 +++---- .../steamwar/fightsystem/fight/FightTeam.java | 8 +++ .../fightsystem/record/PacketProcessor.java | 10 ++++ .../steamwar/fightsystem/record/Recorder.java | 21 ++++---- .../fightsystem/utils/RandomSeed.java | 52 ------------------- 5 files changed, 40 insertions(+), 70 deletions(-) delete mode 100644 FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index 7c7b6e81..aaffe4c4 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -36,6 +36,7 @@ import de.steamwar.sql.SchematicData; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicType; import lombok.Getter; +import lombok.Setter; import org.bukkit.Bukkit; import org.bukkit.DyeColor; import org.bukkit.Location; @@ -52,7 +53,10 @@ public class FightSchematic extends StateDependent { private final FightTeam team; private final Region region; - private final boolean rotate; + + @Getter + @Setter + private boolean rotate; @Getter private Clipboard clipboard = null; @@ -120,10 +124,13 @@ public class FightSchematic extends StateDependent { } if(ArenaMode.AntiReplay.contains(Config.mode)) { + if (Config.ActiveWinconditions.contains(Winconditions.RANDOM_ROTATE)) { + rotate = new Random().nextBoolean(); + } if(team.isBlue()) - GlobalRecorder.getInstance().blueSchem(schematic); + GlobalRecorder.getInstance().blueSchem(schematic, rotate); else - GlobalRecorder.getInstance().redSchem(schematic); + GlobalRecorder.getInstance().redSchem(schematic, rotate); } Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::paste); @@ -141,12 +148,6 @@ public class FightSchematic extends StateDependent { FreezeWorld freezer = new FreezeWorld(); team.teleportToSpawn(); - - boolean rotate = this.rotate; - if (Fight.getRandomSeed().isInitialized() && Config.ActiveWinconditions.contains(Winconditions.RANDOM_ROTATE)) { - rotate = Fight.getRandomSeed().getRandom(schematic).nextBoolean(); - } - Vector dims = WorldeditWrapper.impl.getDimensions(clipboard); WorldeditWrapper.impl.pasteClipboard( clipboard, diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 0cb68f71..319f2dbb 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -458,6 +458,14 @@ public class FightTeam { return schematic.getId(); } + public boolean getSchematicRotate() { + return schematic.isRotate(); + } + + public void setSchematicRotate(boolean rotate) { + schematic.setRotate(rotate); + } + public Clipboard getClipboard() { return schematic.getClipboard(); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index 84906a7b..2cc84688 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -143,6 +143,8 @@ public class PacketProcessor implements Listener { packetDecoder[0xb2] = this::teams; packetDecoder[0xb3] = () -> pasteEmbeddedSchem(Fight.getBlueTeam()); packetDecoder[0xb4] = () -> pasteEmbeddedSchem(Fight.getRedTeam()); + packetDecoder[0xb5] = () -> rotateSchem(Fight.getBlueTeam()); + packetDecoder[0xb6] = () -> rotateSchem(Fight.getRedTeam()); packetDecoder[0xc0] = this::scoreboardTitle; packetDecoder[0xc1] = this::scoreboardData; packetDecoder[0xc2] = this::bossBar; @@ -529,6 +531,14 @@ public class PacketProcessor implements Listener { execSync(() -> team.pasteSchem(schemId, clipboard)); } + private void rotateSchem(FightTeam team) throws IOException { + boolean rotate = source.readBoolean(); + + execSync(() -> { + team.setSchematicRotate(rotate); + }); + } + private void teams() throws IOException { int blueId = source.readInt(); int redId = source.readInt(); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java index c6b899ef..cf800565 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java @@ -61,9 +61,9 @@ public interface Recorder { default void enableTeam(FightTeam team){ if(FightState.Schem.contains(FightState.getFightState())){ if(team.isBlue()) - blueSchem(team.getSchematic()); + blueSchem(team.getSchematic(), team.getSchematicRotate()); else - redSchem(team.getSchematic()); + redSchem(team.getSchematic(), team.getSchematicRotate()); } if(FightState.AntiSpectate.contains(FightState.getFightState())){ @@ -123,6 +123,8 @@ public interface Recorder { * TeamIDPacket (0xb2) + int blueTeamId, redTeamId * BlueEmbeddedSchemPacket (0xb3) + int blueSchemId + gzipt NBT blob * RedEmbeddedSchemPacket (0xb4) + int redSchemId + gzipt NBT blob + * BlueSchemRotatePacket (0xb5) + boolean rotate + * RedSchemRotatePacket (0xb6) + boolean rotate * * DEPRECATED ScoreboardTitlePacket (0xc0) + String scoreboardTitle * DEPRECATED ScoreboardDataPacket (0xc1) + String key + int value @@ -133,7 +135,6 @@ public interface Recorder { * WinPacket (0xc6) + byte team + Message subtitle * BossBarPacket (0xc7) + double leftBlueProgress, leftRedProgress + Message leftBlueText, leftRedText * - * RandomSeed (0xfd) + long seed * CommentPacket (0xfe) + String comment * TickPacket (0xff) * @@ -260,14 +261,20 @@ public interface Recorder { write(0xb2, blueTeamId, redTeamId); } - default void blueSchem(int schemId) { + default void blueSchem(int schemId, boolean rotate) { + rotate(0xb5, rotate); schem(0xb3, 0xb0, schemId); } - default void redSchem(int schemId) { + default void redSchem(int schemId, boolean rotate) { + rotate(0xb6, rotate); schem(0xb4, 0xb1, schemId); } + default void rotate(int packetId, boolean rotate) { + write(packetId, rotate); + } + default void schem(int embedId, int noEmbedId, int schemId){ if(schemId == 0) { write(noEmbedId, schemId); @@ -311,10 +318,6 @@ public interface Recorder { write(0xc6, bTeam, new Message(subtitle, params)); } - default void seed(long seed) { - write(0xfd, seed); - } - default void tick(){ write(0xff); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java deleted file mode 100644 index 397afcc8..00000000 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/RandomSeed.java +++ /dev/null @@ -1,52 +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 . - */ - -package de.steamwar.fightsystem.utils; - -import de.steamwar.fightsystem.ArenaMode; -import de.steamwar.fightsystem.record.GlobalRecorder; -import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.OneShotStateDependent; -import lombok.Getter; - -import java.util.Random; - -public class RandomSeed { - - @Getter - private boolean initialized = false; - private long seed; - - public RandomSeed() { - new OneShotStateDependent(ArenaMode.AntiReplay, FightState.PreSchemSetup, () -> { - initialized = true; - this.seed = System.nanoTime(); - GlobalRecorder.getInstance().seed(seed); - }); - } - - public void setSeed(long seed) { - initialized = true; - this.seed = seed; - } - - public Random getRandom(int derivation) { - return new Random(seed ^ new Random(derivation).nextLong()); - } -} From f7662cdcba14db42a6ec3acace2fc9e8635245cc Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 13 Jul 2025 18:15:24 +0200 Subject: [PATCH 6/7] Fix build --- .../src/de/steamwar/fightsystem/fight/Fight.java | 3 --- .../de/steamwar/fightsystem/record/PacketProcessor.java | 9 --------- 2 files changed, 12 deletions(-) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java index afd357e8..61f6a162 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java @@ -23,7 +23,6 @@ import de.steamwar.core.Core; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.record.GlobalRecorder; -import de.steamwar.fightsystem.utils.RandomSeed; import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.Sound; @@ -35,8 +34,6 @@ import java.util.HashSet; public class Fight { private Fight(){} - @Getter - private static final RandomSeed randomSeed = new RandomSeed(); @Getter private static final FightTeam redTeam = new FightTeam(Config.TeamRedName, Config.TeamRedColor, Config.TeamRedSpawn, Config.RedPasteRegion, Config.RedExtendRegion, Config.RedRotate, false, Config.RedLeader); @Getter diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index 2cc84688..22b675b4 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -154,7 +154,6 @@ public class PacketProcessor implements Listener { packetDecoder[0xc6] = this::winMessage; packetDecoder[0xc7] = this::bossBarMessage; packetDecoder[0xef] = source::readUTF; - packetDecoder[0xfd] = this::randomSeed; packetDecoder[0xff] = this::tick; execSync(FightWorld::forceLoad); @@ -648,14 +647,6 @@ public class PacketProcessor implements Listener { execSync(() -> entities.get(entityId).setOnFire(perma)); } - private void randomSeed() throws IOException { - long seed = source.readLong(); - - execSync(() -> { - Fight.getRandomSeed().setSeed(seed); - }); - } - private void tick(){ execSync(entityServer::tick); From 104f0cf02da06a1b1238dce052dbf9d21722dfe6 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 13 Jul 2025 18:39:53 +0200 Subject: [PATCH 7/7] Fix final stuff --- .../de/steamwar/fightsystem/FightSystem.java | 1 + .../fightsystem/fight/FightSchematic.java | 26 ++++++++++++------- .../steamwar/fightsystem/fight/FightTeam.java | 8 ++---- .../fightsystem/record/PacketProcessor.java | 4 +-- .../steamwar/fightsystem/record/Recorder.java | 20 +++++++------- 5 files changed, 31 insertions(+), 28 deletions(-) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 9ebc4f0c..d181ce02 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -126,6 +126,7 @@ public class FightSystem extends JavaPlugin { new WinconditionPointsAirShip(); new WinconditionTimeout(); new WinconditionTimeTechKO(); + new WinconditionTimedDamageTechKO(); new EventTeamOffWincondition(); new WinconditionComparisonTimeout(Winconditions.HEART_RATIO_TIMEOUT, "HeartTimeout", "WIN_MORE_HEALTH", FightTeam::getHeartRatio); new WinconditionComparisonTimeout(Winconditions.PERCENT_TIMEOUT, "PercentTimeout", "WIN_LESS_DAMAGE", team -> -Wincondition.getPercentWincondition().getPercent(team)); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index aaffe4c4..63395d03 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -36,7 +36,6 @@ import de.steamwar.sql.SchematicData; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicType; import lombok.Getter; -import lombok.Setter; import org.bukkit.Bukkit; import org.bukkit.DyeColor; import org.bukkit.Location; @@ -54,22 +53,27 @@ public class FightSchematic extends StateDependent { private final FightTeam team; private final Region region; + private final boolean rotate; @Getter - @Setter - private boolean rotate; + private boolean usedRotate; @Getter private Clipboard clipboard = null; private int schematic = 0; - public FightSchematic(FightTeam team, boolean rotate) { + public FightSchematic(FightTeam team, boolean usedRotate) { super(ArenaMode.All, FightState.PostSchemSetup); this.team = team; this.region = team.getSchemRegion(); - this.rotate = rotate; + this.rotate = usedRotate; + this.usedRotate = usedRotate; register(); } + public void setChangeRotate(boolean rotate) { + this.usedRotate = this.rotate ^ rotate; + } + public boolean hasSchematic() { return clipboard != null; } @@ -124,13 +128,15 @@ public class FightSchematic extends StateDependent { } if(ArenaMode.AntiReplay.contains(Config.mode)) { + boolean changeRotation = false; if (Config.ActiveWinconditions.contains(Winconditions.RANDOM_ROTATE)) { - rotate = new Random().nextBoolean(); + changeRotation = new Random().nextBoolean(); + usedRotate = rotate ^ changeRotation; } if(team.isBlue()) - GlobalRecorder.getInstance().blueSchem(schematic, rotate); + GlobalRecorder.getInstance().blueSchem(schematic, changeRotation); else - GlobalRecorder.getInstance().redSchem(schematic, rotate); + GlobalRecorder.getInstance().redSchem(schematic, changeRotation); } Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::paste); @@ -156,8 +162,8 @@ public class FightSchematic extends StateDependent { Config.PasteAligned && Config.BlueToRedX != 0 ? region.getSizeX()/2.0 - dims.getBlockX() : -dims.getBlockX()/2.0, Config.WaterDepth != 0 ? Config.WaterDepth - WorldeditWrapper.impl.getWaterDepth(clipboard) : 0, Config.PasteAligned && Config.BlueToRedZ != 0 ? region.getSizeZ()/2.0 - dims.getBlockZ() : -dims.getBlockZ()/2.0 - ).add(new Vector(rotate ? 1 : 0, 0, rotate ? 1 : 0)), - new AffineTransform().rotateY(rotate ? 180 : 0) + ).add(new Vector(usedRotate ? 1 : 0, 0, usedRotate ? 1 : 0)), + new AffineTransform().rotateY(usedRotate ? 180 : 0) ); FightSystem.getHullHider().initialize(team); team.getPlayers().forEach(fightPlayer -> fightPlayer.ifAI(ai -> ai.schematic(clipboard))); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 319f2dbb..6c9c0345 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -458,12 +458,8 @@ public class FightTeam { return schematic.getId(); } - public boolean getSchematicRotate() { - return schematic.isRotate(); - } - - public void setSchematicRotate(boolean rotate) { - schematic.setRotate(rotate); + public void setSchematicChangeRotate(boolean rotate) { + schematic.setChangeRotate(rotate); } public Clipboard getClipboard() { diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index 22b675b4..f4906f42 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -531,10 +531,10 @@ public class PacketProcessor implements Listener { } private void rotateSchem(FightTeam team) throws IOException { - boolean rotate = source.readBoolean(); + boolean changeRotate = source.readBoolean(); execSync(() -> { - team.setSchematicRotate(rotate); + team.setSchematicChangeRotate(changeRotate); }); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java index cf800565..8b159660 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java @@ -61,9 +61,9 @@ public interface Recorder { default void enableTeam(FightTeam team){ if(FightState.Schem.contains(FightState.getFightState())){ if(team.isBlue()) - blueSchem(team.getSchematic(), team.getSchematicRotate()); + blueSchem(team.getSchematic(), false); else - redSchem(team.getSchematic(), team.getSchematicRotate()); + redSchem(team.getSchematic(), false); } if(FightState.AntiSpectate.contains(FightState.getFightState())){ @@ -123,8 +123,8 @@ public interface Recorder { * TeamIDPacket (0xb2) + int blueTeamId, redTeamId * BlueEmbeddedSchemPacket (0xb3) + int blueSchemId + gzipt NBT blob * RedEmbeddedSchemPacket (0xb4) + int redSchemId + gzipt NBT blob - * BlueSchemRotatePacket (0xb5) + boolean rotate - * RedSchemRotatePacket (0xb6) + boolean rotate + * BlueSchemRotatePacket (0xb5) + boolean changeRotate + * RedSchemRotatePacket (0xb6) + boolean changeRotate * * DEPRECATED ScoreboardTitlePacket (0xc0) + String scoreboardTitle * DEPRECATED ScoreboardDataPacket (0xc1) + String key + int value @@ -261,18 +261,18 @@ public interface Recorder { write(0xb2, blueTeamId, redTeamId); } - default void blueSchem(int schemId, boolean rotate) { - rotate(0xb5, rotate); + default void blueSchem(int schemId, boolean changeRotate) { + rotate(0xb5, changeRotate); schem(0xb3, 0xb0, schemId); } - default void redSchem(int schemId, boolean rotate) { - rotate(0xb6, rotate); + default void redSchem(int schemId, boolean changeRotate) { + rotate(0xb6, changeRotate); schem(0xb4, 0xb1, schemId); } - default void rotate(int packetId, boolean rotate) { - write(packetId, rotate); + default void rotate(int packetId, boolean changeRotate) { + write(packetId, changeRotate); } default void schem(int embedId, int noEmbedId, int schemId){