From ac0a0eb24df3aff44f0f46452f820909d4c0b59b Mon Sep 17 00:00:00 2001 From: "nat.io" Date: Tue, 19 Sep 2023 23:40:37 +0200 Subject: [PATCH 01/11] Initialize DAC --- games/dac/build.gradle.kts | 23 +++++ .../ludos/games/dac/EventListener.java | 36 +++++++ .../efreicraft/ludos/games/dac/GameLogic.java | 22 +++++ .../efreicraft/ludos/games/dac/LudosGame.java | 96 +++++++++++++++++++ .../fr/efreicraft/ludos/games/dac/Main.java | 16 ++++ settings.gradle.kts | 3 +- 6 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 games/dac/build.gradle.kts create mode 100644 games/dac/src/main/java/fr/efreicraft/ludos/games/dac/EventListener.java create mode 100644 games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java create mode 100644 games/dac/src/main/java/fr/efreicraft/ludos/games/dac/LudosGame.java create mode 100644 games/dac/src/main/java/fr/efreicraft/ludos/games/dac/Main.java diff --git a/games/dac/build.gradle.kts b/games/dac/build.gradle.kts new file mode 100644 index 0000000..0c2e701 --- /dev/null +++ b/games/dac/build.gradle.kts @@ -0,0 +1,23 @@ +import net.minecrell.pluginyml.bukkit.BukkitPluginDescription + +plugins { + `java-library` + id("net.minecrell.plugin-yml.bukkit") version "0.5.2" // Generates plugin.yml +} + +dependencies { + implementation(project(":core")) + + compileOnly("io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT") + + compileOnly("fr.efreicraft:ECATUP:latest.integration") +} + +bukkit { + load = BukkitPluginDescription.PluginLoadOrder.POSTWORLD + name = "LudosDAC" + main = "fr.efreicraft.ludos.games.dac.Main" + apiVersion = "1.19" + authors = listOf("Nat.io") + prefix = "DAC" +} \ No newline at end of file diff --git a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/EventListener.java b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/EventListener.java new file mode 100644 index 0000000..13e6b22 --- /dev/null +++ b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/EventListener.java @@ -0,0 +1,36 @@ +package fr.efreicraft.ludos.games.dac; + +import fr.efreicraft.ludos.core.Core; +import fr.efreicraft.ludos.core.players.LudosPlayer; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.player.PlayerMoveEvent; + +public record EventListener(GameLogic sumo) implements Listener { + + @EventHandler + public void onPlayerMove(PlayerMoveEvent event) { + if (!event.hasChangedBlock()) { + return; + } + LudosPlayer player = Core.get().getPlayerManager().getPlayer(event.getPlayer()); + if (!player.getTeam().isPlayingTeam()) { + return; + } + if (this.sumo.isOutsideKillzone(event.getTo().getY())) { + sumo.onPlayerBelowKillzone(player); + } + } + + @EventHandler + public void onDamage(EntityDamageEvent event) { + if (event.getEntity() instanceof org.bukkit.entity.Player bukkitPlayer) { + LudosPlayer player = Core.get().getPlayerManager().getPlayer(bukkitPlayer); + if (!player.getTeam().isPlayingTeam()) { + return; + } + event.setDamage(0); + } + } +} diff --git a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java new file mode 100644 index 0000000..a0eeff9 --- /dev/null +++ b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java @@ -0,0 +1,22 @@ +package fr.efreicraft.ludos.games.dac; + +import fr.efreicraft.ludos.core.players.LudosPlayer; +import fr.efreicraft.ludos.core.utils.MessageUtils; +import org.bukkit.Location; + +public class GameLogic { + private int killZonePositionY; + + public void setKillZoneLocation(Location killZoneLocation) { + this.killZonePositionY = killZoneLocation.getBlockY(); + } + + public boolean isOutsideKillzone(double positionY) { + return killZonePositionY > positionY; + } + + public void onPlayerBelowKillzone(LudosPlayer player) { + player.entity().setHealth(0); + player.sendMessage(MessageUtils.ChatPrefix.GAME, "Vous avez été éliminé !"); + } +} diff --git a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/LudosGame.java b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/LudosGame.java new file mode 100644 index 0000000..e621869 --- /dev/null +++ b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/LudosGame.java @@ -0,0 +1,96 @@ +package fr.efreicraft.ludos.games.dac; + +import com.google.common.collect.ImmutableMap; +import fr.efreicraft.ludos.core.Core; +import fr.efreicraft.ludos.core.games.annotations.GameMetadata; +import fr.efreicraft.ludos.core.games.annotations.GameRules; +import fr.efreicraft.ludos.core.games.interfaces.Game; +import fr.efreicraft.ludos.core.players.LudosPlayer; +import fr.efreicraft.ludos.core.teams.TeamRecord; +import fr.efreicraft.ludos.core.utils.ColorUtils; +import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.*; + +import java.util.EnumMap; +import java.util.Map; + +import static fr.efreicraft.ludos.core.teams.DefaultTeamRecordBuilder.DefaultTeamRecords.ONLY_SPECTATOR; + +@GameMetadata( + name = "Dé à coudre", + description = "Poussez votre adversaire en dehors du ring pour gagner !", + authors = {"Nat.io"}, + color = "&b", + rules = @GameRules( + minPlayers = 2, + maxPlayers = 2 + ) +) +public class LudosGame extends Game { + + private final GameLogic gameLogic; + + public LudosGame() { + super(); + this.gameLogic = new GameLogic(); + this.setEventListener(new EventListener(this.gameLogic)); + } + + @Override + public void preMapParse(World world) { + // Nothing to do here + } + + @Override + public void beginGame() { + super.beginGame(); + Core.get().getTeamManager().getTeam("PLAYERS").setFriendlyFire(true); + } + + @Override + public void postMapParse() { + this.gameLogic.setKillZoneLocation( + Core.get().getMapManager().getCurrentMap().getGamePoints().get("KILL_ZONE").get(0).getLocation() + ); + } + + @Override + public void setupScoreboard(LudosPlayer player) { + // No scoreboard for now + } + + @Override + public EnumMap getGamePointsMaterials() { + EnumMap gamePointsMaterials = new EnumMap<>(Material.class); + gamePointsMaterials.put(Material.BEDROCK, "KILL_ZONE"); + return gamePointsMaterials; + } + + @Override + public Map getTeamRecords() { + return ImmutableMap.builder() + .put("PLAYERS", new TeamRecord( + "Joueurs", + 1, + false, + true, + new ColorUtils.TeamColorSet(NamedTextColor.GRAY, DyeColor.WHITE, Color.WHITE), + null, + p -> { + p.entity().setHealth(20); + p.entity().setFoodLevel(20); + p.entity().setSaturation(20); + p.entity().setExp(0); + p.entity().setLevel(0); + p.entity().getInventory().clear(); + p.entity().getInventory().setArmorContents(null); + p.entity().setGameMode(GameMode.ADVENTURE); +// ItemStack kbstick = new ItemStack(Material.STICK); +// kbstick.addUnsafeEnchantment(Enchantment.KNOCKBACK, 1); +// p.entity().getInventory().setItem(0, kbstick); + } + )) + .putAll(ONLY_SPECTATOR.getTeamRecords()) + .build(); + } +} diff --git a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/Main.java b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/Main.java new file mode 100644 index 0000000..88bd358 --- /dev/null +++ b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/Main.java @@ -0,0 +1,16 @@ +package fr.efreicraft.ludos.games.dac; + +import fr.efreicraft.ludos.core.games.interfaces.Game; +import fr.efreicraft.ludos.core.games.interfaces.GamePlugin; + +public class Main extends GamePlugin { + + public Main() { + super(); + } + + @Override + public Class getGameClass() { + return LudosGame.class; + } +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 0ec0d11..41378fc 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -13,7 +13,8 @@ include ( "games:arena", "games:spleef", "games:rush", - "games:sumo" + "games:sumo", + "games:dac" ) if (System.getenv("NEXUS_REPOSITORY") == null) { From ade907522b5efdcf7ea85f5a5d7cc2b513c3344d Mon Sep 17 00:00:00 2001 From: "nat.io" Date: Fri, 6 Oct 2023 18:07:24 +0200 Subject: [PATCH 02/11] Initialize DAC and add a suport for special character --- .../core/games/annotations/GameMetadata.java | 6 ++++++ .../ludos/core/maps/MapManager.java | 10 ++++++++-- .../ludos/games/dac/EventListener.java | 8 +++++--- .../efreicraft/ludos/games/dac/GameLogic.java | 20 +++++++++++-------- .../efreicraft/ludos/games/dac/LudosGame.java | 10 ++++++---- 5 files changed, 37 insertions(+), 17 deletions(-) diff --git a/core/src/main/java/fr/efreicraft/ludos/core/games/annotations/GameMetadata.java b/core/src/main/java/fr/efreicraft/ludos/core/games/annotations/GameMetadata.java index feef3c8..543cecf 100644 --- a/core/src/main/java/fr/efreicraft/ludos/core/games/annotations/GameMetadata.java +++ b/core/src/main/java/fr/efreicraft/ludos/core/games/annotations/GameMetadata.java @@ -18,6 +18,12 @@ */ String name(); + /** + * Nom du dossier de la map. + * @return Nom du dossier de la map. + */ + String mapFolder() default ""; + /** * Couleur du jeu. * @return Couleur du jeu. diff --git a/core/src/main/java/fr/efreicraft/ludos/core/maps/MapManager.java b/core/src/main/java/fr/efreicraft/ludos/core/maps/MapManager.java index 5b4a376..4d3a162 100644 --- a/core/src/main/java/fr/efreicraft/ludos/core/maps/MapManager.java +++ b/core/src/main/java/fr/efreicraft/ludos/core/maps/MapManager.java @@ -74,6 +74,7 @@ public void runManager() { setupLobbyWorld(); } + /** * Répertorie les cartes disponibles d'un jeu, accompagnées de leur type. * Cette fonction est appelée à chaque changement de jeu. @@ -81,8 +82,13 @@ public void runManager() { */ public void setupCurrentGameMaps(Game game) { if (!this.currentGameMaps.isEmpty()) clearGameMaps(); - - File dataFolder = new File(Core.get().getPlugin().getDataFolder(), "game_maps/" + game.getMetadata().name()); + String name; + if (game.getMetadata().mapFolder().isEmpty()) { + name = game.getMetadata().name(); + } else { + name = game.getMetadata().mapFolder(); + } + File dataFolder = new File(Core.get().getPlugin().getDataFolder(), "game_maps/" + name); if(dataFolder.exists()) { for (File file : Objects.requireNonNull(dataFolder.listFiles())) { if (file.isFile() && file.getName().endsWith(".schem")) { diff --git a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/EventListener.java b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/EventListener.java index 13e6b22..bf4f0b7 100644 --- a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/EventListener.java +++ b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/EventListener.java @@ -7,7 +7,7 @@ import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.player.PlayerMoveEvent; -public record EventListener(GameLogic sumo) implements Listener { +public record EventListener(GameLogic dac) implements Listener { @EventHandler public void onPlayerMove(PlayerMoveEvent event) { @@ -18,8 +18,10 @@ public void onPlayerMove(PlayerMoveEvent event) { if (!player.getTeam().isPlayingTeam()) { return; } - if (this.sumo.isOutsideKillzone(event.getTo().getY())) { - sumo.onPlayerBelowKillzone(player); + if (this.dac.isInWater(event.getTo().getY())) { + dac.onPlayerInWater(player); + } else { + dac.onPlayerTouchingGround(player); } } diff --git a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java index a0eeff9..f4296d9 100644 --- a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java +++ b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java @@ -5,18 +5,22 @@ import org.bukkit.Location; public class GameLogic { - private int killZonePositionY; + private int prismarinePositionY; - public void setKillZoneLocation(Location killZoneLocation) { - this.killZonePositionY = killZoneLocation.getBlockY(); + public void setPrismarineLocation(Location prismarineLocation) { + this.prismarinePositionY = prismarineLocation.getBlockY(); } - public boolean isOutsideKillzone(double positionY) { - return killZonePositionY > positionY; + public boolean isInWater(double positionY) { + return prismarinePositionY < positionY; } - public void onPlayerBelowKillzone(LudosPlayer player) { - player.entity().setHealth(0); - player.sendMessage(MessageUtils.ChatPrefix.GAME, "Vous avez été éliminé !"); + public void onPlayerInWater(LudosPlayer player) { + + + } + public void onPlayerTouchingGround(LudosPlayer player) { + player.sendMessage(MessageUtils.ChatPrefix.GAME, "Vous êtes tombé sur un bloc ! Vous êtes éliminé !"); + } } diff --git a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/LudosGame.java b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/LudosGame.java index e621869..7686eb4 100644 --- a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/LudosGame.java +++ b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/LudosGame.java @@ -18,9 +18,11 @@ @GameMetadata( name = "Dé à coudre", - description = "Poussez votre adversaire en dehors du ring pour gagner !", + description = "Essayer de tomber dans l'eau et passez les trois rounds pour gagner !", authors = {"Nat.io"}, color = "&b", + mapFolder = "DAC", + rules = @GameRules( minPlayers = 2, maxPlayers = 2 @@ -49,8 +51,8 @@ public void beginGame() { @Override public void postMapParse() { - this.gameLogic.setKillZoneLocation( - Core.get().getMapManager().getCurrentMap().getGamePoints().get("KILL_ZONE").get(0).getLocation() + this.gameLogic.setPrismarineLocation( + Core.get().getMapManager().getCurrentMap().getGamePoints().get("PRISMARINE").get(0).getLocation() ); } @@ -62,7 +64,7 @@ public void setupScoreboard(LudosPlayer player) { @Override public EnumMap getGamePointsMaterials() { EnumMap gamePointsMaterials = new EnumMap<>(Material.class); - gamePointsMaterials.put(Material.BEDROCK, "KILL_ZONE"); + gamePointsMaterials.put(Material.PRISMARINE, "PRISMARINE"); return gamePointsMaterials; } From fce71bf471b17558eab343297363b9463aa19cbb Mon Sep 17 00:00:00 2001 From: "nat.io" Date: Fri, 6 Oct 2023 20:52:05 +0200 Subject: [PATCH 03/11] Refactor to getMapFolder --- .../ludos/core/maps/MapManager.java | 48 ++++++++++++------- .../efreicraft/ludos/games/dac/GameLogic.java | 9 ++-- .../efreicraft/ludos/games/dac/LudosGame.java | 9 ++-- 3 files changed, 40 insertions(+), 26 deletions(-) diff --git a/core/src/main/java/fr/efreicraft/ludos/core/maps/MapManager.java b/core/src/main/java/fr/efreicraft/ludos/core/maps/MapManager.java index 4d3a162..4116522 100644 --- a/core/src/main/java/fr/efreicraft/ludos/core/maps/MapManager.java +++ b/core/src/main/java/fr/efreicraft/ludos/core/maps/MapManager.java @@ -74,6 +74,13 @@ public void runManager() { setupLobbyWorld(); } + private String getMapFolder(Game game) { + if (game.getMetadata().mapFolder().isEmpty()) { + return game.getMetadata().name(); + } else { + return game.getMetadata().mapFolder(); + } + } /** * Répertorie les cartes disponibles d'un jeu, accompagnées de leur type. @@ -82,13 +89,8 @@ public void runManager() { */ public void setupCurrentGameMaps(Game game) { if (!this.currentGameMaps.isEmpty()) clearGameMaps(); - String name; - if (game.getMetadata().mapFolder().isEmpty()) { - name = game.getMetadata().name(); - } else { - name = game.getMetadata().mapFolder(); - } - File dataFolder = new File(Core.get().getPlugin().getDataFolder(), "game_maps/" + name); + + File dataFolder = new File(Core.get().getPlugin().getDataFolder(), "game_maps/" + getMapFolder(game)); if(dataFolder.exists()) { for (File file : Objects.requireNonNull(dataFolder.listFiles())) { if (file.isFile() && file.getName().endsWith(".schem")) { @@ -216,7 +218,7 @@ private ParseMapArgs loadSchematicMap(String mapName) throws MapLoadingException try { schematic = SchematicUtils.loadSchematic( - Core.get().getGameManager().getCurrentGame().getMetadata().name() + "/" + mapName + getMapFolder(Core.get().getGameManager().getCurrentGame()) + "/" + mapName ); } catch (IOException e) { WorldUtils.deleteWorld(world); @@ -278,12 +280,19 @@ private ParseMapArgs loadSchematicMap(String mapName) throws MapLoadingException private ParseMapArgs loadFolderMap(String mapName) throws MapLoadingException { Core.get().getLogger().log(Level.INFO, "Copying world folder {0}...", mapName); - File sourceFolder = new File(Core.get().getPlugin().getDataFolder(), - "game_maps/" + Core.get().getGameManager().getCurrentGame().getMetadata().name() + "/" + mapName); - if (!sourceFolder.isDirectory()) throw new MapLoadingException(mapName + " n'est pas un dossier ou n'existe pas."); - - Core.get().getLogger().log(Level.INFO, "Path is {0}", Bukkit.getPluginsFolder().getAbsolutePath().substring(0, Bukkit.getPluginsFolder().getAbsolutePath().lastIndexOf(File.separatorChar))); - File destination = new File(Bukkit.getPluginsFolder().getAbsolutePath().substring(0, Bukkit.getPluginsFolder().getAbsolutePath().lastIndexOf(File.separatorChar))); + File sourceFolder = new File( + Core.get().getPlugin().getDataFolder(), + "game_maps/" + getMapFolder(Core.get().getGameManager().getCurrentGame()) + "/" + mapName + ); + if (!sourceFolder.isDirectory()) + throw new MapLoadingException(mapName + " n'est pas un dossier ou n'existe pas."); + + File destination = new File( + Bukkit.getPluginsFolder().getAbsolutePath().substring( + 0, + Bukkit.getPluginsFolder().getAbsolutePath().lastIndexOf(File.separatorChar) + ) + ); try { FileUtils.copyDirectory(sourceFolder, new File(destination, WorldUtils.getNormalizedWorldName(mapName))); @@ -294,14 +303,19 @@ private ParseMapArgs loadFolderMap(String mapName) throws MapLoadingException { org.bukkit.World world = WorldUtils.createWorld(mapName); if (Core.get().getGameManager().getCurrentGame() != null) { Block spongeBlock = world.getSpawnLocation().getBlock(); - if (spongeBlock.getType() != Material.SPONGE) throw new MapLoadingException("World spawn is not The Sponge Block"); + if (spongeBlock.getType() != Material.SPONGE) + throw new MapLoadingException("World spawn is not The Sponge Block"); Sign sign = (Sign) world.getBlockAt(spongeBlock.getLocation().add(0, 1, 0)).getState(); int[] coord1; int[] coord2; try { - coord1 = Arrays.stream(((TextComponent) sign.line(2)).content().split(" ")).mapToInt(Integer::parseInt).toArray(); - coord2 = Arrays.stream(((TextComponent) sign.line(3)).content().split(" ")).mapToInt(Integer::parseInt).toArray(); + coord1 = Arrays.stream(((TextComponent) sign.line(2)).content().split(" ")) + .mapToInt(Integer::parseInt) + .toArray(); + coord2 = Arrays.stream(((TextComponent) sign.line(3)).content().split(" ")) + .mapToInt(Integer::parseInt) + .toArray(); } catch (NumberFormatException e) { throw new MapLoadingException("Bad coords given on the map description Map"); } diff --git a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java index f4296d9..d58b5fd 100644 --- a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java +++ b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java @@ -5,20 +5,21 @@ import org.bukkit.Location; public class GameLogic { - private int prismarinePositionY; + private int bassinPositionY; - public void setPrismarineLocation(Location prismarineLocation) { - this.prismarinePositionY = prismarineLocation.getBlockY(); + public void setBassinLocation(Location bassinLocation) { + this.bassinPositionY = bassinLocation.getBlockY(); } public boolean isInWater(double positionY) { - return prismarinePositionY < positionY; + return bassinPositionY < positionY; } public void onPlayerInWater(LudosPlayer player) { } + public void onPlayerTouchingGround(LudosPlayer player) { player.sendMessage(MessageUtils.ChatPrefix.GAME, "Vous êtes tombé sur un bloc ! Vous êtes éliminé !"); diff --git a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/LudosGame.java b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/LudosGame.java index 7686eb4..048d7e8 100644 --- a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/LudosGame.java +++ b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/LudosGame.java @@ -24,8 +24,7 @@ mapFolder = "DAC", rules = @GameRules( - minPlayers = 2, - maxPlayers = 2 + maxPlayers = 8 ) ) public class LudosGame extends Game { @@ -51,8 +50,8 @@ public void beginGame() { @Override public void postMapParse() { - this.gameLogic.setPrismarineLocation( - Core.get().getMapManager().getCurrentMap().getGamePoints().get("PRISMARINE").get(0).getLocation() + this.gameLogic.setBassinLocation( + Core.get().getMapManager().getCurrentMap().getGamePoints().get("BASSIN").get(0).getLocation() ); } @@ -64,7 +63,7 @@ public void setupScoreboard(LudosPlayer player) { @Override public EnumMap getGamePointsMaterials() { EnumMap gamePointsMaterials = new EnumMap<>(Material.class); - gamePointsMaterials.put(Material.PRISMARINE, "PRISMARINE"); + gamePointsMaterials.put(Material.PRISMARINE_BRICKS, "BASSIN"); return gamePointsMaterials; } From ddc157105be60e9f8f583f72d835c32ed0c001ba Mon Sep 17 00:00:00 2001 From: "nat.io" Date: Fri, 13 Oct 2023 19:20:36 +0200 Subject: [PATCH 04/11] Delete Run Server --- dev/Run Server.run.xml | 44 ------------------------------------------ 1 file changed, 44 deletions(-) delete mode 100644 dev/Run Server.run.xml diff --git a/dev/Run Server.run.xml b/dev/Run Server.run.xml deleted file mode 100644 index 15682ec..0000000 --- a/dev/Run Server.run.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file From 00a46fb1ac48e3fb14d57097240aefa895929a32 Mon Sep 17 00:00:00 2001 From: "nat.io" Date: Sat, 4 Nov 2023 16:36:13 +0100 Subject: [PATCH 05/11] =?UTF-8?q?Cr=C3=A9ation=20du=20d=C3=A9=20=C3=A0=20c?= =?UTF-8?q?oudre=20et=20ajout=20des=20m=C3=A9caniques=20principales?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ludos/games/dac/EventListener.java | 8 +- .../efreicraft/ludos/games/dac/GameLogic.java | 77 +++++++++++++++++-- .../efreicraft/ludos/games/dac/LudosGame.java | 19 ++++- 3 files changed, 90 insertions(+), 14 deletions(-) diff --git a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/EventListener.java b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/EventListener.java index bf4f0b7..7e1a808 100644 --- a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/EventListener.java +++ b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/EventListener.java @@ -2,6 +2,7 @@ import fr.efreicraft.ludos.core.Core; import fr.efreicraft.ludos.core.players.LudosPlayer; +import fr.efreicraft.ludos.core.utils.MessageUtils; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageEvent; @@ -18,13 +19,14 @@ public void onPlayerMove(PlayerMoveEvent event) { if (!player.getTeam().isPlayingTeam()) { return; } - if (this.dac.isInWater(event.getTo().getY())) { - dac.onPlayerInWater(player); - } else { + if (this.dac.isInBassin(event.getTo())) { + dac.onPlayerInBassin(player); + } else if (this.dac.isOnGround(event.getTo().getY())) { dac.onPlayerTouchingGround(player); } } + @EventHandler public void onDamage(EntityDamageEvent event) { if (event.getEntity() instanceof org.bukkit.entity.Player bukkitPlayer) { diff --git a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java index d58b5fd..72b332a 100644 --- a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java +++ b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java @@ -1,27 +1,90 @@ package fr.efreicraft.ludos.games.dac; +import fr.efreicraft.ludos.core.Core; +import fr.efreicraft.ludos.core.maps.points.SpawnPoint; import fr.efreicraft.ludos.core.players.LudosPlayer; import fr.efreicraft.ludos.core.utils.MessageUtils; import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.PluginCommand; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +import java.util.Set; public class GameLogic { - private int bassinPositionY; + private Location bassinPosition; + private Location plateformePosition; + + private Location spawnPosition ; + + private Location boundary1Position; + + private Location boundary2Position; + + private int round = 2; + + public void setBassinLocation(Location bassinLocation) { - this.bassinPositionY = bassinLocation.getBlockY(); + this.bassinPosition = bassinLocation; + } + public void setPlateformeLocation(Location plateformeLocation) { + this.plateformePosition = plateformeLocation.getBlock().getLocation(); + this.plateformePosition.setPitch(0); + this.plateformePosition.setYaw(180); + } + public void setPlateformeBoundaries(Location boundary1Location, Location boundary2Location) { + this.boundary1Position = boundary1Location; + this.boundary2Position = boundary2Location; } - public boolean isInWater(double positionY) { - return bassinPositionY < positionY; + public void setSpawnPosition(Location spawnLocation) { + this.spawnPosition = spawnLocation; + } + public boolean isInBassin(Location position) { + return bassinPosition.getBlockY() > position.getY() & bassinPosition.getBlockY()-2 position.getX() & bassinPosition.getBlockX() -4< position.getX() & bassinPosition.getBlockZ() +4> position.getZ() & bassinPosition.getBlockZ() -4< position.getZ(); } - public void onPlayerInWater(LudosPlayer player) { + public boolean isOnGround(double positionY){return bassinPosition.getBlockY()==positionY;} + public void onPlayerInBassin(LudosPlayer player) { + player.sendMessage(MessageUtils.ChatPrefix.GAME, "Tombé dans l'eau"); + Core.get().getMapManager().getCurrentMap().getWorld().setBlockData(new Location(Core.get().getMapManager().getCurrentMap().getWorld(),player.entity().getLocation().getBlockX(),bassinPosition.getY()-1,player.entity().getLocation().getBlockZ()), Material.BLACK_CONCRETE.createBlockData()); + movePlateforme(this.round); + player.entity().teleport(this.spawnPosition); } - public void onPlayerTouchingGround(LudosPlayer player) { - player.sendMessage(MessageUtils.ChatPrefix.GAME, "Vous êtes tombé sur un bloc ! Vous êtes éliminé !"); + public void movePlateforme(int round){ + int decalagePlateforme=30*(round-1); + for (int y=this.boundary2Position.getBlockY();y>=this.boundary1Position.getBlockY();y--) { + for (int z = this.boundary2Position.getBlockZ(); z <= this.boundary1Position.getBlockZ(); z++) { + for (int x = this.boundary2Position.getBlockX(); x <= this.boundary1Position.getBlockX(); x++) { + Core.get().getMapManager().getCurrentMap().getWorld().getBlockAt(x, y+decalagePlateforme, z).setType(Core.get().getMapManager().getCurrentMap().getWorld().getBlockAt(x, y, z).getType()); + Core.get().getMapManager().getCurrentMap().getWorld().getBlockAt(x, y, z).setType(Material.AIR); + } + }} + this.plateformePosition.setY(this.plateformePosition.getY()+decalagePlateforme); } + + public void onPlayerTouchingGround(LudosPlayer player) { + player.sendMessage(MessageUtils.ChatPrefix.GAME, "Vous êtes tombé sur une bloc ! Vous êtes éliminé !"); + } + public void playRound(int round){ + Set players = Core.get().getPlayerManager().getPlayers(); + if (!(round==1)){ + movePlateforme(round); + } + while(players.size()<8) { + for (LudosPlayer currentPlayer : players) { + if (currentPlayer.getTeam().isPlayingTeam()) { + currentPlayer.entity().teleport(plateformePosition); + } + } + } + this.round = round; + } } diff --git a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/LudosGame.java b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/LudosGame.java index 048d7e8..45e403f 100644 --- a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/LudosGame.java +++ b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/LudosGame.java @@ -45,7 +45,7 @@ public void preMapParse(World world) { @Override public void beginGame() { super.beginGame(); - Core.get().getTeamManager().getTeam("PLAYERS").setFriendlyFire(true); + Core.get().getTeamManager().getTeam("PLAYERS").setFriendlyFire(false); } @Override @@ -53,6 +53,17 @@ public void postMapParse() { this.gameLogic.setBassinLocation( Core.get().getMapManager().getCurrentMap().getGamePoints().get("BASSIN").get(0).getLocation() ); + this.gameLogic.setPlateformeLocation( + Core.get().getMapManager().getCurrentMap().getGamePoints().get("SPAWN_PLATEFORME").get(0).getLocation() + ); + this.gameLogic.setPlateformeBoundaries( + Core.get().getMapManager().getCurrentMap().getGamePoints().get("BORDER_PLATEFORME").get(0).getLocation(), + Core.get().getMapManager().getCurrentMap().getGamePoints().get("BORDER_PLATEFORME").get(1).getLocation() + ); + this.gameLogic.setSpawnPosition( + Core.get().getMapManager().getCurrentMap().getSpawnPoints().get(Core.get().getTeamManager().getTeam("PLAYERS")).get(5).getLocation() + ); + } @Override @@ -64,6 +75,8 @@ public void setupScoreboard(LudosPlayer player) { public EnumMap getGamePointsMaterials() { EnumMap gamePointsMaterials = new EnumMap<>(Material.class); gamePointsMaterials.put(Material.PRISMARINE_BRICKS, "BASSIN"); + gamePointsMaterials.put(Material.END_STONE_BRICKS, "BORDER_PLATEFORME"); + gamePointsMaterials.put(Material.CHISELED_STONE_BRICKS,"SPAWN_PLATEFORME"); return gamePointsMaterials; } @@ -86,9 +99,7 @@ public Map getTeamRecords() { p.entity().getInventory().clear(); p.entity().getInventory().setArmorContents(null); p.entity().setGameMode(GameMode.ADVENTURE); -// ItemStack kbstick = new ItemStack(Material.STICK); -// kbstick.addUnsafeEnchantment(Enchantment.KNOCKBACK, 1); -// p.entity().getInventory().setItem(0, kbstick); + } )) .putAll(ONLY_SPECTATOR.getTeamRecords()) From 6538218b2e19fb3279743903277406bcc14bd645 Mon Sep 17 00:00:00 2001 From: "nat.io" Date: Sat, 9 Dec 2023 18:04:13 +0100 Subject: [PATCH 06/11] =?UTF-8?q?Correction=20de=20certain=20probl=C3=A8me?= =?UTF-8?q?=20et=20ajout=20de=20la=20gestion=20des=20rounds=20et=20autre?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../efreicraft/ludos/games/dac/GameLogic.java | 67 +++++++++++++++---- .../efreicraft/ludos/games/dac/LudosGame.java | 9 ++- 2 files changed, 60 insertions(+), 16 deletions(-) diff --git a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java index 72b332a..a5d40d8 100644 --- a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java +++ b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java @@ -3,7 +3,10 @@ import fr.efreicraft.ludos.core.Core; import fr.efreicraft.ludos.core.maps.points.SpawnPoint; import fr.efreicraft.ludos.core.players.LudosPlayer; +import fr.efreicraft.ludos.core.teams.Team; +import fr.efreicraft.ludos.core.utils.ActionBarUtils; import fr.efreicraft.ludos.core.utils.MessageUtils; +import fr.efreicraft.ludos.core.utils.TitleUtils; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.command.Command; @@ -11,7 +14,7 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; -import java.util.Set; +import java.util.ArrayList; public class GameLogic { private Location bassinPosition; @@ -23,7 +26,11 @@ public class GameLogic { private Location boundary2Position; - private int round = 2; + private int round = 1; + + private int numberOfPlayers; + + private ArrayList players = new ArrayList<>(); @@ -35,6 +42,9 @@ public void setPlateformeLocation(Location plateformeLocation) { this.plateformePosition.setPitch(0); this.plateformePosition.setYaw(180); } + public void setNumberOfPlayers(int numberOfPlayers) { + this.numberOfPlayers = numberOfPlayers; + } public void setPlateformeBoundaries(Location boundary1Location, Location boundary2Location) { this.boundary1Position = boundary1Location; this.boundary2Position = boundary2Location; @@ -52,12 +62,13 @@ public boolean isInBassin(Location position) { public void onPlayerInBassin(LudosPlayer player) { player.sendMessage(MessageUtils.ChatPrefix.GAME, "Tombé dans l'eau"); Core.get().getMapManager().getCurrentMap().getWorld().setBlockData(new Location(Core.get().getMapManager().getCurrentMap().getWorld(),player.entity().getLocation().getBlockX(),bassinPosition.getY()-1,player.entity().getLocation().getBlockZ()), Material.BLACK_CONCRETE.createBlockData()); - movePlateforme(this.round); player.entity().teleport(this.spawnPosition); + nextPlayer(player); } public void movePlateforme(int round){ + if (!(round==1)){ int decalagePlateforme=30*(round-1); for (int y=this.boundary2Position.getBlockY();y>=this.boundary1Position.getBlockY();y--) { for (int z = this.boundary2Position.getBlockZ(); z <= this.boundary1Position.getBlockZ(); z++) { @@ -67,24 +78,52 @@ public void movePlateforme(int round){ } }} this.plateformePosition.setY(this.plateformePosition.getY()+decalagePlateforme); - + } } public void onPlayerTouchingGround(LudosPlayer player) { player.sendMessage(MessageUtils.ChatPrefix.GAME, "Vous êtes tombé sur une bloc ! Vous êtes éliminé !"); + player.setTeam(Core.get().getTeamManager().getTeam("SPECTATORS")); + player.entity().setGameMode(org.bukkit.GameMode.SPECTATOR); + players.remove(player); + nextPlayer(player); + } - public void playRound(int round){ - Set players = Core.get().getPlayerManager().getPlayers(); - if (!(round==1)){ - movePlateforme(round); + + public void nextPlayer(LudosPlayer player) { + player.sendMessage(MessageUtils.ChatPrefix.GAME, "Il reste "+players.size()+" joueurs"); + if (players.size()==1){ + TitleUtils.broadcastTitle(Core.get().getGameManager().getCurrentGame().getMetadata().color() + "Victoire de "+players.get(0).entity().getName(), "", 0, 2, 0.5f); + } - while(players.size()<8) { - for (LudosPlayer currentPlayer : players) { - if (currentPlayer.getTeam().isPlayingTeam()) { - currentPlayer.entity().teleport(plateformePosition); - } + else if (players.size() getTeamRecords() { .put("PLAYERS", new TeamRecord( "Joueurs", 1, - false, true, - new ColorUtils.TeamColorSet(NamedTextColor.GRAY, DyeColor.WHITE, Color.WHITE), + true, + new ColorUtils.TeamColorSet(NamedTextColor.GRAY, DyeColor.WHITE, Color.GRAY), null, p -> { p.entity().setHealth(20); From 6ed415f43e1387c3dd244304491d4d0559ad79b9 Mon Sep 17 00:00:00 2001 From: "nat.io" Date: Sat, 9 Dec 2023 19:40:40 +0100 Subject: [PATCH 07/11] =?UTF-8?q?Am=C3=A9lioration=20du=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../efreicraft/ludos/games/dac/GameLogic.java | 108 ++++++++---------- .../efreicraft/ludos/games/dac/LudosGame.java | 23 +--- 2 files changed, 47 insertions(+), 84 deletions(-) diff --git a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java index a5d40d8..3264446 100644 --- a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java +++ b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java @@ -1,39 +1,22 @@ package fr.efreicraft.ludos.games.dac; - import fr.efreicraft.ludos.core.Core; -import fr.efreicraft.ludos.core.maps.points.SpawnPoint; import fr.efreicraft.ludos.core.players.LudosPlayer; -import fr.efreicraft.ludos.core.teams.Team; -import fr.efreicraft.ludos.core.utils.ActionBarUtils; import fr.efreicraft.ludos.core.utils.MessageUtils; import fr.efreicraft.ludos.core.utils.TitleUtils; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.command.Command; -import org.bukkit.command.PluginCommand; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - import java.util.ArrayList; - +import java.util.List; public class GameLogic { + private List players = new ArrayList<>(); private Location bassinPosition; private Location plateformePosition; - - private Location spawnPosition ; - + private Location spawnPosition; private Location boundary1Position; - private Location boundary2Position; - private int round = 1; - private int numberOfPlayers; - - private ArrayList players = new ArrayList<>(); - - - + private double limitOfPlayers; public void setBassinLocation(Location bassinLocation) { this.bassinPosition = bassinLocation; } @@ -45,84 +28,83 @@ public void setPlateformeLocation(Location plateformeLocation) { public void setNumberOfPlayers(int numberOfPlayers) { this.numberOfPlayers = numberOfPlayers; } + public void setLimitOfPlayers(int numberOfPlayers) {this.limitOfPlayers = Math.ceil(numberOfPlayers/2);} public void setPlateformeBoundaries(Location boundary1Location, Location boundary2Location) { this.boundary1Position = boundary1Location; this.boundary2Position = boundary2Location; } - public void setSpawnPosition(Location spawnLocation) { this.spawnPosition = spawnLocation; } public boolean isInBassin(Location position) { - return bassinPosition.getBlockY() > position.getY() & bassinPosition.getBlockY()-2 position.getX() & bassinPosition.getBlockX() -4< position.getX() & bassinPosition.getBlockZ() +4> position.getZ() & bassinPosition.getBlockZ() -4< position.getZ(); + return bassinPosition.getBlockY() > position.getY() & bassinPosition.getBlockY() - 2 < position.getY() + & bassinPosition.getBlockX() + 4 > position.getX() & bassinPosition.getBlockX() - 4 < position.getX() + & bassinPosition.getBlockZ() + 4 > position.getZ() & bassinPosition.getBlockZ() - 4 < position.getZ(); + } + public boolean isOnGround(double positionY) { + return bassinPosition.getBlockY() == positionY; } - - public boolean isOnGround(double positionY){return bassinPosition.getBlockY()==positionY;} - public void onPlayerInBassin(LudosPlayer player) { player.sendMessage(MessageUtils.ChatPrefix.GAME, "Tombé dans l'eau"); - Core.get().getMapManager().getCurrentMap().getWorld().setBlockData(new Location(Core.get().getMapManager().getCurrentMap().getWorld(),player.entity().getLocation().getBlockX(),bassinPosition.getY()-1,player.entity().getLocation().getBlockZ()), Material.BLACK_CONCRETE.createBlockData()); + Core.get().getMapManager().getCurrentMap().getWorld().setBlockData(new Location(Core.get().getMapManager().getCurrentMap().getWorld(), + player.entity().getLocation().getBlockX(), + bassinPosition.getY() - 1, + player.entity().getLocation().getBlockZ()), + Material.BLACK_CONCRETE.createBlockData()); player.entity().teleport(this.spawnPosition); nextPlayer(player); - } - - public void movePlateforme(int round){ - if (!(round==1)){ - int decalagePlateforme=30*(round-1); - for (int y=this.boundary2Position.getBlockY();y>=this.boundary1Position.getBlockY();y--) { - for (int z = this.boundary2Position.getBlockZ(); z <= this.boundary1Position.getBlockZ(); z++) { - for (int x = this.boundary2Position.getBlockX(); x <= this.boundary1Position.getBlockX(); x++) { - Core.get().getMapManager().getCurrentMap().getWorld().getBlockAt(x, y+decalagePlateforme, z).setType(Core.get().getMapManager().getCurrentMap().getWorld().getBlockAt(x, y, z).getType()); - Core.get().getMapManager().getCurrentMap().getWorld().getBlockAt(x, y, z).setType(Material.AIR); + public void movePlateforme(int round) { + if (round != 1) { + int decalagePlateforme = 30 * (round - 1); + for (int y = this.boundary2Position.getBlockY(); y >= this.boundary1Position.getBlockY(); y--) { + for (int z = this.boundary2Position.getBlockZ(); z <= this.boundary1Position.getBlockZ(); z++) { + for (int x = this.boundary2Position.getBlockX(); x <= this.boundary1Position.getBlockX(); x++) { + Core.get().getMapManager().getCurrentMap().getWorld() + .getBlockAt(x, y + decalagePlateforme, z).setType(Core.get().getMapManager().getCurrentMap().getWorld().getBlockAt(x, y, z).getType()); + Core.get().getMapManager().getCurrentMap().getWorld().getBlockAt(x, y, z).setType(Material.AIR); + } } - }} - this.plateformePosition.setY(this.plateformePosition.getY()+decalagePlateforme); + } + this.plateformePosition.setY(this.plateformePosition.getY() + decalagePlateforme); } } - public void onPlayerTouchingGround(LudosPlayer player) { player.sendMessage(MessageUtils.ChatPrefix.GAME, "Vous êtes tombé sur une bloc ! Vous êtes éliminé !"); player.setTeam(Core.get().getTeamManager().getTeam("SPECTATORS")); player.entity().setGameMode(org.bukkit.GameMode.SPECTATOR); players.remove(player); nextPlayer(player); - } - public void nextPlayer(LudosPlayer player) { - player.sendMessage(MessageUtils.ChatPrefix.GAME, "Il reste "+players.size()+" joueurs"); - if (players.size()==1){ - TitleUtils.broadcastTitle(Core.get().getGameManager().getCurrentGame().getMetadata().color() + "Victoire de "+players.get(0).entity().getName(), "", 0, 2, 0.5f); - - } - else if (players.size() getGamePointsMaterials() { EnumMap gamePointsMaterials = new EnumMap<>(Material.class); gamePointsMaterials.put(Material.PRISMARINE_BRICKS, "BASSIN"); gamePointsMaterials.put(Material.END_STONE_BRICKS, "BORDER_PLATEFORME"); - gamePointsMaterials.put(Material.CHISELED_STONE_BRICKS,"SPAWN_PLATEFORME"); + gamePointsMaterials.put(Material.CHISELED_STONE_BRICKS, "SPAWN_PLATEFORME"); return gamePointsMaterials; } - @Override public Map getTeamRecords() { return ImmutableMap.builder() @@ -104,7 +86,6 @@ public Map getTeamRecords() { p.entity().getInventory().clear(); p.entity().getInventory().setArmorContents(null); p.entity().setGameMode(GameMode.ADVENTURE); - } )) .putAll(ONLY_SPECTATOR.getTeamRecords()) From 4c5a4fe2e97a6adeef23772f0123ee3d5ae8b2e0 Mon Sep 17 00:00:00 2001 From: JiveOff Date: Sun, 10 Dec 2023 16:10:50 +0100 Subject: [PATCH 08/11] =?UTF-8?q?=F0=9F=94=A8=20Fix=20code=20style=20+=20i?= =?UTF-8?q?gnore=20games?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/codeStyles/Project.xml | 54 ++++++++++++ .idea/codeStyles/codeStyleConfig.xml | 5 ++ build.gradle.kts | 4 + .../efreicraft/ludos/games/dac/GameLogic.java | 84 ++++++++++++++----- 4 files changed, 128 insertions(+), 19 deletions(-) create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..a2287ef --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,54 @@ + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 43c2c0c..78e813e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,6 +9,10 @@ java { subprojects { + if(project.name == "games") { + return@subprojects + } + apply(plugin = "maven-publish") apply(plugin = "java") diff --git a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java index 3264446..338e537 100644 --- a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java +++ b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java @@ -1,14 +1,18 @@ package fr.efreicraft.ludos.games.dac; + import fr.efreicraft.ludos.core.Core; import fr.efreicraft.ludos.core.players.LudosPlayer; import fr.efreicraft.ludos.core.utils.MessageUtils; import fr.efreicraft.ludos.core.utils.TitleUtils; import org.bukkit.Location; import org.bukkit.Material; + import java.util.ArrayList; import java.util.List; + public class GameLogic { - private List players = new ArrayList<>(); + + private final List players = new ArrayList<>(); private Location bassinPosition; private Location plateformePosition; private Location spawnPosition; @@ -17,51 +21,80 @@ public class GameLogic { private int round = 1; private int numberOfPlayers; private double limitOfPlayers; + public void setBassinLocation(Location bassinLocation) { this.bassinPosition = bassinLocation; } + public void setPlateformeLocation(Location plateformeLocation) { this.plateformePosition = plateformeLocation.getBlock().getLocation(); this.plateformePosition.setPitch(0); this.plateformePosition.setYaw(180); } + public void setNumberOfPlayers(int numberOfPlayers) { this.numberOfPlayers = numberOfPlayers; } - public void setLimitOfPlayers(int numberOfPlayers) {this.limitOfPlayers = Math.ceil(numberOfPlayers/2);} + + public void setLimitOfPlayers(int numberOfPlayers) { + this.limitOfPlayers = Math.ceil((double) numberOfPlayers / 2); + } + public void setPlateformeBoundaries(Location boundary1Location, Location boundary2Location) { this.boundary1Position = boundary1Location; this.boundary2Position = boundary2Location; } + public void setSpawnPosition(Location spawnLocation) { this.spawnPosition = spawnLocation; } + public boolean isInBassin(Location position) { - return bassinPosition.getBlockY() > position.getY() & bassinPosition.getBlockY() - 2 < position.getY() - & bassinPosition.getBlockX() + 4 > position.getX() & bassinPosition.getBlockX() - 4 < position.getX() - & bassinPosition.getBlockZ() + 4 > position.getZ() & bassinPosition.getBlockZ() - 4 < position.getZ(); + return bassinPosition.getBlockY() > position.getY() & bassinPosition.getBlockY() - 2 < position.getY() & + bassinPosition.getBlockX() + 4 > position.getX() & bassinPosition.getBlockX() - 4 < position.getX() & + bassinPosition.getBlockZ() + 4 > position.getZ() & bassinPosition.getBlockZ() - 4 < position.getZ(); } + public boolean isOnGround(double positionY) { return bassinPosition.getBlockY() == positionY; } + public void onPlayerInBassin(LudosPlayer player) { player.sendMessage(MessageUtils.ChatPrefix.GAME, "Tombé dans l'eau"); - Core.get().getMapManager().getCurrentMap().getWorld().setBlockData(new Location(Core.get().getMapManager().getCurrentMap().getWorld(), - player.entity().getLocation().getBlockX(), - bassinPosition.getY() - 1, - player.entity().getLocation().getBlockZ()), - Material.BLACK_CONCRETE.createBlockData()); + Core.get().getMapManager().getCurrentMap().getWorld().setBlockData(new Location( + Core.get() + .getMapManager() + .getCurrentMap() + .getWorld(), + player.entity() + .getLocation() + .getBlockX(), + bassinPosition.getY() - 1, + player.entity() + .getLocation() + .getBlockZ() + ), Material.BLACK_CONCRETE.createBlockData()); player.entity().teleport(this.spawnPosition); nextPlayer(player); } + public void movePlateforme(int round) { if (round != 1) { int decalagePlateforme = 30 * (round - 1); for (int y = this.boundary2Position.getBlockY(); y >= this.boundary1Position.getBlockY(); y--) { for (int z = this.boundary2Position.getBlockZ(); z <= this.boundary1Position.getBlockZ(); z++) { for (int x = this.boundary2Position.getBlockX(); x <= this.boundary1Position.getBlockX(); x++) { - Core.get().getMapManager().getCurrentMap().getWorld() - .getBlockAt(x, y + decalagePlateforme, z).setType(Core.get().getMapManager().getCurrentMap().getWorld().getBlockAt(x, y, z).getType()); + Core.get() + .getMapManager() + .getCurrentMap() + .getWorld() + .getBlockAt(x, y + decalagePlateforme, z) + .setType(Core.get() + .getMapManager() + .getCurrentMap() + .getWorld() + .getBlockAt(x, y, z) + .getType()); Core.get().getMapManager().getCurrentMap().getWorld().getBlockAt(x, y, z).setType(Material.AIR); } } @@ -69,6 +102,7 @@ public void movePlateforme(int round) { this.plateformePosition.setY(this.plateformePosition.getY() + decalagePlateforme); } } + public void onPlayerTouchingGround(LudosPlayer player) { player.sendMessage(MessageUtils.ChatPrefix.GAME, "Vous êtes tombé sur une bloc ! Vous êtes éliminé !"); player.setTeam(Core.get().getTeamManager().getTeam("SPECTATORS")); @@ -76,32 +110,44 @@ public void onPlayerTouchingGround(LudosPlayer player) { players.remove(player); nextPlayer(player); } + public void nextPlayer(LudosPlayer player) { player.sendMessage(MessageUtils.ChatPrefix.GAME, "Il reste " + players.size() + " joueurs"); - if (players.size()==1) { - TitleUtils.broadcastTitle("&9" + "Victoire de " + players.get(0).entity().getName(), - "", 0, 2, 0.5f); - } else if (players.size() Date: Sun, 10 Dec 2023 16:11:23 +0100 Subject: [PATCH 09/11] =?UTF-8?q?=F0=9F=94=A8=20Fix=20code=20style?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ludos/games/dac/EventListener.java | 1 - .../efreicraft/ludos/games/dac/GameLogic.java | 43 +++++++++---------- .../efreicraft/ludos/games/dac/LudosGame.java | 11 +++++ 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/EventListener.java b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/EventListener.java index 7e1a808..22ae761 100644 --- a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/EventListener.java +++ b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/EventListener.java @@ -2,7 +2,6 @@ import fr.efreicraft.ludos.core.Core; import fr.efreicraft.ludos.core.players.LudosPlayer; -import fr.efreicraft.ludos.core.utils.MessageUtils; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageEvent; diff --git a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java index 338e537..20cdab3 100644 --- a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java +++ b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/GameLogic.java @@ -63,16 +63,16 @@ public void onPlayerInBassin(LudosPlayer player) { player.sendMessage(MessageUtils.ChatPrefix.GAME, "Tombé dans l'eau"); Core.get().getMapManager().getCurrentMap().getWorld().setBlockData(new Location( Core.get() - .getMapManager() - .getCurrentMap() - .getWorld(), + .getMapManager() + .getCurrentMap() + .getWorld(), player.entity() - .getLocation() - .getBlockX(), + .getLocation() + .getBlockX(), bassinPosition.getY() - 1, player.entity() - .getLocation() - .getBlockZ() + .getLocation() + .getBlockZ() ), Material.BLACK_CONCRETE.createBlockData()); player.entity().teleport(this.spawnPosition); nextPlayer(player); @@ -85,16 +85,16 @@ public void movePlateforme(int round) { for (int z = this.boundary2Position.getBlockZ(); z <= this.boundary1Position.getBlockZ(); z++) { for (int x = this.boundary2Position.getBlockX(); x <= this.boundary1Position.getBlockX(); x++) { Core.get() - .getMapManager() - .getCurrentMap() - .getWorld() - .getBlockAt(x, y + decalagePlateforme, z) - .setType(Core.get() - .getMapManager() - .getCurrentMap() - .getWorld() - .getBlockAt(x, y, z) - .getType()); + .getMapManager() + .getCurrentMap() + .getWorld() + .getBlockAt(x, y + decalagePlateforme, z) + .setType(Core.get() + .getMapManager() + .getCurrentMap() + .getWorld() + .getBlockAt(x, y, z) + .getType()); Core.get().getMapManager().getCurrentMap().getWorld().getBlockAt(x, y, z).setType(Material.AIR); } } @@ -115,17 +115,14 @@ public void nextPlayer(LudosPlayer player) { player.sendMessage(MessageUtils.ChatPrefix.GAME, "Il reste " + players.size() + " joueurs"); if (players.size() == 1) { TitleUtils.broadcastTitle("&9" + "Victoire de " + players.get(0).entity().getName(), "", 0, 2, 0.5f); - } - else if (players.size() < limitOfPlayers + Math.abs(round % 2 - 1)) { + } else if (players.size() < limitOfPlayers + Math.abs(round % 2 - 1)) { this.round++; playRound(this.round); - } - else { + } else { for (LudosPlayer currentPlayer : players) { if (currentPlayer == player && players.lastIndexOf(player) < players.size()) { players.iterator().next().entity().teleport(this.plateformePosition); - } - else { + } else { players.get(0).entity().teleport(this.plateformePosition); } } diff --git a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/LudosGame.java b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/LudosGame.java index f14adef..12d53fb 100644 --- a/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/LudosGame.java +++ b/games/dac/src/main/java/fr/efreicraft/ludos/games/dac/LudosGame.java @@ -1,4 +1,5 @@ package fr.efreicraft.ludos.games.dac; + import com.google.common.collect.ImmutableMap; import fr.efreicraft.ludos.core.Core; import fr.efreicraft.ludos.core.games.annotations.GameMetadata; @@ -9,9 +10,12 @@ import fr.efreicraft.ludos.core.utils.ColorUtils; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.*; + import java.util.EnumMap; import java.util.Map; + import static fr.efreicraft.ludos.core.teams.DefaultTeamRecordBuilder.DefaultTeamRecords.ONLY_SPECTATOR; + @GameMetadata( name = "Dé à coudre", description = "Essayer de tomber dans l'eau et passez les trois rounds pour gagner !", @@ -24,21 +28,25 @@ ) public class LudosGame extends Game { private final GameLogic gameLogic; + public LudosGame() { super(); this.gameLogic = new GameLogic(); this.setEventListener(new EventListener(this.gameLogic)); } + @Override public void preMapParse(World world) { // Nothing to do here } + @Override public void beginGame() { super.beginGame(); Core.get().getTeamManager().getTeam("PLAYERS").setFriendlyFire(false); gameLogic.onGameStart(); } + @Override public void postMapParse() { this.gameLogic.setBassinLocation( @@ -55,10 +63,12 @@ public void postMapParse() { Core.get().getMapManager().getCurrentMap().getSpawnPoints().get(Core.get().getTeamManager().getTeam("PLAYERS")).get(5).getLocation() ); } + @Override public void setupScoreboard(LudosPlayer player) { // No scoreboard for now } + @Override public EnumMap getGamePointsMaterials() { EnumMap gamePointsMaterials = new EnumMap<>(Material.class); @@ -67,6 +77,7 @@ public EnumMap getGamePointsMaterials() { gamePointsMaterials.put(Material.CHISELED_STONE_BRICKS, "SPAWN_PLATEFORME"); return gamePointsMaterials; } + @Override public Map getTeamRecords() { return ImmutableMap.builder() From 2b760ede43669e34c2e0e8d12d1dd92ed2568516 Mon Sep 17 00:00:00 2001 From: Mathu-lmn <80094438+Mathu-lmn@users.noreply.github.com> Date: Fri, 14 Jun 2024 23:13:18 +0200 Subject: [PATCH 10/11] fix(removePlayers) : fixed game status condition --- core/src/main/java/fr/efreicraft/ludos/core/teams/Team.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/fr/efreicraft/ludos/core/teams/Team.java b/core/src/main/java/fr/efreicraft/ludos/core/teams/Team.java index 5ab1842..c21c9b0 100644 --- a/core/src/main/java/fr/efreicraft/ludos/core/teams/Team.java +++ b/core/src/main/java/fr/efreicraft/ludos/core/teams/Team.java @@ -11,6 +11,7 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextDecoration; +import org.bukkit.Bukkit; import org.bukkit.Location; import java.util.HashSet; @@ -214,7 +215,7 @@ public void removePlayers(Set players) { if(player.isEphemeral() && !player.entity().hasPermission("ludos.admin")) { player.entity().kick(Component.text("Fin de la partie.")); } - if(Core.get().getGameManager().getStatus() == GameManager.GameStatus.WAITING) { + if(Core.get().getGameManager().getStatus() == GameManager.GameStatus.ENDING) { LobbyPlayerHelper.preparePlayerItems(player); } } From 5e2b9e8f3e90f4149587d34eba271677735320a9 Mon Sep 17 00:00:00 2001 From: Mathu-lmn <80094438+Mathu-lmn@users.noreply.github.com> Date: Fri, 14 Jun 2024 23:14:01 +0200 Subject: [PATCH 11/11] debug(log) : added debug logs --- .../main/java/fr/efreicraft/ludos/core/games/GameManager.java | 1 + .../java/fr/efreicraft/ludos/core/handlers/RedisHandler.java | 3 +++ 2 files changed, 4 insertions(+) diff --git a/core/src/main/java/fr/efreicraft/ludos/core/games/GameManager.java b/core/src/main/java/fr/efreicraft/ludos/core/games/GameManager.java index fa1eb3e..5241a5a 100644 --- a/core/src/main/java/fr/efreicraft/ludos/core/games/GameManager.java +++ b/core/src/main/java/fr/efreicraft/ludos/core/games/GameManager.java @@ -363,6 +363,7 @@ public void setStatus(GameStatus status) { case ENDING -> currentGame.endGame(); case WAITING -> { this.unregisterCurrentGame(); + Core.get().getLogger().log(Level.INFO, "Default game: {0}, Auto start: {1}", new Object[]{defaultGamePluginName, autoGameStart}); if (defaultGamePluginName != null && autoGameStart) { try { this.loadGame(defaultGamePluginName); diff --git a/core/src/main/java/fr/efreicraft/ludos/core/handlers/RedisHandler.java b/core/src/main/java/fr/efreicraft/ludos/core/handlers/RedisHandler.java index deff98e..2ef5c3c 100644 --- a/core/src/main/java/fr/efreicraft/ludos/core/handlers/RedisHandler.java +++ b/core/src/main/java/fr/efreicraft/ludos/core/handlers/RedisHandler.java @@ -3,10 +3,13 @@ import fr.efreicraft.animus.IRedisMessageHandler; import fr.efreicraft.ludos.core.Core; +import java.util.logging.Level; + public class RedisHandler implements IRedisMessageHandler { @Override public void run(String... args) { + Core.get().getLogger().log(Level.INFO, "Recieved Redis message with args : " + String.join(" ", args)); switch (args[0]) { case "changeRequestedGame": Core.get().getGameManager().changeDefaultGame(args[1]);