aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMyles <mylesandmore9@gmail.com>2024-08-01 20:52:15 -0500
committerMyles <mylesandmore9@gmail.com>2024-08-01 20:52:15 -0500
commitd3c2467476f92ad3c5bcbe8fb5aa8b568c971518 (patch)
tree20dff1d8e255f36a8eab1d07f3e9ea976083e1fa /src
parent839be68b900d46d52899c224a779fa90d06d6c74 (diff)
downloadTumble-d3c2467476f92ad3c5bcbe8fb5aa8b568c971518.tar.gz
Tumble-d3c2467476f92ad3c5bcbe8fb5aa8b568c971518.tar.bz2
Tumble-d3c2467476f92ad3c5bcbe8fb5aa8b568c971518.zip
LayerManager bugfixes/improvements
- test and fix LayerManager - add layer and within-layer weights - add docs for layers.tml in readme
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/MylesAndMore/Tumble/Main.java11
-rw-r--r--src/main/java/com/MylesAndMore/Tumble/config/ArenaManager.java1
-rw-r--r--src/main/java/com/MylesAndMore/Tumble/config/LayerManager.java64
-rw-r--r--src/main/resources/layers.yml432
4 files changed, 292 insertions, 216 deletions
diff --git a/src/main/java/com/MylesAndMore/Tumble/Main.java b/src/main/java/com/MylesAndMore/Tumble/Main.java
index 56a46c1..b6fdb1f 100644
--- a/src/main/java/com/MylesAndMore/Tumble/Main.java
+++ b/src/main/java/com/MylesAndMore/Tumble/Main.java
@@ -10,6 +10,7 @@ import com.MylesAndMore.Tumble.game.Arena;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
+import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Objects;
@@ -24,12 +25,18 @@ public class Main extends JavaPlugin {
LanguageManager.readConfig();
ConfigManager.readConfig();
ArenaManager.readConfig();
- LayerManager.readConfig();
+ try {
+ LayerManager.readConfig();
+ } catch (InvalidConfigurationException e) {
+ this.getLogger().severe(e.getMessage());
+ Bukkit.getServer().getPluginManager().disablePlugin(this);
+ return;
+ }
Objects.requireNonNull(this.getCommand("tumble")).setExecutor(new Tumble());
new Metrics(this, 16940);
- Bukkit.getServer().getLogger().info("[Tumble] Tumble successfully enabled!");
+ this.getLogger().info("Tumble successfully enabled!");
}
@Override
diff --git a/src/main/java/com/MylesAndMore/Tumble/config/ArenaManager.java b/src/main/java/com/MylesAndMore/Tumble/config/ArenaManager.java
index af85b9f..84f5595 100644
--- a/src/main/java/com/MylesAndMore/Tumble/config/ArenaManager.java
+++ b/src/main/java/com/MylesAndMore/Tumble/config/ArenaManager.java
@@ -61,6 +61,7 @@ public class ArenaManager {
arenas.put(arena.name, arena);
}
validate(); // Validate arenas
+ plugin.getLogger().info("arenas.yml: Loaded " + arenas.size() + (arenas.size() > 1 ? " arenas" : " arena"));
}
/**
diff --git a/src/main/java/com/MylesAndMore/Tumble/config/LayerManager.java b/src/main/java/com/MylesAndMore/Tumble/config/LayerManager.java
index f834a24..73b301f 100644
--- a/src/main/java/com/MylesAndMore/Tumble/config/LayerManager.java
+++ b/src/main/java/com/MylesAndMore/Tumble/config/LayerManager.java
@@ -3,16 +3,18 @@ package com.MylesAndMore.Tumble.config;
import com.MylesAndMore.Tumble.plugin.CustomConfig;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.Random;
import static com.MylesAndMore.Tumble.Main.plugin;
public class LayerManager {
- public static List<List<Material>> layers;
+ public static List<List<Material>> layers = new ArrayList<>();
private static final CustomConfig layersYml = new CustomConfig("layers.yml");
private static final FileConfiguration config = layersYml.getConfig();
@@ -20,22 +22,30 @@ public class LayerManager {
/**
* Read layers from layers.yml and populate this.layers
*/
- public static void readConfig() {
+ public static void readConfig() throws InvalidConfigurationException {
layersYml.saveDefaultConfig();
ConfigurationSection layersSection = config.getConfigurationSection("layers");
if (layersSection == null) {
- plugin.getLogger().warning("layers.yml is missing section 'layers'");
- return;
+ throw new InvalidConfigurationException("layers.yml is missing section 'layers'");
}
for (String layerPath : layersSection.getKeys(false)) {
List<Material> layer = readLayer(layerPath);
if (layer == null) {
- plugin.getLogger().warning("layers.yml: error loading layer at'"+layerPath+"'");
+ plugin.getLogger().warning("layers.yml: Failed to load layer '" + layerPath + "'");
} else {
- layers.add(layer);
+ int weight = getLayerWeight(layerPath);
+ for (int i = 0; i < weight; i++) {
+ layers.add(layer);
+ }
}
}
+
+ if (layers.isEmpty()) {
+ throw new InvalidConfigurationException("No layers were found in layers.yml");
+ }
+ int numLayers = layersSection.getKeys(false).size(); // Don't use layers.size() because it includes duplicates for weighted layers
+ plugin.getLogger().info("layers.yml: Loaded " + numLayers + (numLayers > 1 ? " layers" : " layer"));
}
/**
@@ -44,17 +54,45 @@ public class LayerManager {
* @return The list of materials for the layer to be composed of
*/
public static List<Material> readLayer(String path) {
- List<String> list = config.getStringList(path);
- List<Material> layer = new ArrayList<>();
- for (String entry : list) {
- Material tmp = Material.getMaterial(entry);
- if (tmp == null) {
+ List<Map<?, ?>> materialsSection = config.getMapList("layers." + path + ".materials");
+ if (materialsSection.isEmpty()) {
+ plugin.getLogger().warning("layers.yml: Layer '" + path + "' is missing section 'materials'");
+ return null;
+ }
+ List<Material> materials = new ArrayList<>();
+
+ for (Map<?, ?> materialMap : materialsSection) {
+ String matName = (String)materialMap.get("material");
+ Material mat = Material.getMaterial(matName);
+
+ Object weightObj = materialMap.get("weight");
+ int weight = 1;
+ if (weightObj != null) {
+ if (weightObj instanceof Integer) {
+ weight = (Integer)weightObj;
+ } else {
+ plugin.getLogger().warning("layers.yml: Invalid weight in layer '" + path + "'");
+ return null;
+ }
+ }
+ if (mat == null) {
+ plugin.getLogger().warning("layers.yml: Invalid material '" + matName + "' in layer '" + path + "'");
return null;
}
- layer.add(tmp);
+ if (weight < 1) {
+ plugin.getLogger().warning("layers.yml: Invalid weight '" + weight + "' in layer '" + path + "'");
+ return null;
+ }
+ for (int i = 0; i < weight; i++) {
+ materials.add(mat);
+ }
}
- return layer;
+ return materials;
+ }
+
+ public static int getLayerWeight(String path) {
+ return config.getInt("layers." + path + ".weight", 1);
}
public static List<Material> getRandom() {
diff --git a/src/main/resources/layers.yml b/src/main/resources/layers.yml
index acc5be9..ff0f353 100644
--- a/src/main/resources/layers.yml
+++ b/src/main/resources/layers.yml
@@ -1,202 +1,232 @@
layers:
- 1:
- - YELLOW_GLAZED_TERRACOTTA
- - LIGHT_BLUE_GLAZED_TERRACOTTA
- - GRAY_GLAZED_TERRACOTTA
- - PODZOL
- - PODZOL
- - PODZOL
- - ORANGE_GLAZED_TERRACOTTA
- 2:
- - PINK_TERRACOTTA
- - PURPLE_TERRACOTTA
- - GRAY_TERRACOTTA
- - BLUE_TERRACOTTA
- - LIGHT_BLUE_TERRACOTTA
- - WHITE_TERRACOTTA
- - BROWN_TERRACOTTA
- - GREEN_TERRACOTTA
- - YELLOW_TERRACOTTA
- - PINK_TERRACOTTA
- - PURPLE_TERRACOTTA
- - GRAY_TERRACOTTA
- - BLUE_TERRACOTTA
- - LIGHT_BLUE_TERRACOTTA
- - WHITE_TERRACOTTA
- - BROWN_TERRACOTTA
- - GREEN_TERRACOTTA
- - YELLOW_TERRACOTTA
- - WHITE_STAINED_GLASS
- - HONEYCOMB_BLOCK
- - HONEYCOMB_BLOCK
- 3:
- - DIAMOND_BLOCK
- - GOLD_BLOCK
- - REDSTONE_BLOCK
- - REDSTONE_BLOCK
- - LAPIS_BLOCK
- - LAPIS_BLOCK
- - IRON_BLOCK
- - COAL_BLOCK
- - IRON_BLOCK
- - COAL_BLOCK
- - IRON_BLOCK
- - COAL_BLOCK
- - COAL_BLOCK
- 4:
- - WHITE_TERRACOTTA
- - BLUE_ICE
- - SOUL_SAND
- - STONE_SLAB
- - WHITE_TERRACOTTA
- - BLUE_ICE
- - SOUL_SAND
- - STONE_SLAB
- - WHITE_TERRACOTTA
- - BLUE_ICE
- - SOUL_SAND
- - STONE_SLAB
- - GLOWSTONE
- - GLOWSTONE
- - HONEY_BLOCK
- - SLIME_BLOCK
- 5:
- - END_STONE
- - END_STONE_BRICKS
- - END_STONE
- - END_STONE_BRICKS
- - END_STONE
- - END_STONE_BRICKS
- - END_STONE
- - END_STONE_BRICKS
- - OBSIDIAN
- - PURPUR_BLOCK
- - PURPUR_PILLAR
- - COBBLESTONE
- 6:
- - PRISMARINE
- - DARK_PRISMARINE
- - BLUE_STAINED_GLASS
- - WET_SPONGE
- - PRISMARINE_BRICKS
- - PRISMARINE_BRICK_SLAB
- - DARK_PRISMARINE
- - SEA_LANTERN
- - TUBE_CORAL_BLOCK
- - BRAIN_CORAL_BLOCK
- - BUBBLE_CORAL_BLOCK
- 7:
- - OAK_LOG
- - SPRUCE_LOG
- - ACACIA_LOG
- - STRIPPED_OAK_LOG
- - STRIPPED_SPRUCE_LOG
- - STRIPPED_ACACIA_LOG
- - OAK_WOOD
- - SPRUCE_WOOD
- - ACACIA_WOOD
- - OAK_LEAVES
- - SPRUCE_LEAVES
- - ACACIA_LEAVES
- - OAK_LEAVES
- - SPRUCE_LEAVES
- - ACACIA_LEAVES
- 8:
- - YELLOW_GLAZED_TERRACOTTA
- - LIGHT_BLUE_GLAZED_TERRACOTTA
- - GRAY_GLAZED_TERRACOTTA
- - PODZOL
- - PODZOL
- - PODZOL
- - ORANGE_GLAZED_TERRACOTTA
- 9:
- - COAL_ORE
- - COAL_ORE
- - COAL_ORE
- - COAL_ORE
- - COAL_ORE
- - IRON_ORE
- - REDSTONE_ORE
- - EMERALD_ORE
- - GOLD_ORE
- - LAPIS_ORE
- - DIAMOND_ORE
- - GRASS_BLOCK
- - GRASS_BLOCK
- - GRASS_BLOCK
- - GRASS_BLOCK
- - COBWEB
- 10:
- - PACKED_ICE
- - PACKED_ICE
- - JUKEBOX
- - TNT
- - LIGHT_BLUE_CONCRETE
- - GLASS
- - PACKED_ICE
- - PACKED_ICE
- - JUKEBOX
- - TNT
- - LIGHT_BLUE_CONCRETE
- - GLASS
- - SOUL_SAND
- 11:
- - NETHERRACK
- - NETHERRACK
- - NETHERRACK
- - NETHER_BRICKS
- - NETHER_BRICKS
- - NETHERRACK
- - NETHERRACK
- - NETHERRACK
- - NETHER_BRICKS
- - NETHER_BRICKS
- - NETHER_GOLD_ORE
- - NETHER_GOLD_ORE
- - CRIMSON_NYLIUM
- - WARPED_NYLIUM
- - SOUL_SOIL
- - CRACKED_NETHER_BRICKS
- - RED_NETHER_BRICKS
- - NETHER_WART_BLOCK
- - CRYING_OBSIDIAN
- - MAGMA_BLOCK
- 12:
- - REDSTONE_BLOCK
- - REDSTONE_BLOCK
- - REDSTONE_LAMP
- - TARGET
- - SLIME_BLOCK
- - OBSERVER
- 13:
- - DIRT
- - GRASS_PATH
- - GRASS_BLOCK
- - OAK_SLAB
- - BRICK_WALL
- - BRICK_STAIRS
- 14:
- - OAK_PLANKS
- - OBSIDIAN
- - SPONGE
- - BEEHIVE
- - DRIED_KELP_BLOCK
- 15:
- - SANDSTONE
- - SANDSTONE_SLAB
- - RED_SANDSTONE
- - RED_SANDSTONE_SLAB
- - RED_TERRACOTTA
- - TERRACOTTA
- - YELLOW_TERRACOTTA
- 16:
- - JUNGLE_LOG
- - STRIPPED_JUNGLE_LOG
- - JUNGLE_WOOD
- - STRIPPED_JUNGLE_WOOD
- - MOSSY_COBBLESTONE
- - MOSSY_COBBLESTONE
- - MOSSY_COBBLESTONE
- - JUNGLE_LEAVES
- - JUNGLE_SLAB
- - JUNGLE_TRAPDOOR \ No newline at end of file
+ ores:
+ weight: 5
+ materials:
+ - material: COBBLESTONE
+ weight: 5
+ - material: COAL_ORE
+ weight: 3
+ - material: GRASS_BLOCK
+ weight: 2
+ - material: IRON_ORE
+ - material: GOLD_ORE
+ - material: REDSTONE_ORE
+ - material: EMERALD_ORE
+ - material: LAPIS_ORE
+ - material: DIAMOND_ORE
+ - material: COBWEB
+ ore_blocks:
+ weight: 5
+ materials:
+ - material: COAL_BLOCK
+ weight: 4
+ - material: IRON_BLOCK
+ weight: 3
+ - material: GOLD_BLOCK
+ weight: 2
+ - material: REDSTONE_BLOCK
+ weight: 2
+ - material: LAPIS_BLOCK
+ - material: DIAMOND_BLOCK
+ nether:
+ weight: 5
+ materials:
+ - material: NETHERRACK
+ weight: 6
+ - material: NETHER_BRICKS
+ weight: 4
+ - material: NETHER_GOLD_ORE
+ weight: 2
+ - material: NETHER_QUARTZ_ORE
+ weight: 2
+ - material: CRIMSON_NYLIUM
+ - material: WARPED_NYLIUM
+ - material: CRACKED_NETHER_BRICKS
+ - material: RED_NETHER_BRICKS
+ - material: NETHER_WART_BLOCK
+ - material: CRYING_OBSIDIAN
+ - material: SHROOMLIGHT
+ - material: BLACKSTONE
+ - material: BASALT
+ - material: SOUL_SAND
+ end:
+ weight: 5
+ materials:
+ - material: END_STONE
+ weight: 4
+ - material: END_STONE_BRICKS
+ weight: 2
+ - material: PURPUR_BLOCK
+ weight: 2
+ - material: PURPUR_PILLAR
+ - material: OBSIDIAN
+ - material: COBBLESTONE
+ redstone:
+ weight: 4
+ materials:
+ - material: REDSTONE_BLOCK
+ weight: 2
+ - material: REDSTONE_LAMP
+ - material: TARGET
+ - material: SLIME_BLOCK
+ - material: OBSERVER
+ - material: DAYLIGHT_DETECTOR
+ ocean:
+ weight: 4
+ materials:
+ - material: PRISMARINE
+ weight: 2
+ - material: DARK_PRISMARINE
+ - material: PRISMARINE_BRICKS
+ - material: PRISMARINE_BRICK_SLAB
+ - material: BLUE_STAINED_GLASS
+ - material: SEA_LANTERN
+ - material: SPONGE
+ - material: TUBE_CORAL_BLOCK
+ - material: BRAIN_CORAL_BLOCK
+ - material: BUBBLE_CORAL_BLOCK
+ desert:
+ weight: 4
+ materials:
+ - material: SANDSTONE
+ weight: 2
+ - material: RED_SANDSTONE
+ weight: 2
+ - material: CHISELED_SANDSTONE
+ - material: SMOOTH_SANDSTONE
+ - material: CUT_SANDSTONE
+ - material: SANDSTONE_SLAB
+ - material: RED_SANDSTONE_SLAB
+ - material: RED_TERRACOTTA
+ - material: ORANGE_TERRACOTTA
+ - material: YELLOW_TERRACOTTA
+ - material: TERRACOTTA
+ forest:
+ weight: 4
+ materials:
+ - material: OAK_LEAVES
+ weight: 2
+ - material: SPRUCE_LEAVES
+ weight: 2
+ - material: ACACIA_LEAVES
+ weight: 2
+ - material: OAK_LOG
+ - material: SPRUCE_LOG
+ - material: ACACIA_LOG
+ - material: STRIPPED_OAK_LOG
+ - material: STRIPPED_SPRUCE_LOG
+ - material: STRIPPED_ACACIA_LOG
+ - material: OAK_WOOD
+ - material: SPRUCE_WOOD
+ - material: ACACIA_WOOD
+ jungle:
+ weight: 3
+ materials:
+ - material: MOSSY_COBBLESTONE
+ weight: 3
+ - material: COBBLESTONE
+ weight: 2
+ - material: JUNGLE_LEAVES
+ weight: 2
+ - material: JUNGLE_LOG
+ weight: 2
+ - material: STRIPPED_JUNGLE_LOG
+ - material: JUNGLE_WOOD
+ - material: STRIPPED_JUNGLE_WOOD
+ - material: JUNGLE_PLANKS
+ - material: JUNGLE_SLAB
+ overworld:
+ weight: 3
+ materials:
+ - material: DIRT
+ - material: COARSE_DIRT
+ - material: GRASS_BLOCK
+ - material: DIRT_PATH
+ - material: MYCELIUM
+ - material: PODZOL
+ - material: OAK_SLAB
+ - material: BRICK_WALL
+ - material: BRICK_STAIRS
+ terracotta:
+ weight: 3
+ materials:
+ - material: PINK_TERRACOTTA
+ weight: 2
+ - material: PURPLE_TERRACOTTA
+ weight: 2
+ - material: GRAY_TERRACOTTA
+ weight: 2
+ - material: BLUE_TERRACOTTA
+ weight: 2
+ - material: LIGHT_BLUE_TERRACOTTA
+ weight: 2
+ - material: WHITE_TERRACOTTA
+ weight: 2
+ - material: BROWN_TERRACOTTA
+ weight: 2
+ - material: GREEN_TERRACOTTA
+ weight: 2
+ - material: YELLOW_TERRACOTTA
+ weight: 2
+ - material: HONEYCOMB_BLOCK
+ weight: 2
+ - material: WHITE_STAINED_GLASS
+ glazed_terracotta:
+ weight: 3
+ materials:
+ - material: PODZOL
+ weight: 3
+ - material: YELLOW_GLAZED_TERRACOTTA
+ - material: LIGHT_BLUE_GLAZED_TERRACOTTA
+ - material: GRAY_GLAZED_TERRACOTTA
+ sticky:
+ weight: 3
+ materials:
+ - material: WHITE_TERRACOTTA
+ weight: 3
+ - material: BLUE_ICE
+ weight: 3
+ - material: STONE_SLAB
+ weight: 3
+ - material: SOUL_SOIL
+ weight: 2
+ - material: GLOWSTONE
+ weight: 2
+ - material: SLIME_BLOCK
+ - material: HONEY_BLOCK
+ annoying_movement:
+ weight: 2
+ materials:
+ - material: PACKED_ICE
+ weight: 4
+ - material: JUKEBOX
+ weight: 2
+ - material: TNT
+ weight: 2
+ - material: LIGHT_BLUE_CONCRETE
+ weight: 2
+ - material: GLASS
+ weight: 2
+ - material: SMOOTH_STONE_SLAB
+ weight: 2
+ - material: SOUL_SAND
+ insanity:
+ weight: 2
+ materials:
+ - material: OAK_PLANKS
+ - material: OBSIDIAN
+ - material: SPONGE
+ - material: BEEHIVE
+ - material: DRIED_KELP_BLOCK
+ glass:
+ weight: 1
+ materials:
+ - material: GLASS
+ weight: 30
+ - material: WHITE_STAINED_GLASS
+
+# <NAME>:
+# weight:
+# materials:
+# - material:
+# weight: