Skip to content

Commit

Permalink
Fix entity location when going through end portal
Browse files Browse the repository at this point in the history
  • Loading branch information
benwoo1110 committed Aug 31, 2024
1 parent b539342 commit caab066
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,10 @@ public void onEntityPortal(EntityPortalEvent event) {
return;
}

// Some shortcuts for later
Entity entity = event.getEntity();

Location fromLocation = this.locationManipulation.getBlockLocation(event.getFrom());
Location originalToLocation = this.locationManipulation.getBlockLocation(event.getTo());
Location fromLocation = event.getFrom();
Location originalToLocation = event.getTo();

World fromWorld = fromLocation.getWorld();
World originalToWorld = originalToLocation.getWorld();
Expand Down Expand Up @@ -388,7 +387,7 @@ else if (fromWorld.getEnvironment() == World.Environment.NETHER && type == Porta
}
// If we are going to the end from anywhere
else if (newToWorld.getEnvironment() == World.Environment.THE_END && type == PortalType.ENDER) {
Location spawnLocation = EndPlatformCreator.getVanillaLocation(newToWorld);
Location spawnLocation = EndPlatformCreator.getVanillaLocation(entity, newToWorld);
event.setTo(spawnLocation);
EndPlatformCreator.createEndPlatform(spawnLocation, plugin.isEndPlatformDropBlocks());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ public void onPlayerPortal(PlayerPortalEvent event) {
return;
}

Player player = event.getPlayer();

if (type == PortalType.NETHER) {
try {
Class.forName("org.bukkit.TravelAgent");
event.useTravelAgent(true);
} catch (ClassNotFoundException ignore) {
Logging.fine("TravelAgent not available for PlayerPortalEvent for " + event.getPlayer().getName());
Logging.fine("TravelAgent not available for PlayerPortalEvent for " + player.getName());
}
}

Expand All @@ -79,24 +81,24 @@ public void onPlayerPortal(PlayerPortalEvent event) {
if (currentWorld.equalsIgnoreCase(linkedWorld)) {
newTo = null;
} else if (linkedWorld != null) {
newTo = this.linkChecker.findNewTeleportLocation(currentLocation, linkedWorld, event.getPlayer());
newTo = this.linkChecker.findNewTeleportLocation(currentLocation, linkedWorld, player);
} else if (this.nameChecker.isValidNetherName(currentWorld)) {
if (type == PortalType.NETHER) {
newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getNormalName(currentWorld, PortalType.NETHER), event.getPlayer());
newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getNormalName(currentWorld, PortalType.NETHER), player);
} else {
newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getEndName(this.nameChecker.getNormalName(currentWorld, PortalType.NETHER)), event.getPlayer());
newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getEndName(this.nameChecker.getNormalName(currentWorld, PortalType.NETHER)), player);
}
} else if (this.nameChecker.isValidEndName(currentWorld)) {
if (type == PortalType.NETHER) {
newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getNetherName(this.nameChecker.getNormalName(currentWorld, PortalType.ENDER)), event.getPlayer());
newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getNetherName(this.nameChecker.getNormalName(currentWorld, PortalType.ENDER)), player);
} else {
newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getNormalName(currentWorld, PortalType.ENDER), event.getPlayer());
newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getNormalName(currentWorld, PortalType.ENDER), player);
}
} else {
if (type == PortalType.ENDER) {
newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getEndName(currentWorld), event.getPlayer());
newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getEndName(currentWorld), player);
} else {
newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getNetherName(currentWorld), event.getPlayer());
newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getNetherName(currentWorld), player);
}
}

