aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMyles <mylesandmore9@gmail.com>2022-12-10 14:59:58 -0600
committerMyles <mylesandmore9@gmail.com>2022-12-10 14:59:58 -0600
commitcf6bdc376b91e3c1ab5403e018470a7fee589986 (patch)
treea99f03b40e70fa42c71c9521df4e6e99fce9731d
parent735fd623a2cb14223df65b17705c4eb6e01a681a (diff)
downloadTumble-cf6bdc376b91e3c1ab5403e018470a7fee589986.tar.gz
Tumble-cf6bdc376b91e3c1ab5403e018470a7fee589986.tar.bz2
Tumble-cf6bdc376b91e3c1ab5403e018470a7fee589986.zip
THE CLUMPS WORK
-rw-r--r--README.md7
-rw-r--r--src/main/java/com/MylesAndMore/tumble/EventListener.java4
-rw-r--r--src/main/java/com/MylesAndMore/tumble/Game.java70
-rw-r--r--src/main/java/com/MylesAndMore/tumble/api/Generator.java40
-rw-r--r--src/main/java/com/MylesAndMore/tumble/api/Layers.java95
5 files changed, 169 insertions, 47 deletions
diff --git a/README.md b/README.md
index e0d0663..a560e7c 100644
--- a/README.md
+++ b/README.md
@@ -5,8 +5,9 @@ once this list is complete and all bugs are fixed, we *should* be ready for rele
## generation
-- [ ] layers should be able to generate w/ "clumps" of blocks; instead of only one material as a whole
- - [ ] the clump size should be customizable (for later); be able to set a min/max val and it will choose randomly per each clump (not in config file yet, just internally)
+- [x] layers should be able to generate w/ "clumps" of blocks; instead of only one material as a whole
+ - [x] the clump size should be customizable (for later); be able to set a min/max val and it will choose randomly per each clump (not in config file yet, just internally)
+ - *Note: this is done through the amount of times each Material shows up in the List--there's no config for it.*
- [ ] make shovels generation actually work properly
- make different types of platforms (square, circle, multi-tiered, etc.); still should be pseudo-random
- [ ] make snowballs generation actually work properly (shocker)
@@ -18,7 +19,7 @@ once this list is complete and all bugs are fixed, we *should* be ready for rele
- [x] make it so that you can't move until the game begins
- [x] make the game blocks breakable very fast, but **not instantly--very important for balancing!!**
- Basically, just set a "cooldown" on both snowballs and shovels--not a long one--but one at that
-- [ ] add infinite snowballs in the gamemanager for tumble mode
+- [x] add infinite snowballs in the gamemanager for tumble mode
- [x] make it so that you can't remove any of the game items from your inventory
- [x] make snowballs actually break blocks (duh)
- [x] make the randomized mode logic
diff --git a/src/main/java/com/MylesAndMore/tumble/EventListener.java b/src/main/java/com/MylesAndMore/tumble/EventListener.java
index 8e07509..7e7bf94 100644
--- a/src/main/java/com/MylesAndMore/tumble/EventListener.java
+++ b/src/main/java/com/MylesAndMore/tumble/EventListener.java
@@ -128,8 +128,8 @@ public class EventListener implements Listener {
if (event.getEntity().getWorld() == Bukkit.getWorld(TumbleManager.getGameWorld())) {
if (event.getEntity() instanceof Snowball) {
if (event.getEntity().getShooter() instanceof Player player) {
- // Check to see if the last snowball was thrown less than 200ms ago, if so, don't allow another
- if ((System.currentTimeMillis() - lastTimeP) < 200) { event.setCancelled(true); }
+ // Check to see if the last snowball was thrown less than 210ms ago, if so, don't allow another
+ if ((System.currentTimeMillis() - lastTimeP) < 205) { event.setCancelled(true); }
else {
// Otherwise, continue with logic
lastTimeP = System.currentTimeMillis();
diff --git a/src/main/java/com/MylesAndMore/tumble/Game.java b/src/main/java/com/MylesAndMore/tumble/Game.java
index 7de988a..789edff 100644
--- a/src/main/java/com/MylesAndMore/tumble/Game.java
+++ b/src/main/java/com/MylesAndMore/tumble/Game.java
@@ -2,6 +2,7 @@ package com.MylesAndMore.tumble;
import com.MylesAndMore.tumble.api.Generator;
+import com.MylesAndMore.tumble.api.Layers;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
@@ -37,8 +38,8 @@ public class Game {
// Define local game vars
// The gameState keeps the current state of the game (I'm so creative, I know)
private String gameState;
- // Define a variable for the roundType
- private String roundType;
+ // Define a variable for the gameType
+ private String gameType;
// Define a variable for the autostart PID
private int autoStartID = -1;
@@ -77,8 +78,8 @@ public class Game {
// Define the gameType
if (Objects.equals(type, "shovels")) {
gameState = "starting";
- // Set the roundType to gameType since it won't change for this mode
- roundType = type;
+ // Set the type to gameType since it won't change for this mode
+ gameType = type;
// Clear the players' inventories so they can't bring any items into the game
clearInventories(TumbleManager.getPlayersInLobby());
// Generate the correct layers for a Shovels game
@@ -94,7 +95,7 @@ public class Game {
}
else if (Objects.equals(type, "snowballs")) {
gameState = "starting";
- roundType = type;
+ gameType = type;
clearInventories(TumbleManager.getPlayersInLobby());
if (generateLayers(type)) {
scatterPlayers(TumbleManager.getPlayersInLobby());
@@ -105,7 +106,7 @@ public class Game {
}
else if (Objects.equals(type, "mixed")) {
gameState = "starting";
- roundType = type;
+ gameType = type;
clearInventories(TumbleManager.getPlayersInLobby());
if (generateLayers(type)) {
scatterPlayers(TumbleManager.getPlayersInLobby());
@@ -184,6 +185,7 @@ public class Game {
*/
public void playerDeath(Player player) {
player.setGameMode(GameMode.SPECTATOR);
+ player.teleport(gameSpawn);
// If there are more than 2 players in the game,
if (roundPlayers.size() > 2) {
// remove that player (who just died) from the roundPlayersArray, effectively eliminating them,
@@ -201,11 +203,6 @@ public class Game {
// Methods to get the game type and game state for other classes outside the Game
/**
- * @return The round type of the current round as a String ("shovels", "snowballs")
- */
- public String getRoundType() { return roundType; }
-
- /**
* @return The game's current state as a String ("waiting", "starting", "running", "complete")
* Can also be null if not initialized.
*/
@@ -225,20 +222,20 @@ public class Game {
* @param type can be either "shovels", "snowballs", or "mixed", anything else will fail generation
* @return true if gameType was recognized and layers were (hopefully) generated, false if unrecognized
*/
+ // Initialize Layers
+ private final Layers layers = new Layers();
private boolean generateLayers(String type) {
// Create a new Location for the layers to work with--this is so that we don't modify the actual gameSpawn var
Location layer = new Location(gameSpawn.getWorld(), gameSpawn.getX(), gameSpawn.getY(), gameSpawn.getZ(), gameSpawn.getYaw(), gameSpawn.getPitch());
if (Objects.equals(type, "shovels")) {
layer.setY(layer.getY() - 1);
- Generator.generateLayer(layer, 17, 1, Material.SNOW_BLOCK);
+ Generator.generateClumps(Generator.generateLayer(layer, 17, 1, Material.SNOW_BLOCK), layers.getMaterialList());
Generator.generateLayer(layer, 13, 1, Material.AIR);
layer.setY(layer.getY() - 1);
- Generator.generateLayer(layer, 13, 1, Material.GRASS_BLOCK);
+ Generator.generateClumps(Generator.generateLayer(layer, 13, 1, Material.GRASS_BLOCK), layers.getMaterialList());
Generator.generateLayer(layer, 4, 1, Material.AIR);
layer.setY(layer.getY() - 1);
- Generator.generateLayer(layer, 4, 1, Material.PODZOL);
- layer.setY(layer.getY() + 2);
- Generator.generateLayer(layer, 4, 2, Material.TALL_GRASS);
+ Generator.generateClumps(Generator.generateLayer(layer, 4, 1, Material.PODZOL), layers.getMaterialList());
ItemStack shovel = new ItemStack(Material.IRON_SHOVEL);
shovel.addEnchantment(Enchantment.SILK_TOUCH, 1);
if (Objects.equals(gameState, "running")) {
@@ -250,13 +247,13 @@ public class Game {
}
else if (Objects.equals(type, "snowballs")) {
layer.setY(layer.getY() - 1);
- Generator.generateLayer(layer, 17, 1, Material.COAL_ORE);
+ Generator.generateClumps(Generator.generateLayer(layer, 17, 1, Material.STONE), layers.getMaterialList());
Generator.generateLayer(layer, 13, 1, Material.AIR);
layer.setY(layer.getY() - 1);
- Generator.generateLayer(layer, 13, 1, Material.GRANITE);
+ Generator.generateClumps(Generator.generateLayer(layer, 13, 1, Material.GRANITE), layers.getMaterialList());
Generator.generateLayer(layer, 4, 1, Material.AIR);
layer.setY(layer.getY() - 1);
- Generator.generateLayer(layer, 4, 1, Material.LIME_GLAZED_TERRACOTTA);
+ Generator.generateClumps(Generator.generateLayer(layer, 4, 1, Material.LIME_GLAZED_TERRACOTTA), layers.getMaterialList());
if (Objects.equals(gameState, "running")) {
giveItems(TumbleManager.getPlayersInGame(), new ItemStack(Material.SNOWBALL));
}
@@ -403,30 +400,33 @@ public class Game {
roundPlayers.addAll(gamePlayers);
clearInventories(gamePlayers);
displayTitles(gamePlayers, ChatColor.RED + "Round over!", ChatColor.GOLD + winner.getName() + " has won the round!", 5, 60, 5);
- // Re-generate layers
- generateLayers(roundType);
- // Wait 5s (100t) for tp method
+ // Wait for player to respawn before completely l a g g i n g the server ._.
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> {
- // Re-scatter players
- gameState = "starting";
- scatterPlayers(gamePlayers);
- playSound(gamePlayers, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 1, 1);
- displayTitles(gamePlayers, ChatColor.DARK_GREEN + "3", null, 3, 10, 7);
+ // Re-generate layers
+ generateLayers(gameType);
+ // Wait 5s (100t) for tp method
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> {
+ // Re-scatter players
+ gameState = "starting";
+ scatterPlayers(gamePlayers);
playSound(gamePlayers, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 1, 1);
- displayTitles(gamePlayers, ChatColor.YELLOW + "2", null, 3, 10, 7);
+ displayTitles(gamePlayers, ChatColor.DARK_GREEN + "3", null, 3, 10, 7);
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> {
playSound(gamePlayers, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 1, 1);
- displayTitles(gamePlayers, ChatColor.DARK_RED + "1", null, 3, 10, 7);
+ displayTitles(gamePlayers, ChatColor.YELLOW + "2", null, 3, 10, 7);
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> {
- playSound(gamePlayers, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 1, 2);
- displayTitles(gamePlayers, ChatColor.GREEN + "Go!", null, 1, 5, 1);
- setGamemode(gamePlayers, GameMode.SURVIVAL);
- gameState = "running";
+ playSound(gamePlayers, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 1, 1);
+ displayTitles(gamePlayers, ChatColor.DARK_RED + "1", null, 3, 10, 7);
+ Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(TumbleManager.getPlugin(), () -> {
+ playSound(gamePlayers, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 1, 2);
+ displayTitles(gamePlayers, ChatColor.GREEN + "Go!", null, 1, 5, 1);
+ setGamemode(gamePlayers, GameMode.SURVIVAL);
+ gameState = "running";
+ }, 20);
}, 20);
}, 20);
- }, 20);
- }, 100);
+ }, 100);
+ }, 1);
}
}
diff --git a/src/main/java/com/MylesAndMore/tumble/api/Generator.java b/src/main/java/com/MylesAndMore/tumble/api/Generator.java
index 533ee97..f4439b6 100644
--- a/src/main/java/com/MylesAndMore/tumble/api/Generator.java
+++ b/src/main/java/com/MylesAndMore/tumble/api/Generator.java
@@ -1,12 +1,14 @@
package com.MylesAndMore.tumble.api;
+import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
-import org.bukkit.util.BlockVector;
+import org.bukkit.block.BlockFace;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Random;
@@ -45,21 +47,45 @@ public class Generator {
/**
* Generates clumps in a pre-generated layer.
- * @param blocks A list of block Locations that this method is allowed to edit
- * @param materials A list of Materials for the generator to randomly choose from.
+ * @param blockList A list of block Locations that this method is allowed to edit
+ * @param materialList A list of Materials for the generator to randomly choose from.
* Keep in mind that not all Materials may be used, the amount used depends on the size of the layer.
* More Materials = more randomization
*/
- public static void generateClumps(List<Block> blocks, List<Material> materials) {
+ public static void generateClumps(List<Block> blockList, List<Material> materialList) {
// Define random class
Random random = new Random();
- // This for loop will run until there are no blocks left to change
- for (Block aBlock : blocks) {
+ // Define new blocks list so we can manipulate it
+ List<Block> blocks = new ArrayList<>(blockList);
+ // Define new shuffled Materials list
+ List<Material> materials = new ArrayList<>(materialList);
+ Collections.shuffle(materials);
+ // This loop will run until there are no blocks left to change
+ while (blocks.size() > 0) {
// Get a random Material from the provided materials list
Material randomMaterial = materials.get(random.nextInt(materials.size()));
+ // Gets the first Block from the list, to modify
+ Block aBlock = blocks.get(0);
+ // Modifies the block
aBlock.setType(randomMaterial);
// Get the blocks around that and change it to that same material
- // ...
+ if (blocks.contains(aBlock.getRelative(BlockFace.NORTH))) {
+ aBlock.getRelative(BlockFace.NORTH).setType(randomMaterial);
+ blocks.remove(aBlock.getRelative(BlockFace.NORTH));
+ }
+ if (blocks.contains(aBlock.getRelative(BlockFace.SOUTH))) {
+ aBlock.getRelative(BlockFace.SOUTH).setType(randomMaterial);
+ blocks.remove(aBlock.getRelative(BlockFace.SOUTH));
+ }
+ if (blocks.contains(aBlock.getRelative(BlockFace.EAST))) {
+ aBlock.getRelative(BlockFace.EAST).setType(randomMaterial);
+ blocks.remove(aBlock.getRelative(BlockFace.EAST));
+ }
+ if (blocks.contains(aBlock.getRelative(BlockFace.WEST))) {
+ aBlock.getRelative(BlockFace.WEST).setType(randomMaterial);
+ blocks.remove(aBlock.getRelative(BlockFace.WEST));
+ }
+ blocks.remove(aBlock);
}
}
diff --git a/src/main/java/com/MylesAndMore/tumble/api/Layers.java b/src/main/java/com/MylesAndMore/tumble/api/Layers.java
new file mode 100644
index 0000000..b970891
--- /dev/null
+++ b/src/main/java/com/MylesAndMore/tumble/api/Layers.java
@@ -0,0 +1,95 @@
+package com.MylesAndMore.tumble.api;
+
+import org.bukkit.Material;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+/**
+ * This class is dedicated to storing the different types of layers that can be generated.
+ */
+public class Layers {
+
+ public Layers(){
+ matList.add(gen0);
+ matList.add(gen0);
+ matList.add(gen0);
+ matList.add(gen1);
+ matList.add(gen1);
+ matList.add(gen0);
+ matList.add(gen0);
+ matList.add(gen0);
+ matList.add(gen1);
+ matList.add(gen1);
+ matList.add(gen2);
+ }
+
+ // Define Random class
+ Random random = new Random();
+ /**
+ * @return A random predefined List of Materials that are okay to use in the clump generator
+ */
+ public List<Material> getMaterialList() {
+ return matList.get(random.nextInt(matList.size()));
+ }
+
+
+ // Begin lists
+
+ // private final List<Material> gen = new ArrayList<>() {{
+ // add(Material.);
+ // }};
+
+ private final List<Material> gen0 = new ArrayList<>() {{
+ add(Material.COAL_ORE);
+ add(Material.COAL_ORE);
+ add(Material.COAL_ORE);
+ add(Material.COAL_ORE);
+ add(Material.COAL_ORE);
+ add(Material.IRON_ORE);
+ add(Material.REDSTONE_ORE);
+ add(Material.EMERALD_ORE);
+ add(Material.GOLD_ORE);
+ add(Material.LAPIS_ORE);
+ add(Material.DIAMOND_ORE);
+ add(Material.COBWEB);
+ add(Material.GRASS_BLOCK);
+ add(Material.GRASS_BLOCK);
+ }};
+
+ private final List<Material> gen1 = new ArrayList<>() {{
+ add(Material.YELLOW_GLAZED_TERRACOTTA);
+ add(Material.LIGHT_BLUE_GLAZED_TERRACOTTA);
+ add(Material.GRAY_GLAZED_TERRACOTTA);
+ add(Material.PODZOL);
+ add(Material.PODZOL);
+ add(Material.PODZOL);
+ add(Material.ORANGE_GLAZED_TERRACOTTA);
+ }};
+
+ private final List<Material> gen2 = new ArrayList<>() {{
+ add(Material.PINK_TERRACOTTA);
+ add(Material.PURPLE_TERRACOTTA);
+ add(Material.GRAY_TERRACOTTA);
+ add(Material.BLUE_TERRACOTTA);
+ add(Material.LIGHT_BLUE_TERRACOTTA);
+ add(Material.WHITE_TERRACOTTA);
+ add(Material.BROWN_TERRACOTTA);
+ add(Material.GREEN_TERRACOTTA);
+ add(Material.YELLOW_TERRACOTTA);
+ add(Material.PINK_TERRACOTTA);
+ add(Material.PURPLE_TERRACOTTA);
+ add(Material.GRAY_TERRACOTTA);
+ add(Material.BLUE_TERRACOTTA);
+ add(Material.LIGHT_BLUE_TERRACOTTA);
+ add(Material.WHITE_TERRACOTTA);
+ add(Material.BROWN_TERRACOTTA);
+ add(Material.GREEN_TERRACOTTA);
+ add(Material.YELLOW_TERRACOTTA);
+ add(Material.WHITE_STAINED_GLASS);
+ }};
+
+ private final List<List<Material>> matList = new ArrayList<>();
+
+}