From 6c4776f88af5c23dcf757207c0c0ed25c4931d5c Mon Sep 17 00:00:00 2001 From: Steven Tracey Date: Tue, 20 Dec 2022 16:13:45 -0500 Subject: [PATCH] Work has been done --- .idea/vcs.xml | 6 ++ README.md | 6 ++ build.gradle | 2 +- .../java/org/lunamc/letthemeatcake/Game.java | 76 +++++++++++++++++++ .../lunamc/letthemeatcake/GamesManager.java | 20 +++++ .../letthemeatcake/JoinGameCommand.java | 26 +++++++ .../lunamc/letthemeatcake/LetThemEatCake.java | 38 ++++++++-- .../lunamc/letthemeatcake/PointsManager.java | 63 +++++++++++++-- 8 files changed, 221 insertions(+), 16 deletions(-) create mode 100644 .idea/vcs.xml create mode 100644 src/main/java/org/lunamc/letthemeatcake/Game.java create mode 100644 src/main/java/org/lunamc/letthemeatcake/GamesManager.java create mode 100644 src/main/java/org/lunamc/letthemeatcake/JoinGameCommand.java diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 45c4e57..20cb24b 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,8 @@ # LetThemEatCake +## Game concept + +### Goal +- Idea 1 - As you kill people, you gain their points, for each hit you gain points based on damage dealt and distance for bow shots. Winner is the person with the most points after 1 minute. +- Idea 2 - Center monument with a cake at the top, winner is the one who eats the most cake? +- Idea 3 - As you kill people, you give them your points, for each hit, the person hit gains points based on damage and distance, person with the most points gets decapitated during an end game show? Winner is the person with the least points. diff --git a/build.gradle b/build.gradle index 9d3afa9..098bdb4 100644 --- a/build.gradle +++ b/build.gradle @@ -48,4 +48,4 @@ processResources { filesMatching('plugin.yml') { expand props } -} +} \ No newline at end of file diff --git a/src/main/java/org/lunamc/letthemeatcake/Game.java b/src/main/java/org/lunamc/letthemeatcake/Game.java new file mode 100644 index 0000000..77b12dc --- /dev/null +++ b/src/main/java/org/lunamc/letthemeatcake/Game.java @@ -0,0 +1,76 @@ +package org.lunamc.letthemeatcake; + +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.ArrayList; +import java.util.List; + +public class Game { + private JavaPlugin plugin; + private boolean openStatus; + private List players; + + public Game(JavaPlugin plugin) { + this.plugin = plugin; + openStatus = true; + players = new ArrayList<>(); + } + + /** + * Adds player to the game queue + * @param player player that will join the game queue + * @return 0 if the player has been added, 1 if the game is full + */ + public int addPlayer(Player player) { + players.add(player); + if (players.size() == 8) { + openStatus = false; + return 0; + } + return 1; + } + + /** + * Adds multiple players to the game queue + * @param players array of players to be added + * @return 0 if the players have been added, 1 if the game is full, or 2 if the players have been added AND the queue is full (use to trigger start early) + */ + public int addPlayers(Player ... players) { + if (players.length <= (8 - this.players.size())) { + this.players.addAll(List.of(players)); + if (this.players.size() == 8) { + openStatus = false; + return 2; + } + return 0; + } + return 1; + } + + /** + * Adds multiple players to the game queue + * @param players array of players to be added + * @return 0 if the players have been added, 1 if the game is full, or 2 if the players have been added AND the queue is full (use to trigger start early) + */ + public int addPlayers(List players) { + if (players.size() <= (8 - this.players.size())) { + this.players.addAll(players); + if (this.players.size() == 8) { + openStatus = false; + return 2; + } + return 0; + } + return 1; + } + + public void start() { + openStatus = false; + } + + public boolean isOpen() { + return openStatus; + } + +} diff --git a/src/main/java/org/lunamc/letthemeatcake/GamesManager.java b/src/main/java/org/lunamc/letthemeatcake/GamesManager.java new file mode 100644 index 0000000..f39483a --- /dev/null +++ b/src/main/java/org/lunamc/letthemeatcake/GamesManager.java @@ -0,0 +1,20 @@ +package org.lunamc.letthemeatcake; + +import java.util.ArrayList; +import java.util.List; + +public class GamesManager { + private static List games = new ArrayList<>(); + + public static void addToGame() { + for (Game game : games) { + if (game.isOpen()) { + switch (game.addPlayers()) { + case 0: {} // Success + case 1: {} // Full + case 2: {} // Success and Full + } + } + } + } +} diff --git a/src/main/java/org/lunamc/letthemeatcake/JoinGameCommand.java b/src/main/java/org/lunamc/letthemeatcake/JoinGameCommand.java new file mode 100644 index 0000000..150b85e --- /dev/null +++ b/src/main/java/org/lunamc/letthemeatcake/JoinGameCommand.java @@ -0,0 +1,26 @@ +package org.lunamc.letthemeatcake; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; + +public class JoinGameCommand implements CommandExecutor { + + private final JavaPlugin plugin; + + public JoinGameCommand(JavaPlugin plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + if (sender instanceof Player player) { + + } + + return true; + } +} diff --git a/src/main/java/org/lunamc/letthemeatcake/LetThemEatCake.java b/src/main/java/org/lunamc/letthemeatcake/LetThemEatCake.java index d13f427..4cc893a 100644 --- a/src/main/java/org/lunamc/letthemeatcake/LetThemEatCake.java +++ b/src/main/java/org/lunamc/letthemeatcake/LetThemEatCake.java @@ -1,24 +1,48 @@ package org.lunamc.letthemeatcake; +import com.grinderwolf.swm.api.SlimePlugin; +import com.grinderwolf.swm.api.exceptions.CorruptedWorldException; +import com.grinderwolf.swm.api.exceptions.NewerFormatException; +import com.grinderwolf.swm.api.exceptions.UnknownWorldException; +import com.grinderwolf.swm.api.exceptions.WorldInUseException; +import com.grinderwolf.swm.api.loaders.SlimeLoader; +import com.grinderwolf.swm.api.world.SlimeWorld; import com.grinderwolf.swm.api.world.properties.SlimeProperties; -import com.grinderwolf.swm.api.world.properties.SlimeProperty; import com.grinderwolf.swm.api.world.properties.SlimePropertyMap; -import com.grinderwolf.swm.api.world.properties.type.SlimePropertyString; +import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; +import java.io.IOException; + public final class LetThemEatCake extends JavaPlugin { + private SlimePropertyMap properties; + private SlimePlugin swm; + private SlimeLoader swmLoader; + private SlimeWorld swmWorld; @Override public void onEnable() { - SlimePropertyMap propertymap = new SlimePropertyMap(); - propertymap.setValue(SlimeProperties.SPAWN_X, 0); - propertymap.setValue(SlimeProperties.SPAWN_Y, 0); - propertymap.setValue(SlimeProperties.SPAWN_Z, 0); } @Override public void onDisable() { - // Plugin shutdown logic + // Unload swm worlds + } + + private void loadSWM() { + properties = new SlimePropertyMap(); + properties.setValue(SlimeProperties.SPAWN_X, 0); + properties.setValue(SlimeProperties.SPAWN_Y, 0); + properties.setValue(SlimeProperties.SPAWN_Z, 0); + + swm = (SlimePlugin) Bukkit.getPluginManager().getPlugin("SlimeWorldManager"); + swmLoader = swm.getLoader("file"); + try { + swmWorld = swm.loadWorld(swmLoader, "map", true, properties); + swm.generateWorld(swmWorld); + } catch (UnknownWorldException | IOException | CorruptedWorldException | NewerFormatException | WorldInUseException e) { + e.printStackTrace(); + } } } diff --git a/src/main/java/org/lunamc/letthemeatcake/PointsManager.java b/src/main/java/org/lunamc/letthemeatcake/PointsManager.java index de8da70..4d0455b 100644 --- a/src/main/java/org/lunamc/letthemeatcake/PointsManager.java +++ b/src/main/java/org/lunamc/letthemeatcake/PointsManager.java @@ -2,15 +2,62 @@ package org.lunamc.letthemeatcake; import org.bukkit.entity.Player; -import java.util.HashMap; -import java.util.Map; - public class PointsManager { + private int playerSize; + private Player[] players; + private int[] points; - private Map playerPoints; - - public PointsManager() { - playerPoints = new HashMap<>(); - + public PointsManager(int playerSize) { + this.playerSize = playerSize; + players = new Player[playerSize]; + points = new int[playerSize]; } + + public Player[] getPlayers() { + return players; + } + + public int getPlayerNumber(Player player) { + for (int i = 0; i < players.length; i++) { + if (players[i].equals(player)) { + return i; + } + } + return -1; + } + + public Player getPlayerByNumber(int player) { + if (player < 0 || player > playerSize) { + return null; + } + return players[player]; + } + + /** + * If player does not exist, returns -1; + * @param player player to get points from + * @return int value of points + */ + public int getPlayerPoints(int player) { + if (player < 0 || player > playerSize) { + return -1; + } + return points[player]; + } + + /** + * Use {@link org.lunamc.letthemeatcake.PointsManager#getPlayerPoints(int)} if possible for performance reasons.
+ * If player does not exist, returns -1; + * @param player player to get points from + * @return int value of points + */ + public int getPlayerPoints(Player player) { + for (int i = 0; i < players.length; i++) { + if (players[i].equals(player)) { + return points[i]; + } + } + return -1; + } + }