Skip to content

Commit 0ee2ac3

Browse files
committed
Defensive code to prevent nether border if it doesn't need one.
1 parent 5f46951 commit 0ee2ac3

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/main/java/world/bentobox/border/listeners/ShowVirtualWorldBorder.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ public void showBorder(Player player, Island island) {
3535
|| !Objects.requireNonNull(User.getInstance(player)).getMetaData(BORDER_STATE_META_DATA).map(MetaDataValue::asBoolean).orElse(addon.getSettings().isShowByDefault())) {
3636
return;
3737
}
38-
Location l = island.getProtectionCenter();
38+
39+
if (player.getWorld().getEnvironment() == Environment.NETHER && !addon.getPlugin().getIWM().isIslandNether(player.getWorld())) {
40+
return;
41+
}
42+
Location l = island.getProtectionCenter().toVector().toLocation(player.getWorld());
3943
if (player.getWorld().getEnvironment() == Environment.NETHER) {
4044
l.multiply(8);
4145
}

src/test/java/world/bentobox/border/listeners/ShowVirtualWorldBorderTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.bukkit.Bukkit;
99
import org.bukkit.WorldBorder;
1010
import org.bukkit.entity.Player;
11+
import org.bukkit.util.Vector;
1112
import org.eclipse.jdt.annotation.NonNull;
1213
import org.junit.jupiter.api.AfterEach;
1314
import org.junit.jupiter.api.BeforeEach;
@@ -50,11 +51,13 @@ public void setUp() throws Exception {
5051
// Island
5152
when(island.getRange()).thenReturn(400);
5253
when(island.getProtectionRange()).thenReturn(100);
54+
when(island.getProtectionCenter()).thenReturn(location);
5355

5456
// User
5557
MockedStatic<User> mockedUser = Mockito.mockStatic(User.class, Mockito.RETURNS_MOCKS);
5658
mockedUser.when(() -> User.getInstance(any(Player.class))).thenReturn(user);
5759
when(user.getPlayer()).thenReturn(mockPlayer);
60+
when(location.toVector()).thenReturn(new Vector(0,0,0));
5861
when(mockPlayer.getLocation()).thenReturn(location);
5962
when(mockPlayer.getWorld()).thenReturn(world);
6063

0 commit comments

Comments
 (0)