mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-12 13:54:22 +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")
|
||||
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
|
||||
@ConfigEntry(path = "island.custom-ranks", experimental = true)
|
||||
private Map<String, Integer> customRanks = new HashMap<>();
|
||||
@ -373,6 +378,20 @@ public class Settings implements DataObject {
|
||||
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() {
|
||||
return customRanks;
|
||||
}
|
||||
@ -397,4 +416,6 @@ public class Settings implements DataObject {
|
||||
this.uniqueId = uniqueId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -90,6 +90,7 @@ public class IslandResetCommand extends ConfirmableCommand {
|
||||
// Reset the island
|
||||
Player player = user.getPlayer();
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
user.sendMessage("commands.island.create.creating-island");
|
||||
// Get the player's old island
|
||||
Island oldIsland = getIslands().getIsland(getWorld(), player.getUniqueId());
|
||||
// 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));
|
||||
}
|
||||
// Exit spectator mode if in it
|
||||
|
||||
if (player.getGameMode().equals(GameMode.SPECTATOR)) {
|
||||
player.setGameMode(plugin.getIWM().getDefaultGameMode(world));
|
||||
}
|
||||
@ -679,25 +680,23 @@ public class IslandsManager {
|
||||
* @param island to remove players from
|
||||
*/
|
||||
public void removePlayersFromIsland(Island island) {
|
||||
// Teleport players away
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (island.inIslandSpace(player.getLocation().getBlockX(), player.getLocation().getBlockZ())) {
|
||||
World w = island.getWorld();
|
||||
Bukkit.getOnlinePlayers().stream().filter(p -> island.onIsland(p.getLocation())).forEach(p -> {
|
||||
// Teleport island players to their island home
|
||||
if (hasIsland(island.getWorld(), player.getUniqueId()) || plugin.getIslands().inTeam(island.getWorld(), player.getUniqueId())) {
|
||||
homeTeleport(island.getWorld(), player);
|
||||
if (!island.getMemberSet().contains(p.getUniqueId()) && (hasIsland(w, p.getUniqueId()) || inTeam(w, p.getUniqueId()))) {
|
||||
homeTeleport(w, p);
|
||||
} else {
|
||||
// Move player to spawn
|
||||
if (spawn.containsKey(island.getWorld())) {
|
||||
if (spawn.containsKey(w)) {
|
||||
// go to island spawn
|
||||
player.teleport(spawn.get(island.getWorld()).getSpawnPoint(island.getWorld().getEnvironment()));
|
||||
p.teleport(spawn.get(w).getSpawnPoint(w.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);
|
||||
}
|
||||
}
|
||||
plugin.logWarning("During island deletion player " + p.getName() + " could not be sent home so was placed into spectator mode.");
|
||||
p.setGameMode(GameMode.SPECTATOR);
|
||||
p.setFlying(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,11 +46,7 @@ public class NewIsland {
|
||||
this.reason = reason;
|
||||
this.world = world;
|
||||
this.name = name;
|
||||
newIsland();
|
||||
if (oldIsland != null) {
|
||||
// Delete the old island
|
||||
plugin.getIslands().deleteIsland(oldIsland, true);
|
||||
}
|
||||
newIsland(oldIsland);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -121,8 +117,9 @@ public class NewIsland {
|
||||
|
||||
/**
|
||||
* Makes an island.
|
||||
* @param oldIsland
|
||||
*/
|
||||
public void newIsland() {
|
||||
public void newIsland(Island oldIsland) {
|
||||
Location next = getNextIsland();
|
||||
if (next == null) {
|
||||
plugin.logError("Failed to make island - no unoccupied spot found");
|
||||
@ -165,6 +162,12 @@ public class NewIsland {
|
||||
|
||||
// Teleport player after this island is built
|
||||
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
|
||||
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 {
|
||||
|
||||
// Speed of pasting
|
||||
private static final int BLOCKS_PER_TICK = Integer.MAX_VALUE;
|
||||
private int pasteSpeed = 200;
|
||||
|
||||
// Commonly used texts along this class.
|
||||
private static final String ATTACHED = "attached";
|
||||
@ -87,6 +87,7 @@ public class Clipboard {
|
||||
schemFolder.mkdirs();
|
||||
}
|
||||
this.schemFolder = schemFolder;
|
||||
pasteSpeed = plugin.getSettings().getPasteSpeed();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -198,7 +199,7 @@ public class Clipboard {
|
||||
Iterator<String> it = blockConfig.getConfigurationSection(BLOCK).getKeys(false).iterator();
|
||||
pastingTask = Bukkit.getScheduler().runTaskTimer(plugin, () -> {
|
||||
int count = 0;
|
||||
while (count < BLOCKS_PER_TICK && it.hasNext()) {
|
||||
while (count < pasteSpeed && it.hasNext()) {
|
||||
pasteBlock(world, island, loc, blockConfig.getConfigurationSection(BLOCK + "." + it.next()));
|
||||
count++;
|
||||
}
|
||||
|
@ -75,6 +75,9 @@ island:
|
||||
# These set the minimum and maximum size of a name.
|
||||
min-length: 4
|
||||
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.
|
||||
custom-ranks: {}
|
||||
# These settings should not be edited
|
||||
|
@ -246,7 +246,7 @@ commands:
|
||||
parameters: "<schem>"
|
||||
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."
|
||||
creating-island: "&aCreating your island..."
|
||||
creating-island: "&aCreating your island, please wait a moment..."
|
||||
pick-world: "&cPick a world from [worlds]."
|
||||
unknown-schem: "&cThat schem has not been loaded yet."
|
||||
info:
|
||||
|
@ -108,6 +108,7 @@ public class AdminClearresetsallCommandTest {
|
||||
/**
|
||||
* Test method for .
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testExecuteCheckConfirm() {
|
||||
AdminClearresetsallCommand itl = new AdminClearresetsallCommand(ac);
|
||||
|
@ -47,6 +47,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
@ -148,6 +149,11 @@ public class ClipboardTest {
|
||||
sched = mock(BukkitScheduler.class);
|
||||
when(Bukkit.getScheduler()).thenReturn(sched);
|
||||
|
||||
// Settings
|
||||
Settings settings = mock(Settings.class);
|
||||
when(settings.getPasteSpeed()).thenReturn(200);
|
||||
when(plugin.getSettings()).thenReturn(settings);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -282,7 +288,7 @@ public class ClipboardTest {
|
||||
cb.pasteIsland(world, island, () -> {});
|
||||
Mockito.verify(plugin).logError(Mockito.eq("Clipboard has no block data in it to paste!"));
|
||||
// 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
|
||||
@ -294,19 +300,8 @@ public class ClipboardTest {
|
||||
cb.setPos2(loc2);
|
||||
cb.copy(user, false);
|
||||
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
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user