diff --git a/pom.xml b/pom.xml
index 31bce21..d82eec1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -58,8 +58,8 @@
2.0.9
- 1.20.4-R0.1-SNAPSHOT
- 2.5.0-SNAPSHOT
+ 1.21.3-R0.1-SNAPSHOT
+ 2.7.1-SNAPSHOT
2.6.2
1.3.0
diff --git a/src/main/java/world/bentobox/aoneblock/Settings.java b/src/main/java/world/bentobox/aoneblock/Settings.java
index 83647ed..a313e16 100644
--- a/src/main/java/world/bentobox/aoneblock/Settings.java
+++ b/src/main/java/world/bentobox/aoneblock/Settings.java
@@ -14,8 +14,6 @@
import org.bukkit.block.Biome;
import org.bukkit.entity.EntityType;
-import com.google.common.base.Enums;
-
import world.bentobox.aoneblock.listeners.BlockListener;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.configuration.ConfigComment;
@@ -232,13 +230,13 @@ public class Settings implements WorldSettings {
@ConfigComment("The default biome for the overworld")
@ConfigEntry(path = "world.default-biome")
- private Biome defaultBiome = Biome.PLAINS;
+ private Biome defaultBiome;
@ConfigComment("The default biome for the nether world (this may affect what mobs can spawn)")
@ConfigEntry(path = "world.default-nether-biome")
- private Biome defaultNetherBiome = Enums.getIfPresent(Biome.class, "NETHER").or(Enums.getIfPresent(Biome.class, "NETHER_WASTES").or(Biome.BADLANDS));
+ private Biome defaultNetherBiome;
@ConfigComment("The default biome for the end world (this may affect what mobs can spawn)")
@ConfigEntry(path = "world.default-end-biome")
- private Biome defaultEndBiome = Biome.THE_END;
+ private Biome defaultEndBiome;
@ConfigComment("The maximum number of players a player can ban at any one time in this game mode.")
@ConfigComment("The permission acidisland.ban.maxlimit.X where X is a number can also be used per player")
@@ -1446,7 +1444,7 @@ public boolean isWaterUnsafe() {
* @return default biome
*/
public Biome getDefaultBiome() {
- return defaultBiome;
+ return defaultBiome == null ? Biome.PLAINS : defaultBiome;
}
/**
@@ -1891,7 +1889,7 @@ public void setDropOnTop(boolean dropOnTop) {
* @return the defaultNetherBiome
*/
public Biome getDefaultNetherBiome() {
- return defaultNetherBiome;
+ return defaultNetherBiome == null ? Biome.NETHER_WASTES : defaultNetherBiome;
}
/**
@@ -1905,7 +1903,7 @@ public void setDefaultNetherBiome(Biome defaultNetherBiome) {
* @return the defaultEndBiome
*/
public Biome getDefaultEndBiome() {
- return defaultEndBiome;
+ return defaultEndBiome == null ? Biome.THE_END : defaultEndBiome;
}
/**
diff --git a/src/main/java/world/bentobox/aoneblock/commands/island/IslandRespawnBlockCommand.java b/src/main/java/world/bentobox/aoneblock/commands/island/IslandRespawnBlockCommand.java
index 27ae4ae..7937f78 100644
--- a/src/main/java/world/bentobox/aoneblock/commands/island/IslandRespawnBlockCommand.java
+++ b/src/main/java/world/bentobox/aoneblock/commands/island/IslandRespawnBlockCommand.java
@@ -87,7 +87,7 @@ else if (Material.BEDROCK.equals(island.getCenter().getBlock().getType()) ||
for (double x = 0.0; x <= 1.0; x += 0.5) {
for (double y = 0.0; y <= 1.0; y += 0.5) {
for (double z = 0.0; z < 1.0; z += 0.5) {
- island.getWorld().spawnParticle(Particle.REDSTONE, island.getCenter().add(new Vector(x, y, z)),
+ island.getWorld().spawnParticle(Particle.DUST, island.getCenter().add(new Vector(x, y, z)),
5, 0.1, 0, 0.1, 1, new Particle.DustOptions(BlockProtect.GREEN, 1));
}
}
diff --git a/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java b/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java
index e0135a2..c1de47a 100644
--- a/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java
+++ b/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java
@@ -107,19 +107,19 @@ public class BlockListener implements Listener {
* @param addon - OneBlock
*/
public BlockListener(@NonNull AOneBlock addon) {
- this.addon = addon;
- handler = new Database<>(addon, OneBlockIslands.class);
- cache = new HashMap<>();
- oneBlocksManager = addon.getOneBlockManager();
- check = new CheckPhase(addon, this);
- warningSounder = new WarningSounder(addon);
+ this.addon = addon;
+ handler = new Database<>(addon, OneBlockIslands.class);
+ cache = new HashMap<>();
+ oneBlocksManager = addon.getOneBlockManager();
+ check = new CheckPhase(addon, this);
+ warningSounder = new WarningSounder(addon);
}
/**
* Save the island cache
*/
public void saveCache() {
- cache.values().forEach(handler::saveObjectAsync);
+ cache.values().forEach(handler::saveObjectAsync);
}
// ---------------------------------------------------------------------
@@ -128,24 +128,24 @@ public void saveCache() {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onNewIsland(IslandCreatedEvent e) {
- if (addon.inWorld(e.getIsland().getWorld())) {
- setUp(e.getIsland());
- }
+ if (addon.inWorld(e.getIsland().getWorld())) {
+ setUp(e.getIsland());
+ }
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onNewIsland(IslandResettedEvent e) {
- if (addon.inWorld(e.getIsland().getWorld())) {
- setUp(e.getIsland());
- }
+ if (addon.inWorld(e.getIsland().getWorld())) {
+ setUp(e.getIsland());
+ }
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onDeletedIsland(IslandDeleteEvent e) {
- if (addon.inWorld(e.getIsland().getWorld())) {
- cache.remove(e.getIsland().getUniqueId());
- handler.deleteID(e.getIsland().getUniqueId());
- }
+ if (addon.inWorld(e.getIsland().getWorld())) {
+ cache.remove(e.getIsland().getUniqueId());
+ handler.deleteID(e.getIsland().getUniqueId());
+ }
}
/**
@@ -155,22 +155,22 @@ public void onDeletedIsland(IslandDeleteEvent e) {
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlockFromTo(final BlockFromToEvent e) {
- if (!addon.inWorld(e.getBlock().getWorld())) {
- return;
- }
- Location l = e.getToBlock().getLocation();
- // Cannot flow to center block
- e.setCancelled(addon.getIslands().getIslandAt(l).filter(i -> l.equals(i.getCenter())).isPresent());
+ if (!addon.inWorld(e.getBlock().getWorld())) {
+ return;
+ }
+ Location l = e.getToBlock().getLocation();
+ // Cannot flow to center block
+ e.setCancelled(addon.getIslands().getIslandAt(l).filter(i -> l.equals(i.getCenter())).isPresent());
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockBreak(final BlockBreakEvent e) {
- if (!addon.inWorld(e.getBlock().getWorld())) {
- return;
- }
- Location l = e.getBlock().getLocation();
- addon.getIslands().getIslandAt(l).filter(i -> l.equals(i.getCenter()))
- .ifPresent(i -> process(e, i, e.getPlayer(), e.getPlayer().getWorld()));
+ if (!addon.inWorld(e.getBlock().getWorld())) {
+ return;
+ }
+ Location l = e.getBlock().getLocation();
+ addon.getIslands().getIslandAt(l).filter(i -> l.equals(i.getCenter()))
+ .ifPresent(i -> process(e, i, e.getPlayer(), e.getPlayer().getWorld()));
}
/**
@@ -181,12 +181,12 @@ public void onBlockBreak(final BlockBreakEvent e) {
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlockBreakByMinion(final EntityInteractEvent e) {
- if (!addon.inWorld(e.getBlock().getWorld()) || !e.getEntityType().equals(EntityType.ARMOR_STAND)) {
- return;
- }
- Location l = e.getBlock().getLocation();
- addon.getIslands().getIslandAt(l).filter(i -> l.equals(i.getCenter()))
- .ifPresent(i -> process(e, i, null, e.getBlock().getWorld()));
+ if (!addon.inWorld(e.getBlock().getWorld()) || !e.getEntityType().equals(EntityType.ARMOR_STAND)) {
+ return;
+ }
+ Location l = e.getBlock().getLocation();
+ addon.getIslands().getIslandAt(l).filter(i -> l.equals(i.getCenter()))
+ .ifPresent(i -> process(e, i, null, e.getBlock().getWorld()));
}
/**
@@ -196,11 +196,11 @@ public void onBlockBreakByMinion(final EntityInteractEvent e) {
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlockBreak(final PlayerBucketFillEvent e) {
- if (addon.inWorld(e.getBlock().getWorld())) {
- Location l = e.getBlock().getLocation();
- addon.getIslands().getIslandAt(l).filter(i -> l.equals(i.getCenter()))
- .ifPresent(i -> process(e, i, e.getPlayer(), e.getPlayer().getWorld()));
- }
+ if (addon.inWorld(e.getBlock().getWorld())) {
+ Location l = e.getBlock().getLocation();
+ addon.getIslands().getIslandAt(l).filter(i -> l.equals(i.getCenter()))
+ .ifPresent(i -> process(e, i, e.getPlayer(), e.getPlayer().getWorld()));
+ }
}
/**
@@ -210,32 +210,32 @@ public void onBlockBreak(final PlayerBucketFillEvent e) {
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onItemStackSpawn(EntitySpawnEvent event) {
- if (!this.addon.getSettings().isDropOnTop()) {
- // Do nothing as item spawning is not interested in this case.
- return;
- }
-
- if (!EntityType.DROPPED_ITEM.equals(event.getEntityType())) {
- // We are interested only in dropped item entities.
- return;
- }
-
- if (!this.addon.inWorld(event.getLocation().getWorld())) {
- // Not correct world
- return;
- }
-
- Entity entity = event.getEntity();
- Location location = event.getLocation();
-
- Optional optionalIsland = this.addon.getIslands().getIslandAt(location)
- .filter(island -> location.getBlock().getLocation().equals(island.getCenter()));
-
- if (optionalIsland.isPresent()) {
- // Teleport entity to the top of magic block.
- entity.teleport(optionalIsland.get().getCenter().add(0.5, 1, 0.5));
- entity.setVelocity(new Vector(0, 0, 0));
- }
+ if (!this.addon.getSettings().isDropOnTop()) {
+ // Do nothing as item spawning is not interested in this case.
+ return;
+ }
+
+ if (!EntityType.ITEM.equals(event.getEntityType())) {
+ // We are interested only in dropped item entities.
+ return;
+ }
+
+ if (!this.addon.inWorld(event.getLocation().getWorld())) {
+ // Not correct world
+ return;
+ }
+
+ Entity entity = event.getEntity();
+ Location location = event.getLocation();
+
+ Optional optionalIsland = this.addon.getIslands().getIslandAt(location)
+ .filter(island -> location.getBlock().getLocation().equals(island.getCenter()));
+
+ if (optionalIsland.isPresent()) {
+ // Teleport entity to the top of magic block.
+ entity.teleport(optionalIsland.get().getCenter().add(0.5, 1, 0.5));
+ entity.setVelocity(new Vector(0, 0, 0));
+ }
}
// ---------------------------------------------------------------------
@@ -243,14 +243,14 @@ public void onItemStackSpawn(EntitySpawnEvent event) {
// ---------------------------------------------------------------------
private void setUp(@NonNull Island island) {
- // Set the bedrock to the initial block
- Util.getChunkAtAsync(Objects.requireNonNull(island.getCenter()))
- .thenRun(() -> island.getCenter().getBlock().setType(Material.GRASS_BLOCK));
- // Create a database entry
- OneBlockIslands is = new OneBlockIslands(island.getUniqueId());
- cache.put(island.getUniqueId(), is);
- handler.saveObjectAsync(is);
- addon.getHoloListener().setUp(island, is, true);
+ // Set the bedrock to the initial block
+ Util.getChunkAtAsync(Objects.requireNonNull(island.getCenter()))
+ .thenRun(() -> island.getCenter().getBlock().setType(Material.GRASS_BLOCK));
+ // Create a database entry
+ OneBlockIslands is = new OneBlockIslands(island.getUniqueId());
+ cache.put(island.getUniqueId(), is);
+ handler.saveObjectAsync(is);
+ addon.getHoloListener().setUp(island, is, true);
}
/**
@@ -262,148 +262,148 @@ private void setUp(@NonNull Island island) {
* @param world - world where the block is being broken
*/
private void process(@NonNull Cancellable e, @NonNull Island i, @Nullable Player player, @NonNull World world) {
- // Get the block that is being broken
- Block block = Objects.requireNonNull(i.getCenter()).toVector().toLocation(world).getBlock();
-
- // Get oneblock island
- OneBlockIslands is = getIsland(i);
-
- // Get the phase for current block number
- OneBlockPhase phase = oneBlocksManager.getPhase(is.getBlockNumber());
-
- // Save previous processing phase name
- String prevPhaseName = is.getPhaseName();
-
- // Check if phase contains `gotoBlock`
- if(Objects.requireNonNull(phase).getGotoBlock() != null){
- phase = handleGoto(is, phase.getGotoBlock());
- }
-
- // Get current phase name
- String currPhaseName = phase.getPhaseName() == null ? "" : phase.getPhaseName();
-
- // Get the phase for next block number
- OneBlockPhase nextPhase = oneBlocksManager.getPhase(is.getBlockNumber() + 1);
-
- // Check if nextPhase contains `gotoBlock` and override `nextPhase`
- if (Objects.requireNonNull(nextPhase).getGotoBlock() != null) {
- nextPhase = oneBlocksManager.getPhase(nextPhase.getGotoBlock());
- }
-
- // Get next phase name
- String nextPhaseName = nextPhase == null || nextPhase.getPhaseName() == null ? "" : nextPhase.getPhaseName();
-
- // If next phase is new, log break time of the last block of this phase
- if (!currPhaseName.equalsIgnoreCase(nextPhaseName)) {
- is.setLastPhaseChangeTime(System.currentTimeMillis());
- }
-
- boolean isCurrPhaseNew = !is.getPhaseName().equalsIgnoreCase(currPhaseName);
-
- if (isCurrPhaseNew) {
-
- // Check if requirements for new phase are met
- if (check.phaseRequirementsFail(player, i, is, phase, world)) {
- e.setCancelled(true);
- return;
- }
-
- check.setNewPhase(player, i, is, phase);
- is.clearQueue();
-
- // Set the biome for the block and one block above it
- setBiome(block, phase.getPhaseBiome());
-
- // Fire new phase event
- Bukkit.getPluginManager()
- .callEvent(new MagicBlockPhaseEvent(i, player == null ? null : player.getUniqueId(), block,
- phase.getPhaseName(), prevPhaseName, is.getBlockNumber()));
- }
-
- if (!isCurrPhaseNew && is.getBlockNumber() % SAVE_EVERY == 0) {
- // Save island data every MAX_LOOK_AHEAD blocks.
- saveIsland(i);
- }
-
- // Get the block number in this phase
- int materialBlocksInQueue = (int) is.getQueue().stream().filter(obo -> obo.isMaterial() || obo.isCustomBlock())
- .count();
- int blockNumber = is.getBlockNumber() - (phase.getBlockNumberValue() - 1) + materialBlocksInQueue;
-
- // Fill a 5 block queue
- if (is.getQueue().isEmpty() || isCurrPhaseNew) {
- // Add initial 5 blocks
- for (int j = 0; j < MAX_LOOK_AHEAD; j++) {
- is.add(phase.getNextBlock(addon, blockNumber++));
- }
- }
-
- // Manage Holograms
- addon.getHoloListener().process(i, is, phase);
-
- // Play warning sound for upcoming mobs
- if (addon.getSettings().getMobWarning() > 0) {
- warningSounder.play(is, block);
- }
-
- // Get the next block
- OneBlockObject nextBlock = (isCurrPhaseNew && phase.getFirstBlock() != null) ? phase.getFirstBlock()
- : is.pollAndAdd(phase.getNextBlock(addon, blockNumber));
-
- // Entity
- if (nextBlock.isEntity()) {
- if (!(e instanceof EntitySpawnEvent)) {
- e.setCancelled(true);
- }
- // Entity spawns do not increment the block number or break the block
- spawnEntity(nextBlock, block);
- // Fire event
- Bukkit.getPluginManager().callEvent(new MagicBlockEntityEvent(i,
- player == null ? null : player.getUniqueId(), block, nextBlock.getEntityType()));
- return;
- }
-
- // Break the block
- if (e instanceof BlockBreakEvent) {
- this.breakBlock(player, block, nextBlock, i);
- } else if (e instanceof PlayerBucketFillEvent) {
- Bukkit.getScheduler().runTask(addon.getPlugin(), () -> spawnBlock(nextBlock, block));
- // Fire event
- ItemStack tool = Objects.requireNonNull(player).getInventory().getItemInMainHand();
- Bukkit.getPluginManager()
- .callEvent(new MagicBlockEvent(i, player.getUniqueId(), tool, block, nextBlock.getMaterial()));
- } else if (e instanceof EntitySpawnEvent) {
- Bukkit.getScheduler().runTask(addon.getPlugin(), () -> spawnBlock(nextBlock, block));
- } else if (e instanceof EntityInteractEvent) {
- // Minion breaking block
- Bukkit.getScheduler().runTask(addon.getPlugin(), () -> spawnBlock(nextBlock, block));
- // Fire event
- Bukkit.getPluginManager().callEvent(new MagicBlockEvent(i, null, null, block, nextBlock.getMaterial()));
- }
-
- // Increment the block number
- is.incrementBlockNumber();
+ // Get the block that is being broken
+ Block block = Objects.requireNonNull(i.getCenter()).toVector().toLocation(world).getBlock();
+
+ // Get oneblock island
+ OneBlockIslands is = getIsland(i);
+
+ // Get the phase for current block number
+ OneBlockPhase phase = oneBlocksManager.getPhase(is.getBlockNumber());
+
+ // Save previous processing phase name
+ String prevPhaseName = is.getPhaseName();
+
+ // Check if phase contains `gotoBlock`
+ if (Objects.requireNonNull(phase).getGotoBlock() != null) {
+ phase = handleGoto(is, phase.getGotoBlock());
+ }
+
+ // Get current phase name
+ String currPhaseName = phase.getPhaseName() == null ? "" : phase.getPhaseName();
+
+ // Get the phase for next block number
+ OneBlockPhase nextPhase = oneBlocksManager.getPhase(is.getBlockNumber() + 1);
+
+ // Check if nextPhase contains `gotoBlock` and override `nextPhase`
+ if (Objects.requireNonNull(nextPhase).getGotoBlock() != null) {
+ nextPhase = oneBlocksManager.getPhase(nextPhase.getGotoBlock());
+ }
+
+ // Get next phase name
+ String nextPhaseName = nextPhase == null || nextPhase.getPhaseName() == null ? "" : nextPhase.getPhaseName();
+
+ // If next phase is new, log break time of the last block of this phase
+ if (!currPhaseName.equalsIgnoreCase(nextPhaseName)) {
+ is.setLastPhaseChangeTime(System.currentTimeMillis());
+ }
+
+ boolean isCurrPhaseNew = !is.getPhaseName().equalsIgnoreCase(currPhaseName);
+
+ if (isCurrPhaseNew) {
+
+ // Check if requirements for new phase are met
+ if (check.phaseRequirementsFail(player, i, is, phase, world)) {
+ e.setCancelled(true);
+ return;
+ }
+
+ check.setNewPhase(player, i, is, phase);
+ is.clearQueue();
+
+ // Set the biome for the block and one block above it
+ setBiome(block, phase.getPhaseBiome());
+
+ // Fire new phase event
+ Bukkit.getPluginManager()
+ .callEvent(new MagicBlockPhaseEvent(i, player == null ? null : player.getUniqueId(), block,
+ phase.getPhaseName(), prevPhaseName, is.getBlockNumber()));
+ }
+
+ if (!isCurrPhaseNew && is.getBlockNumber() % SAVE_EVERY == 0) {
+ // Save island data every MAX_LOOK_AHEAD blocks.
+ saveIsland(i);
+ }
+
+ // Get the block number in this phase
+ int materialBlocksInQueue = (int) is.getQueue().stream().filter(obo -> obo.isMaterial() || obo.isCustomBlock())
+ .count();
+ int blockNumber = is.getBlockNumber() - (phase.getBlockNumberValue() - 1) + materialBlocksInQueue;
+
+ // Fill a 5 block queue
+ if (is.getQueue().isEmpty() || isCurrPhaseNew) {
+ // Add initial 5 blocks
+ for (int j = 0; j < MAX_LOOK_AHEAD; j++) {
+ is.add(phase.getNextBlock(addon, blockNumber++));
+ }
+ }
+
+ // Manage Holograms
+ addon.getHoloListener().process(i, is, phase);
+
+ // Play warning sound for upcoming mobs
+ if (addon.getSettings().getMobWarning() > 0) {
+ warningSounder.play(is, block);
+ }
+
+ // Get the next block
+ OneBlockObject nextBlock = (isCurrPhaseNew && phase.getFirstBlock() != null) ? phase.getFirstBlock()
+ : is.pollAndAdd(phase.getNextBlock(addon, blockNumber));
+
+ // Entity
+ if (nextBlock.isEntity()) {
+ if (!(e instanceof EntitySpawnEvent)) {
+ e.setCancelled(true);
+ }
+ // Entity spawns do not increment the block number or break the block
+ spawnEntity(nextBlock, block);
+ // Fire event
+ Bukkit.getPluginManager().callEvent(new MagicBlockEntityEvent(i,
+ player == null ? null : player.getUniqueId(), block, nextBlock.getEntityType()));
+ return;
+ }
+
+ // Break the block
+ if (e instanceof BlockBreakEvent) {
+ this.breakBlock(player, block, nextBlock, i);
+ } else if (e instanceof PlayerBucketFillEvent) {
+ Bukkit.getScheduler().runTask(addon.getPlugin(), () -> spawnBlock(nextBlock, block));
+ // Fire event
+ ItemStack tool = Objects.requireNonNull(player).getInventory().getItemInMainHand();
+ Bukkit.getPluginManager()
+ .callEvent(new MagicBlockEvent(i, player.getUniqueId(), tool, block, nextBlock.getMaterial()));
+ } else if (e instanceof EntitySpawnEvent) {
+ Bukkit.getScheduler().runTask(addon.getPlugin(), () -> spawnBlock(nextBlock, block));
+ } else if (e instanceof EntityInteractEvent) {
+ // Minion breaking block
+ Bukkit.getScheduler().runTask(addon.getPlugin(), () -> spawnBlock(nextBlock, block));
+ // Fire event
+ Bukkit.getPluginManager().callEvent(new MagicBlockEvent(i, null, null, block, nextBlock.getMaterial()));
+ }
+
+ // Increment the block number
+ is.incrementBlockNumber();
}
private OneBlockPhase handleGoto(OneBlockIslands is, int gotoBlock) {
- // Store lifetime
- is.setLifetime(is.getLifetime() + gotoBlock);
- // Set current block
- is.setBlockNumber(gotoBlock);
- return oneBlocksManager.getPhase(gotoBlock);
+ // Store lifetime
+ is.setLifetime(is.getLifetime() + gotoBlock);
+ // Set current block
+ is.setBlockNumber(gotoBlock);
+ return oneBlocksManager.getPhase(gotoBlock);
}
private void setBiome(@NonNull Block block, @Nullable Biome biome) {
- if (biome == null) {
- return;
- }
- for (int x = -4; x <= 4; x++) {
- for (int z = -4; z <= 4; z++) {
- for (int y = -4; y <= 4; y++) {
- block.getWorld().setBiome(block.getX() + x, block.getY() + y, block.getZ() + z, biome);
- }
- }
- }
+ if (biome == null) {
+ return;
+ }
+ for (int x = -4; x <= 4; x++) {
+ for (int z = -4; z <= 4; z++) {
+ for (int y = -4; y <= 4; y++) {
+ block.getWorld().setBiome(block.getX() + x, block.getY() + y, block.getZ() + z, biome);
+ }
+ }
+ }
}
/**
@@ -416,96 +416,96 @@ private void setBiome(@NonNull Block block, @Nullable Biome biome) {
* @param island Island where player is located.
*/
private void breakBlock(@Nullable Player player, Block block, @NonNull OneBlockObject nextBlock,
- @NonNull Island island) {
- ItemStack tool = Objects.requireNonNull(player).getInventory().getItemInMainHand();
-
- // Break normally and lift the player up so they don't fall
- Bukkit.getScheduler().runTask(addon.getPlugin(), () -> this.spawnBlock(nextBlock, block));
-
- if (player.getLocation().getBlock().equals(block)) {
- double delta = 1 - (player.getLocation().getY() - block.getY());
- player.teleport(player.getLocation().add(new Vector(0, delta, 0)));
- player.setVelocity(new Vector(0, 0, 0));
- } else if (player.getLocation().getBlock().equals(block.getRelative(BlockFace.UP))) {
- player.teleport(player.getLocation());
- player.setVelocity(new Vector(0, 0, 0));
- }
-
- // Fire event
- Bukkit.getPluginManager()
- .callEvent(new MagicBlockEvent(island, player.getUniqueId(), tool, block, nextBlock.getMaterial()));
+ @NonNull Island island) {
+ ItemStack tool = Objects.requireNonNull(player).getInventory().getItemInMainHand();
+
+ // Break normally and lift the player up so they don't fall
+ Bukkit.getScheduler().runTask(addon.getPlugin(), () -> this.spawnBlock(nextBlock, block));
+
+ if (player.getLocation().getBlock().equals(block)) {
+ double delta = 1 - (player.getLocation().getY() - block.getY());
+ player.teleport(player.getLocation().add(new Vector(0, delta, 0)));
+ player.setVelocity(new Vector(0, 0, 0));
+ } else if (player.getLocation().getBlock().equals(block.getRelative(BlockFace.UP))) {
+ player.teleport(player.getLocation());
+ player.setVelocity(new Vector(0, 0, 0));
+ }
+
+ // Fire event
+ Bukkit.getPluginManager()
+ .callEvent(new MagicBlockEvent(island, player.getUniqueId(), tool, block, nextBlock.getMaterial()));
}
private void spawnBlock(@NonNull OneBlockObject nextBlock, @NonNull Block block) {
- if (nextBlock.isCustomBlock()) {
- nextBlock.getCustomBlock().execute(addon, block);
- } else {
- @NonNull
- Material type = nextBlock.getMaterial();
- // Place new block with no physics
- block.setType(type, false);
- // Fill the chest
- if (type.equals(Material.CHEST) && nextBlock.getChest() != null) {
- fillChest(nextBlock, block);
- return;
- } else if (Tag.LEAVES.isTagged(type)) {
- Leaves leaves = (Leaves) block.getState().getBlockData();
- leaves.setPersistent(true);
- block.setBlockData(leaves);
- } else if (block.getState() instanceof BrushableBlock bb) {
- LootTable lt = switch (bb.getBlock().getBiome()) {
- default -> {
- if (random.nextDouble() < 0.8) {
- yield LootTables.TRAIL_RUINS_ARCHAEOLOGY_COMMON.getLootTable();
- } else {
- // 20% rare
- yield LootTables.TRAIL_RUINS_ARCHAEOLOGY_RARE.getLootTable();
- }
- }
- case DESERT -> LootTables.DESERT_PYRAMID_ARCHAEOLOGY.getLootTable();
- case FROZEN_OCEAN -> LootTables.OCEAN_RUIN_COLD_ARCHAEOLOGY.getLootTable();
- case OCEAN -> LootTables.OCEAN_RUIN_COLD_ARCHAEOLOGY.getLootTable();
- case WARM_OCEAN -> LootTables.OCEAN_RUIN_WARM_ARCHAEOLOGY.getLootTable();
- };
- bb.setLootTable(lt);
- bb.update();
- }
- }
+ if (nextBlock.isCustomBlock()) {
+ nextBlock.getCustomBlock().execute(addon, block);
+ } else {
+ @NonNull
+ Material type = nextBlock.getMaterial();
+ // Place new block with no physics
+ block.setType(type, false);
+ // Fill the chest
+ if (type.equals(Material.CHEST) && nextBlock.getChest() != null) {
+ fillChest(nextBlock, block);
+ return;
+ } else if (Tag.LEAVES.isTagged(type)) {
+ Leaves leaves = (Leaves) block.getState().getBlockData();
+ leaves.setPersistent(true);
+ block.setBlockData(leaves);
+ } else if (block.getState() instanceof BrushableBlock bb) {
+ LootTable lt = switch (bb.getBlock().getBiome().getKey().getKey()) {
+ default -> {
+ if (random.nextDouble() < 0.8) {
+ yield LootTables.TRAIL_RUINS_ARCHAEOLOGY_COMMON.getLootTable();
+ } else {
+ // 20% rare
+ yield LootTables.TRAIL_RUINS_ARCHAEOLOGY_RARE.getLootTable();
+ }
+ }
+ case "DESERT" -> LootTables.DESERT_PYRAMID_ARCHAEOLOGY.getLootTable();
+ case "FROZEN_OCEAN" -> LootTables.OCEAN_RUIN_COLD_ARCHAEOLOGY.getLootTable();
+ case "OCEAN" -> LootTables.OCEAN_RUIN_COLD_ARCHAEOLOGY.getLootTable();
+ case "WARM_OCEAN" -> LootTables.OCEAN_RUIN_WARM_ARCHAEOLOGY.getLootTable();
+ };
+ bb.setLootTable(lt);
+ bb.update();
+ }
+ }
}
private void spawnEntity(@NonNull OneBlockObject nextBlock, @NonNull Block block) {
- if (block.isEmpty())
- block.setType(Material.STONE);
- Location spawnLoc = block.getLocation().add(new Vector(0.5D, 1D, 0.5D));
- Entity entity = block.getWorld().spawnEntity(spawnLoc, nextBlock.getEntityType());
- // Make space for entity - this will blot out blocks
- if (addon.getSettings().isClearBlocks()) {
- new MakeSpace(addon).makeSpace(entity, spawnLoc);
- }
- block.getWorld().playSound(block.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 1F, 2F);
+ if (block.isEmpty())
+ block.setType(Material.STONE);
+ Location spawnLoc = block.getLocation().add(new Vector(0.5D, 1D, 0.5D));
+ Entity entity = block.getWorld().spawnEntity(spawnLoc, nextBlock.getEntityType());
+ // Make space for entity - this will blot out blocks
+ if (addon.getSettings().isClearBlocks()) {
+ new MakeSpace(addon).makeSpace(entity, spawnLoc);
+ }
+ block.getWorld().playSound(block.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 1F, 2F);
}
private void fillChest(@NonNull OneBlockObject nextBlock, @NonNull Block block) {
- Chest chest = (Chest) block.getState();
- nextBlock.getChest().forEach(chest.getBlockInventory()::setItem);
- Color color = Color.fromBGR(0, 255, 255); // yellow
- switch (nextBlock.getRarity()) {
- case EPIC:
- color = Color.fromBGR(255, 0, 255); // magenta
- break;
- case RARE:
- color = Color.fromBGR(255, 255, 255); // cyan
- break;
- case UNCOMMON:
- // Yellow
- break;
- default:
- // No sparkles for regular chests
- return;
- }
- block.getWorld().spawnParticle(Particle.REDSTONE, block.getLocation().add(new Vector(0.5, 1.0, 0.5)), 50, 0.5,
- 0, 0.5, 1, new Particle.DustOptions(color, 1));
+ Chest chest = (Chest) block.getState();
+ nextBlock.getChest().forEach(chest.getBlockInventory()::setItem);
+ Color color = Color.fromBGR(0, 255, 255); // yellow
+ switch (nextBlock.getRarity()) {
+ case EPIC:
+ color = Color.fromBGR(255, 0, 255); // magenta
+ break;
+ case RARE:
+ color = Color.fromBGR(255, 255, 255); // cyan
+ break;
+ case UNCOMMON:
+ // Yellow
+ break;
+ default:
+ // No sparkles for regular chests
+ return;
+ }
+ block.getWorld().spawnParticle(Particle.DUST, block.getLocation().add(new Vector(0.5, 1.0, 0.5)), 50, 0.5,
+ 0, 0.5, 1, new Particle.DustOptions(color, 1));
}
/**
@@ -516,7 +516,7 @@ private void fillChest(@NonNull OneBlockObject nextBlock, @NonNull Block block)
*/
@NonNull
public OneBlockIslands getIsland(@NonNull Island i) {
- return cache.containsKey(i.getUniqueId()) ? cache.get(i.getUniqueId()) : loadIsland(i.getUniqueId());
+ return cache.containsKey(i.getUniqueId()) ? cache.get(i.getUniqueId()) : loadIsland(i.getUniqueId());
}
/**
@@ -525,27 +525,27 @@ public OneBlockIslands getIsland(@NonNull Island i) {
* @return list of oneblock islands
*/
public List getAllIslands() {
- return handler.loadObjects();
+ return handler.loadObjects();
}
@NonNull
private OneBlockIslands loadIsland(@NonNull String uniqueId) {
- if (handler.objectExists(uniqueId)) {
- OneBlockIslands island = handler.loadObject(uniqueId);
- if (island != null) {
- // Add to cache
- cache.put(island.getUniqueId(), island);
- return island;
- }
- }
- return cache.computeIfAbsent(uniqueId, OneBlockIslands::new);
+ if (handler.objectExists(uniqueId)) {
+ OneBlockIslands island = handler.loadObject(uniqueId);
+ if (island != null) {
+ // Add to cache
+ cache.put(island.getUniqueId(), island);
+ return island;
+ }
+ }
+ return cache.computeIfAbsent(uniqueId, OneBlockIslands::new);
}
/**
* @return the oneBlocksManager
*/
public OneBlocksManager getOneBlocksManager() {
- return oneBlocksManager;
+ return oneBlocksManager;
}
/**
@@ -556,9 +556,9 @@ public OneBlocksManager getOneBlocksManager() {
* failed
*/
public CompletableFuture 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/BlockProtect.java b/src/main/java/world/bentobox/aoneblock/listeners/BlockProtect.java
index e0d994e..2f9ac39 100644
--- a/src/main/java/world/bentobox/aoneblock/listeners/BlockProtect.java
+++ b/src/main/java/world/bentobox/aoneblock/listeners/BlockProtect.java
@@ -29,7 +29,7 @@
public class BlockProtect implements Listener {
public static final Color GREEN = Color.fromBGR(0, 100, 0);
- private static final List PARTICLES = new ArrayList<>(List.of(Particle.REDSTONE));
+ private static final List PARTICLES = new ArrayList<>(List.of(Particle.DUST));
private Iterator particleIterator = Collections.emptyIterator();
private final AOneBlock addon;
diff --git a/src/main/java/world/bentobox/aoneblock/listeners/WarningSounder.java b/src/main/java/world/bentobox/aoneblock/listeners/WarningSounder.java
index 7e98258..18445f4 100644
--- a/src/main/java/world/bentobox/aoneblock/listeners/WarningSounder.java
+++ b/src/main/java/world/bentobox/aoneblock/listeners/WarningSounder.java
@@ -35,9 +35,22 @@ public WarningSounder(AOneBlock addon) {
/**
* Mob aspects.
*/
- private static final Map MOB_ASPECTS;
+ private Map MOB_ASPECTS;
- static {
+ void play(@NonNull OneBlockIslands is, @NonNull Block block) {
+ if (MOB_ASPECTS == null) {
+ initialize(); // Done to avoid static definition with Sound due to test issues
+ }
+ List opMob = is.getNearestMob(addon.getSettings().getMobWarning());
+ opMob.stream().filter(MOB_ASPECTS::containsKey).map(MOB_ASPECTS::get).forEach(s -> {
+ block.getWorld().playSound(block.getLocation(), s.sound(), 1F, 1F);
+ block.getWorld().spawnParticle(Particle.DUST, block.getLocation().add(new Vector(0.5, 1.0, 0.5)), 10, 0.5,
+ 0, 0.5, 1, new Particle.DustOptions(s.color(), 1));
+ });
+
+ }
+
+ private void initialize() {
Map m = new EnumMap<>(EntityType.class);
m.put(EntityType.BLAZE, new MobAspects(Sound.ENTITY_BLAZE_AMBIENT, Color.fromRGB(238, 211, 91)));
m.put(EntityType.CAVE_SPIDER, new MobAspects(Sound.ENTITY_SPIDER_AMBIENT, Color.fromRGB(63, 37, 31)));
@@ -72,14 +85,6 @@ public WarningSounder(AOneBlock addon) {
m.put(EntityType.ZOMBIE_VILLAGER, new MobAspects(Sound.ENTITY_ZOMBIE_VILLAGER_AMBIENT, Color.fromRGB(111, 104, 90)));
MOB_ASPECTS = Collections.unmodifiableMap(m);
- }
-
- void play(@NonNull OneBlockIslands is, @NonNull Block block) {
- List opMob = is.getNearestMob(addon.getSettings().getMobWarning());
- opMob.stream().filter(MOB_ASPECTS::containsKey).map(MOB_ASPECTS::get).forEach(s -> {
- block.getWorld().playSound(block.getLocation(), s.sound(), 1F, 1F);
- block.getWorld().spawnParticle(Particle.REDSTONE, block.getLocation().add(new Vector(0.5, 1.0, 0.5)), 10, 0.5, 0, 0.5, 1, new Particle.DustOptions(s.color(), 1));
- });
}
diff --git a/src/main/java/world/bentobox/aoneblock/oneblocks/OneBlocksManager.java b/src/main/java/world/bentobox/aoneblock/oneblocks/OneBlocksManager.java
index e551650..a2c88e1 100644
--- a/src/main/java/world/bentobox/aoneblock/oneblocks/OneBlocksManager.java
+++ b/src/main/java/world/bentobox/aoneblock/oneblocks/OneBlocksManager.java
@@ -6,6 +6,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@@ -20,6 +21,8 @@
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.Material;
+import org.bukkit.NamespacedKey;
+import org.bukkit.Registry;
import org.bukkit.block.Biome;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -74,9 +77,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<>();
}
/**
@@ -85,34 +88,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);
+ }
}
/**
@@ -121,49 +124,49 @@ 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 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);
- }
+ 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);
+ }
}
/**
@@ -175,105 +178,105 @@ private void loadPhase(File phaseFile) throws IOException {
* @throws IOException if there's an error in the config file
*/
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));
- }
+ // 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;
- }
+ if (firstBlocksConfig == null) {
+ return;
+ }
- Map result = parseFirstBlocksConfig(firstBlocksConfig);
+ 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);
+ // 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<>();
+ 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;
+ 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);
- }
+ int k) {
+ if (firstBlocksConfig.isConfigurationSection(key)) {
+ parseObjectBlock(result, firstBlocksConfig, key, k);
+ } else {
+ parseStringBlock(result, firstBlocksConfig, key, k);
+ }
}
/**
@@ -286,15 +289,15 @@ private void parseBlock(Map result, ConfigurationSectio
* @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.");
- }
+ 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.");
+ }
}
/**
@@ -307,239 +310,237 @@ private void parseObjectBlock(Map result, Configuration
* @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.");
- }
- }
+ 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;
+ }
+ NamespacedKey key = NamespacedKey.fromString(string.toLowerCase(Locale.ENGLISH));
+ Biome result = Registry.BIOME.get(key);
+ if (result == null) {
+ addon.logError("Biome " + string + " is invalid! Use one of these...");
+ Registry.BIOME.stream().sorted(Comparator.comparing(biome -> biome.getKey().getKey()))
+ .forEach(biome -> addon.logError(biome.getKey().getKey()));
+ return Biome.PLAINS;
+ }
+ return result;
}
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)) {
- addMaterial(obPhase, material, Objects.toString(blocks.get(material)));
- }
- } else if (phase.isList(BLOCKS)) {
- List