From e4cd7755b23db1880937e4de0652b5f2075fca75 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 4 Sep 2020 17:59:15 +0200 Subject: [PATCH] Schematic now nullable Signed-off-by: Lixfel --- .../commands/LockschemCommand.java | 3 +- .../steamwar/fightsystem/fight/FightTeam.java | 33 ++++++++++++------- .../fightsystem/utils/FightStatistics.java | 27 ++++++++++++--- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LockschemCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/LockschemCommand.java index ab6f3c9..9f3f6be 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LockschemCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/LockschemCommand.java @@ -22,6 +22,7 @@ package de.steamwar.fightsystem.commands; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.sql.Schematic; import de.steamwar.sql.SchematicType; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserGroup; @@ -59,7 +60,7 @@ public class LockschemCommand implements CommandExecutor { player.sendMessage(FightSystem.PREFIX + "§cDieses Team existiert nicht!"); return false; } - fightTeam.getSchematic().setSchemType(SchematicType.Normal); + Schematic.getSchemFromDB(fightTeam.getSchematic()).setSchemType(SchematicType.Normal); player.sendMessage(FightSystem.PREFIX + "Schematic von " + fightTeam.getColoredName() + " §cgesperrt!"); return false; } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index cf3be39..415e0a7 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -61,7 +61,7 @@ public class FightTeam implements IFightTeam{ private final String name; private final String prefix; private final ChatColor color; - private Schematic schematic; + private int schematic = 0; private final Team team; private final boolean blue; @@ -257,31 +257,40 @@ public class FightTeam implements IFightTeam{ public void pasteSchematic(){ FreezeWorld freezer = new FreezeWorld(); DyeColor c = ColorConverter.chat2dye(color); + Schematic schem; + try{ + schem = Schematic.getSchemFromDB(this.schematic); + }catch(SecurityException e){ + pasteDummy(); + return; + } + EditSession e; + try { switch(Core.getVersion()){ case 15: - e = FightTeam_15.pasteSchematic(schematic, pasteX, pasteY, pasteZ, rotate); + e = FightTeam_15.pasteSchematic(schem, pasteX, pasteY, pasteZ, rotate); FightTeam_15.replaceTeamColor(e, c, cornerX, cornerY, cornerZ); break; case 14: - e = FightTeam_14.pasteSchematic(schematic, pasteX, pasteY, pasteZ, rotate); + e = FightTeam_14.pasteSchematic(schem, pasteX, pasteY, pasteZ, rotate); FightTeam_14.replaceTeamColor(e, c, cornerX, cornerY, cornerZ); break; case 10: - e = FightTeam_10.pasteSchematic(schematic, pasteX, pasteY, pasteZ, rotate); + e = FightTeam_10.pasteSchematic(schem, pasteX, pasteY, pasteZ, rotate); FightTeam_10.replaceTeamColor(e, c, cornerX, cornerY, cornerZ); break; case 9: - e = FightTeam_9.pasteSchematic(schematic, pasteX, pasteY, pasteZ, rotate); + e = FightTeam_9.pasteSchematic(schem, pasteX, pasteY, pasteZ, rotate); FightTeam_9.replaceTeamColor(e, c, cornerX, cornerY, cornerZ); break; case 8: - e = FightTeam_8.pasteSchematic(schematic, pasteX, pasteY, pasteZ, rotate); + e = FightTeam_8.pasteSchematic(schem, pasteX, pasteY, pasteZ, rotate); FightTeam_8.replaceTeamColor(e, c, cornerX, cornerY, cornerZ); break; default: - e = FightTeam_12.pasteSchematic(schematic, pasteX, pasteY, pasteZ, rotate); + e = FightTeam_12.pasteSchematic(schem, pasteX, pasteY, pasteZ, rotate); FightTeam_12.replaceTeamColor(e, c, cornerX, cornerY, cornerZ); } } catch (Schematic.WrongVersionException ex) { @@ -301,7 +310,7 @@ public class FightTeam implements IFightTeam{ if(publics.isEmpty()) return; - schematic = publics.get(new Random().nextInt(publics.size())); + schematic = publics.get(new Random().nextInt(publics.size())).getSchemID(); pasteSchematic(); if(!Config.test() && leader != null) @@ -309,7 +318,7 @@ public class FightTeam implements IFightTeam{ } public void setSchematic(Schematic schematic){ - this.schematic = schematic; + this.schematic = schematic.getSchemID(); broadcast(FightSystem.PREFIX + "§7Das §e" + Config.GameName + " " + schematic.getSchemName() + " §7wird für den Kampf verwendet!"); if(!Config.test()) @@ -323,13 +332,13 @@ public class FightTeam implements IFightTeam{ } public boolean hasSchematic(){ - return schematic != null; + return schematic != 0; } public void setReady(boolean ready) { Player l = leader.getPlayer(); - if(schematic == null){ + if(schematic == 0){ l.sendMessage(FightSystem.PREFIX + "§cZuerst muss eine Schematic gewählt sein!"); return; } @@ -362,7 +371,7 @@ public class FightTeam implements IFightTeam{ return prefix; } - public Schematic getSchematic() { + public int getSchematic() { return schematic; } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java index 46e7c4a..0b948b3 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -25,11 +25,13 @@ import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.sql.Elo; +import de.steamwar.sql.Schematic; import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; import java.sql.Timestamp; import java.time.Instant; +import java.util.logging.Level; import static de.steamwar.sql.Fight.create; @@ -58,14 +60,29 @@ public class FightStatistics { }else{ blueResult = 0.5; } - if(Fight.getBlueTeam().getSchematic() != null && Fight.getRedTeam().getSchematic() != null){ - int fightId = create(gameMode, Bukkit.getWorlds().get(0).getName(), starttime, Config.TimeoutTime - FightSystem.getFightTime(), - blueLeader.getId(), redLeader.getId(), Fight.getBlueTeam().getSchematic().getSchemID(), Fight.getRedTeam().getSchematic().getSchemID(), win, windescription); - for(FightPlayer fp : Fight.getBlueTeam().getPlayers()) + Integer blueSchem, redSchem; + try{ + blueSchem = Schematic.getSchemFromDB(Fight.getBlueTeam().getSchematic()).getSchemID(); + }catch(SecurityException e){ + blueSchem = null; + } + try{ + redSchem = Schematic.getSchemFromDB(Fight.getRedTeam().getSchematic()).getSchemID(); + }catch(SecurityException e){ + redSchem = null; + } + + try { + int fightId = create(gameMode, Bukkit.getWorlds().get(0).getName(), starttime, Config.TimeoutTime - FightSystem.getFightTime(), + blueLeader.getId(), redLeader.getId(), blueSchem, redSchem, win, windescription); + + for (FightPlayer fp : Fight.getBlueTeam().getPlayers()) savePlayerStats(fp, fightId); - for(FightPlayer fp : Fight.getRedTeam().getPlayers()) + for (FightPlayer fp : Fight.getRedTeam().getPlayers()) savePlayerStats(fp, fightId); + }catch(Exception e){ + Bukkit.getLogger().log(Level.SEVERE, "Failed to save statistics", e); } if(Config.Ranked && !Config.event()){