Fixes issue with teleporting from standard nether or end

https://github.com/BentoBoxWorld/BentoBox/issues/634
This commit is contained in:
tastybento 2019-04-17 09:35:55 -07:00
parent 6bf66ec98c
commit 197d51add0
3 changed files with 47 additions and 32 deletions

View File

@ -10,6 +10,7 @@ import org.bukkit.event.entity.EntityPortalEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.util.Util;
import world.bentobox.bentobox.util.teleport.SafeSpotTeleport;
@ -51,30 +52,30 @@ public class PortalTeleportationListener implements Listener {
return false;
}
World fromWorld = e.getFrom().getWorld();
if (fromWorld == null || !plugin.getIWM().inWorld(fromWorld) || !plugin.getIWM().isEndGenerate(fromWorld)) {
World overWorld = Util.getWorld(fromWorld);
if (fromWorld == null || !plugin.getIWM().inWorld(overWorld) || !plugin.getIWM().isEndGenerate(overWorld)) {
// Do nothing special
return false;
}
// STANDARD END
if (!plugin.getIWM().isEndIslands(fromWorld)) {
if (!plugin.getIWM().isEndIslands(overWorld)) {
if (fromWorld.getEnvironment() != Environment.THE_END) {
// To Standard end
e.setTo(plugin.getIWM().getEndWorld(fromWorld).getSpawnLocation());
e.setTo(plugin.getIWM().getEndWorld(overWorld).getSpawnLocation());
}
// From standard end - check if player has an island to go to
else if (plugin.getIslands().hasIsland(Util.getWorld(fromWorld), e.getPlayer().getUniqueId())
|| plugin.getIslands().inTeam(Util.getWorld(fromWorld), e.getPlayer().getUniqueId())) {
else if (plugin.getIslands().hasIsland(overWorld, e.getPlayer().getUniqueId())
|| plugin.getIslands().inTeam(overWorld, e.getPlayer().getUniqueId())) {
e.setCancelled(true);
plugin.getIslands().homeTeleport(Util.getWorld(fromWorld), e.getPlayer());
plugin.getIslands().homeTeleport(overWorld, e.getPlayer());
}
// No island, so just do nothing
return false;
}
// FROM END
World overWorld = Util.getWorld(fromWorld);
// If entering an ender portal in the End.
if (fromWorld.getEnvironment() == Environment.THE_END) {
// If this is from the island nether, then go to the same vector, otherwise try island home location
@ -112,28 +113,28 @@ public class PortalTeleportationListener implements Listener {
return false;
}
World fromWorld = e.getFrom().getWorld();
if (fromWorld == null || !plugin.getIWM().inWorld(fromWorld) || !plugin.getIWM().isNetherGenerate(fromWorld)) {
World overWorld = Util.getWorld(fromWorld);
if (fromWorld == null || !plugin.getIWM().inWorld(overWorld) || !plugin.getIWM().isNetherGenerate(overWorld)) {
// Do nothing special
return false;
}
// STANDARD NETHER
if (!plugin.getIWM().isNetherIslands(fromWorld)) {
if (!plugin.getIWM().isNetherIslands(overWorld)) {
if (fromWorld.getEnvironment() != Environment.NETHER) {
// To Standard Nether
e.setTo(plugin.getIWM().getNetherWorld(fromWorld).getSpawnLocation());
e.setTo(plugin.getIWM().getNetherWorld(overWorld).getSpawnLocation());
e.useTravelAgent(true);
}
// From standard nether
else {
e.setCancelled(true);
plugin.getIslands().homeTeleport(Util.getWorld(fromWorld), e.getPlayer());
plugin.getIslands().homeTeleport(overWorld, e.getPlayer());
}
return false;
}
// FROM NETHER
World overWorld = Util.getWorld(fromWorld);
// If entering a nether portal in the nether, teleport to portal in overworld if there is one
if (fromWorld.getEnvironment() == Environment.NETHER) {
// If this is from the island nether, then go to the same vector, otherwise try island home location

View File

@ -1,6 +1,16 @@
package world.bentobox.bentobox.managers;
import com.google.common.collect.ImmutableMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
@ -19,6 +29,9 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import com.google.common.collect.ImmutableMap;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.api.events.island.IslandEvent;
@ -35,17 +48,6 @@ import world.bentobox.bentobox.util.DeleteIslandChunks;
import world.bentobox.bentobox.util.Util;
import world.bentobox.bentobox.util.teleport.SafeSpotTeleport;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
/**
* The job of this class is manage all island related data.
* It also handles island ownership, including team, trustees, coops, etc.
@ -404,7 +406,7 @@ public class IslandsManager {
public Set<UUID> getMembers(World world, UUID playerUUID, int minimumRank) {
return islandCache.getMembers(world, playerUUID, minimumRank);
}
/**
* Returns a set of island member UUID's for the island of playerUUID.
* Only includes players of rank {@link RanksManager#MEMBER_RANK} and above.

View File

@ -15,7 +15,19 @@ import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.*;
import org.bukkit.entity.Animals;
import org.bukkit.entity.Bat;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Flying;
import org.bukkit.entity.IronGolem;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.entity.PufferFish;
import org.bukkit.entity.Shulker;
import org.bukkit.entity.Slime;
import org.bukkit.entity.Snowman;
import org.bukkit.entity.WaterMob;
import org.bukkit.util.Vector;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
@ -199,8 +211,8 @@ public class Util {
* @param world - world
* @return over world
*/
public static World getWorld(World world) {
return world.getEnvironment().equals(Environment.NORMAL) ? world : Bukkit.getWorld(world.getName().replaceAll(NETHER, "").replaceAll(THE_END, ""));
public static World getWorld(@Nullable World world) {
return world == null ? null : world.getEnvironment().equals(Environment.NORMAL) ? world : Bukkit.getWorld(world.getName().replaceAll(NETHER, "").replaceAll(THE_END, ""));
}
/**
@ -310,7 +322,7 @@ public class Util {
// PufferFish is a unique fix.
return entity instanceof Monster || entity instanceof Flying || entity instanceof Slime ||
entity instanceof Shulker || entity instanceof EnderDragon || entity instanceof PufferFish;
entity instanceof Shulker || entity instanceof EnderDragon || entity instanceof PufferFish;
}
@ -328,6 +340,6 @@ public class Util {
// Most of passive mobs extends Animals
return entity instanceof Animals || entity instanceof IronGolem || entity instanceof Snowman ||
entity instanceof WaterMob && !(entity instanceof PufferFish) || entity instanceof Bat;
entity instanceof WaterMob && !(entity instanceof PufferFish) || entity instanceof Bat;
}
}