saveIsland(@NonNull Island island) {
- if (cache.containsKey(island.getUniqueId())) {
- return handler.saveObjectAsync(cache.get(island.getUniqueId()));
- }
- return CompletableFuture.completedFuture(true);
+ if (cache.containsKey(island.getUniqueId())) {
+ return handler.saveObjectAsync(cache.get(island.getUniqueId()));
+ }
+ return CompletableFuture.completedFuture(true);
}
}
diff --git a/src/main/java/world/bentobox/aoneblock/listeners/CheckPhase.java b/src/main/java/world/bentobox/aoneblock/listeners/CheckPhase.java
index 7cb0a734..6423a345 100644
--- a/src/main/java/world/bentobox/aoneblock/listeners/CheckPhase.java
+++ b/src/main/java/world/bentobox/aoneblock/listeners/CheckPhase.java
@@ -1,6 +1,7 @@
package world.bentobox.aoneblock.listeners;
import java.util.List;
+import java.util.Objects;
import java.util.stream.Collectors;
import org.bukkit.World;
@@ -22,6 +23,7 @@
/**
* Performs end of phase checking
+ *
* @author tastybento
*
*/
@@ -31,121 +33,153 @@ public class CheckPhase {
private final OneBlocksManager oneBlocksManager;
private final BlockListener blockListener;
-
/**
- * @param addon AOneBlock
+ * @param addon AOneBlock
* @param blockListener
*/
public CheckPhase(AOneBlock addon, BlockListener blockListener) {
- this.addon = addon;
- this.oneBlocksManager = addon.getOneBlockManager();
- this.blockListener = blockListener;
+ this.addon = addon;
+ this.oneBlocksManager = addon.getOneBlockManager();
+ this.blockListener = blockListener;
}
/**
- * Checks whether the player can proceed to the next phase
+ * Runs end phase commands, sets new phase and runs new phase commands
*
* @param player - player
* @param i - island
- * @param phase - one block phase
- * @param world - world
- * @return true if the player cannot proceed to the next phase.
+ * @param is - OneBlockIslands object
+ * @param phase - current phase
*/
- protected boolean phaseRequirementsFail(@Nullable Player player, @NonNull Island i, OneBlockPhase phase, @NonNull World world) {
- if (phase.getRequirements().isEmpty()) {
- return false;
- }
- // Check requirements
- boolean blocked = false;
- for (Requirement r : phase.getRequirements()) {
- boolean b = switch (r.getType()) {
- case LEVEL -> addon.getAddonByName("Level").map(l -> {
- if (((Level) l).getIslandLevel(world, i.getOwner()) < r.getLevel()) {
- User.getInstance(player).sendMessage("aoneblock.phase.insufficient-level", TextVariables.NUMBER, String.valueOf(r.getLevel()));
- return true;
- }
- return false;
- }).orElse(false);
- case BANK -> addon.getAddonByName("Bank").map(l -> {
- if (((Bank) l).getBankManager().getBalance(i).getValue() < r.getBank()) {
- User.getInstance(player).sendMessage("aoneblock.phase.insufficient-bank-balance", TextVariables.NUMBER, String.valueOf(r.getBank()));
- return true;
- }
- return false;
- }).orElse(false);
- case ECO -> addon.getPlugin().getVault().map(l -> {
- if (l.getBalance(User.getInstance(player), world) < r.getEco()) {
- User.getInstance(player).sendMessage("aoneblock.phase.insufficient-funds", TextVariables.NUMBER, String.valueOf(r.getEco()));
- return true;
- }
- return false;
- }).orElse(false);
- case PERMISSION -> {
- if (player != null && !player.hasPermission(r.getPermission())) {
- User.getInstance(player).sendMessage("aoneblock.phase.insufficient-permission", TextVariables.NAME, String.valueOf(r.getPermission()));
- yield true;
- }
- yield false;
- }
- };
- if (b) blocked = true;
- }
- return blocked;
+ void setNewPhase(@Nullable Player player, @NonNull Island i, @NonNull OneBlockIslands is,
+ @NonNull OneBlockPhase phase) {
+ // Handle NPCs
+ User user;
+ if (player == null || player.hasMetadata("NPC")) {
+ // Default to the owner
+ user = addon.getPlayers().getUser(i.getOwner());
+ } else {
+ user = User.getInstance(player);
+ }
+
+ String newPhaseName = Objects.requireNonNullElse(phase.getPhaseName(), "");
+
+ // Run previous phase end commands
+ oneBlocksManager.getPhase(is.getPhaseName()).ifPresent(oldPhase -> {
+ String oldPhaseName = oldPhase.getPhaseName() == null ? "" : oldPhase.getPhaseName();
+ Util.runCommands(user,
+ replacePlaceholders(player, oldPhaseName, phase.getBlockNumber(), i, oldPhase.getEndCommands()),
+ "Commands run for end of " + oldPhaseName);
+ // If first time
+ if (is.getBlockNumber() >= is.getLifetime()) {
+ Util.runCommands(user,
+ replacePlaceholders(player, oldPhaseName, phase.getBlockNumber(), i,
+ oldPhase.getFirstTimeEndCommands()),
+ "Commands run for first time completing " + oldPhaseName);
+ }
+ });
+ // Set the phase name
+ is.setPhaseName(newPhaseName);
+ if (user.isPlayer() && user.isOnline() && addon.inWorld(user.getWorld())) {
+ user.getPlayer().sendTitle(newPhaseName, null, -1, -1, -1);
+ }
+ // Run phase start commands
+ Util.runCommands(user,
+ replacePlaceholders(player, newPhaseName, phase.getBlockNumber(), i, phase.getStartCommands()),
+ "Commands run for start of " + newPhaseName);
+
+ blockListener.saveIsland(i);
}
/**
- * Check whether this phase is done or not.
+ * Checks whether the player can proceed to the next phase
*
* @param player - player
* @param i - island
- * @param is - OneBlockIslands object
- * @param phase - current phase name
- * @return true if this is a new phase, false if not
+ * @param phase - one block phase
+ * @param world - world
+ * @return true if the player cannot proceed to the next phase.
*/
- protected boolean checkPhase(@Nullable Player player, @NonNull Island i, @NonNull OneBlockIslands is, @NonNull OneBlockPhase phase) {
- // Handle NPCs
- User user;
- if (player == null || player.hasMetadata("NPC")) {
- // Default to the owner
- user = addon.getPlayers().getUser(i.getOwner());
- } else {
- user = User.getInstance(player);
- }
-
- String phaseName = phase.getPhaseName() == null ? "" : phase.getPhaseName();
- if (!is.getPhaseName().equalsIgnoreCase(phaseName)) {
- // Run previous phase end commands
- oneBlocksManager.getPhase(is.getPhaseName()).ifPresent(oldPhase -> {
- String oldPhaseName = oldPhase.getPhaseName() == null ? "" : oldPhase.getPhaseName();
- Util.runCommands(user,
- replacePlaceholders(player, oldPhaseName, phase.getBlockNumber(), i, oldPhase.getEndCommands()),
- "Commands run for end of " + oldPhaseName);
- // If first time
- if (is.getBlockNumber() >= is.getLifetime()) {
- Util.runCommands(user,
- replacePlaceholders(player, oldPhaseName, phase.getBlockNumber(), i, oldPhase.getFirstTimeEndCommands()),
- "Commands run for first time completing " + oldPhaseName);
- }
- });
- // Set the phase name
- is.setPhaseName(phaseName);
- if (user.isPlayer() && user.isOnline() && addon.inWorld(user.getWorld())) {
- user.getPlayer().sendTitle(phaseName, null, -1, -1, -1);
- }
- // Run phase start commands
- Util.runCommands(user,
- replacePlaceholders(player, phaseName, phase.getBlockNumber(), i, phase.getStartCommands()),
- "Commands run for start of " + phaseName);
-
- blockListener.saveIsland(i);
- return true;
- }
- return false;
+ protected boolean phaseRequirementsFail(@Nullable Player player, @NonNull Island i, @NonNull OneBlockIslands is,
+ OneBlockPhase phase, @NonNull World world) {
+
+ if (phase.getRequirements().isEmpty()) {
+ return false;
+ }
+
+ return phase.getRequirements().stream()
+ .anyMatch(r -> checkRequirement(r, User.getInstance(player), i, is, world));
+ }
+
+ private boolean checkRequirement(Requirement r, User user, Island i, OneBlockIslands is, World world) {
+ return switch (r.getType()) {
+ case LEVEL -> checkLevelRequirement(r, user, i, world);
+ case BANK -> checkBankRequirement(r, user, i);
+ case ECO -> checkEcoRequirement(r, user, world);
+ case PERMISSION -> checkPermissionRequirement(r, user);
+ case COOLDOWN -> checkCooldownRequirement(r, user, is);
+ };
+ }
+
+ private boolean checkLevelRequirement(Requirement r, User user, Island i, World world) {
+ // Level checking logic
+ return addon.getAddonByName("Level").map(l -> {
+ if (((Level) l).getIslandLevel(world, i.getOwner()) < r.getLevel()) {
+ user.sendMessage("aoneblock.phase.insufficient-level", TextVariables.NUMBER,
+ String.valueOf(r.getLevel()));
+ return true;
+ }
+ return false;
+ }).orElse(false);
+ }
+
+ private boolean checkBankRequirement(Requirement r, User user, Island i) {
+ // Bank checking logic
+ return addon.getAddonByName("Bank").map(l -> {
+ if (((Bank) l).getBankManager().getBalance(i).getValue() < r.getBank()) {
+ user.sendMessage("aoneblock.phase.insufficient-bank-balance", TextVariables.NUMBER,
+ String.valueOf(r.getBank()));
+ return true;
+ }
+ return false;
+ }).orElse(false);
+ }
+
+ private boolean checkEcoRequirement(Requirement r, User user, World world) {
+ // Eco checking logic
+ return addon.getPlugin().getVault().map(vaultHook -> {
+ if (vaultHook.getBalance(user, world) < r.getEco()) {
+ user.sendMessage("aoneblock.phase.insufficient-funds", TextVariables.NUMBER,
+ vaultHook.format(r.getEco()));
+ return true;
+ }
+ return false;
+ }).orElse(false);
+ }
+
+ private boolean checkPermissionRequirement(Requirement r, User user) {
+ // Permission checking logic
+ if (user != null && !user.hasPermission(r.getPermission())) {
+ user.sendMessage("aoneblock.phase.insufficient-permission", TextVariables.NAME, r.getPermission());
+ return true;
+ }
+ return false;
+ }
+
+ private boolean checkCooldownRequirement(Requirement r, User player, OneBlockIslands is) {
+ // Cooldown checking logic
+ long remainingTime = r.getCooldown() - (System.currentTimeMillis() - is.getLastPhaseChangeTime()) / 1000;
+ if (remainingTime > 0) {
+ player.sendMessage("aoneblock.phase.cooldown", TextVariables.NUMBER, String.valueOf(remainingTime));
+ return true;
+ }
+ return false;
}
/**
* Replaces placeholders in commands.
+ *
*
* [island] - Island name
* [owner] - Island owner's name
@@ -165,23 +199,23 @@ protected boolean checkPhase(@Nullable Player player, @NonNull Island i, @NonNul
* @return list of commands with placeholders replaced
*/
@NonNull
- List replacePlaceholders(@Nullable Player player, @NonNull String phaseName, @NonNull String phaseNumber, @NonNull Island i, List commands) {
- return commands.stream()
- .map(c -> {
- long level = addon.getAddonByName("Level").map(l -> ((Level) l).getIslandLevel(addon.getOverWorld(), i.getOwner())).orElse(0L);
- double balance = addon.getAddonByName("Bank").map(b -> ((Bank) b).getBankManager().getBalance(i).getValue()).orElse(0D);
- double ecoBalance = addon.getPlugin().getVault().map(v -> v.getBalance(User.getInstance(player), addon.getOverWorld())).orElse(0D);
-
- return c.replace("[island]", i.getName() == null ? "" : i.getName())
- .replace("[owner]", addon.getPlayers().getName(i.getOwner()))
- .replace("[phase]", phaseName)
- .replace("[blocks]", phaseNumber)
- .replace("[level]", String.valueOf(level))
- .replace("[bank-balance]", String.valueOf(balance))
- .replace("[eco-balance]", String.valueOf(ecoBalance));
-
- })
- .map(c -> addon.getPlugin().getPlaceholdersManager().replacePlaceholders(player, c))
- .collect(Collectors.toList());
+ List replacePlaceholders(@Nullable Player player, @NonNull String phaseName, @NonNull String phaseNumber,
+ @NonNull Island i, List commands) {
+ return commands.stream().map(c -> {
+ long level = addon.getAddonByName("Level")
+ .map(l -> ((Level) l).getIslandLevel(addon.getOverWorld(), i.getOwner())).orElse(0L);
+ double balance = addon.getAddonByName("Bank").map(b -> ((Bank) b).getBankManager().getBalance(i).getValue())
+ .orElse(0D);
+ double ecoBalance = addon.getPlugin().getVault()
+ .map(v -> v.getBalance(User.getInstance(player), addon.getOverWorld())).orElse(0D);
+
+ return c.replace("[island]", i.getName() == null ? "" : i.getName())
+ .replace("[owner]", addon.getPlayers().getName(i.getOwner())).replace("[phase]", phaseName)
+ .replace("[blocks]", phaseNumber).replace("[level]", String.valueOf(level))
+ .replace("[bank-balance]", String.valueOf(balance))
+ .replace("[eco-balance]", String.valueOf(ecoBalance));
+
+ }).map(c -> addon.getPlugin().getPlaceholdersManager().replacePlaceholders(player, c))
+ .collect(Collectors.toList());
}
}
diff --git a/src/main/java/world/bentobox/aoneblock/listeners/HoloListener.java b/src/main/java/world/bentobox/aoneblock/listeners/HoloListener.java
index 8a3efb22..21f3dc78 100644
--- a/src/main/java/world/bentobox/aoneblock/listeners/HoloListener.java
+++ b/src/main/java/world/bentobox/aoneblock/listeners/HoloListener.java
@@ -1,5 +1,10 @@
package world.bentobox.aoneblock.listeners;
+import java.util.IdentityHashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.UUID;
+
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
@@ -9,6 +14,7 @@
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.eclipse.jdt.annotation.NonNull;
+
import world.bentobox.aoneblock.AOneBlock;
import world.bentobox.aoneblock.dataobjects.OneBlockIslands;
import world.bentobox.aoneblock.oneblocks.OneBlockPhase;
@@ -17,11 +23,6 @@
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.util.Util;
-import java.util.IdentityHashMap;
-import java.util.Map;
-import java.util.Optional;
-import java.util.UUID;
-
/**
* Handles Holographic elements
*
diff --git a/src/main/java/world/bentobox/aoneblock/listeners/ItemsAdderListener.java b/src/main/java/world/bentobox/aoneblock/listeners/ItemsAdderListener.java
index a6948c77..bf4c25bb 100644
--- a/src/main/java/world/bentobox/aoneblock/listeners/ItemsAdderListener.java
+++ b/src/main/java/world/bentobox/aoneblock/listeners/ItemsAdderListener.java
@@ -1,8 +1,9 @@
package world.bentobox.aoneblock.listeners;
-import dev.lone.itemsadder.api.Events.ItemsAdderLoadDataEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
+
+import dev.lone.itemsadder.api.Events.ItemsAdderLoadDataEvent;
import world.bentobox.aoneblock.AOneBlock;
/**
diff --git a/src/main/java/world/bentobox/aoneblock/listeners/MakeSpace.java b/src/main/java/world/bentobox/aoneblock/listeners/MakeSpace.java
index 75d2dce1..5dfa914a 100644
--- a/src/main/java/world/bentobox/aoneblock/listeners/MakeSpace.java
+++ b/src/main/java/world/bentobox/aoneblock/listeners/MakeSpace.java
@@ -52,7 +52,7 @@ public MakeSpace(AOneBlock addon) {
* @param entity Entity that is spawned.
* @param spawnLocation Location where entity is spawned.
*/
- void makeSpace(@NonNull Entity entity, @NonNull Location spawnLocation)
+ public void makeSpace(@NonNull Entity entity, @NonNull Location spawnLocation)
{
World world = entity.getWorld();
List airBlocks = new ArrayList<>();
diff --git a/src/main/java/world/bentobox/aoneblock/oneblocks/OneBlockCustomBlock.java b/src/main/java/world/bentobox/aoneblock/oneblocks/OneBlockCustomBlock.java
index 40560508..458eb47a 100644
--- a/src/main/java/world/bentobox/aoneblock/oneblocks/OneBlockCustomBlock.java
+++ b/src/main/java/world/bentobox/aoneblock/oneblocks/OneBlockCustomBlock.java
@@ -2,16 +2,18 @@
import org.bukkit.block.Block;
+import world.bentobox.aoneblock.AOneBlock;
+
/**
- * Represents a custom block
+ * Represents a custom block with custom executable
*
* @author HSGamer
*/
public interface OneBlockCustomBlock {
/**
- * Set the block
+ * Executes the custom logic
*
* @param block the block
*/
- void setBlock(Block block);
+ void execute(AOneBlock addon, Block block);
}
diff --git a/src/main/java/world/bentobox/aoneblock/oneblocks/OneBlockCustomBlockCreator.java b/src/main/java/world/bentobox/aoneblock/oneblocks/OneBlockCustomBlockCreator.java
index 36cb8af2..d46b507c 100644
--- a/src/main/java/world/bentobox/aoneblock/oneblocks/OneBlockCustomBlockCreator.java
+++ b/src/main/java/world/bentobox/aoneblock/oneblocks/OneBlockCustomBlockCreator.java
@@ -1,10 +1,16 @@
package world.bentobox.aoneblock.oneblocks;
-import world.bentobox.aoneblock.oneblocks.customblock.BlockDataCustomBlock;
-
-import java.util.*;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
import java.util.function.Function;
+import world.bentobox.aoneblock.oneblocks.customblock.BlockDataCustomBlock;
+import world.bentobox.aoneblock.oneblocks.customblock.MobCustomBlock;
+
/**
* A creator for {@link OneBlockCustomBlock}
*
@@ -16,6 +22,7 @@ public final class OneBlockCustomBlockCreator {
static {
register("block-data", BlockDataCustomBlock::fromMap);
+ register("mob", MobCustomBlock::fromMap);
register("short", map -> {
String type = Objects.toString(map.get("data"), null);
if (type == null) {
diff --git a/src/main/java/world/bentobox/aoneblock/oneblocks/OneBlockObject.java b/src/main/java/world/bentobox/aoneblock/oneblocks/OneBlockObject.java
index 64646f8d..b86eb693 100644
--- a/src/main/java/world/bentobox/aoneblock/oneblocks/OneBlockObject.java
+++ b/src/main/java/world/bentobox/aoneblock/oneblocks/OneBlockObject.java
@@ -42,7 +42,6 @@ public enum Rarity {
private Map chest;
private Rarity rarity;
private OneBlockCustomBlock customBlock;
- private String itemsAdderBlock;
private int prob;
/**
@@ -78,18 +77,6 @@ public OneBlockObject(OneBlockCustomBlock customBlock, int prob) {
this.prob = prob;
}
- /**
- * An ItemsAdder block
- *
- * @param namedSpaceID - ItemsAdder block
- * @param prob - relative probability
- */
-
- public OneBlockObject(String namedSpaceID, int prob) {
- this.itemsAdderBlock = namedSpaceID;
- this.prob = prob;
- }
-
/**
* A chest
*
@@ -113,7 +100,6 @@ public OneBlockObject(OneBlockObject ob) {
this.rarity = ob.getRarity();
this.prob = ob.getProb();
this.customBlock = ob.getCustomBlock();
- this.itemsAdderBlock = ob.getItemsAdderBlock();
}
/**
@@ -147,11 +133,6 @@ public OneBlockCustomBlock getCustomBlock() {
return customBlock;
}
- /**
- * @return the itemsAdderBlock
- */
- public String getItemsAdderBlock() { return itemsAdderBlock; }
-
/**
* @return the isMaterial
@@ -176,13 +157,6 @@ public boolean isCustomBlock() {
return customBlock != null;
}
- /**
- * @return the isItemsAdderBlock
- */
- public boolean isItemsAdderBlock() {
- return itemsAdderBlock != null;
- }
-
/**
* @return the rarity
*/
diff --git a/src/main/java/world/bentobox/aoneblock/oneblocks/OneBlockPhase.java b/src/main/java/world/bentobox/aoneblock/oneblocks/OneBlockPhase.java
index 9f9efbe4..af595537 100644
--- a/src/main/java/world/bentobox/aoneblock/oneblocks/OneBlockPhase.java
+++ b/src/main/java/world/bentobox/aoneblock/oneblocks/OneBlockPhase.java
@@ -165,17 +165,6 @@ public void addCustomBlock(OneBlockCustomBlock customBlock, int prob) {
probMap.put(total, new OneBlockObject(customBlock, prob));
}
- /**
- * Adds a ItemsAdder's custom block and associated probability
- * @param namedSpaceID - name space and ID
- * @param prob - probability
- */
- public void addItemsAdderCustomBlock(String namedSpaceID, int prob) {
- total += prob;
- blockTotal += prob;
- probMap.put(total, new OneBlockObject(namedSpaceID, prob));
- }
-
/**
* Adds an entity type and associated probability
*
diff --git a/src/main/java/world/bentobox/aoneblock/oneblocks/OneBlocksManager.java b/src/main/java/world/bentobox/aoneblock/oneblocks/OneBlocksManager.java
index e369b6bb..e5516509 100644
--- a/src/main/java/world/bentobox/aoneblock/oneblocks/OneBlocksManager.java
+++ b/src/main/java/world/bentobox/aoneblock/oneblocks/OneBlocksManager.java
@@ -31,8 +31,6 @@
import com.google.common.base.Enums;
import com.google.common.io.Files;
-import dev.lone.itemsadder.api.CustomBlock;
-import dev.lone.itemsadder.api.ItemsAdder;
import world.bentobox.aoneblock.AOneBlock;
import world.bentobox.aoneblock.dataobjects.OneBlockIslands;
import world.bentobox.aoneblock.oneblocks.OneBlockObject.Rarity;
@@ -42,6 +40,7 @@
/**
* Provides a manager for all phases
+ *
* @author tastybento
*
*/
@@ -65,6 +64,9 @@ public class OneBlocksManager {
private static final String END_COMMANDS = "end-commands";
private static final String END_COMMANDS_FIRST_TIME = "end-commands-first-time";
private static final String REQUIREMENTS = "requirements";
+ private static final String BLOCK = "Block ";
+ private static final String BUT_ALREADY_SET_TO = " but already set to ";
+ private static final String DUPLICATE = " Duplicate phase file?";
private final AOneBlock addon;
private TreeMap blockProbs;
@@ -72,9 +74,9 @@ public class OneBlocksManager {
* @param addon - addon
*/
public OneBlocksManager(AOneBlock addon) {
- this.addon = addon;
- // Initialize block probabilities
- blockProbs = new TreeMap<>();
+ this.addon = addon;
+ // Initialize block probabilities
+ blockProbs = new TreeMap<>();
}
/**
@@ -83,34 +85,34 @@ public OneBlocksManager(AOneBlock addon) {
* @throws IOException - if config file has bad syntax or migration fails
*/
public void loadPhases() throws IOException {
- // Clear block probabilities
- blockProbs = new TreeMap<>();
- // Check for folder
- File check = new File(addon.getDataFolder(), PHASES);
- if (check.mkdirs()) {
- addon.log(check.getAbsolutePath() + " does not exist, made folder.");
- // Check for oneblock.yml
- File oneblockFile = new File(addon.getDataFolder(), ONE_BLOCKS_YML);
- if (oneblockFile.exists()) {
- // Migrate to new folders
- File renamedFile = new File(check, ONE_BLOCKS_YML);
- Files.move(oneblockFile, renamedFile);
- loadPhase(renamedFile);
- this.saveOneBlockConfig();
- java.nio.file.Files.delete(oneblockFile.toPath());
- java.nio.file.Files.delete(renamedFile.toPath());
- blockProbs.clear();
- } else {
- // Copy files from JAR
- copyPhasesFromAddonJar(check);
- }
- }
- // Get files in folder
- // Filter for files ending with .yml
- FilenameFilter ymlFilter = (dir, name) -> name.toLowerCase(java.util.Locale.ENGLISH).endsWith(".yml");
- for (File phaseFile : Objects.requireNonNull(check.listFiles(ymlFilter))) {
- loadPhase(phaseFile);
- }
+ // Clear block probabilities
+ blockProbs = new TreeMap<>();
+ // Check for folder
+ File check = new File(addon.getDataFolder(), PHASES);
+ if (check.mkdirs()) {
+ addon.log(check.getAbsolutePath() + " does not exist, made folder.");
+ // Check for oneblock.yml
+ File oneblockFile = new File(addon.getDataFolder(), ONE_BLOCKS_YML);
+ if (oneblockFile.exists()) {
+ // Migrate to new folders
+ File renamedFile = new File(check, ONE_BLOCKS_YML);
+ Files.move(oneblockFile, renamedFile);
+ loadPhase(renamedFile);
+ this.saveOneBlockConfig();
+ java.nio.file.Files.delete(oneblockFile.toPath());
+ java.nio.file.Files.delete(renamedFile.toPath());
+ blockProbs.clear();
+ } else {
+ // Copy files from JAR
+ copyPhasesFromAddonJar(check);
+ }
+ }
+ // Get files in folder
+ // Filter for files ending with .yml
+ FilenameFilter ymlFilter = (dir, name) -> name.toLowerCase(java.util.Locale.ENGLISH).endsWith(".yml");
+ for (File phaseFile : Objects.requireNonNull(check.listFiles(ymlFilter))) {
+ loadPhase(phaseFile);
+ }
}
/**
@@ -119,391 +121,425 @@ public void loadPhases() throws IOException {
* @param file - the file to copy
*/
void copyPhasesFromAddonJar(File file) {
- try (JarFile jar = new JarFile(addon.getFile())) {
- // Obtain any locale files, save them and update
- Util.listJarFiles(jar, PHASES, ".yml").forEach(lf -> addon.saveResource(lf, file, false, true));
- } catch (Exception e) {
- addon.logError(e.getMessage());
- }
+ try (JarFile jar = new JarFile(addon.getFile())) {
+ // Obtain any locale files, save them and update
+ Util.listJarFiles(jar, PHASES, ".yml").forEach(lf -> addon.saveResource(lf, file, false, true));
+ } catch (Exception e) {
+ addon.logError(e.getMessage());
+ }
}
private void loadPhase(File phaseFile) throws IOException {
- addon.log("Loading " + phaseFile.getName());
- // Load the config file
- YamlConfiguration oneBlocks = new YamlConfiguration();
- try {
- oneBlocks.load(phaseFile);
- } catch (Exception e) {
- addon.logError(e.getMessage());
- return;
- }
- for (String blockNumber : oneBlocks.getKeys(false)) {
- Integer blockNum = Integer.valueOf(blockNumber);
- OneBlockPhase obPhase = blockProbs.computeIfAbsent(blockNum, k -> new OneBlockPhase(blockNumber));
- // Get config Section
- ConfigurationSection phase = oneBlocks.getConfigurationSection(blockNumber);
- // goto
- if (phase.contains(GOTO_BLOCK)) {
- obPhase.setGotoBlock(phase.getInt(GOTO_BLOCK, 0));
- continue;
- }
- initBlock(blockNumber, obPhase, phase);
- // Blocks
- addBlocks(obPhase, phase);
- // Mobs
- addMobs(obPhase, phase);
- // Chests
- addChests(obPhase, phase);
- // Commands
- addCommands(obPhase, phase);
- // Requirements
- addRequirements(obPhase, phase);
- // Add to the map
- blockProbs.put(blockNum, obPhase);
- }
+ addon.log("Loading " + phaseFile.getName());
+ // Load the config file
+ YamlConfiguration oneBlocks = new YamlConfiguration();
+ try {
+ oneBlocks.load(phaseFile);
+ } catch (Exception e) {
+ addon.logError(e.getMessage());
+ return;
+ }
+ for (String phaseStartBlockNumKey : oneBlocks.getKeys(false)) {
+ Integer phaseStartBlockNum = Integer.valueOf(phaseStartBlockNumKey);
+ OneBlockPhase obPhase = blockProbs.computeIfAbsent(phaseStartBlockNum,
+ k -> new OneBlockPhase(phaseStartBlockNumKey));
+ // Get config Section
+ ConfigurationSection phaseConfig = oneBlocks.getConfigurationSection(phaseStartBlockNumKey);
+ // goto
+ if (phaseConfig.contains(GOTO_BLOCK)) {
+ obPhase.setGotoBlock(phaseConfig.getInt(GOTO_BLOCK, 0));
+ continue;
+ }
+ initBlock(phaseStartBlockNumKey, obPhase, phaseConfig);
+ // Blocks
+ addBlocks(obPhase, phaseConfig);
+ // Mobs
+ addMobs(obPhase, phaseConfig);
+ // Chests
+ addChests(obPhase, phaseConfig);
+ // Commands
+ addCommands(obPhase, phaseConfig);
+ // Requirements
+ addRequirements(obPhase, phaseConfig);
+ // Add to the map
+ blockProbs.put(phaseStartBlockNum, obPhase);
+ }
}
/**
* Load in the phase's init
+ *
* @param blockNumber string representation of this phase's block number
- * @param obPhase OneBlockPhase
- * @param phase configuration section being read
+ * @param obPhase OneBlockPhase
+ * @param phaseConfig configuration section being read
* @throws IOException if there's an error in the config file
*/
- void initBlock(String blockNumber, OneBlockPhase obPhase, ConfigurationSection phase) throws IOException {
- if (phase.contains(NAME, true)) {
- if (obPhase.getPhaseName() != null) {
- throw new IOException("Block " + blockNumber + ": Phase name trying to be set to " + phase.getString(NAME) + " but already set to " + obPhase.getPhaseName() + ". Duplicate phase file?");
- }
- // name
- obPhase.setPhaseName(phase.getString(NAME, blockNumber));
- }
- // biome
- if (phase.contains(BIOME, true)) {
- if (obPhase.getPhaseBiome() != null) {
- throw new IOException("Block " + blockNumber + ": Biome trying to be set to " + phase.getString(BIOME) + " but already set to " + obPhase.getPhaseBiome() + " Duplicate phase file?");
- }
- obPhase.setPhaseBiome(getBiome(phase.getString(BIOME)));
- }
- // First block
- if (phase.contains(FIRST_BLOCK)) {
- if (obPhase.getFirstBlock() != null) {
- throw new IOException("Block " + blockNumber + ": First block trying to be set to " + phase.getString(FIRST_BLOCK) + " but already set to " + obPhase.getFirstBlock() + " Duplicate phase file?");
- }
- addFirstBlock(obPhase, phase.getString(FIRST_BLOCK));
- }
- // Icon block
- if (phase.contains(ICON)) {
- ItemStack icon = ItemParser.parse(phase.getString(ICON));
-
- if (icon == null) {
- throw new IOException("ItemParser failed to parse icon: '" + phase.getString(ICON) + "' for phase " + obPhase.getFirstBlock() + ". Can you check if it is correct?");
- }
-
- obPhase.setIconBlock(icon);
- }
- // First blocks
- if (phase.contains(FIXED_BLOCKS)) {
- if (!obPhase.getFixedBlocks().isEmpty()) {
- throw new IOException("Block " + blockNumber + ": Fixed blocks trying to be set to " + phase.getString(FIXED_BLOCKS) + " but already set to " + obPhase.getFixedBlocks() + " Duplicate phase file?");
- }
- addFixedBlocks(obPhase, phase.getConfigurationSection(FIXED_BLOCKS));
- }
-
- if (phase.contains(HOLOGRAMS)) {
- if (!obPhase.getHologramLines().isEmpty()) {
- throw new IOException("Block " + blockNumber + ": Hologram Lines trying to be set to " + phase.getString(HOLOGRAMS) + " but already set to " + obPhase.getHologramLines() + " Duplicate phase file?");
- }
- addHologramLines(obPhase, phase.getConfigurationSection(HOLOGRAMS));
- }
- }
-
- private void addFixedBlocks(OneBlockPhase obPhase, ConfigurationSection fb) {
- if (fb == null) {
- return;
- }
- Map result = new HashMap<>();
- for (String key : fb.getKeys(false)) {
- if (!NumberUtils.isNumber(key)) {
- addon.logError("Fixed block key must be an integer. " + key);
- continue;
- }
- int k = Integer.parseInt(key);
- if (fb.isConfigurationSection(key)) {
- Map map = fb.getConfigurationSection(key).getValues(false);
- Optional customBlock = OneBlockCustomBlockCreator.create(map);
- if (customBlock.isPresent()) {
- result.put(k, new OneBlockObject(customBlock.get(), 0));
- } else {
- addon.logError("Fixed block key " + key + " material is not a valid custom block. Ignoring.");
- }
- } else {
- String mat = fb.getString(key);
- if (mat == null) {
- continue;
- }
-
- Optional customBlock = OneBlockCustomBlockCreator.create(mat);
- if (customBlock.isPresent()) {
- result.put(k, new OneBlockObject(customBlock.get(), 0));
- } else {
- Material m = Material.matchMaterial(mat);
- if (m != null && m.isBlock()) {
- result.put(k, new OneBlockObject(m, 0));
- } else {
- addon.logError("Fixed block key " + key + " material is invalid or not a block. Ignoring.");
- }
- }
- }
- }
- // Set the first block if it exists
- if (result.containsKey(0)) {
- obPhase.setFirstBlock(result.get(0));
- }
- // Store the remainder
- obPhase.setFixedBlocks(result);
+ void initBlock(String blockNumber, OneBlockPhase obPhase, ConfigurationSection phaseConfig) throws IOException {
+ // Set name
+ if (phaseConfig.contains(NAME, true)) {
+ if (obPhase.getPhaseName() != null) {
+ throw new IOException(
+ BLOCK + blockNumber + ": Phase name trying to be set to " + phaseConfig.getString(NAME)
+ + BUT_ALREADY_SET_TO + obPhase.getPhaseName() + ". Duplicate phase file?");
+ }
+ obPhase.setPhaseName(phaseConfig.getString(NAME, blockNumber));
+ }
+
+ // Set biome
+ if (phaseConfig.contains(BIOME, true)) {
+ if (obPhase.getPhaseBiome() != null) {
+ throw new IOException(BLOCK + blockNumber + ": Biome trying to be set to "
+ + phaseConfig.getString(BIOME) + BUT_ALREADY_SET_TO + obPhase.getPhaseBiome() + DUPLICATE);
+ }
+ obPhase.setPhaseBiome(getBiome(phaseConfig.getString(BIOME)));
+ }
+
+ // Set first block
+ if (phaseConfig.contains(FIRST_BLOCK)) {
+ if (obPhase.getFirstBlock() != null) {
+ throw new IOException(
+ BLOCK + blockNumber + ": First block trying to be set to " + phaseConfig.getString(FIRST_BLOCK)
+ + BUT_ALREADY_SET_TO + obPhase.getFirstBlock() + DUPLICATE);
+ }
+ addFirstBlock(obPhase, phaseConfig.getString(FIRST_BLOCK));
+ }
+
+ // Set icon
+ if (phaseConfig.contains(ICON)) {
+ ItemStack icon = ItemParser.parse(phaseConfig.getString(ICON));
+
+ if (icon == null) {
+ throw new IOException("ItemParser failed to parse icon: '" + phaseConfig.getString(ICON)
+ + "' for phase " + obPhase.getFirstBlock() + ". Can you check if it is correct?");
+ }
+
+ obPhase.setIconBlock(icon);
+ }
+
+ // Add fixed blocks
+ if (phaseConfig.contains(FIXED_BLOCKS)) {
+ if (!obPhase.getFixedBlocks().isEmpty()) {
+ throw new IOException(BLOCK + blockNumber + ": Fixed blocks trying to be set to "
+ + phaseConfig.getString(FIXED_BLOCKS) + BUT_ALREADY_SET_TO + obPhase.getFixedBlocks()
+ + DUPLICATE);
+ }
+ addFixedBlocks(obPhase, phaseConfig.getConfigurationSection(FIXED_BLOCKS));
+ }
+
+ // Add holograms
+ if (phaseConfig.contains(HOLOGRAMS)) {
+ if (!obPhase.getHologramLines().isEmpty()) {
+ throw new IOException(
+ BLOCK + blockNumber + ": Hologram Lines trying to be set to " + phaseConfig.getString(HOLOGRAMS)
+ + BUT_ALREADY_SET_TO + obPhase.getHologramLines() + DUPLICATE);
+ }
+ addHologramLines(obPhase, phaseConfig.getConfigurationSection(HOLOGRAMS));
+ }
+ }
+
+ private void addFixedBlocks(OneBlockPhase obPhase, ConfigurationSection firstBlocksConfig) {
+ if (firstBlocksConfig == null) {
+ return;
+ }
+
+ Map result = parseFirstBlocksConfig(firstBlocksConfig);
+
+ // Set the first block if it exists
+ if (result.containsKey(0)) {
+ addon.log("Found firstBlock in fixedBlocks.");
+ obPhase.setFirstBlock(result.get(0));
+ }
+ // Store the remainder
+ obPhase.setFixedBlocks(result);
+ }
+
+ private Map parseFirstBlocksConfig(ConfigurationSection firstBlocksConfig) {
+ Map result = new HashMap<>();
+
+ for (String key : firstBlocksConfig.getKeys(false)) {
+ if (!NumberUtils.isNumber(key)) {
+ addon.logError("Fixed block key must be an integer. " + key);
+ continue;
+ }
+ int k = Integer.parseInt(key);
+ parseBlock(result, firstBlocksConfig, key, k);
+ }
+ return result;
+ }
+
+ private void parseBlock(Map result, ConfigurationSection firstBlocksConfig, String key,
+ int k) {
+ if (firstBlocksConfig.isConfigurationSection(key)) {
+ parseObjectBlock(result, firstBlocksConfig, key, k);
+ } else {
+ parseStringBlock(result, firstBlocksConfig, key, k);
+ }
+ }
+
+ /**
+ * This method handles the case where the block's value is a configuration
+ * section, indicating that the block is defined as an object.
+ *
+ * @param result the resulting map
+ * @param firstBlocksConfig config
+ * @param key key
+ * @param k integer value of key
+ */
+ private void parseObjectBlock(Map result, ConfigurationSection firstBlocksConfig,
+ String key, int k) {
+ // Object block parsing logic
+ Map map = firstBlocksConfig.getConfigurationSection(key).getValues(false);
+ Optional customBlock = OneBlockCustomBlockCreator.create(map);
+ if (customBlock.isPresent()) {
+ result.put(k, new OneBlockObject(customBlock.get(), 0));
+ } else {
+ addon.logError("Fixed block key " + key + " material is not a valid custom block. Ignoring.");
+ }
+ }
+ /**
+ * This method handles the case where the block's value is a string, which could
+ * either be a custom block or a standard Minecraft material.
+ *
+ * @param result the resulting map
+ * @param firstBlocksConfig config
+ * @param key key
+ * @param k integer value of key
+ */
+ private void parseStringBlock(Map result, ConfigurationSection firstBlocksConfig,
+ String key, int k) {
+ // String block parsing logic
+ String mat = firstBlocksConfig.getString(key);
+ if (mat == null) {
+ return;
+ }
+
+ Optional customBlock = OneBlockCustomBlockCreator.create(mat);
+ if (customBlock.isPresent()) {
+ result.put(k, new OneBlockObject(customBlock.get(), 0));
+ } else {
+ Material m = Material.matchMaterial(mat);
+ if (m != null && m.isBlock()) {
+ result.put(k, new OneBlockObject(m, 0));
+ } else {
+ addon.logError("Fixed block key " + key + " material is invalid or not a block. Ignoring.");
+ }
+ }
}
private void addHologramLines(OneBlockPhase obPhase, ConfigurationSection fb) {
- if (fb == null) return;
- Map result = new HashMap<>();
- for (String key : fb.getKeys(false)) {
- if (!NumberUtils.isNumber(key)) {
- addon.logError("Fixed block key must be an integer. " + key);
- continue;
- }
- int k = Integer.parseInt(key);
- String line = fb.getString(key);
- if (line != null) {
- result.put(k, line);
- }
- }
- // Set Hologram Lines
- obPhase.setHologramLines(result);
+ if (fb == null)
+ return;
+ Map result = new HashMap<>();
+ for (String key : fb.getKeys(false)) {
+ if (!NumberUtils.isNumber(key)) {
+ addon.logError("Fixed block key must be an integer. " + key);
+ continue;
+ }
+ int k = Integer.parseInt(key);
+ String line = fb.getString(key);
+ if (line != null) {
+ result.put(k, line);
+ }
+ }
+ // Set Hologram Lines
+ obPhase.setHologramLines(result);
}
private Biome getBiome(String string) {
- if (string == null) {
- return Biome.PLAINS;
- }
- if (Enums.getIfPresent(Biome.class, string).isPresent()) {
- return Biome.valueOf(string);
- }
- // Special case for nether
- if (string.equals("NETHER") || string.equals("NETHER_WASTES")) {
- return Enums.getIfPresent(Biome.class, "NETHER")
- .or(Enums.getIfPresent(Biome.class, "NETHER_WASTES").or(Biome.PLAINS));
- }
- addon.logError("Biome " + string.toUpperCase() + " is invalid! Use one of these...");
- addon.logError(Arrays.stream(Biome.values()).map(Biome::name).collect(Collectors.joining(",")));
- return Biome.PLAINS;
+ if (string == null) {
+ return Biome.PLAINS;
+ }
+ if (Enums.getIfPresent(Biome.class, string).isPresent()) {
+ return Biome.valueOf(string);
+ }
+ // Special case for nether
+ if (string.equals("NETHER") || string.equals("NETHER_WASTES")) {
+ return Enums.getIfPresent(Biome.class, "NETHER")
+ .or(Enums.getIfPresent(Biome.class, "NETHER_WASTES").or(Biome.PLAINS));
+ }
+ addon.logError("Biome " + string.toUpperCase() + " is invalid! Use one of these...");
+ addon.logError(Arrays.stream(Biome.values()).map(Biome::name).collect(Collectors.joining(",")));
+ return Biome.PLAINS;
}
void addFirstBlock(OneBlockPhase obPhase, @Nullable String material) {
- if (material == null) {
- return;
- }
- Material m = Material.matchMaterial(material);
- if (m == null || !m.isBlock()) {
- addon.logError("Bad firstBlock material: " + material);
- } else {
- obPhase.setFirstBlock(new OneBlockObject(m, 0));
- }
+ if (material == null) {
+ return;
+ }
+ Material m = Material.matchMaterial(material);
+ if (m == null || !m.isBlock()) {
+ addon.logError("Bad firstBlock material: " + material);
+ } else {
+ obPhase.setFirstBlock(new OneBlockObject(m, 0));
+ }
}
void addCommands(OneBlockPhase obPhase, ConfigurationSection phase) {
- if (phase.contains(START_COMMANDS)) {
- obPhase.setStartCommands(phase.getStringList(START_COMMANDS));
- }
- if (phase.contains(END_COMMANDS)) {
- obPhase.setEndCommands(phase.getStringList(END_COMMANDS));
- }
- if (phase.contains(END_COMMANDS_FIRST_TIME)) {
- obPhase.setFirstTimeEndCommands(phase.getStringList(END_COMMANDS_FIRST_TIME));
- }
+ if (phase.contains(START_COMMANDS)) {
+ obPhase.setStartCommands(phase.getStringList(START_COMMANDS));
+ }
+ if (phase.contains(END_COMMANDS)) {
+ obPhase.setEndCommands(phase.getStringList(END_COMMANDS));
+ }
+ if (phase.contains(END_COMMANDS_FIRST_TIME)) {
+ obPhase.setFirstTimeEndCommands(phase.getStringList(END_COMMANDS_FIRST_TIME));
+ }
}
void addRequirements(OneBlockPhase obPhase, ConfigurationSection phase) {
- List reqList = new ArrayList<>();
- if (!phase.isConfigurationSection(REQUIREMENTS)) {
- return;
- }
- ConfigurationSection reqs = phase.getConfigurationSection(REQUIREMENTS);
- for (ReqType key : Requirement.ReqType.values()) {
- if (reqs.contains(key.getKey())) {
- Requirement r;
- if (key.getClazz().equals(Double.class)) {
- r = new Requirement(key, reqs.getDouble(key.getKey()));
- } else if (key.getClazz().equals(Long.class)) {
- r = new Requirement(key, reqs.getLong(key.getKey()));
- } else {
- r = new Requirement(key, reqs.getString(key.getKey()));
- }
- reqList.add(r);
- }
- }
- obPhase.setRequirements(reqList);
+ List reqList = new ArrayList<>();
+ if (!phase.isConfigurationSection(REQUIREMENTS)) {
+ return;
+ }
+ ConfigurationSection reqs = phase.getConfigurationSection(REQUIREMENTS);
+ for (ReqType key : Requirement.ReqType.values()) {
+ if (reqs.contains(key.getKey())) {
+ Requirement r;
+ if (key.getClazz().equals(Double.class)) {
+ r = new Requirement(key, reqs.getDouble(key.getKey()));
+ } else if (key.getClazz().equals(Long.class)) {
+ r = new Requirement(key, reqs.getLong(key.getKey()));
+ } else {
+ r = new Requirement(key, reqs.getString(key.getKey()));
+ }
+ reqList.add(r);
+ }
+ }
+ obPhase.setRequirements(reqList);
}
void addChests(OneBlockPhase obPhase, ConfigurationSection phase) throws IOException {
- if (!phase.isConfigurationSection(CHESTS)) {
- return;
- }
- if (!obPhase.getChests().isEmpty()) {
- throw new IOException(obPhase.getPhaseName() + ": Chests cannot be set more than once. Duplicate file?");
- }
- ConfigurationSection chests = phase.getConfigurationSection(CHESTS);
- for (String chestId : chests.getKeys(false)) {
- ConfigurationSection chest = chests.getConfigurationSection(chestId);
- Rarity rarity = Rarity.COMMON;
- try {
- rarity = OneBlockObject.Rarity.valueOf(chest.getString(RARITY, "COMMON").toUpperCase());
- } catch (Exception e) {
- addon.logError(
- "Rarity value of " + chest.getString(RARITY, "UNKNOWN") + " is invalid! Use one of these...");
- addon.logError(Arrays.stream(Rarity.values()).map(Rarity::name).collect(Collectors.joining(",")));
- rarity = Rarity.COMMON;
- }
- Map items = new HashMap<>();
- ConfigurationSection contents = chest.getConfigurationSection(CONTENTS);
- if (contents != null) {
- for (String index : contents.getKeys(false)) {
- int slot = Integer.parseInt(index);
- ItemStack item = contents.getItemStack(index);
- if (item != null) {
- items.put(slot, item);
- }
- }
- }
- obPhase.addChest(items, rarity);
- }
+ if (!phase.isConfigurationSection(CHESTS)) {
+ return;
+ }
+ if (!obPhase.getChests().isEmpty()) {
+ throw new IOException(obPhase.getPhaseName() + ": Chests cannot be set more than once. Duplicate file?");
+ }
+ ConfigurationSection chests = phase.getConfigurationSection(CHESTS);
+ for (String chestId : chests.getKeys(false)) {
+ ConfigurationSection chest = chests.getConfigurationSection(chestId);
+ Rarity rarity = Rarity.COMMON;
+ try {
+ rarity = OneBlockObject.Rarity.valueOf(chest.getString(RARITY, "COMMON").toUpperCase());
+ } catch (Exception e) {
+ addon.logError(
+ "Rarity value of " + chest.getString(RARITY, "UNKNOWN") + " is invalid! Use one of these...");
+ addon.logError(Arrays.stream(Rarity.values()).map(Rarity::name).collect(Collectors.joining(",")));
+ rarity = Rarity.COMMON;
+ }
+ Map items = new HashMap<>();
+ ConfigurationSection contents = chest.getConfigurationSection(CONTENTS);
+ if (contents != null) {
+ for (String index : contents.getKeys(false)) {
+ int slot = Integer.parseInt(index);
+ ItemStack item = contents.getItemStack(index);
+ if (item != null) {
+ items.put(slot, item);
+ }
+ }
+ }
+ obPhase.addChest(items, rarity);
+ }
}
void addMobs(OneBlockPhase obPhase, ConfigurationSection phase) throws IOException {
- if (!phase.isConfigurationSection(MOBS)) {
- return;
- }
- if (!obPhase.getMobs().isEmpty()) {
- throw new IOException(obPhase.getPhaseName() + ": Mobs cannot be set more than once. Duplicate file?");
- }
- ConfigurationSection mobs = phase.getConfigurationSection(MOBS);
- for (String entity : mobs.getKeys(false)) {
- String name = entity.toUpperCase(Locale.ENGLISH);
- EntityType et = null;
- // Pig zombie handling
- if (name.equals("PIG_ZOMBIE") || name.equals("ZOMBIFIED_PIGLIN")) {
- et = Enums.getIfPresent(EntityType.class, "ZOMBIFIED_PIGLIN")
- .or(Enums.getIfPresent(EntityType.class, "PIG_ZOMBIE").or(EntityType.PIG));
- } else {
- et = Enums.getIfPresent(EntityType.class, name).orNull();
- }
- if (et == null) {
- // Does not exist
- addon.logError("Bad entity type in " + obPhase.getPhaseName() + ": " + entity);
- addon.logError("Try one of these...");
- addon.logError(Arrays.stream(EntityType.values()).filter(EntityType::isSpawnable)
- .filter(EntityType::isAlive).map(EntityType::name).collect(Collectors.joining(",")));
- return;
- }
- if (et.isSpawnable() && et.isAlive()) {
- if (mobs.getInt(entity) > 0) {
- obPhase.addMob(et, mobs.getInt(entity));
- } else {
- addon.logWarning("Bad entity weight for " + obPhase.getPhaseName() + ": " + entity + ". Must be positive number above 1.");
- }
- } else {
- addon.logError("Entity type is not spawnable " + obPhase.getPhaseName() + ": " + entity);
- }
- }
+ if (!phase.isConfigurationSection(MOBS)) {
+ return;
+ }
+ if (!obPhase.getMobs().isEmpty()) {
+ throw new IOException(obPhase.getPhaseName() + ": Mobs cannot be set more than once. Duplicate file?");
+ }
+ ConfigurationSection mobs = phase.getConfigurationSection(MOBS);
+ for (String entity : mobs.getKeys(false)) {
+ String name = entity.toUpperCase(Locale.ENGLISH);
+ EntityType et = null;
+ // Pig zombie handling
+ if (name.equals("PIG_ZOMBIE") || name.equals("ZOMBIFIED_PIGLIN")) {
+ et = Enums.getIfPresent(EntityType.class, "ZOMBIFIED_PIGLIN")
+ .or(Enums.getIfPresent(EntityType.class, "PIG_ZOMBIE").or(EntityType.PIG));
+ } else {
+ et = Enums.getIfPresent(EntityType.class, name).orNull();
+ }
+ if (et == null) {
+ // Does not exist
+ addon.logError("Bad entity type in " + obPhase.getPhaseName() + ": " + entity);
+ addon.logError("Try one of these...");
+ addon.logError(Arrays.stream(EntityType.values()).filter(EntityType::isSpawnable)
+ .filter(EntityType::isAlive).map(EntityType::name).collect(Collectors.joining(",")));
+ return;
+ }
+ if (et.isSpawnable() && et.isAlive()) {
+ if (mobs.getInt(entity) > 0) {
+ obPhase.addMob(et, mobs.getInt(entity));
+ } else {
+ addon.logWarning("Bad entity weight for " + obPhase.getPhaseName() + ": " + entity
+ + ". Must be positive number above 1.");
+ }
+ } else {
+ addon.logError("Entity type is not spawnable " + obPhase.getPhaseName() + ": " + entity);
+ }
+ }
}
void addBlocks(OneBlockPhase obPhase, ConfigurationSection phase) {
- if (phase.isConfigurationSection(BLOCKS)) {
- ConfigurationSection blocks = phase.getConfigurationSection(BLOCKS);
- for (String material : blocks.getKeys(false)) {
- if (Material.getMaterial(material) != null) {
- addMaterial(obPhase, material, Objects.toString(blocks.get(material)));
- } else {
- if (addon.hasItemsAdder()) {
- CustomBlock block = CustomBlock.getInstance(material);
- if (block != null) {
- addItemsAdderBlock(obPhase, material, Objects.toString(blocks.get(material)));
- } else if (ItemsAdder.getAllItems() != null){
- if (ItemsAdder.getAllItems().size() != 0) {
- addon.logError("Bad block material in " + obPhase.getPhaseName() + ": " + material);
- }
- }
- } else {
- addon.logError("Bad block material in " + obPhase.getPhaseName() + ": " + material);
- }
- }
- }
- } else if (phase.isList(BLOCKS)) {
- List