mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-01 05:57:54 +01:00
WIP pastes but attachments fall when split across paste boundaries
This commit is contained in:
parent
cf0fdf45b9
commit
c4a5eb2c88
@ -146,6 +146,11 @@ public class Settings implements DataObject {
|
|||||||
@ConfigEntry(path = "island.name.max-length")
|
@ConfigEntry(path = "island.name.max-length")
|
||||||
private int nameMaxLength = 20;
|
private int nameMaxLength = 20;
|
||||||
|
|
||||||
|
@ConfigComment("Number of blocks to paste per tick when pasting a schem")
|
||||||
|
@ConfigComment("Smaller values will help reduce noticeable lag but will make pasting take longer")
|
||||||
|
@ConfigEntry(path = "island.paste-speed")
|
||||||
|
private int pasteSpeed = 1000;
|
||||||
|
|
||||||
// Ranks
|
// Ranks
|
||||||
@ConfigEntry(path = "island.custom-ranks", experimental = true)
|
@ConfigEntry(path = "island.custom-ranks", experimental = true)
|
||||||
private Map<String, Integer> customRanks = new HashMap<>();
|
private Map<String, Integer> customRanks = new HashMap<>();
|
||||||
@ -373,6 +378,20 @@ public class Settings implements DataObject {
|
|||||||
this.nameMaxLength = nameMaxLength;
|
this.nameMaxLength = nameMaxLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param pasteSpeed the pasteSpeed to set
|
||||||
|
*/
|
||||||
|
public void setPasteSpeed(int pasteSpeed) {
|
||||||
|
this.pasteSpeed = pasteSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return paste speed in blocks per tick
|
||||||
|
*/
|
||||||
|
public int getPasteSpeed() {
|
||||||
|
return this.pasteSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
public Map<String, Integer> getCustomRanks() {
|
public Map<String, Integer> getCustomRanks() {
|
||||||
return customRanks;
|
return customRanks;
|
||||||
}
|
}
|
||||||
@ -397,4 +416,6 @@ public class Settings implements DataObject {
|
|||||||
this.uniqueId = uniqueId;
|
this.uniqueId = uniqueId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -90,6 +90,7 @@ public class IslandResetCommand extends ConfirmableCommand {
|
|||||||
// Reset the island
|
// Reset the island
|
||||||
Player player = user.getPlayer();
|
Player player = user.getPlayer();
|
||||||
player.setGameMode(GameMode.SPECTATOR);
|
player.setGameMode(GameMode.SPECTATOR);
|
||||||
|
user.sendMessage("commands.island.create.creating-island");
|
||||||
// Get the player's old island
|
// Get the player's old island
|
||||||
Island oldIsland = getIslands().getIsland(getWorld(), player.getUniqueId());
|
Island oldIsland = getIslands().getIsland(getWorld(), player.getUniqueId());
|
||||||
// Remove them from this island (it still exists and will be deleted later)
|
// Remove them from this island (it still exists and will be deleted later)
|
||||||
|
@ -564,6 +564,7 @@ public class IslandsManager {
|
|||||||
user.sendMessage("commands.island.go.teleported", TextVariables.NUMBER, String.valueOf(number));
|
user.sendMessage("commands.island.go.teleported", TextVariables.NUMBER, String.valueOf(number));
|
||||||
}
|
}
|
||||||
// Exit spectator mode if in it
|
// Exit spectator mode if in it
|
||||||
|
|
||||||
if (player.getGameMode().equals(GameMode.SPECTATOR)) {
|
if (player.getGameMode().equals(GameMode.SPECTATOR)) {
|
||||||
player.setGameMode(plugin.getIWM().getDefaultGameMode(world));
|
player.setGameMode(plugin.getIWM().getDefaultGameMode(world));
|
||||||
}
|
}
|
||||||
@ -679,25 +680,23 @@ public class IslandsManager {
|
|||||||
* @param island to remove players from
|
* @param island to remove players from
|
||||||
*/
|
*/
|
||||||
public void removePlayersFromIsland(Island island) {
|
public void removePlayersFromIsland(Island island) {
|
||||||
// Teleport players away
|
World w = island.getWorld();
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
Bukkit.getOnlinePlayers().stream().filter(p -> island.onIsland(p.getLocation())).forEach(p -> {
|
||||||
if (island.inIslandSpace(player.getLocation().getBlockX(), player.getLocation().getBlockZ())) {
|
// Teleport island players to their island home
|
||||||
// Teleport island players to their island home
|
if (!island.getMemberSet().contains(p.getUniqueId()) && (hasIsland(w, p.getUniqueId()) || inTeam(w, p.getUniqueId()))) {
|
||||||
if (hasIsland(island.getWorld(), player.getUniqueId()) || plugin.getIslands().inTeam(island.getWorld(), player.getUniqueId())) {
|
homeTeleport(w, p);
|
||||||
homeTeleport(island.getWorld(), player);
|
} else {
|
||||||
|
// Move player to spawn
|
||||||
|
if (spawn.containsKey(w)) {
|
||||||
|
// go to island spawn
|
||||||
|
p.teleport(spawn.get(w).getSpawnPoint(w.getEnvironment()));
|
||||||
} else {
|
} else {
|
||||||
// Move player to spawn
|
plugin.logWarning("During island deletion player " + p.getName() + " could not be sent home so was placed into spectator mode.");
|
||||||
if (spawn.containsKey(island.getWorld())) {
|
p.setGameMode(GameMode.SPECTATOR);
|
||||||
// go to island spawn
|
p.setFlying(true);
|
||||||
player.teleport(spawn.get(island.getWorld()).getSpawnPoint(island.getWorld().getEnvironment()));
|
|
||||||
} else {
|
|
||||||
plugin.logWarning("During island deletion player " + player.getName() + " could not be sent home so was placed into spectator mode.");
|
|
||||||
player.setGameMode(GameMode.SPECTATOR);
|
|
||||||
player.getPlayer().setFlying(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -797,13 +796,13 @@ public class IslandsManager {
|
|||||||
*/
|
*/
|
||||||
public void setOwner(User user, UUID targetUUID, Island island) {
|
public void setOwner(User user, UUID targetUUID, Island island) {
|
||||||
islandCache.setOwner(island, targetUUID);
|
islandCache.setOwner(island, targetUUID);
|
||||||
user.sendMessage("commands.island.team.setowner.name-is-the-owner", "[name]", plugin.getPlayers().getName(targetUUID));
|
user.sendMessage("commands.island.team.setowner.name-is-the-owner", "[name]", plugin.getPlayers().getName(targetUUID));
|
||||||
plugin.getIWM().getAddon(island.getWorld()).ifPresent(addon -> {
|
plugin.getIWM().getAddon(island.getWorld()).ifPresent(addon -> {
|
||||||
User target = User.getInstance(targetUUID);
|
User target = User.getInstance(targetUUID);
|
||||||
// Tell target. If they are offline, then they may receive a message when they login
|
// Tell target. If they are offline, then they may receive a message when they login
|
||||||
target.sendMessage("commands.island.team.setowner.you-are-the-owner");
|
target.sendMessage("commands.island.team.setowner.you-are-the-owner");
|
||||||
// Permission checks for range changes only work when the target is online
|
// Permission checks for range changes only work when the target is online
|
||||||
if (target.isOnline()) {
|
if (target.isOnline()) {
|
||||||
// Check if new owner has a different range permission than the island size
|
// Check if new owner has a different range permission than the island size
|
||||||
int range = target.getPermissionValue(
|
int range = target.getPermissionValue(
|
||||||
addon.getPermissionPrefix() + "island.range",
|
addon.getPermissionPrefix() + "island.range",
|
||||||
|
@ -46,11 +46,7 @@ public class NewIsland {
|
|||||||
this.reason = reason;
|
this.reason = reason;
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
newIsland();
|
newIsland(oldIsland);
|
||||||
if (oldIsland != null) {
|
|
||||||
// Delete the old island
|
|
||||||
plugin.getIslands().deleteIsland(oldIsland, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -121,8 +117,9 @@ public class NewIsland {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes an island.
|
* Makes an island.
|
||||||
|
* @param oldIsland
|
||||||
*/
|
*/
|
||||||
public void newIsland() {
|
public void newIsland(Island oldIsland) {
|
||||||
Location next = getNextIsland();
|
Location next = getNextIsland();
|
||||||
if (next == null) {
|
if (next == null) {
|
||||||
plugin.logError("Failed to make island - no unoccupied spot found");
|
plugin.logError("Failed to make island - no unoccupied spot found");
|
||||||
@ -165,6 +162,12 @@ public class NewIsland {
|
|||||||
|
|
||||||
// Teleport player after this island is built
|
// Teleport player after this island is built
|
||||||
plugin.getIslands().homeTeleport(world, user.getPlayer(), true);
|
plugin.getIslands().homeTeleport(world, user.getPlayer(), true);
|
||||||
|
|
||||||
|
// Delete old island
|
||||||
|
if (oldIsland != null) {
|
||||||
|
// Delete the old island
|
||||||
|
plugin.getIslands().deleteIsland(oldIsland, true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
// Make nether island
|
// Make nether island
|
||||||
if (plugin.getIWM().isNetherGenerate(world) && plugin.getIWM().isNetherIslands(world) && plugin.getIWM().getNetherWorld(world) != null) {
|
if (plugin.getIWM().isNetherGenerate(world) && plugin.getIWM().isNetherIslands(world) && plugin.getIWM().getNetherWorld(world) != null) {
|
||||||
|
@ -58,7 +58,7 @@ import world.bentobox.bentobox.util.Util;
|
|||||||
public class Clipboard {
|
public class Clipboard {
|
||||||
|
|
||||||
// Speed of pasting
|
// Speed of pasting
|
||||||
private static final int BLOCKS_PER_TICK = Integer.MAX_VALUE;
|
private int pasteSpeed = 200;
|
||||||
|
|
||||||
// Commonly used texts along this class.
|
// Commonly used texts along this class.
|
||||||
private static final String ATTACHED = "attached";
|
private static final String ATTACHED = "attached";
|
||||||
@ -87,6 +87,7 @@ public class Clipboard {
|
|||||||
schemFolder.mkdirs();
|
schemFolder.mkdirs();
|
||||||
}
|
}
|
||||||
this.schemFolder = schemFolder;
|
this.schemFolder = schemFolder;
|
||||||
|
pasteSpeed = plugin.getSettings().getPasteSpeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -198,7 +199,7 @@ public class Clipboard {
|
|||||||
Iterator<String> it = blockConfig.getConfigurationSection(BLOCK).getKeys(false).iterator();
|
Iterator<String> it = blockConfig.getConfigurationSection(BLOCK).getKeys(false).iterator();
|
||||||
pastingTask = Bukkit.getScheduler().runTaskTimer(plugin, () -> {
|
pastingTask = Bukkit.getScheduler().runTaskTimer(plugin, () -> {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
while (count < BLOCKS_PER_TICK && it.hasNext()) {
|
while (count < pasteSpeed && it.hasNext()) {
|
||||||
pasteBlock(world, island, loc, blockConfig.getConfigurationSection(BLOCK + "." + it.next()));
|
pasteBlock(world, island, loc, blockConfig.getConfigurationSection(BLOCK + "." + it.next()));
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
@ -75,6 +75,9 @@ island:
|
|||||||
# These set the minimum and maximum size of a name.
|
# These set the minimum and maximum size of a name.
|
||||||
min-length: 4
|
min-length: 4
|
||||||
max-length: 20
|
max-length: 20
|
||||||
|
# Number of blocks to paste per tick when pasting a schem
|
||||||
|
# Smaller values will help reduce noticeable lag but will make pasting take longer
|
||||||
|
paste-speed: 1000
|
||||||
# /!\ This feature is experimental and might not work as expected or might not work at all.
|
# /!\ This feature is experimental and might not work as expected or might not work at all.
|
||||||
custom-ranks: {}
|
custom-ranks: {}
|
||||||
# These settings should not be edited
|
# These settings should not be edited
|
||||||
|
@ -246,7 +246,7 @@ commands:
|
|||||||
parameters: "<schem>"
|
parameters: "<schem>"
|
||||||
too-many-islands: "&cThere are too many islands in this world: there isn't enough room for yours to be created."
|
too-many-islands: "&cThere are too many islands in this world: there isn't enough room for yours to be created."
|
||||||
unable-create-island: "&cYour island could not be generated, please contact an administrator."
|
unable-create-island: "&cYour island could not be generated, please contact an administrator."
|
||||||
creating-island: "&aCreating your island..."
|
creating-island: "&aCreating your island, please wait a moment..."
|
||||||
pick-world: "&cPick a world from [worlds]."
|
pick-world: "&cPick a world from [worlds]."
|
||||||
unknown-schem: "&cThat schem has not been loaded yet."
|
unknown-schem: "&cThat schem has not been loaded yet."
|
||||||
info:
|
info:
|
||||||
|
@ -108,6 +108,7 @@ public class AdminClearresetsallCommandTest {
|
|||||||
/**
|
/**
|
||||||
* Test method for .
|
* Test method for .
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteCheckConfirm() {
|
public void testExecuteCheckConfirm() {
|
||||||
AdminClearresetsallCommand itl = new AdminClearresetsallCommand(ac);
|
AdminClearresetsallCommand itl = new AdminClearresetsallCommand(ac);
|
||||||
|
@ -47,6 +47,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
|
|||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
|
import world.bentobox.bentobox.Settings;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
@ -76,7 +77,7 @@ public class ClipboardTest {
|
|||||||
block = mock(Block.class);
|
block = mock(Block.class);
|
||||||
when(block.getType()).thenReturn(Material.GRASS);
|
when(block.getType()).thenReturn(Material.GRASS);
|
||||||
when(block.getLocation()).thenReturn(loc);
|
when(block.getLocation()).thenReturn(loc);
|
||||||
|
|
||||||
BlockData bd = mock(BlockData.class);
|
BlockData bd = mock(BlockData.class);
|
||||||
when(bd.getAsString()).thenReturn("Block_data");
|
when(bd.getAsString()).thenReturn("Block_data");
|
||||||
when(block.getBlockData()).thenReturn(bd);
|
when(block.getBlockData()).thenReturn(bd);
|
||||||
@ -87,7 +88,7 @@ public class ClipboardTest {
|
|||||||
when(loc.getBlockZ()).thenReturn(3);
|
when(loc.getBlockZ()).thenReturn(3);
|
||||||
when(loc.getBlock()).thenReturn(block);
|
when(loc.getBlock()).thenReturn(block);
|
||||||
when(loc.toVector()).thenReturn(new Vector(1,2,3));
|
when(loc.toVector()).thenReturn(new Vector(1,2,3));
|
||||||
|
|
||||||
loc2 = mock(Location.class);
|
loc2 = mock(Location.class);
|
||||||
when(loc2.getWorld()).thenReturn(world);
|
when(loc2.getWorld()).thenReturn(world);
|
||||||
when(loc2.getBlockX()).thenReturn(2);
|
when(loc2.getBlockX()).thenReturn(2);
|
||||||
@ -95,7 +96,7 @@ public class ClipboardTest {
|
|||||||
when(loc2.getBlockZ()).thenReturn(4);
|
when(loc2.getBlockZ()).thenReturn(4);
|
||||||
when(loc2.getBlock()).thenReturn(block);
|
when(loc2.getBlock()).thenReturn(block);
|
||||||
// Living entities
|
// Living entities
|
||||||
|
|
||||||
List<LivingEntity> ents = new ArrayList<>();
|
List<LivingEntity> ents = new ArrayList<>();
|
||||||
Pig pig = mock(Pig.class);
|
Pig pig = mock(Pig.class);
|
||||||
Player player = mock(Player.class);
|
Player player = mock(Player.class);
|
||||||
@ -109,7 +110,7 @@ public class ClipboardTest {
|
|||||||
when(player.getLocation()).thenReturn(loc);
|
when(player.getLocation()).thenReturn(loc);
|
||||||
when(sheep.getLocation()).thenReturn(loc);
|
when(sheep.getLocation()).thenReturn(loc);
|
||||||
when(horse.getLocation()).thenReturn(loc);
|
when(horse.getLocation()).thenReturn(loc);
|
||||||
|
|
||||||
when(pig.getType()).thenReturn(EntityType.PIG);
|
when(pig.getType()).thenReturn(EntityType.PIG);
|
||||||
when(player.getType()).thenReturn(EntityType.PLAYER);
|
when(player.getType()).thenReturn(EntityType.PLAYER);
|
||||||
when(cow.getType()).thenReturn(EntityType.COW);
|
when(cow.getType()).thenReturn(EntityType.COW);
|
||||||
@ -122,7 +123,7 @@ public class ClipboardTest {
|
|||||||
|
|
||||||
HorseInventory inv = mock(HorseInventory.class);
|
HorseInventory inv = mock(HorseInventory.class);
|
||||||
when(horse.getInventory()).thenReturn(inv);
|
when(horse.getInventory()).thenReturn(inv);
|
||||||
|
|
||||||
// UUIDs (I'm going to assume these will all be unique (prays to god of randomness)
|
// UUIDs (I'm going to assume these will all be unique (prays to god of randomness)
|
||||||
when(creeper.getUniqueId()).thenReturn(UUID.randomUUID());
|
when(creeper.getUniqueId()).thenReturn(UUID.randomUUID());
|
||||||
when(player.getUniqueId()).thenReturn(UUID.randomUUID());
|
when(player.getUniqueId()).thenReturn(UUID.randomUUID());
|
||||||
@ -138,29 +139,34 @@ public class ClipboardTest {
|
|||||||
ents.add(sheep);
|
ents.add(sheep);
|
||||||
ents.add(horse);
|
ents.add(horse);
|
||||||
when(world.getLivingEntities()).thenReturn(ents);
|
when(world.getLivingEntities()).thenReturn(ents);
|
||||||
|
|
||||||
user = mock(User.class);
|
user = mock(User.class);
|
||||||
User.setPlugin(plugin);
|
User.setPlugin(plugin);
|
||||||
when(user.getLocation()).thenReturn(loc);
|
when(user.getLocation()).thenReturn(loc);
|
||||||
|
|
||||||
// Scheduler
|
// Scheduler
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
sched = mock(BukkitScheduler.class);
|
sched = mock(BukkitScheduler.class);
|
||||||
when(Bukkit.getScheduler()).thenReturn(sched);
|
when(Bukkit.getScheduler()).thenReturn(sched);
|
||||||
|
|
||||||
|
// Settings
|
||||||
|
Settings settings = mock(Settings.class);
|
||||||
|
when(settings.getPasteSpeed()).thenReturn(200);
|
||||||
|
when(plugin.getSettings()).thenReturn(settings);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClipboard() {
|
public void testClipboard() {
|
||||||
when(schemFolder.exists()).thenReturn(false);
|
when(schemFolder.exists()).thenReturn(false);
|
||||||
new Clipboard(plugin, schemFolder);
|
new Clipboard(plugin, schemFolder);
|
||||||
Mockito.verify(schemFolder).mkdirs();
|
Mockito.verify(schemFolder).mkdirs();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetGetPos1() {
|
public void testSetGetPos1() {
|
||||||
Clipboard cb = new Clipboard(plugin, schemFolder);
|
Clipboard cb = new Clipboard(plugin, schemFolder);
|
||||||
assertNull(cb.getPos1());
|
assertNull(cb.getPos1());
|
||||||
cb.setPos1(loc);
|
cb.setPos1(loc);
|
||||||
assertEquals(loc, cb.getPos1());
|
assertEquals(loc, cb.getPos1());
|
||||||
@ -169,7 +175,7 @@ public class ClipboardTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetGetPos2() {
|
public void testSetGetPos2() {
|
||||||
Clipboard cb = new Clipboard(plugin, schemFolder);
|
Clipboard cb = new Clipboard(plugin, schemFolder);
|
||||||
assertNull(cb.getPos2());
|
assertNull(cb.getPos2());
|
||||||
cb.setPos2(loc);
|
cb.setPos2(loc);
|
||||||
assertEquals(loc, cb.getPos2());
|
assertEquals(loc, cb.getPos2());
|
||||||
@ -177,7 +183,7 @@ public class ClipboardTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetGetOrigin() {
|
public void testSetGetOrigin() {
|
||||||
Clipboard cb = new Clipboard(plugin, schemFolder);
|
Clipboard cb = new Clipboard(plugin, schemFolder);
|
||||||
assertNull(cb.getOrigin());
|
assertNull(cb.getOrigin());
|
||||||
cb.setOrigin(loc);
|
cb.setOrigin(loc);
|
||||||
assertEquals(loc, cb.getOrigin());
|
assertEquals(loc, cb.getOrigin());
|
||||||
@ -185,28 +191,28 @@ public class ClipboardTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCopyNoPos1Pos2() {
|
public void testCopyNoPos1Pos2() {
|
||||||
Clipboard cb = new Clipboard(plugin, schemFolder);
|
Clipboard cb = new Clipboard(plugin, schemFolder);
|
||||||
cb.copy(user, false);
|
cb.copy(user, false);
|
||||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.admin.schem.need-pos1-pos2"));
|
Mockito.verify(user).sendMessage(Mockito.eq("commands.admin.schem.need-pos1-pos2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCopyNoPos2() {
|
public void testCopyNoPos2() {
|
||||||
Clipboard cb = new Clipboard(plugin, schemFolder);
|
Clipboard cb = new Clipboard(plugin, schemFolder);
|
||||||
cb.setPos1(loc);
|
cb.setPos1(loc);
|
||||||
cb.copy(user, false);
|
cb.copy(user, false);
|
||||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.admin.schem.need-pos1-pos2"));
|
Mockito.verify(user).sendMessage(Mockito.eq("commands.admin.schem.need-pos1-pos2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCopy() {
|
public void testCopy() {
|
||||||
Clipboard cb = new Clipboard(plugin, schemFolder);
|
Clipboard cb = new Clipboard(plugin, schemFolder);
|
||||||
cb.setPos1(loc);
|
cb.setPos1(loc);
|
||||||
cb.setPos2(loc2);
|
cb.setPos2(loc2);
|
||||||
cb.copy(user, false);
|
cb.copy(user, false);
|
||||||
Mockito.verify(user).sendMessage("commands.admin.schem.copied-blocks", TextVariables.NUMBER, "8");
|
Mockito.verify(user).sendMessage("commands.admin.schem.copied-blocks", TextVariables.NUMBER, "8");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCopySigns() {
|
public void testCopySigns() {
|
||||||
when(block.getType()).thenReturn(Material.SIGN);
|
when(block.getType()).thenReturn(Material.SIGN);
|
||||||
@ -214,7 +220,7 @@ public class ClipboardTest {
|
|||||||
String[] lines = {"line1", "line2", "line3", "line4"};
|
String[] lines = {"line1", "line2", "line3", "line4"};
|
||||||
when(bs.getLines()).thenReturn(lines);
|
when(bs.getLines()).thenReturn(lines);
|
||||||
when(block.getState()).thenReturn(bs);
|
when(block.getState()).thenReturn(bs);
|
||||||
Clipboard cb = new Clipboard(plugin, schemFolder);
|
Clipboard cb = new Clipboard(plugin, schemFolder);
|
||||||
cb.setPos1(loc);
|
cb.setPos1(loc);
|
||||||
cb.setPos2(loc2);
|
cb.setPos2(loc2);
|
||||||
cb.copy(user, false);
|
cb.copy(user, false);
|
||||||
@ -232,7 +238,7 @@ public class ClipboardTest {
|
|||||||
when(inv.getContents()).thenReturn(contents);
|
when(inv.getContents()).thenReturn(contents);
|
||||||
when(bs.getInventory()).thenReturn(inv);
|
when(bs.getInventory()).thenReturn(inv);
|
||||||
when(block.getState()).thenReturn(bs);
|
when(block.getState()).thenReturn(bs);
|
||||||
Clipboard cb = new Clipboard(plugin, schemFolder);
|
Clipboard cb = new Clipboard(plugin, schemFolder);
|
||||||
cb.setPos1(loc);
|
cb.setPos1(loc);
|
||||||
cb.setPos2(loc2);
|
cb.setPos2(loc2);
|
||||||
cb.copy(user, false);
|
cb.copy(user, false);
|
||||||
@ -240,14 +246,14 @@ public class ClipboardTest {
|
|||||||
// Every block is a sign, so this should be called 8 times
|
// Every block is a sign, so this should be called 8 times
|
||||||
Mockito.verify(bs, Mockito.times(8)).getInventory();
|
Mockito.verify(bs, Mockito.times(8)).getInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCopyCreatureSpawners() {
|
public void testCopyCreatureSpawners() {
|
||||||
when(block.getType()).thenReturn(Material.SPAWNER);
|
when(block.getType()).thenReturn(Material.SPAWNER);
|
||||||
CreatureSpawner bs = mock(CreatureSpawner.class);
|
CreatureSpawner bs = mock(CreatureSpawner.class);
|
||||||
when(bs.getSpawnedType()).thenReturn(EntityType.CAVE_SPIDER);
|
when(bs.getSpawnedType()).thenReturn(EntityType.CAVE_SPIDER);
|
||||||
when(block.getState()).thenReturn(bs);
|
when(block.getState()).thenReturn(bs);
|
||||||
Clipboard cb = new Clipboard(plugin, schemFolder);
|
Clipboard cb = new Clipboard(plugin, schemFolder);
|
||||||
cb.setPos1(loc);
|
cb.setPos1(loc);
|
||||||
cb.setPos2(loc2);
|
cb.setPos2(loc2);
|
||||||
cb.copy(user, false);
|
cb.copy(user, false);
|
||||||
@ -255,7 +261,7 @@ public class ClipboardTest {
|
|||||||
// Every block is a sign, so this should be called 8 times
|
// Every block is a sign, so this should be called 8 times
|
||||||
Mockito.verify(bs, Mockito.times(8)).getMaxNearbyEntities();
|
Mockito.verify(bs, Mockito.times(8)).getMaxNearbyEntities();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCopyAir() {
|
public void testCopyAir() {
|
||||||
// No entities
|
// No entities
|
||||||
@ -263,7 +269,7 @@ public class ClipboardTest {
|
|||||||
when(block.getType()).thenReturn(Material.AIR);
|
when(block.getType()).thenReturn(Material.AIR);
|
||||||
BlockState bs = mock(BlockState.class);
|
BlockState bs = mock(BlockState.class);
|
||||||
when(block.getState()).thenReturn(bs);
|
when(block.getState()).thenReturn(bs);
|
||||||
Clipboard cb = new Clipboard(plugin, schemFolder);
|
Clipboard cb = new Clipboard(plugin, schemFolder);
|
||||||
cb.setPos1(loc);
|
cb.setPos1(loc);
|
||||||
cb.setPos2(loc2);
|
cb.setPos2(loc2);
|
||||||
// Do not copy air
|
// Do not copy air
|
||||||
@ -273,7 +279,7 @@ public class ClipboardTest {
|
|||||||
Mockito.verify(user).sendMessage("commands.admin.schem.copied-blocks", TextVariables.NUMBER, "8");
|
Mockito.verify(user).sendMessage("commands.admin.schem.copied-blocks", TextVariables.NUMBER, "8");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPasteIslandNoData() {
|
public void testPasteIslandNoData() {
|
||||||
Clipboard cb = new Clipboard(plugin, schemFolder);
|
Clipboard cb = new Clipboard(plugin, schemFolder);
|
||||||
@ -281,10 +287,10 @@ public class ClipboardTest {
|
|||||||
when(island.getCenter()).thenReturn(loc);
|
when(island.getCenter()).thenReturn(loc);
|
||||||
cb.pasteIsland(world, island, () -> {});
|
cb.pasteIsland(world, island, () -> {});
|
||||||
Mockito.verify(plugin).logError(Mockito.eq("Clipboard has no block data in it to paste!"));
|
Mockito.verify(plugin).logError(Mockito.eq("Clipboard has no block data in it to paste!"));
|
||||||
// Verify the task is run
|
// Verify the task is run
|
||||||
Mockito.verify(sched).runTaskLater(Mockito.eq(plugin), Mockito.any(Runnable.class), Mockito.eq(2L));
|
Mockito.verify(sched, Mockito.never()).runTaskTimer(Mockito.any(), Mockito.any(Runnable.class), Mockito.eq(0L), Mockito.eq(1L));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPasteIslandWithData() {
|
public void testPasteIslandWithData() {
|
||||||
Clipboard cb = new Clipboard(plugin, schemFolder);
|
Clipboard cb = new Clipboard(plugin, schemFolder);
|
||||||
@ -294,19 +300,8 @@ public class ClipboardTest {
|
|||||||
cb.setPos2(loc2);
|
cb.setPos2(loc2);
|
||||||
cb.copy(user, false);
|
cb.copy(user, false);
|
||||||
cb.pasteIsland(world, island, () -> {});
|
cb.pasteIsland(world, island, () -> {});
|
||||||
// This is set just once because the coords of the block are always the same
|
|
||||||
Mockito.verify(block).setBlockData(Mockito.any());
|
|
||||||
// Verify the entities are spawned
|
|
||||||
Mockito.verify(world).spawnEntity(Mockito.eq(null), Mockito.eq(EntityType.PIG));
|
|
||||||
Mockito.verify(world).spawnEntity(Mockito.eq(null), Mockito.eq(EntityType.CREEPER));
|
|
||||||
Mockito.verify(world).spawnEntity(Mockito.eq(null), Mockito.eq(EntityType.HORSE));
|
|
||||||
Mockito.verify(world).spawnEntity(Mockito.eq(null), Mockito.eq(EntityType.SHEEP));
|
|
||||||
Mockito.verify(world).spawnEntity(Mockito.eq(null), Mockito.eq(EntityType.COW));
|
|
||||||
// Player should NOT spawn!!
|
|
||||||
Mockito.verify(world, Mockito.never()).spawnEntity(Mockito.eq(null), Mockito.eq(EntityType.PLAYER));
|
|
||||||
|
|
||||||
// Verify the task is run
|
// Verify the task is run
|
||||||
Mockito.verify(sched).runTaskLater(Mockito.eq(plugin), Mockito.any(Runnable.class), Mockito.eq(2L));
|
Mockito.verify(sched).runTaskTimer(Mockito.any(), Mockito.any(Runnable.class), Mockito.eq(0L), Mockito.eq(1L));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -315,7 +310,7 @@ public class ClipboardTest {
|
|||||||
cb.pasteClipboard(loc);
|
cb.pasteClipboard(loc);
|
||||||
Mockito.verify(plugin).logError(Mockito.eq("Clipboard has no block data in it to paste!"));
|
Mockito.verify(plugin).logError(Mockito.eq("Clipboard has no block data in it to paste!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPasteClipboard() {
|
public void testPasteClipboard() {
|
||||||
Clipboard cb = new Clipboard(plugin, schemFolder);
|
Clipboard cb = new Clipboard(plugin, schemFolder);
|
||||||
|
Loading…
Reference in New Issue
Block a user