diff --git a/pom.xml b/pom.xml
index bdfa63e..6154cbe 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
AOneBlock
AOneBlock is an add-on for BentoBox, an expandable Minecraft Bukkit plugin for island-type games like SkyBlock or AcidIsland.
- https://github.com/BentoBoxWorlgit checkout masterd/AOneBlock
+ https://github.com/BentoBoxWorld/AOneBlock
2020
@@ -67,7 +67,7 @@
-LOCAL
- 1.14.1
+ 1.14.2
BentoBoxWorld_AOneBlock
bentobox-world
@@ -215,7 +215,7 @@
com.github.LoneDev6
API-ItemsAdder
- 3.2.5
+ 3.5.0b
provided
diff --git a/src/main/java/world/bentobox/aoneblock/AOneBlock.java b/src/main/java/world/bentobox/aoneblock/AOneBlock.java
index e87660e..ea49175 100644
--- a/src/main/java/world/bentobox/aoneblock/AOneBlock.java
+++ b/src/main/java/world/bentobox/aoneblock/AOneBlock.java
@@ -41,7 +41,7 @@ public class AOneBlock extends GameModeAddon {
private static final String NETHER = "_nether";
private static final String THE_END = "_the_end";
- public static boolean hasItemsAdder = false;
+ private boolean hasItemsAdder = false;
// Settings
private Settings settings;
diff --git a/src/main/java/world/bentobox/aoneblock/commands/admin/AdminSanityCheck.java b/src/main/java/world/bentobox/aoneblock/commands/admin/AdminSanityCheck.java
index 9496591..8f27cfd 100644
--- a/src/main/java/world/bentobox/aoneblock/commands/admin/AdminSanityCheck.java
+++ b/src/main/java/world/bentobox/aoneblock/commands/admin/AdminSanityCheck.java
@@ -8,6 +8,11 @@
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
+/**
+ * Command to run a sanity check
+ * @author tastybento
+ *
+ */
public class AdminSanityCheck extends CompositeCommand {
private AOneBlock addon;
diff --git a/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java b/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java
index bc11b62..94553c2 100644
--- a/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java
+++ b/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java
@@ -407,46 +407,46 @@ else if (player.getLocation().getBlock().equals(block.getRelative(BlockFace.UP))
private void spawnBlock(@NonNull OneBlockObject nextBlock, @NonNull Block block) {
if (nextBlock.isCustomBlock()) {
nextBlock.getCustomBlock().setBlock(block);
- return;
} else if (nextBlock.isItemsAdderBlock()) {
//Get Custom Block from ItemsAdder and place it
CustomBlock cBlock = CustomBlock.getInstance(nextBlock.getItemsAdderBlock());
if (cBlock != null) {
+ block.getLocation().getBlock().setType(Material.AIR);
cBlock.place(block.getLocation());
+ }
+ } 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();
}
}
- @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();
- }
}
private void spawnEntity(@NonNull OneBlockObject nextBlock, @NonNull Block block) {
diff --git a/src/main/java/world/bentobox/aoneblock/listeners/CheckPhase.java b/src/main/java/world/bentobox/aoneblock/listeners/CheckPhase.java
index d5e4f85..7cb0a73 100644
--- a/src/main/java/world/bentobox/aoneblock/listeners/CheckPhase.java
+++ b/src/main/java/world/bentobox/aoneblock/listeners/CheckPhase.java
@@ -50,51 +50,48 @@ public CheckPhase(AOneBlock addon, BlockListener blockListener) {
* @param i - island
* @param phase - one block phase
* @param world - world
- * @return true if the player can proceed to the next phase, false if not or if there is no next phase.
+ * @return true if the player cannot proceed to the next 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()) {
- switch (r.getType()) {
- case LEVEL:
- return 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:
- return 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:
- return 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()));
+ 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;
- default:
- break;
-
+ }).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 false;
+ return blocked;
}
/**
diff --git a/src/main/java/world/bentobox/aoneblock/oneblocks/OneBlocksManager.java b/src/main/java/world/bentobox/aoneblock/oneblocks/OneBlocksManager.java
index 45796fa..e369b6b 100644
--- a/src/main/java/world/bentobox/aoneblock/oneblocks/OneBlocksManager.java
+++ b/src/main/java/world/bentobox/aoneblock/oneblocks/OneBlocksManager.java
@@ -18,8 +18,6 @@
import java.util.jar.JarFile;
import java.util.stream.Collectors;
-import dev.lone.itemsadder.api.CustomBlock;
-import dev.lone.itemsadder.api.ItemsAdder;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.Material;
import org.bukkit.block.Biome;
@@ -33,6 +31,8 @@
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;
@@ -163,6 +163,13 @@ private void loadPhase(File phaseFile) throws IOException {
}
}
+ /**
+ * 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
+ * @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) {
@@ -323,10 +330,18 @@ void addRequirements(OneBlockPhase obPhase, ConfigurationSection phase) {
if (!phase.isConfigurationSection(REQUIREMENTS)) {
return;
}
+ ConfigurationSection reqs = phase.getConfigurationSection(REQUIREMENTS);
for (ReqType key : Requirement.ReqType.values()) {
- ConfigurationSection reqs = phase.getConfigurationSection(REQUIREMENTS);
if (reqs.contains(key.getKey())) {
- reqList.add(new Requirement(key, reqs.get(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);
@@ -415,8 +430,10 @@ void addBlocks(OneBlockPhase obPhase, ConfigurationSection phase) {
CustomBlock block = CustomBlock.getInstance(material);
if (block != null) {
addItemsAdderBlock(obPhase, material, Objects.toString(blocks.get(material)));
- } else if (ItemsAdder.getAllItems().size() != 0){
- addon.logError("Bad block material in " + obPhase.getPhaseName() + ": " + 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);
@@ -783,6 +800,9 @@ public void getProbs(OneBlockPhase phase) {
}
}
+ /**
+ * Get all the probs for each phases and log to console
+ */
public void getAllProbs() {
blockProbs.values().forEach(this::getProbs);
}
diff --git a/src/main/java/world/bentobox/aoneblock/panels/PhasesPanel.java b/src/main/java/world/bentobox/aoneblock/panels/PhasesPanel.java
index d3b8b8f..2eeb76d 100644
--- a/src/main/java/world/bentobox/aoneblock/panels/PhasesPanel.java
+++ b/src/main/java/world/bentobox/aoneblock/panels/PhasesPanel.java
@@ -26,6 +26,7 @@
import world.bentobox.aoneblock.oneblocks.OneBlockPhase;
import world.bentobox.aoneblock.oneblocks.Requirement;
import world.bentobox.bank.Bank;
+import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.panels.PanelItem;
import world.bentobox.bentobox.api.panels.TemplatedPanel;
@@ -337,11 +338,23 @@ private PanelItem createPhaseButton(ItemTemplateRecord template, Map.Entry {
switch (requirement.getType())
{
case ECO -> economyText.append(this.user.getTranslationOrNothing(reference + "economy",
- TextVariables.NUMBER, String.valueOf(requirement.getEco())));
-
+ TextVariables.NUMBER, String.valueOf(requirement.getEco())));
+
case BANK -> bankText.append(this.user.getTranslationOrNothing(reference + "bank",
- TextVariables.NUMBER, String.valueOf(requirement.getBank())));
-
+ TextVariables.NUMBER, String.valueOf(requirement.getBank())));
+
case LEVEL -> levelText.append(this.user.getTranslationOrNothing(reference + "level",
- TextVariables.NUMBER, String.valueOf(requirement.getLevel())));
-
+ TextVariables.NUMBER, String.valueOf(requirement.getLevel())));
+
case PERMISSION -> permissionText.append(this.user.getTranslationOrNothing(reference + "permission",
- TextVariables.NUMBER, requirement.getPermission()));
-
+ PERMISSION, requirement.getPermission()));
+
}
});
if (template.description() != null)
{
+ String biomeText = phase.getPhaseBiome() == null ? "" : LangUtilsHook.getBiomeName(phase.getPhaseBiome(), this.user);
+
descriptionText = this.user.getTranslationOrNothing(template.description(),
TextVariables.NUMBER, phase.getBlockNumber(),
- BIOME, LangUtilsHook.getBiomeName(phase.getPhaseBiome(), this.user),
+ BIOME, biomeText,
BANK, bankText.toString(),
ECONOMY, economyText.toString(),
LEVEL, levelText.toString(),
@@ -404,9 +420,10 @@ private PanelItem createPhaseButton(ItemTemplateRecord template, Map.Entry
- this.addon.getAddonByName("Level").map(a ->
- ((Level) a).getIslandLevel(this.world, this.island.getOwner()) < requirement.getLevel()).
- orElse(false);
- case BANK ->
- this.addon.getAddonByName("Bank").map(a ->
- ((Bank) a).getBankManager().getBalance(this.island).getValue() < requirement.getBank()).
- orElse(false);
- case ECO ->
- this.addon.getPlugin().getVault().map(a ->
- a.getBalance(this.user, this.world) < requirement.getEco()).
- orElse(false);
- case PERMISSION ->
- this.user != null && !this.user.hasPermission(requirement.getPermission());
- };
- if (result) {
- break;
- }
- }
+ if (switch (requirement.getType()) {
+ case LEVEL -> this.addon.getAddonByName("Level").filter(Addon::isEnabled).map(a ->
+ ((Level) a).getIslandLevel(this.world, this.island.getOwner()) < requirement.getLevel()).orElse(false);
+
+ case BANK -> this.addon.getAddonByName("Bank").filter(Addon::isEnabled).map(a ->
+ ((Bank) a).getBankManager().getBalance(this.island).getValue() < requirement.getBank()).orElse(false);
- return result;
+ case ECO -> this.addon.getPlugin().getVault().map(a -> a.getBalance(this.user, this.world) < requirement.getEco()).orElse(false);
+
+ case PERMISSION -> this.user != null && !this.user.hasPermission(requirement.getPermission());
+ }) {
+ return true;
+ }
+ }
+ return false;
}
@@ -551,17 +551,17 @@ private boolean phaseRequirementsFail(OneBlockPhase phase)
private void runCommandCall(String command, OneBlockPhase phase)
{
// Get first player command label.
- this.addon.getPlayerCommand().ifPresent(mainCommand ->
- mainCommand.getSubCommand(command).ifPresent(subCommand -> {
- // Check if subcommand is setCount command.
- if (Arrays.stream(this.addon.getSettings().getSetCountCommand().split(" ")).
+ this.addon.getPlayerCommand().ifPresent(mainCommand ->
+ mainCommand.getSubCommand(command).ifPresent(subCommand -> {
+ // Check if subcommand is setCount command.
+ if (Arrays.stream(this.addon.getSettings().getSetCountCommand().split(" ")).
anyMatch(text -> text.equalsIgnoreCase(subCommand.getLabel())))
- {
- this.addon.log(this.user.getName() + " called: `" + mainCommand.getTopLabel() + " " + subCommand.getLabel() + " " + phase.getBlockNumber());
- // Confirmation is done via GUI. Bypass.
- this.user.performCommand(mainCommand.getTopLabel() + " " + subCommand.getLabel() + " " + phase.getBlockNumber());
- }
- }));
+ {
+ this.addon.log(this.user.getName() + " called: `" + mainCommand.getTopLabel() + " " + subCommand.getLabel() + " " + phase.getBlockNumber());
+ // Confirmation is done via GUI. Bypass.
+ this.user.performCommand(mainCommand.getTopLabel() + " " + subCommand.getLabel() + " " + phase.getBlockNumber());
+ }
+ }));
// Close inventory
this.user.closeInventory();
diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml
index 23c4249..cb9e857 100755
--- a/src/main/resources/locales/en-US.yml
+++ b/src/main/resources/locales/en-US.yml
@@ -42,9 +42,9 @@ aoneblock:
set: "&a Count set to [number]."
too-high: "&c The maximum you can set is [number]!"
respawn-block:
- description: "respawns magic block in situations when they disappear"
- block-exist: "&a Block exist, do not require respawning. I marked it for you."
- block-respawned: "&a Block respawned, please, do not void it again."
+ description: "respawns magic block in situations when it disappears"
+ block-exist: "&a Block exists, did not require respawning. I marked it for you."
+ block-respawned: "&a Block respawned."
phase:
insufficient-level: "&c Your island level is too low to proceed! It must be [number]."
insufficient-funds: "&c Your funds are too low to proceed! They must be [number]."
diff --git a/src/main/resources/locales/vi.yml b/src/main/resources/locales/vi.yml
index 4635f97..6203537 100644
--- a/src/main/resources/locales/vi.yml
+++ b/src/main/resources/locales/vi.yml
@@ -6,7 +6,7 @@ aoneblock:
parameters: " "
description: chỉnh số đếm khối của người chơi
set: "&a Số đếm khối của [name] được đặt thành [number]"
- set-lifetime: "& bộ đếm thời gian tồn tại của [name] được đặt thành [number]"
+ set-lifetime: "&a Bộ đếm thời gian tồn tại của [name] được đặt thành [number]"
setchest:
parameters: " <độ hiếm>"
description: thêm rương đang nhìn vào một giai đoạn với độ hiếm được chỉ định
@@ -36,7 +36,7 @@ aoneblock:
setcount:
parameters: ""
description: đặt số khối thành giá trị đã hoàn thành trước đó
- set: "& Bộ đếm được đặt thành [number]."
+ set: "&a Bộ đếm được đặt thành [number]."
too-high: "&cMức tối đa bạn có thể đặt là[number]!"
phase:
insufficient-level: Cấp đảo của bạn quá thấp để thực thi! Nó phải là [number].
diff --git a/src/test/java/world/bentobox/aoneblock/oneblocks/OneBlocksManagerTest2.java b/src/test/java/world/bentobox/aoneblock/oneblocks/OneBlocksManagerTest2.java
new file mode 100644
index 0000000..b894ef1
--- /dev/null
+++ b/src/test/java/world/bentobox/aoneblock/oneblocks/OneBlocksManagerTest2.java
@@ -0,0 +1,446 @@
+package world.bentobox.aoneblock.oneblocks;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Comparator;
+import java.util.List;
+import java.util.NavigableMap;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+
+import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.UnsafeValues;
+import org.bukkit.block.Biome;
+import org.bukkit.configuration.InvalidConfigurationException;
+import org.bukkit.configuration.file.YamlConfiguration;
+import org.bukkit.inventory.ItemFactory;
+import org.bukkit.inventory.meta.ItemMeta;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.reflect.Whitebox;
+
+import world.bentobox.aoneblock.AOneBlock;
+import world.bentobox.aoneblock.dataobjects.OneBlockIslands;
+import world.bentobox.bentobox.BentoBox;
+import world.bentobox.bentobox.api.addons.AddonDescription;
+import world.bentobox.bentobox.api.user.User;
+import world.bentobox.bentobox.managers.AddonsManager;
+
+/**
+ * @author tastybento
+ *
+ */
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({Bukkit.class, BentoBox.class, User.class})
+public class OneBlocksManagerTest2 {
+
+ private static File jFile;
+ private static YamlConfiguration oneBlocks;
+ @Mock
+ private BentoBox plugin;
+ private AOneBlock addon;
+ @Mock
+ private AddonsManager am;
+ private OneBlocksManager obm;
+ private OneBlockPhase obPhase;
+ @Mock
+ private @NonNull OneBlockIslands obi;
+
+ @BeforeClass
+ public static void beforeClass() throws IOException, InvalidConfigurationException {
+ // Make the addon jar
+ jFile = new File("addon.jar");
+ // Copy over config file from src folder
+ /*
+ Path fromPath = Paths.get("src/main/resources/config.yml");
+ Path path = Paths.get("config.yml");
+ Files.copy(fromPath, path);*/
+ // Dummy oneblocks.yml
+ String oneblocks =
+ "'0':\n" +
+ " name: Plains\n" +
+ " icon: GRASS_BLOCK\n" +
+ " firstBlock: GRASS_BLOCK\n" +
+ " biome: PLAINS\n" +
+ " fixedBlocks:\n" +
+ " 0: GRASS_BLOCK\n" +
+ " 1: GRASS_BLOCK\n" +
+ " holograms:\n" +
+ " 0: &aGood Luck!\n" +
+ " blocks:\n" +
+ " GRASS_BLOCK: 2000\n" +
+ " BIRCH_LOG: 500\n" +
+ " mobs:\n" +
+ " SHEEP: 150\n" +
+ " VILLAGER: 30\n" +
+ "'700':\n" +
+ " name: Underground\n" +
+ " firstBlock: STONE\n" +
+ " biome: TAIGA\n" +
+ " blocks:\n" +
+ " EMERALD_ORE: 5\n" +
+ " COBWEB: 250\n" +
+ " DIRT: 500\n" +
+ "'11000':\n" +
+ " gotoBlock: 0";
+ oneBlocks = new YamlConfiguration();
+ oneBlocks.loadFromString(oneblocks);
+ // Save
+ File obFileDir = new File("phases");
+
+ File obFile = new File(obFileDir, "0_plains.yml");
+ obFileDir.mkdirs();
+ oneBlocks.save(obFile);
+ /*
+ // Copy over block config file from src folder
+ fromPath = Paths.get("src/main/resources/oneblocks.yml");
+ path = Paths.get("oneblocks.yml");
+ Files.copy(fromPath, path);
+ */
+ try (JarOutputStream tempJarOutputStream = new JarOutputStream(new FileOutputStream(jFile))) {
+ //Added the new files to the jar.
+ try (FileInputStream fis = new FileInputStream(obFile)) {
+ byte[] buffer = new byte[1024];
+ int bytesRead = 0;
+ JarEntry entry = new JarEntry(obFile.toPath().toString());
+ tempJarOutputStream.putNextEntry(entry);
+ while((bytesRead = fis.read(buffer)) != -1) {
+ tempJarOutputStream.write(buffer, 0, bytesRead);
+ }
+ }
+ }
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ // Set up plugin
+ Whitebox.setInternalState(BentoBox.class, "instance", plugin);
+ // Addon
+ addon = new AOneBlock();
+ File dataFolder = new File("addons/AOneBlock");
+ addon.setDataFolder(dataFolder);
+ addon.setFile(jFile);
+ AddonDescription desc = new AddonDescription.Builder("bentobox", "AOneBlock", "1.3").description("test").authors("tastybento").build();
+ addon.setDescription(desc);
+ //addon.setSettings(new Settings());
+ // Addons manager
+ when(plugin.getAddonsManager()).thenReturn(am);
+
+ // Bukkit
+ PowerMockito.mockStatic(Bukkit.class);
+ ItemMeta meta = mock(ItemMeta.class);
+ ItemFactory itemFactory = mock(ItemFactory.class);
+ when(itemFactory.getItemMeta(any())).thenReturn(meta);
+ when(Bukkit.getItemFactory()).thenReturn(itemFactory);
+ UnsafeValues unsafe = mock(UnsafeValues.class);
+ when(unsafe.getDataVersion()).thenReturn(777);
+ when(Bukkit.getUnsafe()).thenReturn(unsafe);
+
+ // Phase
+ obPhase = new OneBlockPhase("0");
+
+ // Class under test
+ obm = new OneBlocksManager(addon);
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ deleteAll(new File("database"));
+ }
+
+ @AfterClass
+ public static void cleanUp() throws Exception {
+
+ new File("addon.jar").delete();
+ new File("config.yml").delete();
+
+ deleteAll(new File("addons"));
+ deleteAll(new File("phases"));
+ }
+
+ private static void deleteAll(File file) throws IOException {
+ if (file.exists()) {
+ Files.walk(file.toPath())
+ .sorted(Comparator.reverseOrder())
+ .map(Path::toFile)
+ .forEach(File::delete);
+ }
+ }
+ /**
+ * Test method for {@link world.bentobox.aoneblock.oneblocks.OneBlocksManager#OneBlocksManager(world.bentobox.aoneblock.AOneBlock)}.
+ * @throws IOException
+ */
+ @Test
+ public void testOneBlocksManager() throws IOException {
+ File f = new File("phases", "0_plains.yml");
+ assertTrue(f.exists());
+ }
+
+ /**
+ * Test method for {@link world.bentobox.aoneblock.oneblocks.OneBlocksManager#loadPhases()}.
+ * @throws InvalidConfigurationException
+ * @throws IOException
+ * @throws NumberFormatException
+ */
+ //@Ignore("Cannot deserialize objects right now")
+ @Test
+ public void testLoadPhases() throws NumberFormatException, IOException, InvalidConfigurationException {
+ obm.loadPhases();
+ verify(plugin, never()).logError(anyString());
+ assertEquals(Material.GRASS_BLOCK, obm.getPhase(0).getFirstBlock().getMaterial());
+ assertEquals(Biome.PLAINS, obm.getPhase(0).getPhaseBiome());
+ assertEquals("Plains", obm.getPhase(0).getPhaseName());
+ assertNull(obm.getPhase(0).getGotoBlock());
+
+ assertEquals(Material.STONE, obm.getPhase(700).getFirstBlock().getMaterial());
+ assertEquals(Biome.TAIGA, obm.getPhase(700).getPhaseBiome());
+ assertEquals("Underground", obm.getPhase(700).getPhaseName());
+ assertNull(obm.getPhase(700).getGotoBlock());
+
+ assertEquals(0, (int)obm.getPhase(11000).getGotoBlock());
+
+
+ }
+
+ /**
+ * Test method for {@link world.bentobox.aoneblock.oneblocks.OneBlocksManager#getPhaseList()}.
+ * @throws InvalidConfigurationException
+ * @throws IOException
+ * @throws NumberFormatException
+ */
+ @Test
+ public void testGetPhaseList() throws NumberFormatException, IOException, InvalidConfigurationException {
+ testLoadPhases();
+ List l = obm.getPhaseList();
+ assertEquals(2, l.size());
+ assertEquals("Plains", l.get(0));
+ assertEquals("Underground", l.get(1));
+
+ }
+
+ /**
+ * Test method for {@link world.bentobox.aoneblock.oneblocks.OneBlocksManager#getPhase(java.lang.String)}.
+ * @throws InvalidConfigurationException
+ * @throws IOException
+ * @throws NumberFormatException
+ */
+ @Test
+ public void testGetPhaseString() throws NumberFormatException, IOException, InvalidConfigurationException {
+ testLoadPhases();
+ assertFalse(obm.getPhase("sdf").isPresent());
+ assertTrue(obm.getPhase("Plains").isPresent());
+ assertTrue(obm.getPhase("Underground").isPresent());
+ }
+
+ /**
+ * Test method for {@link world.bentobox.aoneblock.oneblocks.OneBlocksManager#saveOneBlockConfig()}.
+ * @throws InvalidConfigurationException
+ * @throws IOException
+ * @throws NumberFormatException
+ */
+ @Ignore("Not saving")
+ @Test
+ public void testSaveOneBlockConfig() throws NumberFormatException, IOException, InvalidConfigurationException {
+ //testLoadPhases();
+ //assertTrue(obm.saveOneBlockConfig());
+ }
+
+ /**
+ * Test method for {@link world.bentobox.aoneblock.oneblocks.OneBlocksManager#getNextPhase(OneBlockPhase)}.
+ * @throws InvalidConfigurationException
+ * @throws IOException
+ * @throws NumberFormatException
+ */
+ @Test
+ public void testGetNextPhase() throws NumberFormatException, IOException, InvalidConfigurationException {
+ testLoadPhases();
+ OneBlockPhase plains = obm.getPhase("Plains").get();
+ OneBlockPhase underground = obm.getPhase("Underground").get();
+ OneBlockPhase gotoPhase = obm.getPhase(11000);
+ assertEquals(underground, obm.getNextPhase(plains));
+ assertEquals(gotoPhase, obm.getNextPhase(underground));
+ assertNull(obm.getNextPhase(gotoPhase));
+ }
+
+ /**
+ * Test method for {@link world.bentobox.aoneblock.oneblocks.OneBlocksManager#copyPhasesFromAddonJar(java.io.File)}.
+ * @throws IOException
+ */
+ @Test
+ public void testCopyPhasesFromAddonJar() throws IOException {
+ File dest = new File("dest");
+ dest.mkdir();
+ obm.copyPhasesFromAddonJar(dest);
+ File check = new File(dest, "0_plains.yml");
+ assertTrue(check.exists());
+ // Clean up
+ deleteAll(dest);
+ }
+
+ /**
+ * Test method for {@link world.bentobox.aoneblock.oneblocks.OneBlocksManager#initBlock(java.lang.String, world.bentobox.aoneblock.oneblocks.OneBlockPhase, org.bukkit.configuration.ConfigurationSection)}.
+ * @throws IOException
+ */
+ @Test
+ public void testInitBlock() throws IOException {
+ System.out.println(oneBlocks);
+ obm.initBlock("0", obPhase, oneBlocks);
+ assertEquals("", obPhase.getPhaseName());
+ }
+
+ /**
+ * Test method for {@link world.bentobox.aoneblock.oneblocks.OneBlocksManager#addFirstBlock(world.bentobox.aoneblock.oneblocks.OneBlockPhase, java.lang.String)}.
+ */
+ @Test
+ public void testAddFirstBlock() {
+ obm.addFirstBlock(obPhase, "SPONGE");
+ }
+
+ /**
+ * Test method for {@link world.bentobox.aoneblock.oneblocks.OneBlocksManager#addCommands(world.bentobox.aoneblock.oneblocks.OneBlockPhase, org.bukkit.configuration.ConfigurationSection)}.
+ */
+ @Test
+ public void testAddCommands() {
+ obm.addCommands(obPhase, oneBlocks);
+ }
+
+ /**
+ * Test method for {@link world.bentobox.aoneblock.oneblocks.OneBlocksManager#addRequirements(world.bentobox.aoneblock.oneblocks.OneBlockPhase, org.bukkit.configuration.ConfigurationSection)}.
+ */
+ @Test
+ public void testAddRequirements() {
+ obm.addRequirements(obPhase, oneBlocks);
+ }
+
+ /**
+ * Test method for {@link world.bentobox.aoneblock.oneblocks.OneBlocksManager#addChests(world.bentobox.aoneblock.oneblocks.OneBlockPhase, org.bukkit.configuration.ConfigurationSection)}.
+ */
+ @Test
+ public void testAddChests() throws IOException {
+ obm.addChests(obPhase, oneBlocks);
+ }
+
+ /**
+ * Test method for {@link world.bentobox.aoneblock.oneblocks.OneBlocksManager#addMobs(world.bentobox.aoneblock.oneblocks.OneBlockPhase, org.bukkit.configuration.ConfigurationSection)}.
+ */
+ @Test
+ public void testAddMobs() throws IOException {
+ obm.addMobs(obPhase, oneBlocks);
+ }
+
+ /**
+ * Test method for {@link world.bentobox.aoneblock.oneblocks.OneBlocksManager#addBlocks(world.bentobox.aoneblock.oneblocks.OneBlockPhase, org.bukkit.configuration.ConfigurationSection)}.
+ */
+ @Test
+ public void testAddBlocks() throws IOException {
+ obm.addBlocks(obPhase, oneBlocks);
+ }
+
+ /**
+ * Test method for {@link world.bentobox.aoneblock.oneblocks.OneBlocksManager#getPhase(int)}.
+ */
+ @Test
+ public void testGetPhaseInt() {
+ @Nullable
+ OneBlockPhase phase = obm.getPhase(1);
+ }
+
+ /**
+ * Test method for {@link world.bentobox.aoneblock.oneblocks.OneBlocksManager#getBlockProbs()}.
+ */
+ @Test
+ public void testGetBlockProbs() {
+ NavigableMap probs = obm.getBlockProbs();
+ }
+
+ /**
+ * Test method for {@link world.bentobox.aoneblock.oneblocks.OneBlocksManager#savePhase(world.bentobox.aoneblock.oneblocks.OneBlockPhase)}.
+ */
+ @Test
+ public void testSavePhase() {
+ boolean result = obm.savePhase(obPhase);
+ }
+
+ /**
+ * Test method for {@link world.bentobox.aoneblock.oneblocks.OneBlocksManager#getNextPhase(world.bentobox.aoneblock.oneblocks.OneBlockPhase)}.
+ */
+ @Test
+ public void testGetNextPhaseOneBlockPhase() {
+ @Nullable
+ OneBlockPhase phase = obm.getNextPhase(obPhase);
+ }
+
+ /**
+ * Test method for {@link world.bentobox.aoneblock.oneblocks.OneBlocksManager#getNextPhaseBlocks(world.bentobox.aoneblock.dataobjects.OneBlockIslands)}.
+ */
+ @Test
+ public void testGetNextPhaseBlocks() {
+ int phase = obm.getNextPhaseBlocks(obi);
+ }
+
+ /**
+ * Test method for {@link world.bentobox.aoneblock.oneblocks.OneBlocksManager#getPercentageDone(world.bentobox.aoneblock.dataobjects.OneBlockIslands)}.
+ */
+ @Test
+ public void testGetPercentageDone() {
+ double percent = obm.getPercentageDone(obi);
+ }
+
+ /**
+ * Test method for {@link world.bentobox.aoneblock.oneblocks.OneBlocksManager#getProbs(world.bentobox.aoneblock.oneblocks.OneBlockPhase)}.
+ */
+ @Test
+ public void testGetProbs() {
+ obm.getProbs(obPhase);
+ }
+
+ /**
+ * Test method for {@link world.bentobox.aoneblock.oneblocks.OneBlocksManager#getAllProbs()}.
+ */
+ @Test
+ public void testGetAllProbs() {
+ obm.getAllProbs();
+ }
+
+ /**
+ * Test method for {@link world.bentobox.aoneblock.oneblocks.OneBlocksManager#getNextPhase(world.bentobox.aoneblock.dataobjects.OneBlockIslands)}.
+ */
+ @Test
+ public void testGetNextPhaseOneBlockIslands() {
+ String phase = obm.getNextPhase(obi);
+ }
+
+}