-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3142 from Multiverse/ben/mv5/teleport-intercept
Properly implement teleport intercept config option
- Loading branch information
Showing
5 changed files
with
93 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/test/java/org/mvplugins/multiverse/core/config/ConfigTeleportInterceptTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.mvplugins.multiverse.core.config | ||
|
||
import org.bukkit.Location | ||
import org.mockbukkit.mockbukkit.entity.PlayerMock | ||
import org.mvplugins.multiverse.core.TestWithMockBukkit | ||
import org.mvplugins.multiverse.core.teleportation.AsyncSafetyTeleporter | ||
import org.mvplugins.multiverse.core.world.WorldManager | ||
import org.mvplugins.multiverse.core.world.options.CreateWorldOptions | ||
import java.lang.AssertionError | ||
import kotlin.test.* | ||
|
||
class ConfigTeleportInterceptTest : TestWithMockBukkit() { | ||
|
||
private lateinit var config: MVCoreConfig | ||
private lateinit var safetyTeleporter: AsyncSafetyTeleporter | ||
private lateinit var player: PlayerMock | ||
private lateinit var location: Location | ||
|
||
@BeforeTest | ||
fun setUp() { | ||
config = serviceLocator.getActiveService(MVCoreConfig::class.java).takeIf { it != null } ?: run { | ||
throw IllegalStateException("MVCoreConfig is not available as a service") } | ||
|
||
safetyTeleporter = serviceLocator.getActiveService(AsyncSafetyTeleporter::class.java).takeIf { it != null } ?: run { | ||
throw IllegalStateException("AsyncSafetyTeleporter is not available as a service") } | ||
|
||
val worldManager = serviceLocator.getActiveService(WorldManager::class.java).takeIf { it != null } ?: run { | ||
throw IllegalStateException("WorldManager is not available as a service") } | ||
|
||
player = server.addPlayer() | ||
worldManager.createWorld(CreateWorldOptions.worldName("world2")).get() | ||
location = Location(server.getWorld("world2"), 0.0, 0.0, 0.0) | ||
config.enforceAccess = true | ||
} | ||
|
||
@Test | ||
fun `Generic teleport with teleport intercept enabled`() { | ||
config.teleportIntercept = true | ||
assertFalse(player.teleport(location)) | ||
assertEquals("world", player.world.name) | ||
} | ||
|
||
@Test | ||
fun `Generic teleport with teleport intercept disabled - no access checking`() { | ||
config.teleportIntercept = false | ||
assertTrue(player.teleport(location)) | ||
assertEquals("world2", player.world.name) | ||
} | ||
|
||
@Test | ||
fun `Multiverse API teleport with teleport intercept disabled`() { | ||
config.teleportIntercept = false | ||
safetyTeleporter.teleport(player, location).toAttempt() | ||
.onSuccess (Runnable { throw AssertionError("Teleport should have failed") }) | ||
.onFailure(Runnable { assertEquals("world", player.world.name) }) | ||
} | ||
} |