Expand All @@ -112,17 +114,17 @@ public void onPlayerPortal(PlayerPortalEvent event) {

if (!event.isCancelled()) {
if (fromWorld.getEnvironment() == World.Environment.THE_END && type == PortalType.ENDER) {
Logging.fine("Player '" + event.getPlayer().getName() + "' will be teleported to the spawn of '" + toWorld.getName() + "' since they used an end exit portal.");
Logging.fine("Player '" + player.getName() + "' will be teleported to the spawn of '" + toWorld.getName() + "' since they used an end exit portal.");
try {
Class.forName("org.bukkit.TravelAgent");
event.getPortalTravelAgent().setCanCreatePortal(false);
} catch (ClassNotFoundException ignore) {
Logging.fine("TravelAgent not available for PlayerPortalEvent for " + event.getPlayer().getName() + ". There may be a portal created at spawn.");
Logging.fine("TravelAgent not available for PlayerPortalEvent for " + player.getName() + ". There may be a portal created at spawn.");
}
if (toWorld.getBedRespawn()
&& event.getPlayer().getBedSpawnLocation() != null
&& event.getPlayer().getBedSpawnLocation().getWorld().getUID() == toWorld.getCBWorld().getUID()) {
event.setTo(event.getPlayer().getBedSpawnLocation());
&& player.getBedSpawnLocation() != null
&& player.getBedSpawnLocation().getWorld().getUID() == toWorld.getCBWorld().getUID()) {
event.setTo(player.getBedSpawnLocation());
} else {
event.setTo(toWorld.getSpawnLocation());
}
Expand All @@ -132,20 +134,20 @@ public void onPlayerPortal(PlayerPortalEvent event) {
event.getPortalTravelAgent().setCanCreatePortal(true);
event.setTo(event.getPortalTravelAgent().findOrCreate(event.getTo()));
} catch (ClassNotFoundException ignore) {
Logging.fine("TravelAgent not available for PlayerPortalEvent for " + event.getPlayer().getName() + ". Their destination may not be correct.");
Logging.fine("TravelAgent not available for PlayerPortalEvent for " + player.getName() + ". Their destination may not be correct.");
event.setTo(event.getTo());
}
} else if (toWorld.getEnvironment() == World.Environment.THE_END && type == PortalType.ENDER) {
Location spawnLocation = EndPlatformCreator.getVanillaLocation(event.getTo().getWorld());
Location spawnLocation = EndPlatformCreator.getVanillaLocation(player, event.getTo().getWorld());
event.setTo(spawnLocation);
EndPlatformCreator.createEndPlatform(spawnLocation, plugin.isEndPlatformDropBlocks());
}

// Advancements need to be triggered manually
if (type == PortalType.NETHER && event.getTo().getWorld().getEnvironment() == World.Environment.NETHER) {
awardAdvancement(event.getPlayer(), enterNetherAdvancement, ENTER_NETHER_CRITERIA);
awardAdvancement(player, enterNetherAdvancement, ENTER_NETHER_CRITERIA);
} else if (type == PortalType.ENDER && event.getTo().getWorld().getEnvironment() == World.Environment.THE_END) {
awardAdvancement(event.getPlayer(), enterEndAdvancement, ENTER_END_CRITERIA);
awardAdvancement(player, enterEndAdvancement, ENTER_END_CRITERIA);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseNetherPortals.MultiverseNetherPortals;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;

public class EndPlatformCreator {

Expand Down Expand Up @@ -60,14 +61,16 @@ public static void createEndPlatform(Location spawnLocation, boolean dropEndBloc
/**
* The default vanilla location for the end platform
*/
public static Location getVanillaLocation(World world) {
return new Location(world, 100, 49, 0, 90, 0);
public static Location getVanillaLocation(Entity entity, World world) {
return entity instanceof Player
? new Location(world, 100, 49, 0, 90, 0)
: new Location(world, 100.5, 50, 0.5, 90, 0);
}

/**
* The default vanilla location for the end platform
*/
public static Location getVanillaLocation(MultiverseWorld world) {
return getVanillaLocation(world.getCBWorld());
public static Location getVanillaLocation(Entity entity, MultiverseWorld world) {
return getVanillaLocation(entity, world.getCBWorld());
}
}

0 comments on commit caab066

Please sign in to comment.