mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-26 12:46:01 +01:00
Fixes #2219. Island homes were set incorrectly with a new island.
This commit is contained in:
parent
4200fe4abb
commit
6d09a5a359
@ -17,6 +17,8 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.eclipse.jdt.annotation.NonNull;
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
|
import world.bentobox.bentobox.api.panels.reader.ItemTemplateRecord.ActionRecords;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This Record contains all necessary information about Item Template that can be used to craft panel item.
|
* This Record contains all necessary information about Item Template that can be used to craft panel item.
|
||||||
*
|
*
|
||||||
|
@ -15,6 +15,7 @@ import org.eclipse.jdt.annotation.NonNull;
|
|||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.panels.Panel;
|
import world.bentobox.bentobox.api.panels.Panel;
|
||||||
|
import world.bentobox.bentobox.api.panels.reader.PanelTemplateRecord.TemplateItem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is template object for the panel reader. It contains data that can exist in the panel.
|
* This is template object for the panel reader. It contains data that can exist in the panel.
|
||||||
|
@ -22,6 +22,7 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.World.Environment;
|
import org.bukkit.World.Environment;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.BoundingBox;
|
import org.bukkit.util.BoundingBox;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
import org.eclipse.jdt.annotation.NonNull;
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
@ -1676,6 +1677,14 @@ public class Island implements DataObject, MetaDataAble {
|
|||||||
* @since 1.16.0
|
* @since 1.16.0
|
||||||
*/
|
*/
|
||||||
public void addHome(String name, Location location) {
|
public void addHome(String name, Location location) {
|
||||||
|
if (location != null) {
|
||||||
|
Vector v = location.toVector();
|
||||||
|
if (!this.getBoundingBox().contains(v)) {
|
||||||
|
BentoBox.getInstance().logWarning("Tried to set a home location " + location + " outside of the island. This generally should not happen.");
|
||||||
|
BentoBox.getInstance().logWarning("Island is at " + this.getCenter() + ". The island file may need editing to remove this home.");
|
||||||
|
BentoBox.getInstance().logWarning("Please report this issue and logs around this item to BentoBox");
|
||||||
|
}
|
||||||
|
}
|
||||||
getHomes().put(name.toLowerCase(), location);
|
getHomes().put(name.toLowerCase(), location);
|
||||||
setChanged();
|
setChanged();
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ public class PrimaryIslandListener implements Listener {
|
|||||||
|
|
||||||
private void setIsland(Player player, Location location) {
|
private void setIsland(Player player, Location location) {
|
||||||
im.getIslandAt(location)
|
im.getIslandAt(location)
|
||||||
.filter(i -> i.getOwner() != null && i.getOwner().equals(player.getUniqueId()))
|
.filter(i -> player.getUniqueId().equals(i.getOwner()))
|
||||||
.ifPresent(i -> im.setPrimaryIsland(player.getUniqueId(), i));
|
.ifPresent(i -> im.setPrimaryIsland(player.getUniqueId(), i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,7 +198,8 @@ public class NewIsland {
|
|||||||
// Do nothing of other cases
|
// Do nothing of other cases
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Set the player's primary island
|
||||||
|
plugin.getIslands().setPrimaryIsland(user.getUniqueId(), island);
|
||||||
// Run task to run after creating the island in one tick if island is not being pasted
|
// Run task to run after creating the island in one tick if island is not being pasted
|
||||||
if (noPaste) {
|
if (noPaste) {
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> postCreationTask(oldIsland));
|
Bukkit.getScheduler().runTask(plugin, () -> postCreationTask(oldIsland));
|
||||||
@ -244,13 +245,11 @@ public class NewIsland {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Cleans up a user before moving them to a new island.
|
* Cleans up a user before moving them to a new island.
|
||||||
* Removes any old home locations. Sets the next home location. Resets deaths.
|
* Resets deaths.
|
||||||
* Checks range permissions and saves the player to the database.
|
* Checks range permissions and saves the player to the database.
|
||||||
* @param loc - the new island location
|
* @param loc - the new island location
|
||||||
*/
|
*/
|
||||||
private void cleanUpUser(Location loc) {
|
private void cleanUpUser(Location loc) {
|
||||||
// Set home location
|
|
||||||
plugin.getIslands().setHomeLocation(user, new Location(loc.getWorld(), loc.getX() + 0.5D, loc.getY(), loc.getZ() + 0.5D));
|
|
||||||
// Reset deaths
|
// Reset deaths
|
||||||
if (plugin.getIWM().isDeathsResetOnNewIsland(world)) {
|
if (plugin.getIWM().isDeathsResetOnNewIsland(world)) {
|
||||||
plugin.getPlayers().setDeaths(world, user.getUniqueId(), 0);
|
plugin.getPlayers().setDeaths(world, user.getUniqueId(), 0);
|
||||||
|
@ -6,6 +6,9 @@ import static org.junit.Assert.assertNotNull;
|
|||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -21,6 +24,7 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.World.Environment;
|
import org.bukkit.World.Environment;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
import org.eclipse.jdt.annotation.NonNull;
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@ -85,6 +89,7 @@ public class IslandTest {
|
|||||||
|
|
||||||
// Location
|
// Location
|
||||||
when(location.clone()).thenReturn(location);
|
when(location.clone()).thenReturn(location);
|
||||||
|
when(location.toVector()).thenReturn(new Vector(0,0,0));
|
||||||
when(world.getName()).thenReturn("bskyblock_world");
|
when(world.getName()).thenReturn("bskyblock_world");
|
||||||
when(location.getWorld()).thenReturn(world);
|
when(location.getWorld()).thenReturn(world);
|
||||||
when(world.getEnvironment()).thenReturn(Environment.NORMAL);
|
when(world.getEnvironment()).thenReturn(Environment.NORMAL);
|
||||||
@ -1174,6 +1179,18 @@ public class IslandTest {
|
|||||||
assertEquals(location, i.getHome("backyard"));
|
assertEquals(location, i.getHome("backyard"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link world.bentobox.bentobox.database.objects.Island#addHome(java.lang.String, org.bukkit.Location)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testAddHomeOutsideIsland() {
|
||||||
|
when(location.toVector()).thenReturn(new Vector(1000000, 0, 10000000));
|
||||||
|
i.addHome("backyard", location);
|
||||||
|
// Check there is a warning about this home being outside of the island
|
||||||
|
verify(plugin, times(3)).logWarning(anyString());
|
||||||
|
assertEquals(location, i.getHome("backyard"));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.database.objects.Island#removeHome(java.lang.String)}.
|
* Test method for {@link world.bentobox.bentobox.database.objects.Island#removeHome(java.lang.String)}.
|
||||||
*/
|
*/
|
||||||
|
@ -198,7 +198,7 @@ public class NewIslandTest {
|
|||||||
verify(bpb).getUniqueId();
|
verify(bpb).getUniqueId();
|
||||||
verify(ice).getBlueprintBundle();
|
verify(ice).getBlueprintBundle();
|
||||||
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
||||||
verify(im).setHomeLocation(eq(user), any());
|
verify(im, never()).setHomeLocation(eq(user), any());
|
||||||
verify(island).setProtectionRange(eq(20));
|
verify(island).setProtectionRange(eq(20));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ public class NewIslandTest {
|
|||||||
verify(ice, never()).getBlueprintBundle();
|
verify(ice, never()).getBlueprintBundle();
|
||||||
verify(ire).getBlueprintBundle();
|
verify(ire).getBlueprintBundle();
|
||||||
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
||||||
verify(im).setHomeLocation(eq(user), any());
|
verify(im, never()).setHomeLocation(eq(user), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -235,7 +235,7 @@ public class NewIslandTest {
|
|||||||
verify(bpb).getUniqueId();
|
verify(bpb).getUniqueId();
|
||||||
verify(ice).getBlueprintBundle();
|
verify(ice).getBlueprintBundle();
|
||||||
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
||||||
verify(im).setHomeLocation(eq(user), any());
|
verify(im, never()).setHomeLocation(eq(user), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -252,7 +252,7 @@ public class NewIslandTest {
|
|||||||
verify(bpb).getUniqueId();
|
verify(bpb).getUniqueId();
|
||||||
verify(ice).getBlueprintBundle();
|
verify(ice).getBlueprintBundle();
|
||||||
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
||||||
verify(im).setHomeLocation(eq(user), any());
|
verify(im, never()).setHomeLocation(eq(user), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -270,7 +270,7 @@ public class NewIslandTest {
|
|||||||
verify(bpb).getUniqueId();
|
verify(bpb).getUniqueId();
|
||||||
verify(ice).getBlueprintBundle();
|
verify(ice).getBlueprintBundle();
|
||||||
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
||||||
verify(im).setHomeLocation(eq(user), any());
|
verify(im, never()).setHomeLocation(eq(user), any());
|
||||||
verify(island).setProtectionRange(eq(20));
|
verify(island).setProtectionRange(eq(20));
|
||||||
verify(island).setReserved(eq(false));
|
verify(island).setReserved(eq(false));
|
||||||
}
|
}
|
||||||
@ -291,7 +291,7 @@ public class NewIslandTest {
|
|||||||
verify(bpb).getUniqueId();
|
verify(bpb).getUniqueId();
|
||||||
verify(ice).getBlueprintBundle();
|
verify(ice).getBlueprintBundle();
|
||||||
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
||||||
verify(im).setHomeLocation(eq(user), any());
|
verify(im, never()).setHomeLocation(eq(user), any());
|
||||||
verify(island).setProtectionRange(eq(20));
|
verify(island).setProtectionRange(eq(20));
|
||||||
verify(plugin).logError("New island for user tastybento was not reserved!");
|
verify(plugin).logError("New island for user tastybento was not reserved!");
|
||||||
}
|
}
|
||||||
@ -312,7 +312,7 @@ public class NewIslandTest {
|
|||||||
verify(bpb).getUniqueId();
|
verify(bpb).getUniqueId();
|
||||||
verify(ice).getBlueprintBundle();
|
verify(ice).getBlueprintBundle();
|
||||||
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
verify(pm).setDeaths(eq(world), eq(uuid), eq(0));
|
||||||
verify(im).setHomeLocation(eq(user), any());
|
verify(im, never()).setHomeLocation(eq(user), any());
|
||||||
verify(island).setProtectionRange(eq(20));
|
verify(island).setProtectionRange(eq(20));
|
||||||
verify(plugin).logError("New island for user tastybento was not reserved!");
|
verify(plugin).logError("New island for user tastybento was not reserved!");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user