SteamWar/FightSystem
Archiviert
13
1

Initialisation refactoring #299

Zusammengeführt
Lixfel hat 1 Commits von initRefactor nach master 2021-10-29 11:58:54 +02:00 zusammengeführt
7 geänderte Dateien mit 51 neuen und 40 gelöschten Zeilen
Nur Änderungen aus Commit 594816bb7d werden angezeigt - Alle Commits anzeigen

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> 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> 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;
import de.steamwar.core.CommandRemover;
import de.steamwar.fightsystem.commands.*;
import de.steamwar.fightsystem.countdown.*;
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.record.*;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.OneShotStateDependent;
import de.steamwar.fightsystem.utils.*;
import de.steamwar.fightsystem.winconditions.*;
import de.steamwar.message.Message;
@ -40,8 +38,6 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.logging.Level;
public class FightSystem extends JavaPlugin {
private static FightSystem plugin;
@ -50,6 +46,7 @@ public class FightSystem extends JavaPlugin {
private Message message;
private FightTeam lastWinner;
private String lastWinreason;
@Override
public void onLoad() {
@ -92,6 +89,7 @@ public class FightSystem extends JavaPlugin {
new TechHider();
new FightWorld();
new FightUI();
new FightStatistics();
new BungeeFightInfo();
new WinconditionAllDead();
@ -122,6 +120,7 @@ public class FightSystem extends JavaPlugin {
new RemoveCommand();
new AcceptCommand();
new DeclineCommand();
new GamemodeCommand();
new InviteCommand();
new ReadyCommand();
new AkCommand();
@ -135,17 +134,6 @@ public class FightSystem extends JavaPlugin {
new LiveRecorder();
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();
if(Config.mode == ArenaMode.EVENT) {
@ -167,9 +155,6 @@ public class FightSystem extends JavaPlugin {
public static void setPreLeaderState() {
FightState.setFightState(FightState.PRE_LEADER_SETUP);
Fight.getBlueTeam().reset();
Fight.getRedTeam().reset();
}
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) {
plugin.lastWinner = winFightTeam;
plugin.lastWinreason = winreason;
FightUI.printWin(winFightTeam, subtitle, params);
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){
@ -241,6 +214,10 @@ public class FightSystem extends JavaPlugin {
return plugin.lastWinner;
}
public static String getLastWinreason() {
return plugin.lastWinreason;
}
public static void shutdown() {
//Staggered kick to prevent lobby overloading
if(Bukkit.getOnlinePlayers().isEmpty()){

Datei anzeigen

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

Den umstellen auf das neue System wäre ganz nett. ;)

Den umstellen auf das neue System wäre ganz nett. ;)
CommandInjector.injectCommand(this);
} catch (Exception e) {
FightSystem.getPlugin().getLogger().log(Level.SEVERE, "Failed to replace commands", e);
}
}
@Override

Datei anzeigen

@ -30,7 +30,7 @@ public class PostSchemCountdown extends Countdown {
public PostSchemCountdown() {
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

Datei anzeigen

@ -28,6 +28,7 @@ import de.steamwar.fightsystem.listener.FightScoreboard;
import de.steamwar.fightsystem.listener.PersonalKitCreator;
import de.steamwar.fightsystem.record.GlobalRecorder;
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.inventory.SWItem;
@ -90,6 +91,8 @@ public class FightTeam {
BountifulWrapper.impl.setNametagVisibility(team);
team.setNameTagVisibility(NameTagVisibility.HIDE_FOR_OTHER_TEAMS);
team.setAllowFriendlyFire(false);
new OneShotStateDependent(ArenaMode.All, FightState.PreLeaderSetup, () -> Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::reset));
}
public void setPrefixAndName(String prefix, String name){
@ -149,7 +152,7 @@ public class FightTeam {
return false;
}
public void reset(){
public void reset() {
skip = false;
ready = false;
schematic.reset();

Datei anzeigen

@ -27,6 +27,8 @@ import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.fight.FightTeam;
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.sql.Elo;
import de.steamwar.sql.Schematic;
@ -42,16 +44,33 @@ import static de.steamwar.sql.Fight.create;
import static de.steamwar.sql.Fight.setReplay;
public class FightStatistics {
private FightStatistics(){}
private static Timestamp starttime = Timestamp.from(Instant.now());
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());
}
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();
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)
return SteamwarUser.get(team.getLeader().getPlayer().getUniqueId()).getId();
else if(team.getDesignatedLeader() != null)
@ -128,7 +147,7 @@ public class FightStatistics {
return 0;
}
private static void savePlayerStats(FightPlayer fp, int fightId){
private void savePlayerStats(FightPlayer fp, int fightId){
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());
}

Datei anzeigen

@ -27,6 +27,7 @@ import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.record.GlobalRecorder;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.OneShotStateDependent;
import de.steamwar.fightsystem.states.StateDependentCountdown;
import de.steamwar.fightsystem.states.StateDependentTask;
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.All, FightState.All, this::sendToPlayers, 5, 5);
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;
}