From 03e5cf62a26eaace49013fc11dd536e3224fdd47 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 19 Jan 2020 07:38:54 +0100 Subject: [PATCH 1/7] Removing pair from fight system Signed-off-by: Lixfel --- .../fightsystem/utils/TechHider_10.java | 5 ++- .../fightsystem/utils/TechHider_12.java | 5 ++- .../fightsystem/utils/TechHider_14.java | 5 ++- .../fightsystem/utils/TechHider_15.java | 5 ++- .../fightsystem/utils/TechHider_8.java | 5 ++- .../fightsystem/utils/TechHider_9.java | 5 ++- .../fightsystem/utils/ITechHider.java | 18 ++++++++++ .../de/steamwar/fightsystem/FightSystem.java | 6 ++-- .../de/steamwar/fightsystem/commands/GUI.java | 36 +++++++++---------- .../steamwar/fightsystem/fight/FightTeam.java | 10 ++---- .../steamwar/fightsystem/utils/TechHider.java | 15 ++++---- 11 files changed, 61 insertions(+), 54 deletions(-) diff --git a/FightSystem_10/src/de/steamwar/fightsystem/utils/TechHider_10.java b/FightSystem_10/src/de/steamwar/fightsystem/utils/TechHider_10.java index 9597762..19f11b3 100644 --- a/FightSystem_10/src/de/steamwar/fightsystem/utils/TechHider_10.java +++ b/FightSystem_10/src/de/steamwar/fightsystem/utils/TechHider_10.java @@ -1,6 +1,5 @@ package de.steamwar.fightsystem.utils; -import javafx.util.Pair; import net.minecraft.server.v1_10_R1.PacketPlayOutMapChunk; import org.bukkit.craftbukkit.v1_10_R1.CraftChunk; import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; @@ -9,7 +8,7 @@ import org.bukkit.entity.Player; class TechHider_10 { private TechHider_10(){} - static void reloadChunk(Player p, Pair chunk){ - ((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunk.getKey(), chunk.getValue())).getHandle(), 65535)); + static void reloadChunk(Player p, ITechHider.ChunkPos chunk){ + ((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunk.x(), chunk.z())).getHandle(), 65535)); } } diff --git a/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider_12.java b/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider_12.java index b9533dd..99f1c2a 100644 --- a/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider_12.java +++ b/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider_12.java @@ -12,7 +12,6 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.IFightSystem; import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; -import javafx.util.Pair; import net.minecraft.server.v1_12_R1.PacketPlayOutMapChunk; import org.bukkit.craftbukkit.v1_12_R1.CraftChunk; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; @@ -27,8 +26,8 @@ class TechHider_12 { private static final short obfuscateShift4 = (short)(Config.ObfuscateWith << 4); - static void reloadChunk(Player p, Pair chunk){ - ((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunk.getKey(), chunk.getValue())).getHandle(), 65535)); + static void reloadChunk(Player p, ITechHider.ChunkPos chunk){ + ((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunk.x(), chunk.z())).getHandle(), 65535)); } static void start(){ diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider_14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider_14.java index 5a48108..46263f9 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider_14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider_14.java @@ -12,7 +12,6 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.IFightSystem; import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; -import javafx.util.Pair; import net.minecraft.server.v1_14_R1.PacketPlayOutMapChunk; import org.bukkit.craftbukkit.v1_14_R1.CraftChunk; import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; @@ -25,8 +24,8 @@ import static de.steamwar.fightsystem.utils.ITechHider.bypass; public class TechHider_14 { private TechHider_14(){} - static void reloadChunk(Player p, Pair chunk){ - ((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunk.getKey(), chunk.getValue())).getHandle(), 65535)); + static void reloadChunk(Player p, ITechHider.ChunkPos chunk){ + ((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunk.x(), chunk.z())).getHandle(), 65535)); } static void start(){ diff --git a/FightSystem_15/src/de/steamwar/fightsystem/utils/TechHider_15.java b/FightSystem_15/src/de/steamwar/fightsystem/utils/TechHider_15.java index 5e306ca..75bbd25 100644 --- a/FightSystem_15/src/de/steamwar/fightsystem/utils/TechHider_15.java +++ b/FightSystem_15/src/de/steamwar/fightsystem/utils/TechHider_15.java @@ -1,6 +1,5 @@ package de.steamwar.fightsystem.utils; -import javafx.util.Pair; import net.minecraft.server.v1_15_R1.PacketPlayOutMapChunk; import org.bukkit.craftbukkit.v1_15_R1.CraftChunk; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; @@ -9,8 +8,8 @@ import org.bukkit.entity.Player; public class TechHider_15 { private TechHider_15(){} - static void reloadChunk(Player p, Pair chunk){ - ((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunk.getKey(), chunk.getValue())).getHandle(), 65535)); + static void reloadChunk(Player p, ITechHider.ChunkPos chunk){ + ((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunk.x(), chunk.z())).getHandle(), 65535)); } static void start(){ diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/TechHider_8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/TechHider_8.java index a9dcc61..bd722f4 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/TechHider_8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/TechHider_8.java @@ -1,6 +1,5 @@ package de.steamwar.fightsystem.utils; -import javafx.util.Pair; import net.minecraft.server.v1_8_R3.PacketPlayOutMapChunk; import org.bukkit.craftbukkit.v1_8_R3.CraftChunk; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; @@ -9,7 +8,7 @@ import org.bukkit.entity.Player; class TechHider_8 { private TechHider_8(){} - static void reloadChunk(Player p, Pair chunk){ - ((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunk.getKey(), chunk.getValue())).getHandle(), true, 65535)); + static void reloadChunk(Player p, ITechHider.ChunkPos chunk){ + ((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunk.x(), chunk.z())).getHandle(), true, 65535)); } } diff --git a/FightSystem_9/src/de/steamwar/fightsystem/utils/TechHider_9.java b/FightSystem_9/src/de/steamwar/fightsystem/utils/TechHider_9.java index 9ce621e..ec11a29 100644 --- a/FightSystem_9/src/de/steamwar/fightsystem/utils/TechHider_9.java +++ b/FightSystem_9/src/de/steamwar/fightsystem/utils/TechHider_9.java @@ -1,6 +1,5 @@ package de.steamwar.fightsystem.utils; -import javafx.util.Pair; import net.minecraft.server.v1_9_R2.PacketPlayOutMapChunk; import org.bukkit.craftbukkit.v1_9_R2.CraftChunk; import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer; @@ -9,7 +8,7 @@ import org.bukkit.entity.Player; class TechHider_9 { private TechHider_9(){} - static void reloadChunk(Player p, Pair chunk){ - ((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunk.getKey(), chunk.getValue())).getHandle(), 65535)); + static void reloadChunk(Player p, ITechHider.ChunkPos chunk){ + ((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunk.x(), chunk.z())).getHandle(), 65535)); } } diff --git a/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java b/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java index cb8da02..d8540b4 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java @@ -136,4 +136,22 @@ public class ITechHider { } while (value != 0); return Bytes.toArray(buffer); } + + public static class ChunkPos{ + final int x; + final int z; + + ChunkPos(int x, int z){ + this.x = x; + this.z = z; + } + + final int x(){ + return x; + } + + final int z(){ + return z; + } + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index 00766cd..6fd1d5d 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -10,11 +10,11 @@ import de.steamwar.fightsystem.listener.*; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.utils.FightScoreboard; +import de.steamwar.fightsystem.utils.ITechHider; import de.steamwar.fightsystem.utils.TechHider; import de.steamwar.fightsystem.utils.WaterRemover; import de.steamwar.fightsystem.winconditions.*; import de.steamwar.sql.EventFight; -import javafx.util.Pair; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.entity.Player; @@ -167,8 +167,8 @@ public class FightSystem extends JavaPlugin { throw new SecurityException(fightState.name()); setFightState(FightState.ENTERN); - final List> chunksBlue = TechHider.prepareChunkReload(Fight.getBlueTeam().getPlayers().iterator().next().getPlayer()); - final List> chunksRed = TechHider.prepareChunkReload(Fight.getRedTeam().getPlayers().iterator().next().getPlayer()); + final List chunksBlue = TechHider.prepareChunkReload(Fight.getBlueTeam().getPlayers().iterator().next().getPlayer()); + final List chunksRed = TechHider.prepareChunkReload(Fight.getRedTeam().getPlayers().iterator().next().getPlayer()); IFightSystem.setEntern(true); for(FightPlayer player : Fight.getBlueTeam().getPlayers()){ TechHider.reloadChunks(player.getPlayer(), chunksBlue); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java index dc9fe1d..9c94214 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java @@ -13,7 +13,6 @@ import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; import de.steamwar.sql.Schematic; import de.steamwar.sql.SteamwarUser; -import javafx.util.Pair; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -48,26 +47,26 @@ public class GUI { } public static void chooseInvitation(Player p){ - List> players = SWListInv.createPlayerList(p); - players.removeIf(swItemUUIDPair -> Fight.getFightPlayer(Bukkit.getPlayer(swItemUUIDPair.getValue())) != null); - SWListInv inv = new SWListInv<>(p, "Spieler einladen", (ClickType click, UUID player) -> { + List> players = SWListInv.createPlayerList(p.getUniqueId()); + players.removeIf(swItemUUIDPair -> Fight.getFightPlayer(Bukkit.getPlayer(swItemUUIDPair.getObject())) != null); + SWListInv inv = new SWListInv<>(p, "Spieler einladen", players, (ClickType click, UUID player) -> { Commands.invite(p, SteamwarUser.get(player).getUserName()); p.closeInventory(); - }, players); + }); inv.setCallback(-999, (ClickType click) -> p.closeInventory()); inv.open(); } public static void chooseRemove(Player p){ - List> players = SWListInv.createPlayerList(p); + List> players = SWListInv.createPlayerList(p.getUniqueId()); FightTeam team = Fight.getPlayerTeam(p); if(team == null) return; - players.removeIf(swItemUUIDPair -> !team.equals(Fight.getPlayerTeam(Bukkit.getPlayer(swItemUUIDPair.getValue())))); - SWListInv inv = new SWListInv<>(p, "Spieler rauswerfen", (ClickType click, UUID player) -> { + players.removeIf(swItemUUIDPair -> !team.equals(Fight.getPlayerTeam(Bukkit.getPlayer(swItemUUIDPair.getObject())))); + SWListInv inv = new SWListInv<>(p, "Spieler rauswerfen", players, (ClickType click, UUID player) -> { Commands.kick(p, SteamwarUser.get(player).getUserName()); p.closeInventory(); - }, players); + }); inv.setCallback(-999, (ClickType click) -> p.closeInventory()); inv.open(); } @@ -77,14 +76,14 @@ public class GUI { if(fightPlayer == null) return; - List> iconList = new ArrayList<>(); + List> iconList = new ArrayList<>(); List kitList = KitManager.getKits(fightPlayer.isLeader()); for(Kit k : kitList){ - iconList.add(new Pair<>(new SWItem(Material.LEATHER_CHESTPLATE, k.getName(), null, !k.isMemberAllowed(), null), k)); + iconList.add(new SWListInv.SWListEntry<>(new SWItem(Material.LEATHER_CHESTPLATE, k.getName(), null, !k.isMemberAllowed(), null), k)); } - SWListInv inv = new SWListInv<>(p, "Kitauswahl", (ClickType click, Kit k) -> k.preview(p), iconList); + SWListInv inv = new SWListInv<>(p, "Kitauswahl", iconList, (ClickType click, Kit k) -> k.preview(p)); inv.setCallback(-999, (ClickType click) -> p.closeInventory()); inv.open(); } @@ -109,20 +108,21 @@ public class GUI { } private static void schemDialog(Player p, boolean publicSchems){ - List> schems; + List> schems; if(publicSchems) - schems = SWListInv.getSchemList(0, Config.SchematicType); + schems = SWListInv.getSchemList(Config.SchematicType, 0); else if(Config.test()) - schems = SWListInv.getSchemList(SteamwarUser.get(p.getUniqueId()).getId(), null); + schems = SWListInv.getSchemList(null, SteamwarUser.get(p.getUniqueId()).getId()); else - schems = SWListInv.getSchemList(SteamwarUser.get(p.getUniqueId()).getId(), Config.SchematicType); - SWListInv inv = new SWListInv<>(p, Config.GameName + "-Auswahl", (ClickType click, Schematic s) -> { + schems = SWListInv.getSchemList(Config.SchematicType, SteamwarUser.get(p.getUniqueId()).getId()); + + SWListInv inv = new SWListInv<>(p, Config.GameName + "-Auswahl", schems, (ClickType click, Schematic s) -> { FightTeam fightTeam = Fight.getPlayerTeam(p); if(fightTeam == null) return; fightTeam.setSchematic(s); p.closeInventory(); - }, schems); + }); inv.setCallback(-999, (ClickType click) -> p.closeInventory()); inv.open(); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index 8dc57cf..b471ce5 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -7,14 +7,10 @@ import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.IFightSystem; import de.steamwar.fightsystem.kit.KitManager; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.utils.ColorConverter; -import de.steamwar.fightsystem.utils.FightScoreboard; -import de.steamwar.fightsystem.utils.ItemBuilder; -import de.steamwar.fightsystem.utils.TechHider; +import de.steamwar.fightsystem.utils.*; import de.steamwar.inventory.SWItem; import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.Schematic; -import javafx.util.Pair; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.enchantments.Enchantment; @@ -141,7 +137,7 @@ public class FightTeam implements IFightTeam{ } public FightPlayer addMember(Player player) { - final List> chunksToReload = TechHider.prepareChunkReload(player); + final List chunksToReload = TechHider.prepareChunkReload(player); FightPlayer fightPlayer = new FightPlayer(player, this); players.add(fightPlayer); invited.remove(player); @@ -159,7 +155,7 @@ public class FightTeam implements IFightTeam{ public void removePlayer(Player player) { FightPlayer fightPlayer = getFightPlayer(player); - final List> chunksToReload = TechHider.prepareChunkReload(player); + final List chunksToReload = TechHider.prepareChunkReload(player); players.remove(fightPlayer); team.removeEntry(player.getName()); fightPlayer.getPlayer().getInventory().clear(); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java index 2743ead..e6128a6 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java @@ -14,7 +14,6 @@ import de.steamwar.core.Core; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.IFightSystem; -import javafx.util.Pair; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.entity.Player; @@ -168,29 +167,29 @@ public class TechHider { }); } - public static List> prepareChunkReload(Player p){ + public static List prepareChunkReload(Player p){ if(disabled()) return Collections.emptyList(); - List> chunksToReload = new ArrayList<>(); + List chunksToReload = new ArrayList<>(); for(int x = ITechHider.arenaMinX; x <= ITechHider.arenaMaxX; x++) for(int z = ITechHider.arenaMinZ; z <= ITechHider.arenaMaxZ; z++) if(!bypass(p, x, z)) - chunksToReload.add(new Pair<>(x, z)); + chunksToReload.add(new ITechHider.ChunkPos(x, z)); return chunksToReload; } - public static void reloadChunks(Player p, List> chunksToReload){ + public static void reloadChunks(Player p, List chunksToReload){ if(disabled()) return; Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> { - for(Pair chunk : chunksToReload){ - if(bypass(p, chunk.getKey(), chunk.getValue())) + for(ITechHider.ChunkPos chunk : chunksToReload){ + if(bypass(p, chunk.x(), chunk.z())) reloadChunk(p, chunk); } }, 40); } - private static void reloadChunk(Player p, Pair chunk){ + private static void reloadChunk(Player p, ITechHider.ChunkPos chunk){ switch(Core.getVersion()){ case 15: TechHider_15.reloadChunk(p, chunk); From 3c4d5123da175cf8239b292c7a6c4204eafedf91 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 19 Jan 2020 17:32:29 +0100 Subject: [PATCH 2/7] Ignore Public Only rule (for historic gamemodes) Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/Config.java | 2 ++ .../src/de/steamwar/fightsystem/fight/Fight.java | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index aa0782d..b4f251d 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -61,6 +61,7 @@ public class Config { //schematic parameter public static final boolean OnlyPublicSchematics; + public static final boolean IgnorePublicOnly; public static final de.steamwar.sql.SchematicType SchematicType; public static final boolean TeamRedRotate; public static final boolean TeamBlueRotate; @@ -149,6 +150,7 @@ public class Config { WaterDepth = worldconfig.getInt("Arena.WaterDepth"); SchematicType = de.steamwar.sql.SchematicType.fromDB(config.getString("Schematic.SchematicType")); + IgnorePublicOnly = config.getBoolean("Schematic.IgnorePublicOnly"); boolean rotate = config.getBoolean("Schematic.Rotate"); ReplaceObsidian = config.getBoolean("Schematic.ReplaceObsidian"); ReplaceBedrock = config.getBoolean("Schematic.ReplaceBedrock"); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java index 31a7886..b5a6e25 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java @@ -114,6 +114,16 @@ public class Fight { } public static void calcAvailibleSchemTypes() { + if(Config.IgnorePublicOnly){ + onlyPublicSchems = false; + return; + } + + if(Config.OnlyPublicSchematics){ + onlyPublicSchems = true; + return; + } + if(redTeam.getLeader() == null || redTeam.getLeader().getPlayer() == null || blueTeam.getLeader() == null || blueTeam.getLeader().getPlayer() == null){ onlyPublicSchems = false; From 542547fd5befd96c45c1eb8b4d75e98d50c10a0b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 20 Jan 2020 18:46:52 +0100 Subject: [PATCH 3/7] Hotfix NPE Signed-off-by: Lixfel --- .../winconditions/WinconditionPoints.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java index 23d2857..6bbfea8 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java @@ -97,7 +97,7 @@ public class WinconditionPoints extends PlayerWincondition { public static class TeamPoints { private final FightTeam enemy; private final WinconditionRelativePercent.TeamPercent enemyPercent; - private final double factor; + private double factor; private static final int maxPoints = 2000; private int points; @@ -107,18 +107,21 @@ public class WinconditionPoints extends PlayerWincondition { this.enemyPercent = enemyPercent; points = 0; - if(enemyPercent.getBlockCount() < ownPercent.getBlockCount()) - this.factor = 10000; //Original mit 20 (20% = 0.2 ergeben 2000 Punkte - else{ - double f = 10000.0 * ownPercent.getBlockCount() / enemyPercent.getBlockCount(); + //Prevent NPE + Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () ->{ + if(enemyPercent.getBlockCount() < ownPercent.getBlockCount()) + this.factor = 10000; //Original mit 20 (20% = 0.2 ergeben 2000 Punkte + else{ + double f = 10000.0 * ownPercent.getBlockCount() / enemyPercent.getBlockCount(); - if(f > 10000) - f = 10000; - else if(f < 4000) - f = 4000; + if(f > 10000) + f = 10000; + else if(f < 4000) + f = 4000; - this.factor = f; - } + this.factor = f; + } + }); } public int getPoints(){ From 7fe4f09a08e7e6353852e63df4a2c57260f28b12 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 20 Jan 2020 18:48:40 +0100 Subject: [PATCH 4/7] Hotfix NPE Signed-off-by: Lixfel --- FightSystem_Main/src/de/steamwar/fightsystem/kit/Kit.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/kit/Kit.java b/FightSystem_Main/src/de/steamwar/fightsystem/kit/Kit.java index e7a0f7c..d437d7e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/kit/Kit.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/kit/Kit.java @@ -92,6 +92,8 @@ public class Kit { if(armor != null){ for(int i = 0; i < 4; i++){ + if(armor[i] == null) + continue; SWItem item = new SWItem(); item.setItemStack(armor[i]); inv.setItem(36 + i, item); From 2ac00294f9f19e8e1184ce72392db9e608b1aa83 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 21 Jan 2020 17:49:04 +0100 Subject: [PATCH 5/7] Hotfix NPE Signed-off-by: Lixfel --- FightSystem_Main/src/de/steamwar/fightsystem/kit/Kit.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/kit/Kit.java b/FightSystem_Main/src/de/steamwar/fightsystem/kit/Kit.java index d437d7e..bc6c5e8 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/kit/Kit.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/kit/Kit.java @@ -85,6 +85,8 @@ public class Kit { //36 = Inventargröße for(int i = 0; i < 36; i++){ + if(inventory[i] == null) + continue; SWItem item = new SWItem(); item.setItemStack(inventory[i]); inv.setItem(i, item); From e053ecf286855292f2475c28177a0c18bdcc6569 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 23 Jan 2020 17:33:29 +0100 Subject: [PATCH 6/7] Adding fight statistics Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/FightSystem.java | 12 ++--- .../countdown/TechKOCountdown.java | 2 +- .../fightsystem/fight/FightPlayer.java | 10 ++++ .../listener/InFightDamageListener.java | 5 ++ .../fightsystem/utils/FightStatistics.java | 46 +++++++++++++++++++ .../EventTeamOffWincondition.java | 2 +- .../winconditions/WinconditionAllDead.java | 2 +- .../WinconditionCaptainDead.java | 2 +- .../WinconditionHeartRatioTimeout.java | 6 +-- .../WinconditionPercentSystem.java | 4 +- .../winconditions/WinconditionPoints.java | 6 +-- .../WinconditionPumpkinTechKO.java | 2 +- .../WinconditionRelativePercent.java | 2 +- .../winconditions/WinconditionTimeout.java | 2 +- .../WinconditionWaterTechKO.java | 2 +- 15 files changed, 83 insertions(+), 22 deletions(-) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index 6fd1d5d..d188516 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -9,10 +9,7 @@ import de.steamwar.fightsystem.kit.KitManager; import de.steamwar.fightsystem.listener.*; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; -import de.steamwar.fightsystem.utils.FightScoreboard; -import de.steamwar.fightsystem.utils.ITechHider; -import de.steamwar.fightsystem.utils.TechHider; -import de.steamwar.fightsystem.utils.WaterRemover; +import de.steamwar.fightsystem.utils.*; import de.steamwar.fightsystem.winconditions.*; import de.steamwar.sql.EventFight; import org.bukkit.Bukkit; @@ -158,6 +155,7 @@ public class FightSystem extends JavaPlugin { if(Config.Entern) mainCountdown = new EnternCountdown(); + FightStatistics.start(); WaterRemover.init(); Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!"); } @@ -178,7 +176,7 @@ public class FightSystem extends JavaPlugin { } } - public static void setSpectateState(FightTeam winFightTeam) { + public static void setSpectateState(FightTeam winFightTeam, String windescription) { if(!fightState.ingame()) throw new SecurityException(fightState.name()); setFightState(FightState.SPECTATE); @@ -205,8 +203,10 @@ public class FightSystem extends JavaPlugin { getEventFight().setErgebnis(2); } - if(!Config.test()) + if(!Config.test()){ new SpectateOverCountdown(); + FightStatistics.saveStats(winFightTeam, windescription); + } } public static void setFightTime(int fightTime) { diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TechKOCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TechKOCountdown.java index dc88975..33dd17d 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TechKOCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TechKOCountdown.java @@ -23,6 +23,6 @@ public class TechKOCountdown extends Countdown { @Override void countdownFinished() { Bukkit.broadcastMessage(FightSystem.PREFIX + team.getColoredName() + "§7 ist §eTech K§8.§eO§8.!"); - FightSystem.setSpectateState(Fight.getOpposite(team)); + FightSystem.setSpectateState(Fight.getOpposite(team), "TechKO"); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightPlayer.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightPlayer.java index 040dc17..43bfbce 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightPlayer.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightPlayer.java @@ -11,6 +11,7 @@ public class FightPlayer { private final FightTeam team; private boolean isOut; private Kit kit; + private int kills; public void sendMessage(String message) { if (this.player != null && this.player.isOnline()) @@ -22,6 +23,7 @@ public class FightPlayer { this.team = team; this.isOut = false; kit = KitManager.getKitByName(Config.MemberDefault); + kills = 0; } public void setOut() { @@ -52,4 +54,12 @@ public class FightPlayer { public FightTeam getTeam(){ return team; } + + public int getKills(){ + return kills; + } + + public void addKill(){ + kills++; + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamageListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamageListener.java index cbf4d50..fda06cb 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamageListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamageListener.java @@ -10,6 +10,7 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import java.util.EnumSet; +import java.util.Objects; public class InFightDamageListener extends BasicListener { @@ -61,5 +62,9 @@ public class InFightDamageListener extends BasicListener { event.setCancelled(true); toActionbar(damager, TextComponent.fromLegacyText("§cDu darfst deinen Teamkollegen keinen Schaden zufügen!")); } + + if(player.getHealth() - event.getFinalDamage() <= 0){ + Objects.requireNonNull(Fight.getFightPlayer(damager)).addKill(); + } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java new file mode 100644 index 0000000..1b377eb --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -0,0 +1,46 @@ +package de.steamwar.fightsystem.utils; + +import de.steamwar.fightsystem.Config; +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.sql.SteamwarUser; +import org.bukkit.Bukkit; + +import java.sql.Timestamp; +import java.time.Instant; + +import static de.steamwar.sql.Fight.create; + +public class FightStatistics { + private FightStatistics(){} + + private static Timestamp starttime = Timestamp.from(Instant.now()); + + public static void start(){ + starttime = Timestamp.from(Instant.now()); + } + + public static void saveStats(FightTeam winner, String windescription){ + SteamwarUser blueLeader = SteamwarUser.get(Fight.getBlueTeam().getLeader().getPlayer().getUniqueId()); + SteamwarUser redLeader = SteamwarUser.get(Fight.getRedTeam().getLeader().getPlayer().getUniqueId()); + int win = 0; + if(winner == Fight.getBlueTeam()) + win = 1; + else if(winner == Fight.getRedTeam()) + win = 2; + int fightId = create(Config.SchematicType.toDB(), 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()) + savePlayerStats(fp, fightId); + for(FightPlayer fp : Fight.getRedTeam().getPlayers()) + savePlayerStats(fp, fightId); + } + + private static void savePlayerStats(FightPlayer fp, int fightId){ + SteamwarUser user = SteamwarUser.get(fp.getPlayer().getUniqueId()); + de.steamwar.sql.FightPlayer.create(fightId, user.getId(), fp.getKit().getName(), fp.getKills(), !fp.isLiving()); + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java index 2a7edbd..3fcb29e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java @@ -29,7 +29,7 @@ public class EventTeamOffWincondition extends Wincondition { private void teamOff(FightTeam team){ if(team.allPlayersOut()){ Bukkit.broadcastMessage(FightSystem.PREFIX + "§6Das Team " + team.getColoredName() + " §6ist Offline!"); - FightSystem.setSpectateState(Fight.getOpposite(team)); + FightSystem.setSpectateState(Fight.getOpposite(team), "TeamOffline"); } } } \ No newline at end of file diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java index 862fcfe..b8be083 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java @@ -34,7 +34,7 @@ public class WinconditionAllDead extends PlayerWincondition { assert fightTeam != null; // Checked with isTarget if(fightTeam.allPlayersOut()) { Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer letzte Spieler aus " + fightTeam.getColoredName() + message); - FightSystem.setSpectateState(Fight.getOpposite(fightTeam)); + FightSystem.setSpectateState(Fight.getOpposite(fightTeam), "AllDead"); } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java index c716d0c..e4b460a 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java @@ -34,7 +34,7 @@ public class WinconditionCaptainDead extends PlayerWincondition { assert fightTeam != null; // Checked with isTarget if(fightTeam.isPlayerLeader(player)) { Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + fightTeam.getColoredName() + message); - FightSystem.setSpectateState(Fight.getOpposite(fightTeam)); + FightSystem.setSpectateState(Fight.getOpposite(fightTeam), "LeaderDead"); } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java index 18974be..32d8b7c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java @@ -23,11 +23,11 @@ public class WinconditionHeartRatioTimeout extends Wincondition { double redHeartRatio = Fight.getRedTeam().getHeartRatio(); if(blueHeartRatio > redHeartRatio) - FightSystem.setSpectateState(Fight.getBlueTeam()); + FightSystem.setSpectateState(Fight.getBlueTeam(), "HeartTimeout"); else if(blueHeartRatio < redHeartRatio) - FightSystem.setSpectateState(Fight.getRedTeam()); + FightSystem.setSpectateState(Fight.getRedTeam(), "HeartTimeout"); else - FightSystem.setSpectateState(null); + FightSystem.setSpectateState(null, "HeartTimeout"); }); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java index 664c522..441f926 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java @@ -37,7 +37,7 @@ public class WinconditionPercentSystem extends ListenerWincondition { double destroyPercent = doubleBlueDestroyedBlocks * 100 / schematicSize; bluePercent = destroyPercent; if(destroyPercent >= Config.PercentWin) { - FightSystem.setSpectateState(Fight.redTeam); + FightSystem.setSpectateState(Fight.redTeam, "Percent"); } //Team Red }else if(Region.isInRange(entity.getLocation(), Config.TeamRedCornerX, Config.TeamRedCornerY, Config.TeamRedCornerZ, Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ, Config.BorderFromSchematic)) { @@ -46,7 +46,7 @@ public class WinconditionPercentSystem extends ListenerWincondition { double destroyPercent = doubleRedDestroyedBlocks * 100 / schematicSize; redPercent = destroyPercent; if(destroyPercent >= Config.PercentWin) { - FightSystem.setSpectateState(Fight.blueTeam); + FightSystem.setSpectateState(Fight.blueTeam, "Percent"); } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java index 6bbfea8..e0161a8 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java @@ -80,11 +80,11 @@ public class WinconditionPoints extends PlayerWincondition { private void fightEnds(){ if(red.getPoints() > blue.getPoints()) - FightSystem.setSpectateState(blue.enemy); + FightSystem.setSpectateState(blue.enemy, "Points"); else if(red.getPoints() < blue.getPoints()) - FightSystem.setSpectateState(red.enemy); + FightSystem.setSpectateState(red.enemy, "Points"); else - FightSystem.setSpectateState(null); + FightSystem.setSpectateState(null, "Points"); } private TeamPoints getEnemyByTeam(FightTeam team){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java index 6dc6d23..c59d1ae 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java @@ -76,7 +76,7 @@ public class WinconditionPumpkinTechKO extends Wincondition { private static void checkKO(FightTeam team, int pumpkins){ if(pumpkins == 0){ Bukkit.broadcastMessage(FightSystem.PREFIX + "§eDas Team " + team.getColoredName() + " §eist Tech K.O.!"); - Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team))); + Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team), "PumpkinTechKO")); } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java index 413047b..c5a1ac7 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java @@ -105,7 +105,7 @@ public class WinconditionRelativePercent extends Wincondition{ return; if(getPercent() * 100 >= Config.PercentWin){ Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Schiff von " + team.getColoredName() + " §cwurde zu stark beschädigt!"); - FightSystem.setSpectateState(Fight.getOpposite(team)); + FightSystem.setSpectateState(Fight.getOpposite(team), "RelativePercent"); } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java index a2c46ad..6b95af1 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java @@ -17,7 +17,7 @@ public class WinconditionTimeout extends Wincondition { @Override public void enable() { - countdown = new TimeOverCountdown(() -> FightSystem.setSpectateState(null)); + countdown = new TimeOverCountdown(() -> FightSystem.setSpectateState(null, "Timeout")); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java index 84c66ae..f845bca 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java @@ -63,7 +63,7 @@ public class WinconditionWaterTechKO extends Wincondition { private void checkEmpty(FightTeam team, Set teamWater){ if(teamWater.isEmpty()){ Bukkit.broadcastMessage(FightSystem.PREFIX + "§eDas Team " + team.getColoredName() + " §eist Tech K.O.!"); - Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team))); + Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team), "WaterTechKO")); } } From 668f2c948ff6ba857dfc4e800e82f289b7199437 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 26 Jan 2020 08:46:47 +0100 Subject: [PATCH 7/7] Useless commit to test building Signed-off-by: Lixfel --- FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java | 1 - 1 file changed, 1 deletion(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index d188516..1cad9d3 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -139,7 +139,6 @@ public class FightSystem extends JavaPlugin { Bukkit.broadcastMessage(PREFIX + "§aDer Kampf beginnt!"); mainCountdown = new PreRunningCountdown(); - Fight.replaceSync(); if(Config.event())