Merge branch 'develop' of https://github.com/BentoBoxWorld/BentoBox.git into develop

This commit is contained in:
tastybento 2023-02-11 09:09:36 -08:00
commit 0f0b5aacc2
9 changed files with 350 additions and 9 deletions

View File

@ -84,10 +84,10 @@ public class BlueprintPaster {
private final Island island; private final Island island;
/** /**
* Paste a clipboard to a location and run task * Paste a clipboard to a location. Run {@link #paste()} to paste
* @param plugin - BentoBox * @param plugin - BentoBox
* @param clipboard - clipboard to paste * @param clipboard - clipboard to paste
* @param location - location to paste to * @param location - location to which to paste
*/ */
public BlueprintPaster(@NonNull BentoBox plugin, @NonNull BlueprintClipboard clipboard, @NonNull Location location) { public BlueprintPaster(@NonNull BentoBox plugin, @NonNull BlueprintClipboard clipboard, @NonNull Location location) {
this.plugin = plugin; this.plugin = plugin;
@ -97,9 +97,6 @@ public class BlueprintPaster {
this.location = location; this.location = location;
this.world = location.getWorld(); this.world = location.getWorld();
this.island = null; this.island = null;
// Paste
paste();
} }
/** /**

View File

@ -21,7 +21,7 @@ public final class EnumTypeAdapter<T extends Enum<T>> extends TypeAdapter<T> {
/** /**
* Bimap to store name <-> enum references * Bimap to store name,enum pair references
*/ */
private final BiMap<String, T> enumMap = HashBiMap.create(); private final BiMap<String, T> enumMap = HashBiMap.create();

View File

@ -103,7 +103,6 @@ public class CleanSuperFlatListener extends FlagListener {
/** /**
* This method clears the chunk from queue in the given world * This method clears the chunk from queue in the given world
* @param world The world that must be cleared. * @param world The world that must be cleared.
* @param cg Chunk generator.
*/ */
private void cleanChunk(World world) private void cleanChunk(World world)
{ {

View File

@ -4,6 +4,8 @@ import java.util.LinkedList;
import java.util.Queue; import java.util.Queue;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import org.bukkit.Bukkit;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.database.objects.IslandDeletion; import world.bentobox.bentobox.database.objects.IslandDeletion;
import world.bentobox.bentobox.util.DeleteIslandChunks; import world.bentobox.bentobox.util.DeleteIslandChunks;
@ -24,7 +26,7 @@ public class IslandChunkDeletionManager implements Runnable {
this.slowDeletion = plugin.getSettings().isSlowDeletion(); this.slowDeletion = plugin.getSettings().isSlowDeletion();
if (slowDeletion) { if (slowDeletion) {
plugin.getServer().getScheduler().runTaskTimer(plugin, this, 0L, 20L); Bukkit.getScheduler().runTaskTimer(plugin, this, 0L, 20L);
} }
} }

View File

@ -182,9 +182,13 @@ public class ItemParser {
/** /**
* This method parses array of 6 items into an item stack. * This method parses array of 6 items into an item stack.
* Format: * Format:
* <pre>{@code
* POTION:NAME:<LEVEL>:<EXTENDED>:<SPLASH/LINGER>:QTY * POTION:NAME:<LEVEL>:<EXTENDED>:<SPLASH/LINGER>:QTY
* }</pre>
* Example: * Example:
* <pre>{@code
* POTION:STRENGTH:1:EXTENDED:SPLASH:1 * POTION:STRENGTH:1:EXTENDED:SPLASH:1
* }</pre>
* @param part String array that contains 6 elements. * @param part String array that contains 6 elements.
* @return Potion with given properties. * @return Potion with given properties.
*/ */
@ -257,13 +261,17 @@ public class ItemParser {
/** /**
* This method parses array of 2 to 3 elements that represents player head. * This method parses array of 2 to 3 elements that represents player head.
* Format: * Format:
* <pre>{@code
* PLAYER_HEAD:<STRING/Trimmed UUID/UUID/Texture>:QTY * PLAYER_HEAD:<STRING/Trimmed UUID/UUID/Texture>:QTY
* PLAYER_HEAD:<STRING/Trimmed UUID/UUID/Texture> * PLAYER_HEAD:<STRING/Trimmed UUID/UUID/Texture>
* PLAYER_HEAD:QTY * PLAYER_HEAD:QTY
* }</pre>
* Example: * Example:
* <pre>{@code
* PLAYER_HEAD:1 * PLAYER_HEAD:1
* PLAYER_HEAD:BONNe1704 * PLAYER_HEAD:BONNe1704
* PLAYER_HEAD:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYWY1ZjE1OTg4NmNjNTMxZmZlYTBkOGFhNWY5MmVkNGU1ZGE2NWY3MjRjMDU3MGFmODZhOTBiZjAwYzY3YzQyZSJ9fX0:1 * PLAYER_HEAD:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYWY1ZjE1OTg4NmNjNTMxZmZlYTBkOGFhNWY5MmVkNGU1ZGE2NWY3MjRjMDU3MGFmODZhOTBiZjAwYzY3YzQyZSJ9fX0:1
* }</pre>
* @param part String array that contains at least 2 elements. * @param part String array that contains at least 2 elements.
* @return Player head with given properties. * @return Player head with given properties.
*/ */

View File

@ -59,7 +59,7 @@ import world.bentobox.bentobox.nms.WorldRegenerator;
*/ */
public class Util { public class Util {
/** /**
* Use standard color code definition: &<hex>. * Use standard color code definition: {@code &<hex>}.
*/ */
private static final Pattern HEX_PATTERN = Pattern.compile("&#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})"); private static final Pattern HEX_PATTERN = Pattern.compile("&#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})");
private static final String NETHER = "_nether"; private static final String NETHER = "_nether";

View File

@ -0,0 +1,105 @@
package world.bentobox.bentobox.api.events.addon;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import world.bentobox.bentobox.api.addons.Addon;
/**
* @author tastybento
*
*/
@RunWith(PowerMockRunner.class)
public class AddonEnableEventTest {
private AddonEnableEvent aee;
@Mock
private Addon addon;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
Map<String, Object> map = new HashMap<>();
aee = new AddonEnableEvent(addon, map);
}
/**
* Test method for {@link world.bentobox.bentobox.api.events.addon.AddonEnableEvent#getHandlers()}.
*/
@Test
public void testGetHandlers() {
assertNotNull(aee.getHandlers());
}
/**
* Test method for {@link world.bentobox.bentobox.api.events.addon.AddonEnableEvent#getHandlerList()}.
*/
@Test
public void testGetHandlerList() {
assertNotNull(AddonEnableEvent.getHandlerList());
}
/**
* Test method for {@link world.bentobox.bentobox.api.events.addon.AddonEnableEvent#AddonEnableEvent(world.bentobox.bentobox.api.addons.Addon, java.util.Map)}.
*/
@Test
public void testAddonEnableEvent() {
assertNotNull(aee);
}
/**
* Test method for {@link world.bentobox.bentobox.api.events.addon.AddonBaseEvent#getKeyValues()}.
*/
@Test
public void testGetKeyValues() {
assertTrue(aee.getKeyValues().isEmpty());
}
/**
* Test method for {@link world.bentobox.bentobox.api.events.addon.AddonBaseEvent#getAddon()}.
*/
@Test
public void testGetAddon() {
assertEquals(addon, aee.getAddon());
}
/**
* Test method for {@link world.bentobox.bentobox.api.events.addon.AddonBaseEvent#getNewEvent()}.
*/
@Test
public void testGetNewEvent() {
assertTrue(aee.getNewEvent().isEmpty());
}
/**
* Test method for {@link world.bentobox.bentobox.api.events.addon.AddonBaseEvent#setNewEvent(world.bentobox.bentobox.api.events.addon.AddonBaseEvent)}.
*/
@Test
public void testSetNewEvent() {
aee.setNewEvent(aee);
assertEquals(aee, aee.getNewEvent().get());
}
/**
* Test method for {@link world.bentobox.bentobox.api.events.BentoBoxEvent#setKeyValues(java.util.Map)}.
*/
@Test
@Ignore
public void testSetKeyValues() {
// No fields to set values for in the class
}
}

View File

@ -0,0 +1,130 @@
package world.bentobox.bentobox.blueprints;
import static org.junit.Assert.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.util.Vector;
import org.eclipse.jdt.annotation.NonNull;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
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.bentobox.BentoBox;
import world.bentobox.bentobox.Settings;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
/**
* @author tastybento
*
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({BentoBox.class, User.class, Bukkit.class})
public class BlueprintPasterTest {
private BlueprintPaster bp;
private BlueprintPaster bp2;
@Mock
private BentoBox plugin;
@Mock
private @NonNull Blueprint blueprint;
@Mock
private World world;
@Mock
private @NonNull Island island;
@Mock
private Location location;
@Mock
private @NonNull BlueprintClipboard clipboard;
@Mock
private @NonNull User user;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
// Set up plugin
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
// Scheduler
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
Settings settings = new Settings();
// Settings
when(plugin.getSettings()).thenReturn(settings);
// Location
when(location.toVector()).thenReturn(new Vector(1D,2D,3D));
// Island
when(island.getProtectionCenter()).thenReturn(location);
when(island.getOwner()).thenReturn(UUID.randomUUID());
// Clipboard
when(clipboard.getBlueprint()).thenReturn(blueprint);
// User
PowerMockito.mockStatic(User.class, Mockito.RETURNS_MOCKS);
when(User.getInstance(any(UUID.class))).thenReturn(user);
bp = new BlueprintPaster(plugin, blueprint, world, island);
bp2 = new BlueprintPaster(plugin, clipboard, location);
}
/**
* Test method for {@link world.bentobox.bentobox.blueprints.BlueprintPaster#BlueprintPaster(world.bentobox.bentobox.BentoBox, world.bentobox.bentobox.blueprints.BlueprintClipboard, org.bukkit.Location)}.
*/
@Test
public void testBlueprintPasterBentoBoxBlueprintClipboardLocation() {
assertNotNull(bp2);
}
/**
* Test method for {@link world.bentobox.bentobox.blueprints.BlueprintPaster#BlueprintPaster(world.bentobox.bentobox.BentoBox, world.bentobox.bentobox.blueprints.Blueprint, org.bukkit.World, world.bentobox.bentobox.database.objects.Island)}.
*/
@Test
public void testBlueprintPasterBentoBoxBlueprintWorldIsland() {
assertNotNull(bp);
}
/**
* Test method for {@link world.bentobox.bentobox.blueprints.BlueprintPaster#paste()}.
*/
@Test
public void testPaste() {
CompletableFuture<Boolean> result = bp.paste();
assertNotNull(result);
PowerMockito.verifyStatic(Bukkit.class, times(1));
Bukkit.getScheduler();
}
/**
* Test method for {@link world.bentobox.bentobox.blueprints.BlueprintPaster#paste()}.
*/
@Test
public void testPaste2() {
CompletableFuture<Boolean> result = bp2.paste();
assertNotNull(result);
PowerMockito.verifyStatic(Bukkit.class, times(1));
Bukkit.getScheduler();
}
}

View File

@ -0,0 +1,100 @@
package world.bentobox.bentobox.managers;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.bukkit.Bukkit;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
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.bentobox.BentoBox;
import world.bentobox.bentobox.Settings;
import world.bentobox.bentobox.database.objects.IslandDeletion;
import world.bentobox.bentobox.util.DeleteIslandChunks;
/**
* @author tastybento
*
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({BentoBox.class, Bukkit.class, DeleteIslandChunks.class})
public class IslandChunkDeletionManagerTest {
@Mock
private BentoBox plugin;
private IslandChunkDeletionManager icdm;
@Mock
private DeleteIslandChunks dic;
@Mock
private IslandWorldManager iwm;
@Mock
private IslandDeletion id;
private Settings settings;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
// Set up plugin
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
// IWM
when(plugin.getIWM()).thenReturn(iwm);
// Scheduler
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
// DeleteIslandChunks
PowerMockito.whenNew(DeleteIslandChunks.class).withAnyArguments().thenReturn(dic);
settings = new Settings();
settings.setSlowDeletion(true);
// Settings
when(plugin.getSettings()).thenReturn(settings);
icdm = new IslandChunkDeletionManager(plugin);
}
/**
* Test method for {@link world.bentobox.bentobox.managers.IslandChunkDeletionManager#IslandChunkDeletionManager(world.bentobox.bentobox.BentoBox)}.
*/
@Test
public void testIslandChunkDeletionManager() {
PowerMockito.verifyStatic(Bukkit.class, times(1));
Bukkit.getScheduler();
}
/**
* Test method for {@link world.bentobox.bentobox.managers.IslandChunkDeletionManager#run()}.
*/
@Test
public void testRun() {
icdm.add(id);
icdm.run();
verify(id, times(3)).getWorld();
}
/**
* Test method for {@link world.bentobox.bentobox.managers.IslandChunkDeletionManager#add(world.bentobox.bentobox.database.objects.IslandDeletion)}.
*/
@Test
public void testAdd() {
settings.setSlowDeletion(false);
icdm = new IslandChunkDeletionManager(plugin);
icdm.add(id);
verify(id, times(3)).getWorld();
}
}