mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-14 04:02:01 +01:00
Merge pull request #272 from BentoBoxWorld/0.10.0-SNAPSHOT
Switching to 0.10.0-SNAPSHOT (Major changes to SafeSpotTeleport)
This commit is contained in:
commit
0372d71413
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>world.bentobox</groupId>
|
<groupId>world.bentobox</groupId>
|
||||||
<artifactId>bentobox</artifactId>
|
<artifactId>bentobox</artifactId>
|
||||||
<version>0.9.0-SNAPSHOT</version>
|
<version>0.10.0-SNAPSHOT</version>
|
||||||
|
|
||||||
<name>BentoBox</name>
|
<name>BentoBox</name>
|
||||||
<description>BentoBox is an expandable Minecraft Spigot plugin for island-type games like ASkyBlock or AcidIsland.</description>
|
<description>BentoBox is an expandable Minecraft Spigot plugin for island-type games like ASkyBlock or AcidIsland.</description>
|
||||||
|
@ -26,7 +26,7 @@ import world.bentobox.bentobox.managers.LocalesManager;
|
|||||||
import world.bentobox.bentobox.managers.PlayersManager;
|
import world.bentobox.bentobox.managers.PlayersManager;
|
||||||
import world.bentobox.bentobox.managers.RanksManager;
|
import world.bentobox.bentobox.managers.RanksManager;
|
||||||
import world.bentobox.bentobox.managers.SchemsManager;
|
import world.bentobox.bentobox.managers.SchemsManager;
|
||||||
import world.bentobox.bentobox.util.HeadGetter;
|
import world.bentobox.bentobox.util.heads.HeadGetter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main BentoBox class
|
* Main BentoBox class
|
||||||
|
@ -41,6 +41,38 @@ public abstract class Addon implements AddonInterface {
|
|||||||
return BentoBox.getInstance();
|
return BentoBox.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the current run-time state of a {@link Addon}.
|
||||||
|
*
|
||||||
|
* @author Poslovitch
|
||||||
|
*/
|
||||||
|
enum State {
|
||||||
|
/**
|
||||||
|
* The addon has been correctly enabled and is now fully working.
|
||||||
|
*/
|
||||||
|
ENABLED,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The addon is fully disabled.
|
||||||
|
*/
|
||||||
|
DISABLED,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The addon has not been loaded because it requires a different version of BentoBox or of the server software.
|
||||||
|
*/
|
||||||
|
INCOMPATIBLE,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The addon has not been enabled because a dependency is missing.
|
||||||
|
*/
|
||||||
|
MISSING_DEPENDENCY,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The addon loading or enabling process has been interrupted by an unhandled error.
|
||||||
|
*/
|
||||||
|
ERROR
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the addon's default config file
|
* @return the addon's default config file
|
||||||
*/
|
*/
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
package world.bentobox.bentobox.api.addons;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents the current run-time state of a {@link Addon}.
|
|
||||||
*
|
|
||||||
* @author Poslovitch
|
|
||||||
* @since 1.0
|
|
||||||
*/
|
|
||||||
public enum AddonState {
|
|
||||||
/**
|
|
||||||
* The addon has been correctly enabled and is now fully working.
|
|
||||||
*/
|
|
||||||
ENABLED,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The addon is fully disabled.
|
|
||||||
*/
|
|
||||||
DISABLED,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The addon has not been loaded because it requires a different version of BentoBox or of the server software.
|
|
||||||
*/
|
|
||||||
INCOMPATIBLE,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The addon has not been enabled because a dependency is missing.
|
|
||||||
*/
|
|
||||||
MISSING_DEPENDENCY,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The addon loading or enabling process has been interrupted by an unhandled error.
|
|
||||||
*/
|
|
||||||
ERROR
|
|
||||||
}
|
|
@ -11,7 +11,7 @@ import world.bentobox.bentobox.api.commands.CompositeCommand;
|
|||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
import world.bentobox.bentobox.util.teleport.SafeTeleportBuilder;
|
import world.bentobox.bentobox.util.teleport.SafeSpotTeleport;
|
||||||
|
|
||||||
public class AdminTeleportCommand extends CompositeCommand {
|
public class AdminTeleportCommand extends CompositeCommand {
|
||||||
|
|
||||||
@ -51,10 +51,13 @@ public class AdminTeleportCommand extends CompositeCommand {
|
|||||||
// Other wise, go to a safe spot
|
// Other wise, go to a safe spot
|
||||||
String failureMessage = user.getTranslation("commands.admin.tp.manual", "[location]", warpSpot.getBlockX() + " " + warpSpot.getBlockY() + " "
|
String failureMessage = user.getTranslation("commands.admin.tp.manual", "[location]", warpSpot.getBlockX() + " " + warpSpot.getBlockY() + " "
|
||||||
+ warpSpot.getBlockZ());
|
+ warpSpot.getBlockZ());
|
||||||
new SafeTeleportBuilder(getPlugin()).entity(user.getPlayer())
|
|
||||||
.location(warpSpot)
|
new SafeSpotTeleport.Builder(getPlugin())
|
||||||
.failureMessage(failureMessage)
|
.entity(user.getPlayer())
|
||||||
.build();
|
.location(warpSpot)
|
||||||
|
.failureMessage(failureMessage)
|
||||||
|
.overrideGamemode(false)
|
||||||
|
.build();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
user.sendMessage("general.errors.player-has-no-island");
|
user.sendMessage("general.errors.player-has-no-island");
|
||||||
|
@ -12,8 +12,8 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||||||
|
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.listeners.PanelListenerManager;
|
import world.bentobox.bentobox.listeners.PanelListenerManager;
|
||||||
import world.bentobox.bentobox.util.HeadGetter;
|
import world.bentobox.bentobox.util.heads.HeadGetter;
|
||||||
import world.bentobox.bentobox.util.HeadRequester;
|
import world.bentobox.bentobox.util.heads.HeadRequester;
|
||||||
|
|
||||||
public class Panel implements HeadRequester {
|
public class Panel implements HeadRequester {
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ import org.bukkit.util.Vector;
|
|||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
import world.bentobox.bentobox.util.teleport.SafeTeleportBuilder;
|
import world.bentobox.bentobox.util.teleport.SafeSpotTeleport;
|
||||||
|
|
||||||
public class NetherPortals implements Listener {
|
public class NetherPortals implements Listener {
|
||||||
private static final String ERROR_NO_PERMISSION = "general.errors.no-permission";
|
private static final String ERROR_NO_PERMISSION = "general.errors.no-permission";
|
||||||
@ -120,7 +120,7 @@ public class NetherPortals implements Listener {
|
|||||||
// End exists and end islands are being used
|
// End exists and end islands are being used
|
||||||
Location to = plugin.getIslands().getIslandAt(e.getFrom()).map(i -> i.getSpawnPoint(Environment.THE_END)).orElse(e.getFrom().toVector().toLocation(endWorld));
|
Location to = plugin.getIslands().getIslandAt(e.getFrom()).map(i -> i.getSpawnPoint(Environment.THE_END)).orElse(e.getFrom().toVector().toLocation(endWorld));
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
new SafeTeleportBuilder(plugin)
|
new SafeSpotTeleport.Builder(plugin)
|
||||||
.entity(e.getPlayer())
|
.entity(e.getPlayer())
|
||||||
.location(to)
|
.location(to)
|
||||||
.build();
|
.build();
|
||||||
@ -183,7 +183,7 @@ public class NetherPortals implements Listener {
|
|||||||
|
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
// Else other worlds teleport to the nether
|
// Else other worlds teleport to the nether
|
||||||
new SafeTeleportBuilder(plugin)
|
new SafeSpotTeleport.Builder(plugin)
|
||||||
.entity(e.getPlayer())
|
.entity(e.getPlayer())
|
||||||
.location(to)
|
.location(to)
|
||||||
.portal()
|
.portal()
|
||||||
@ -197,7 +197,7 @@ public class NetherPortals implements Listener {
|
|||||||
: nether.getSpawnLocation();
|
: nether.getSpawnLocation();
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
// Else other worlds teleport to the nether
|
// Else other worlds teleport to the nether
|
||||||
new SafeTeleportBuilder(plugin)
|
new SafeSpotTeleport.Builder(plugin)
|
||||||
.entity(e.getPlayer())
|
.entity(e.getPlayer())
|
||||||
.location(to)
|
.location(to)
|
||||||
.portal()
|
.portal()
|
||||||
|
@ -24,7 +24,7 @@ import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
|||||||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
import world.bentobox.bentobox.util.teleport.SafeTeleportBuilder;
|
import world.bentobox.bentobox.util.teleport.SafeSpotTeleport;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listener for invincible visitor settings. Handles click listening and damage events
|
* Listener for invincible visitor settings. Handles click listening and damage events
|
||||||
@ -111,7 +111,7 @@ public class InvincibleVisitorsListener extends AbstractFlagListener implements
|
|||||||
if(e.getCause().equals(DamageCause.VOID)) {
|
if(e.getCause().equals(DamageCause.VOID)) {
|
||||||
// Will be set back after the teleport
|
// Will be set back after the teleport
|
||||||
p.setGameMode(GameMode.SPECTATOR);
|
p.setGameMode(GameMode.SPECTATOR);
|
||||||
getIslands().getIslandAt(p.getLocation()).ifPresent(i -> new SafeTeleportBuilder(getPlugin()).entity(p).island(i).build());
|
getIslands().getIslandAt(p.getLocation()).ifPresent(i -> new SafeSpotTeleport.Builder(getPlugin()).entity(p).island(i).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ import world.bentobox.bentobox.lists.Flags;
|
|||||||
import world.bentobox.bentobox.managers.island.IslandCache;
|
import world.bentobox.bentobox.managers.island.IslandCache;
|
||||||
import world.bentobox.bentobox.util.DeleteIslandChunks;
|
import world.bentobox.bentobox.util.DeleteIslandChunks;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
import world.bentobox.bentobox.util.teleport.SafeTeleportBuilder;
|
import world.bentobox.bentobox.util.teleport.SafeSpotTeleport;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The job of this class is manage all island related data.
|
* The job of this class is manage all island related data.
|
||||||
@ -541,10 +541,11 @@ public class IslandsManager {
|
|||||||
}
|
}
|
||||||
if (home == null) {
|
if (home == null) {
|
||||||
// Try to fix this teleport location and teleport the player if possible
|
// Try to fix this teleport location and teleport the player if possible
|
||||||
new SafeTeleportBuilder(plugin).entity(player)
|
new SafeSpotTeleport.Builder(plugin)
|
||||||
.island(plugin.getIslands().getIsland(world, user))
|
.entity(player)
|
||||||
.homeNumber(number)
|
.island(plugin.getIslands().getIsland(world, user))
|
||||||
.build();
|
.homeNumber(number)
|
||||||
|
.build();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
player.teleport(home);
|
player.teleport(home);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package world.bentobox.bentobox.util;
|
package world.bentobox.bentobox.util.heads;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
@ -1,4 +1,4 @@
|
|||||||
package world.bentobox.bentobox.util;
|
package world.bentobox.bentobox.util.heads;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||||
|
|
@ -39,6 +39,7 @@ public class SafeSpotTeleport {
|
|||||||
private final Location location;
|
private final Location location;
|
||||||
private boolean portal;
|
private boolean portal;
|
||||||
private final int homeNumber;
|
private final int homeNumber;
|
||||||
|
private final boolean overrideGamemode;
|
||||||
|
|
||||||
// Locations
|
// Locations
|
||||||
private Location bestSpot;
|
private Location bestSpot;
|
||||||
@ -55,16 +56,16 @@ public class SafeSpotTeleport {
|
|||||||
* @param portal - true if this is a portal teleport
|
* @param portal - true if this is a portal teleport
|
||||||
* @param homeNumber - home number to go to
|
* @param homeNumber - home number to go to
|
||||||
*/
|
*/
|
||||||
protected SafeSpotTeleport(BentoBox plugin, final Entity entity, final Location location, final String failureMessage, boolean portal,
|
public SafeSpotTeleport(BentoBox plugin, final Entity entity, final Location location, final String failureMessage, boolean portal, int homeNumber, boolean overrideGamemode) {
|
||||||
int homeNumber) {
|
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
this.location = location;
|
this.location = location;
|
||||||
this.portal = portal;
|
this.portal = portal;
|
||||||
this.homeNumber = homeNumber;
|
this.homeNumber = homeNumber;
|
||||||
|
this.overrideGamemode = overrideGamemode;
|
||||||
|
|
||||||
// Put player into spectator mode
|
// Put player into spectator mode
|
||||||
if (entity instanceof Player && ((Player)entity).getGameMode().equals(GameMode.SURVIVAL)) {
|
if (overrideGamemode && entity instanceof Player && ((Player)entity).getGameMode().equals(GameMode.SURVIVAL)) {
|
||||||
((Player)entity).setGameMode(GameMode.SPECTATOR);
|
((Player)entity).setGameMode(GameMode.SPECTATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,13 +117,13 @@ public class SafeSpotTeleport {
|
|||||||
if (portal && bestSpot != null) {
|
if (portal && bestSpot != null) {
|
||||||
// No portals found, teleport to the best spot we found
|
// No portals found, teleport to the best spot we found
|
||||||
teleportEntity(bestSpot);
|
teleportEntity(bestSpot);
|
||||||
if (entity instanceof Player && ((Player)entity).getGameMode().equals(GameMode.SPECTATOR)) {
|
if (overrideGamemode && entity instanceof Player && ((Player)entity).getGameMode().equals(GameMode.SPECTATOR)) {
|
||||||
((Player)entity).setGameMode(plugin.getIWM().getDefaultGameMode(bestSpot.getWorld()));
|
((Player)entity).setGameMode(plugin.getIWM().getDefaultGameMode(bestSpot.getWorld()));
|
||||||
}
|
}
|
||||||
} else if (entity instanceof Player && !failureMessage.isEmpty()) {
|
} else if (entity instanceof Player && !failureMessage.isEmpty()) {
|
||||||
// Failed, no safe spot
|
// Failed, no safe spot
|
||||||
entity.sendMessage(failureMessage);
|
entity.sendMessage(failureMessage);
|
||||||
if (((Player)entity).getGameMode().equals(GameMode.SPECTATOR)) {
|
if (overrideGamemode && ((Player)entity).getGameMode().equals(GameMode.SPECTATOR)) {
|
||||||
if (plugin.getIWM().inWorld(entity.getLocation())) {
|
if (plugin.getIWM().inWorld(entity.getLocation())) {
|
||||||
((Player)entity).setGameMode(plugin.getIWM().getDefaultGameMode(entity.getWorld()));
|
((Player)entity).setGameMode(plugin.getIWM().getDefaultGameMode(entity.getWorld()));
|
||||||
} else {
|
} else {
|
||||||
@ -233,7 +234,7 @@ public class SafeSpotTeleport {
|
|||||||
// Exit spectator mode if in it
|
// Exit spectator mode if in it
|
||||||
if (entity instanceof Player) {
|
if (entity instanceof Player) {
|
||||||
Player player = (Player)entity;
|
Player player = (Player)entity;
|
||||||
if (player.getGameMode().equals(GameMode.SPECTATOR)) {
|
if (overrideGamemode && player.getGameMode().equals(GameMode.SPECTATOR)) {
|
||||||
player.setGameMode(plugin.getIWM().getDefaultGameMode(loc.getWorld()));
|
player.setGameMode(plugin.getIWM().getDefaultGameMode(loc.getWorld()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -309,4 +310,107 @@ public class SafeSpotTeleport {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
private BentoBox plugin;
|
||||||
|
private Entity entity;
|
||||||
|
private int homeNumber = 0;
|
||||||
|
private boolean portal = false;
|
||||||
|
private String failureMessage = "";
|
||||||
|
private Location location;
|
||||||
|
private boolean overrideGamemode = true;
|
||||||
|
|
||||||
|
public Builder(BentoBox plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set who or what is going to teleport
|
||||||
|
* @param entity entity to teleport
|
||||||
|
* @return Builder
|
||||||
|
*/
|
||||||
|
public Builder entity(Entity entity) {
|
||||||
|
this.entity = entity;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the island to teleport to
|
||||||
|
* @param island island destination
|
||||||
|
* @return Builder
|
||||||
|
*/
|
||||||
|
public Builder island(Island island) {
|
||||||
|
this.location = island.getCenter();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the home number to this number
|
||||||
|
* @param homeNumber home number
|
||||||
|
* @return Builder
|
||||||
|
*/
|
||||||
|
public Builder homeNumber(int homeNumber) {
|
||||||
|
this.homeNumber = homeNumber;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a portal teleportation
|
||||||
|
* @return Builder
|
||||||
|
*/
|
||||||
|
public Builder portal() {
|
||||||
|
this.portal = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the failure message if this teleport cannot happen
|
||||||
|
* @param failureMessage failure message to report to user
|
||||||
|
* @return Builder
|
||||||
|
*/
|
||||||
|
public Builder failureMessage(String failureMessage) {
|
||||||
|
this.failureMessage = failureMessage;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the desired location
|
||||||
|
* @param location the location
|
||||||
|
* @return Builder
|
||||||
|
*/
|
||||||
|
public Builder location(Location location) {
|
||||||
|
this.location = location;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether the player's gamemode should be overridden.
|
||||||
|
* @param overrideGamemode whether the player's gamemode should be overridden.
|
||||||
|
* @return Builder
|
||||||
|
*/
|
||||||
|
public Builder overrideGamemode(boolean overrideGamemode) {
|
||||||
|
this.overrideGamemode = overrideGamemode;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try to teleport the player
|
||||||
|
* @return SafeSpotTeleport
|
||||||
|
*/
|
||||||
|
public SafeSpotTeleport build() {
|
||||||
|
// Error checking
|
||||||
|
if (entity == null) {
|
||||||
|
plugin.logError("Attempt to safe teleport a null entity!");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (location == null) {
|
||||||
|
plugin.logError("Attempt to safe teleport to a null location!");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (failureMessage.isEmpty() && entity instanceof Player) {
|
||||||
|
failureMessage = User.getInstance(entity).getTranslation("general.errors.warp-not-safe");
|
||||||
|
}
|
||||||
|
return new SafeSpotTeleport(plugin, entity, location, failureMessage, portal, homeNumber, overrideGamemode);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,104 +0,0 @@
|
|||||||
package world.bentobox.bentobox.util.teleport;
|
|
||||||
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
|
||||||
import world.bentobox.bentobox.api.user.User;
|
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
|
||||||
|
|
||||||
public class SafeTeleportBuilder {
|
|
||||||
|
|
||||||
private BentoBox plugin;
|
|
||||||
private Entity entity;
|
|
||||||
private int homeNumber = 0;
|
|
||||||
private boolean portal = false;
|
|
||||||
private String failureMessage = "";
|
|
||||||
private Location location;
|
|
||||||
|
|
||||||
|
|
||||||
public SafeTeleportBuilder(BentoBox plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set who or what is going to teleport
|
|
||||||
* @param entity - entity to teleport
|
|
||||||
* @return SafeTeleportBuilder
|
|
||||||
*/
|
|
||||||
public SafeTeleportBuilder entity(Entity entity) {
|
|
||||||
this.entity = entity;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the island to teleport to
|
|
||||||
* @param island - island destination
|
|
||||||
* @return SafeTeleportBuilder
|
|
||||||
*/
|
|
||||||
public SafeTeleportBuilder island(Island island) {
|
|
||||||
this.location = island.getCenter();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the home number to this number
|
|
||||||
* @param homeNumber - home number
|
|
||||||
* @return SafeTeleportBuilder
|
|
||||||
*/
|
|
||||||
public SafeTeleportBuilder homeNumber(int homeNumber) {
|
|
||||||
this.homeNumber = homeNumber;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is a portal teleportation
|
|
||||||
* @return SafeTeleportBuilder
|
|
||||||
*/
|
|
||||||
public SafeTeleportBuilder portal() {
|
|
||||||
this.portal = true;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the failure message if this teleport cannot happen
|
|
||||||
* @param failureMessage - failure message to report to user
|
|
||||||
* @return SafeTeleportBuilder
|
|
||||||
*/
|
|
||||||
public SafeTeleportBuilder failureMessage(String failureMessage) {
|
|
||||||
this.failureMessage = failureMessage;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the desired location
|
|
||||||
* @param location - the location
|
|
||||||
* @return SafeTeleportBuilder
|
|
||||||
*/
|
|
||||||
public SafeTeleportBuilder location(Location location) {
|
|
||||||
this.location = location;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Try to teleport the player
|
|
||||||
* @return SafeSpotTeleport
|
|
||||||
*/
|
|
||||||
public SafeSpotTeleport build() {
|
|
||||||
// Error checking
|
|
||||||
if (entity == null) {
|
|
||||||
plugin.logError("Attempt to safe teleport a null entity!");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (location == null) {
|
|
||||||
plugin.logError("Attempt to safe teleport to a null location!");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (failureMessage.isEmpty() && entity instanceof Player) {
|
|
||||||
failureMessage = User.getInstance(entity).getTranslation("general.errors.warp-not-safe");
|
|
||||||
}
|
|
||||||
return new SafeSpotTeleport(plugin, entity, location, failureMessage, portal, homeNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
package world.bentobox.bentobox.util;
|
package world.bentobox.bentobox.util.yaml;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
@ -1,4 +1,4 @@
|
|||||||
package world.bentobox.bentobox.util;
|
package world.bentobox.bentobox.util.yaml;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -1,11 +1,5 @@
|
|||||||
package world.bentobox.bentobox.util.teleport;
|
package world.bentobox.bentobox.util.teleport;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.mockito.Matchers.any;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@ -16,15 +10,20 @@ import org.mockito.Mock;
|
|||||||
import org.powermock.api.mockito.PowerMockito;
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
import world.bentobox.bentobox.managers.LocalesManager;
|
import world.bentobox.bentobox.managers.LocalesManager;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest(SafeTeleportBuilder.class)
|
@PrepareForTest(SafeSpotTeleport.Builder.class)
|
||||||
public class SafeTeleportBuilderTest {
|
public class SafeSpotTeleportBuilderTest {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private SafeSpotTeleport sst;
|
private SafeSpotTeleport sst;
|
||||||
@ -36,14 +35,14 @@ public class SafeTeleportBuilderTest {
|
|||||||
private Location loc;
|
private Location loc;
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private SafeTeleportBuilder stb;
|
private SafeSpotTeleport.Builder sstb;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
PowerMockito.whenNew(SafeSpotTeleport.class).withAnyArguments().thenReturn(sst);
|
PowerMockito.whenNew(SafeSpotTeleport.class).withAnyArguments().thenReturn(sst);
|
||||||
// Users
|
// Users
|
||||||
User.setPlugin(plugin);
|
User.setPlugin(plugin);
|
||||||
// Locales - final
|
// Locales - final
|
||||||
LocalesManager lm = mock(LocalesManager.class);
|
LocalesManager lm = mock(LocalesManager.class);
|
||||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||||
when(lm.get(any(), any())).thenReturn("mock translation");
|
when(lm.get(any(), any())).thenReturn("mock translation");
|
||||||
@ -51,61 +50,61 @@ public class SafeTeleportBuilderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() throws Exception {
|
public void test() throws Exception {
|
||||||
stb = new SafeTeleportBuilder(plugin);
|
sstb = new SafeSpotTeleport.Builder(plugin);
|
||||||
stb.build();
|
sstb.build();
|
||||||
SafeSpotTeleport ttt = new SafeSpotTeleport(plugin, player, loc, null, false, 0);
|
SafeSpotTeleport ttt = new SafeSpotTeleport(plugin, player, loc, null, false, 0, false);
|
||||||
assertEquals(sst, ttt);
|
assertEquals(sst, ttt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSafeTeleportBuilder() {
|
public void testBuilder() {
|
||||||
stb = new SafeTeleportBuilder(plugin);
|
sstb = new SafeSpotTeleport.Builder(plugin);
|
||||||
// Should fail because no data
|
// Should fail because no data
|
||||||
assertNull(stb.build());
|
assertNull(sstb.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEntity() throws Exception {
|
public void testEntity() throws Exception {
|
||||||
// Start builder
|
// Start builder
|
||||||
stb = new SafeTeleportBuilder(plugin);
|
sstb = new SafeSpotTeleport.Builder(plugin);
|
||||||
// Add entity
|
// Add entity
|
||||||
stb.entity(player);
|
sstb.entity(player);
|
||||||
// Test for error
|
// Test for error
|
||||||
assertNull(stb.build());
|
assertNull(sstb.build());
|
||||||
// Add location
|
// Add location
|
||||||
stb.location(loc);
|
sstb.location(loc);
|
||||||
// Build - expect success
|
// Build - expect success
|
||||||
SafeSpotTeleport result = stb.build();
|
SafeSpotTeleport result = sstb.build();
|
||||||
assertEquals(sst, result);
|
assertEquals(sst, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsland() {
|
public void testIsland() {
|
||||||
// Start builder
|
// Start builder
|
||||||
SafeTeleportBuilder stb = new SafeTeleportBuilder(plugin);
|
SafeSpotTeleport.Builder sstb = new SafeSpotTeleport.Builder(plugin);
|
||||||
// Add entity
|
// Add entity
|
||||||
stb.entity(player);
|
sstb.entity(player);
|
||||||
// Add island
|
// Add island
|
||||||
Island island = mock(Island.class);
|
Island island = mock(Island.class);
|
||||||
when(island.getCenter()).thenReturn(loc);
|
when(island.getCenter()).thenReturn(loc);
|
||||||
stb.island(island);
|
sstb.island(island);
|
||||||
// Build - expect success
|
// Build - expect success
|
||||||
SafeSpotTeleport result = stb.build();
|
SafeSpotTeleport result = sstb.build();
|
||||||
assertEquals(sst, result);
|
assertEquals(sst, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHomeNumber() {
|
public void testHomeNumber() {
|
||||||
// Start builder
|
// Start builder
|
||||||
SafeTeleportBuilder stb = new SafeTeleportBuilder(plugin);
|
SafeSpotTeleport.Builder sstb = new SafeSpotTeleport.Builder(plugin);
|
||||||
// Add entity
|
// Add entity
|
||||||
stb.entity(player);
|
sstb.entity(player);
|
||||||
// Add location
|
// Add location
|
||||||
stb.location(loc);
|
sstb.location(loc);
|
||||||
// Add home
|
// Add home
|
||||||
stb.homeNumber(10);
|
sstb.homeNumber(10);
|
||||||
// Build - expect success
|
// Build - expect success
|
||||||
SafeSpotTeleport result = stb.build();
|
SafeSpotTeleport result = sstb.build();
|
||||||
assertEquals(sst, result);
|
assertEquals(sst, result);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -113,31 +112,30 @@ public class SafeTeleportBuilderTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testPortal() {
|
public void testPortal() {
|
||||||
// Start builder
|
// Start builder
|
||||||
SafeTeleportBuilder stb = new SafeTeleportBuilder(plugin);
|
SafeSpotTeleport.Builder sstb = new SafeSpotTeleport.Builder(plugin);
|
||||||
// Add entity
|
// Add entity
|
||||||
stb.entity(player);
|
sstb.entity(player);
|
||||||
// Add location
|
// Add location
|
||||||
stb.location(loc);
|
sstb.location(loc);
|
||||||
// Portal
|
// Portal
|
||||||
stb.portal();
|
sstb.portal();
|
||||||
// Build - expect success
|
// Build - expect success
|
||||||
SafeSpotTeleport result = stb.build();
|
SafeSpotTeleport result = sstb.build();
|
||||||
assertEquals(sst, result);
|
assertEquals(sst, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailureMessage() {
|
public void testFailureMessage() {
|
||||||
// Start builder
|
// Start builder
|
||||||
SafeTeleportBuilder stb = new SafeTeleportBuilder(plugin);
|
SafeSpotTeleport.Builder sstb = new SafeSpotTeleport.Builder(plugin);
|
||||||
// Add entity
|
// Add entity
|
||||||
stb.entity(player);
|
sstb.entity(player);
|
||||||
// Add location
|
// Add location
|
||||||
stb.location(loc);
|
sstb.location(loc);
|
||||||
// Add failure
|
// Add failure
|
||||||
stb.failureMessage("testing 123");
|
sstb.failureMessage("testing 123");
|
||||||
// Build - expect success
|
// Build - expect success
|
||||||
SafeSpotTeleport result = stb.build();
|
SafeSpotTeleport result = sstb.build();
|
||||||
assertEquals(sst, result);
|
assertEquals(sst, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -114,7 +114,8 @@ public class SafeSpotTeleportTest {
|
|||||||
when(loc.getBlock()).thenReturn(block);
|
when(loc.getBlock()).thenReturn(block);
|
||||||
boolean portal = false;
|
boolean portal = false;
|
||||||
int homeNumber = 1;
|
int homeNumber = 1;
|
||||||
new SafeSpotTeleport(plugin, player, loc, "failure message", portal, homeNumber);
|
boolean overrideGamemode = true;
|
||||||
|
new SafeSpotTeleport(plugin, player, loc, "failure message", portal, homeNumber, true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user