SteamWar/FightSystem
Archiviert
13
1

Merge pull request 'Initialisation refactoring' (#299) from initRefactor into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #299
Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Lixfel 2021-10-29 11:58:54 +02:00
Commit ead43fdbea
7 geänderte Dateien mit 51 neuen und 40 gelöschten Zeilen

Datei anzeigen

@ -52,5 +52,5 @@ public enum ArenaMode {
public static final Set<ArenaMode> Restartable = Collections.unmodifiableSet(EnumSet.of(NORMAL, RANKED, REPLAY)); public static final Set<ArenaMode> Restartable = Collections.unmodifiableSet(EnumSet.of(NORMAL, RANKED, REPLAY));
public static final Set<ArenaMode> SoloLeader = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK, PREPARE)); public static final Set<ArenaMode> SoloLeader = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK, PREPARE));
public static final Set<ArenaMode> NotOnBau = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK, PREPARE, REPLAY))); public static final Set<ArenaMode> NotOnBau = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK, PREPARE, REPLAY)));
public static final Set<ArenaMode> VariableTime = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK, REPLAY))); public static final Set<ArenaMode> SeriousFight = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK, REPLAY)));
} }

Datei anzeigen

@ -19,7 +19,6 @@
package de.steamwar.fightsystem; package de.steamwar.fightsystem;
import de.steamwar.core.CommandRemover;
import de.steamwar.fightsystem.commands.*; import de.steamwar.fightsystem.commands.*;
import de.steamwar.fightsystem.countdown.*; import de.steamwar.fightsystem.countdown.*;
import de.steamwar.fightsystem.event.HellsBells; import de.steamwar.fightsystem.event.HellsBells;
@ -30,7 +29,6 @@ import de.steamwar.fightsystem.listener.Shutdown;
import de.steamwar.fightsystem.listener.*; import de.steamwar.fightsystem.listener.*;
import de.steamwar.fightsystem.record.*; import de.steamwar.fightsystem.record.*;
import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.OneShotStateDependent;
import de.steamwar.fightsystem.utils.*; import de.steamwar.fightsystem.utils.*;
import de.steamwar.fightsystem.winconditions.*; import de.steamwar.fightsystem.winconditions.*;
import de.steamwar.message.Message; import de.steamwar.message.Message;
@ -40,8 +38,6 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.util.logging.Level;
public class FightSystem extends JavaPlugin { public class FightSystem extends JavaPlugin {
private static FightSystem plugin; private static FightSystem plugin;
@ -50,6 +46,7 @@ public class FightSystem extends JavaPlugin {
private Message message; private Message message;
private FightTeam lastWinner; private FightTeam lastWinner;
private String lastWinreason;
@Override @Override
public void onLoad() { public void onLoad() {
@ -92,6 +89,7 @@ public class FightSystem extends JavaPlugin {
new TechHider(); new TechHider();
new FightWorld(); new FightWorld();
new FightUI(); new FightUI();
new FightStatistics();
new BungeeFightInfo(); new BungeeFightInfo();
new WinconditionAllDead(); new WinconditionAllDead();
@ -122,6 +120,7 @@ public class FightSystem extends JavaPlugin {
new RemoveCommand(); new RemoveCommand();
new AcceptCommand(); new AcceptCommand();
new DeclineCommand(); new DeclineCommand();
new GamemodeCommand();
new InviteCommand(); new InviteCommand();
new ReadyCommand(); new ReadyCommand();
new AkCommand(); new AkCommand();
@ -135,17 +134,6 @@ public class FightSystem extends JavaPlugin {
new LiveRecorder(); new LiveRecorder();
new FileRecorder(); new FileRecorder();
new OneShotStateDependent(ArenaMode.AntiReplay, FightState.PreRunning, () -> FightUI.addSubtitle("UI_PRE_RUNNING"));
new OneShotStateDependent(ArenaMode.AntiReplay, FightState.Running, () -> FightUI.addSubtitle("UI_RUNNING"));
new OneShotStateDependent(ArenaMode.AntiTest, FightState.Running, FightStatistics::start);
try {
CommandRemover.removeAll("gamemode");
CommandInjector.injectCommand(new GamemodeCommand());
} catch (Exception e) {
getLogger().log(Level.SEVERE, "Failed to replace commands", e);
}
REntity.initWatchers(); REntity.initWatchers();
if(Config.mode == ArenaMode.EVENT) { if(Config.mode == ArenaMode.EVENT) {
@ -167,9 +155,6 @@ public class FightSystem extends JavaPlugin {
public static void setPreLeaderState() { public static void setPreLeaderState() {
FightState.setFightState(FightState.PRE_LEADER_SETUP); FightState.setFightState(FightState.PRE_LEADER_SETUP);
Fight.getBlueTeam().reset();
Fight.getRedTeam().reset();
} }
public static void setPreSchemState() { public static void setPreSchemState() {
@ -190,22 +175,10 @@ public class FightSystem extends JavaPlugin {
public static void setSpectateState(FightTeam winFightTeam, String winreason, String subtitle, Object... params) { public static void setSpectateState(FightTeam winFightTeam, String winreason, String subtitle, Object... params) {
plugin.lastWinner = winFightTeam; plugin.lastWinner = winFightTeam;
plugin.lastWinreason = winreason;
FightUI.printWin(winFightTeam, subtitle, params); FightUI.printWin(winFightTeam, subtitle, params);
FightState.setFightState(FightState.SPECTATE); FightState.setFightState(FightState.SPECTATE);
if(!Config.test() && !PacketProcessor.isReplaying()){
if(Config.mode == ArenaMode.EVENT) {
if (winFightTeam == null)
getEventFight().setErgebnis(0);
else if (winFightTeam.isBlue())
getEventFight().setErgebnis(1);
else
getEventFight().setErgebnis(2);
}
FightStatistics.saveStats(winFightTeam, winreason);
}
} }
public static void setEventLeiter(Player el){ public static void setEventLeiter(Player el){
@ -241,6 +214,10 @@ public class FightSystem extends JavaPlugin {
return plugin.lastWinner; return plugin.lastWinner;
} }
public static String getLastWinreason() {
return plugin.lastWinreason;
}
public static void shutdown() { public static void shutdown() {
//Staggered kick to prevent lobby overloading //Staggered kick to prevent lobby overloading
if(Bukkit.getOnlinePlayers().isEmpty()){ if(Bukkit.getOnlinePlayers().isEmpty()){

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.fightsystem.commands; package de.steamwar.fightsystem.commands;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import de.steamwar.core.CommandRemover;
import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.FightSystem;
import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ChatMessageType;
@ -31,6 +32,7 @@ import org.bukkit.util.StringUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.logging.Level;
public class GamemodeCommand extends BukkitCommand { public class GamemodeCommand extends BukkitCommand {
@ -42,6 +44,13 @@ public class GamemodeCommand extends BukkitCommand {
List<String> aliases = new ArrayList<>(); List<String> aliases = new ArrayList<>();
aliases.add("gm"); aliases.add("gm");
this.setAliases(aliases); this.setAliases(aliases);
try {
CommandRemover.removeAll("gamemode");
CommandInjector.injectCommand(this);
} catch (Exception e) {
FightSystem.getPlugin().getLogger().log(Level.SEVERE, "Failed to replace commands", e);
}
} }
@Override @Override

Datei anzeigen

@ -30,7 +30,7 @@ public class PostSchemCountdown extends Countdown {
public PostSchemCountdown() { public PostSchemCountdown() {
super(Config.SetupDuration, new Message("POST_SCHEM_COUNTDOWN"), null, false); super(Config.SetupDuration, new Message("POST_SCHEM_COUNTDOWN"), null, false);
new StateDependentCountdown(ArenaMode.VariableTime, FightState.PostSchemSetup, this); new StateDependentCountdown(ArenaMode.SeriousFight, FightState.PostSchemSetup, this);
} }
@Override @Override

Datei anzeigen

@ -28,6 +28,7 @@ import de.steamwar.fightsystem.listener.FightScoreboard;
import de.steamwar.fightsystem.listener.PersonalKitCreator; import de.steamwar.fightsystem.listener.PersonalKitCreator;
import de.steamwar.fightsystem.record.GlobalRecorder; import de.steamwar.fightsystem.record.GlobalRecorder;
import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.OneShotStateDependent;
import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.states.StateDependent;
import de.steamwar.fightsystem.utils.*; import de.steamwar.fightsystem.utils.*;
import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWItem;
@ -90,6 +91,8 @@ public class FightTeam {
BountifulWrapper.impl.setNametagVisibility(team); BountifulWrapper.impl.setNametagVisibility(team);
team.setNameTagVisibility(NameTagVisibility.HIDE_FOR_OTHER_TEAMS); team.setNameTagVisibility(NameTagVisibility.HIDE_FOR_OTHER_TEAMS);
team.setAllowFriendlyFire(false); team.setAllowFriendlyFire(false);
new OneShotStateDependent(ArenaMode.All, FightState.PreLeaderSetup, () -> Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::reset));
} }
public void setPrefixAndName(String prefix, String name){ public void setPrefixAndName(String prefix, String name){

Datei anzeigen

@ -27,6 +27,8 @@ import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.record.FileRecorder; import de.steamwar.fightsystem.record.FileRecorder;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.OneShotStateDependent;
import de.steamwar.fightsystem.winconditions.Wincondition; import de.steamwar.fightsystem.winconditions.Wincondition;
import de.steamwar.sql.Elo; import de.steamwar.sql.Elo;
import de.steamwar.sql.Schematic; import de.steamwar.sql.Schematic;
@ -42,16 +44,33 @@ import static de.steamwar.sql.Fight.create;
import static de.steamwar.sql.Fight.setReplay; import static de.steamwar.sql.Fight.setReplay;
public class FightStatistics { public class FightStatistics {
private FightStatistics(){}
private static Timestamp starttime = Timestamp.from(Instant.now());
private static final int K = 20; private static final int K = 20;
public static void start(){ private Timestamp starttime = Timestamp.from(Instant.now());
public FightStatistics() {
new OneShotStateDependent(ArenaMode.SeriousFight, FightState.Running, this::enable);
new OneShotStateDependent(ArenaMode.Event, FightState.Spectate, this::setEventResult);
new OneShotStateDependent(ArenaMode.SeriousFight, FightState.Spectate, this::disable);
}
private void enable(){
starttime = Timestamp.from(Instant.now()); starttime = Timestamp.from(Instant.now());
} }
public static void saveStats(FightTeam winner, String windescription){ private void setEventResult() {
if (FightSystem.getLastWinner() == null)
FightSystem.getEventFight().setErgebnis(0);
else if (FightSystem.getLastWinner().isBlue())
FightSystem.getEventFight().setErgebnis(1);
else
FightSystem.getEventFight().setErgebnis(2);
}
private void disable() {
FightTeam winner = FightSystem.getLastWinner();
String windescription = FightSystem.getLastWinreason();
String gameMode = Config.SchematicType.toDB(); String gameMode = Config.SchematicType.toDB();
int blueLeader = getLeader(Fight.getBlueTeam()); int blueLeader = getLeader(Fight.getBlueTeam());
@ -120,7 +139,7 @@ public class FightStatistics {
} }
} }
private static int getLeader(FightTeam team){ private int getLeader(FightTeam team){
if(team.getLeader() != null) if(team.getLeader() != null)
return SteamwarUser.get(team.getLeader().getPlayer().getUniqueId()).getId(); return SteamwarUser.get(team.getLeader().getPlayer().getUniqueId()).getId();
else if(team.getDesignatedLeader() != null) else if(team.getDesignatedLeader() != null)
@ -128,7 +147,7 @@ public class FightStatistics {
return 0; return 0;
} }
private static void savePlayerStats(FightPlayer fp, int fightId){ private void savePlayerStats(FightPlayer fp, int fightId){
SteamwarUser user = SteamwarUser.get(fp.getPlayer().getUniqueId()); SteamwarUser user = SteamwarUser.get(fp.getPlayer().getUniqueId());
de.steamwar.sql.FightPlayer.create(fightId, user.getId(), fp.getTeam().isBlue(), fp.getKit().getName(), fp.getKills(), !fp.isLiving()); de.steamwar.sql.FightPlayer.create(fightId, user.getId(), fp.getTeam().isBlue(), fp.getKit().getName(), fp.getKills(), !fp.isLiving());
} }

Datei anzeigen

@ -27,6 +27,7 @@ import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.record.GlobalRecorder; import de.steamwar.fightsystem.record.GlobalRecorder;
import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.OneShotStateDependent;
import de.steamwar.fightsystem.states.StateDependentCountdown; import de.steamwar.fightsystem.states.StateDependentCountdown;
import de.steamwar.fightsystem.states.StateDependentTask; import de.steamwar.fightsystem.states.StateDependentTask;
import de.steamwar.fightsystem.winconditions.Wincondition; import de.steamwar.fightsystem.winconditions.Wincondition;
@ -51,6 +52,8 @@ public class FightUI {
new StateDependentTask(ArenaMode.AntiReplay, FightState.All, this::update, 20, 20); new StateDependentTask(ArenaMode.AntiReplay, FightState.All, this::update, 20, 20);
new StateDependentTask(ArenaMode.All, FightState.All, this::sendToPlayers, 5, 5); new StateDependentTask(ArenaMode.All, FightState.All, this::sendToPlayers, 5, 5);
new StateDependentTask(ArenaMode.All, FightState.All, this::tpsWatcher, 20, 20); new StateDependentTask(ArenaMode.All, FightState.All, this::tpsWatcher, 20, 20);
new OneShotStateDependent(ArenaMode.AntiReplay, FightState.PreRunning, () -> addSubtitle("UI_PRE_RUNNING"));
new OneShotStateDependent(ArenaMode.AntiReplay, FightState.Running, () -> addSubtitle("UI_RUNNING"));
instance = this; instance = this;
} }