mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-19 05:41:22 +01:00
Use Bukkit pasting if user is too close to new island.
This prevents players experiencing invisible blocks at the expense of lag.
This commit is contained in:
parent
070c1102db
commit
78f84de3cb
@ -445,7 +445,7 @@ public class BlueprintsManager {
|
|||||||
* @param name - bundle name
|
* @param name - bundle name
|
||||||
*/
|
*/
|
||||||
public void paste(GameModeAddon addon, Island island, String name) {
|
public void paste(GameModeAddon addon, Island island, String name) {
|
||||||
paste(addon, island, name, null);
|
paste(addon, island, name, null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -455,9 +455,10 @@ public class BlueprintsManager {
|
|||||||
* @param island - the island
|
* @param island - the island
|
||||||
* @param name - name of bundle to paste
|
* @param name - name of bundle to paste
|
||||||
* @param task - task to run after pasting is completed
|
* @param task - task to run after pasting is completed
|
||||||
|
* @param useNMS - true to use NMS pasting
|
||||||
* @return true if okay, false is there is a problem
|
* @return true if okay, false is there is a problem
|
||||||
*/
|
*/
|
||||||
public boolean paste(GameModeAddon addon, Island island, String name, Runnable task) {
|
public boolean paste(GameModeAddon addon, Island island, String name, Runnable task, boolean useNMS) {
|
||||||
if (validate(addon, name) == null) {
|
if (validate(addon, name) == null) {
|
||||||
plugin.logError("Tried to paste '" + name + "' but the bundle is not loaded!");
|
plugin.logError("Tried to paste '" + name + "' but the bundle is not loaded!");
|
||||||
return false;
|
return false;
|
||||||
@ -478,7 +479,9 @@ public class BlueprintsManager {
|
|||||||
}
|
}
|
||||||
// Paste
|
// Paste
|
||||||
if (bp != null) {
|
if (bp != null) {
|
||||||
new BlueprintPaster(plugin, bp, addon.getOverWorld(), island).paste().thenAccept(b -> pasteNether(addon, bb, island).thenAccept(b2 ->
|
new BlueprintPaster(plugin, bp, addon.getOverWorld(), island).paste(useNMS)
|
||||||
|
.thenAccept(b -> pasteNether(addon, bb, island).thenAccept(
|
||||||
|
b2 ->
|
||||||
pasteEnd(addon, bb, island).thenAccept(message -> sendMessage(island)).thenAccept(b3 -> Bukkit.getScheduler().runTask(plugin, task))));
|
pasteEnd(addon, bb, island).thenAccept(message -> sendMessage(island)).thenAccept(b3 -> Bukkit.getScheduler().runTask(plugin, task))));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -206,8 +206,11 @@ public class NewIsland {
|
|||||||
if (noPaste) {
|
if (noPaste) {
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> postCreationTask(oldIsland));
|
Bukkit.getScheduler().runTask(plugin, () -> postCreationTask(oldIsland));
|
||||||
} else {
|
} else {
|
||||||
|
// Find out how far away the player is from the new island
|
||||||
|
boolean useNMS = !user.getWorld().equals(island.getWorld())
|
||||||
|
|| (user.getLocation().distance(island.getCenter()) >= Bukkit.getViewDistance() * 16D);
|
||||||
// Create islands, then run task
|
// Create islands, then run task
|
||||||
plugin.getBlueprintsManager().paste(addon, island, name, () -> postCreationTask(oldIsland));
|
plugin.getBlueprintsManager().paste(addon, island, name, () -> postCreationTask(oldIsland), useNMS);
|
||||||
}
|
}
|
||||||
// Set default settings
|
// Set default settings
|
||||||
island.setFlagsDefaults();
|
island.setFlagsDefaults();
|
||||||
|
@ -20,6 +20,7 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
@ -97,6 +98,8 @@ public class NewIslandTest {
|
|||||||
private final UUID uuid = UUID.randomUUID();
|
private final UUID uuid = UUID.randomUUID();
|
||||||
@Mock
|
@Mock
|
||||||
private BlueprintsManager bpm;
|
private BlueprintsManager bpm;
|
||||||
|
@Mock
|
||||||
|
private @NonNull Location location2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
@ -129,6 +132,8 @@ public class NewIslandTest {
|
|||||||
when(user.getPermissionValue(Mockito.anyString(), Mockito.anyInt())).thenReturn(20);
|
when(user.getPermissionValue(Mockito.anyString(), Mockito.anyInt())).thenReturn(20);
|
||||||
when(user.getUniqueId()).thenReturn(uuid);
|
when(user.getUniqueId()).thenReturn(uuid);
|
||||||
when(user.getName()).thenReturn("tastybento");
|
when(user.getName()).thenReturn("tastybento");
|
||||||
|
when(user.getWorld()).thenReturn(world);
|
||||||
|
when(user.getLocation()).thenReturn(location);
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
PowerMockito.mockStatic(IslandEvent.class);
|
PowerMockito.mockStatic(IslandEvent.class);
|
||||||
@ -147,9 +152,11 @@ public class NewIslandTest {
|
|||||||
|
|
||||||
// Location and blocks
|
// Location and blocks
|
||||||
when(island.getWorld()).thenReturn(world);
|
when(island.getWorld()).thenReturn(world);
|
||||||
|
when(island.getCenter()).thenReturn(location2);
|
||||||
when(location.getWorld()).thenReturn(world);
|
when(location.getWorld()).thenReturn(world);
|
||||||
when(world.getMaxHeight()).thenReturn(5);
|
when(world.getMaxHeight()).thenReturn(5);
|
||||||
when(location.getBlock()).thenReturn(block);
|
when(location.getBlock()).thenReturn(block);
|
||||||
|
when(location.distance(any())).thenReturn(320D);
|
||||||
when(block.getType()).thenReturn(Material.AIR);
|
when(block.getType()).thenReturn(Material.AIR);
|
||||||
when(block.isEmpty()).thenReturn(true);
|
when(block.isEmpty()).thenReturn(true);
|
||||||
when(world.getBlockAt(anyInt(), anyInt(), anyInt())).thenReturn(block);
|
when(world.getBlockAt(anyInt(), anyInt(), anyInt())).thenReturn(block);
|
||||||
@ -163,6 +170,7 @@ public class NewIslandTest {
|
|||||||
// Bukkit Scheduler
|
// Bukkit Scheduler
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(Bukkit.getScheduler()).thenReturn(scheduler);
|
when(Bukkit.getScheduler()).thenReturn(scheduler);
|
||||||
|
when(Bukkit.getViewDistance()).thenReturn(10);
|
||||||
|
|
||||||
// Addon
|
// Addon
|
||||||
when(addon.getOverWorld()).thenReturn(world);
|
when(addon.getOverWorld()).thenReturn(world);
|
||||||
@ -250,12 +258,32 @@ public class NewIslandTest {
|
|||||||
* {@link world.bentobox.bentobox.managers.island.NewIsland#builder()}.
|
* {@link world.bentobox.bentobox.managers.island.NewIsland#builder()}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testBuilderNoOldIslandPaste() throws Exception {
|
public void testBuilderNoOldIslandPasteNoNMS() throws Exception {
|
||||||
|
when(location.distance(any())).thenReturn(30D);
|
||||||
NewIsland.builder().addon(addon).name(NAME).player(user).reason(Reason.CREATE).build();
|
NewIsland.builder().addon(addon).name(NAME).player(user).reason(Reason.CREATE).build();
|
||||||
// Verifications
|
// Verifications
|
||||||
verify(im).save(eq(island));
|
verify(im).save(eq(island));
|
||||||
verify(island).setFlagsDefaults();
|
verify(island).setFlagsDefaults();
|
||||||
verify(bpm).paste(eq(addon), eq(island), eq(NAME), any(Runnable.class));
|
verify(bpm).paste(eq(addon), eq(island), eq(NAME), any(Runnable.class), eq(false));
|
||||||
|
verify(builder, times(2)).build();
|
||||||
|
verify(bpb).getUniqueId();
|
||||||
|
verify(ice).getBlueprintBundle();
|
||||||
|
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
||||||
|
verify(im, never()).setHomeLocation(eq(user), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for
|
||||||
|
* {@link world.bentobox.bentobox.managers.island.NewIsland#builder()}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testBuilderNoOldIslandPasteWithNMS() throws Exception {
|
||||||
|
NewIsland.builder().addon(addon).name(NAME).player(user).reason(Reason.CREATE).build();
|
||||||
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
|
// Verifications
|
||||||
|
verify(im).save(eq(island));
|
||||||
|
verify(island).setFlagsDefaults();
|
||||||
|
verify(bpm).paste(eq(addon), eq(island), eq(NAME), any(Runnable.class), eq(true));
|
||||||
verify(builder, times(2)).build();
|
verify(builder, times(2)).build();
|
||||||
verify(bpb).getUniqueId();
|
verify(bpb).getUniqueId();
|
||||||
verify(ice).getBlueprintBundle();
|
verify(ice).getBlueprintBundle();
|
||||||
|
Loading…
Reference in New Issue
Block a user