Skip to content

Commit

Permalink
Fix small bug with the config
Browse files Browse the repository at this point in the history
  • Loading branch information
RealTriassic committed Dec 29, 2022
1 parent 8e2469b commit 95ad24f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 58 deletions.
21 changes: 15 additions & 6 deletions src/main/java/com/triassic/randomcart/RandomCart.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,24 @@ public String getSelectedMinecart() {
}

public static Minecart loadMinecart(Configuration config, Random random) {
List<String> minecartKeys = new ArrayList<>(config.getConfigurationSection("minecarts").getKeys(false));
String selectedMinecart = minecartKeys.get(random.nextInt(minecartKeys.size()));
List<String> minecartKeys = null;

String name = config.getString("minecarts." + selectedMinecart + ".name");
try {
minecartKeys = new ArrayList<>(config.getConfigurationSection("minecarts").getKeys(false));
} catch (NullPointerException ignored) {}

ConfigurationSection itemsConfig = config.getConfigurationSection("minecarts." + selectedMinecart + ".items");
List<String> items = new ArrayList<>(itemsConfig.getKeys(false));
if (minecartKeys != null) {
String selectedMinecart = minecartKeys.get(random.nextInt(minecartKeys.size()));

return new Minecart(name, items, selectedMinecart);
String name = config.getString("minecarts." + selectedMinecart + ".name");

ConfigurationSection itemsConfig = config.getConfigurationSection("minecarts." + selectedMinecart + ".items");
List<String> items = new ArrayList<>(itemsConfig.getKeys(false));

return new Minecart(name, items, selectedMinecart);
}

return null;
}

public static List<Material> loadAllowedBlocks(Configuration config, Logger logger) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,20 @@ public void onBlockBreak(BlockBreakEvent event) {
return;
}

RandomCart.Minecart minecartData = RandomCart.loadMinecart(config, random);

if (minecartData == null) {
return;
}

String selectedMinecart = minecartData.getSelectedMinecart();

Location blockLocation = block.getLocation();
blockLocation.setY(blockLocation.getY() + 0.75);

StorageMinecart chestMinecart = (StorageMinecart) block.getWorld().spawnEntity(blockLocation, EntityType.MINECART_CHEST);
Inventory chestInventory = chestMinecart.getInventory();

RandomCart.Minecart minecartData = RandomCart.loadMinecart(config, random);
String selectedMinecart = minecartData.getSelectedMinecart();
String chestName = ChatColor.translateAlternateColorCodes('&', minecartData.getName());
chestMinecart.setCustomName(chestName);

Expand Down
76 changes: 26 additions & 50 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,57 +15,33 @@
# Plugin created by Triassic.




version: 1.0.0 # DO NOT MODIFY.
randomcart:
chance: 2 # The chance that a RandomCart spawns.
chance: 0.5 # The chance that a RandomCart spawns.
# Blocks that have the ability to spawn RandomCarts.
allowed-blocks:
- DIRT
- STONE
- GRASS_BLOCK
allowed-blocks: []

minecarts:
miner-cart: # Identifier used internally by the plugin.
name: "&9Miner's Cart" # Displayed in the Minecart's Chest GUI as the title.
# List of items that will be included in this preset.
items:
IRON_PICKAXE: # Item Name.
display-name: "&fMiner's Pickaxe" # The Name of the item displayed to players.
amount: 1 # Amount of the item to add.
# Lore of the Item displayed to players.
lore:
- "&7From the deepest depths of the caves."
# Item Enchantments
enchantments:
EFFICIENCY: # Enchantment Name
level: 4 # Enchantment Level
STONE:
amount: 192
STONE_BRICKS:
amount: 128
COOKED_PORKCHOP:
amount: 16
basic-cart:
name: "&6Basic Cart"
items:
STONE_SWORD: []
STONE_PICKAXE: []
STONE_AXE: []
STONE_SHOVEL: []
special-cart:
name: "&bSpecial Cart"
items:
NETHER_STAR:
amount: 4
lore:
- "&7Is this nether star special?"
- "&3Maybe?"
NETHERITE_INGOT:
amount: 6
DIAMOND:
display-name: "&3Shiny Diamond"
lore:
- "&bOoo.. shiny!"
amount: 24
# miner-cart: # Identifier used internally by the plugin.
# name: "&9Miner's Cart" # Displayed in the Minecart's Chest GUI as the title.
# # List of items that will be included in this preset.
# items:
# IRON_PICKAXE: # Item Name.
# display-name: "&fMiner's Pickaxe" # The Name of the item displayed to players.
# amount: 1 # Amount of the item to add.
# # Lore of the Item displayed to players.
# lore:
# - "&7From the deepest depths of the caves."
# # Item Enchantments
# enchantments:
# EFFICIENCY: # Enchantment Name
# level: 4 # Enchantment Level
# STONE:
# amount: 192
# STONE_BRICKS:
# amount: 128
# COOKED_PORKCHOP:
# amount: 16
# COBBLESTONE: []


version: 1.0.0 # DO NOT MODIFY.

0 comments on commit 95ad24f

Please sign in to comment.