Skip to content

Commit 13086f4

Browse files
authored
Merge pull request #270 from Multiverse/ben/entity-end
2 parents b539342 + 386fe87 commit 13086f4

File tree

3 files changed

+38
-45
lines changed

3 files changed

+38
-45
lines changed

src/main/java/com/onarandombox/MultiverseNetherPortals/listeners/MVNPEntityListener.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,10 @@ public void onEntityPortal(EntityPortalEvent event) {
316316
return;
317317
}
318318

319-
// Some shortcuts for later
320319
Entity entity = event.getEntity();
321320

322-
Location fromLocation = this.locationManipulation.getBlockLocation(event.getFrom());
323-
Location originalToLocation = this.locationManipulation.getBlockLocation(event.getTo());
321+
Location fromLocation = event.getFrom();
322+
Location originalToLocation = event.getTo();
324323

325324
World fromWorld = fromLocation.getWorld();
326325
World originalToWorld = originalToLocation.getWorld();
@@ -388,9 +387,9 @@ else if (fromWorld.getEnvironment() == World.Environment.NETHER && type == Porta
388387
}
389388
// If we are going to the end from anywhere
390389
else if (newToWorld.getEnvironment() == World.Environment.THE_END && type == PortalType.ENDER) {
391-
Location spawnLocation = EndPlatformCreator.getVanillaLocation(newToWorld);
390+
Location spawnLocation = EndPlatformCreator.getVanillaLocation(entity, newToWorld);
392391
event.setTo(spawnLocation);
393-
EndPlatformCreator.createEndPlatform(spawnLocation, plugin.isEndPlatformDropBlocks());
392+
EndPlatformCreator.createEndPlatform(spawnLocation.getWorld(), plugin.isEndPlatformDropBlocks());
394393
}
395394
}
396395

src/main/java/com/onarandombox/MultiverseNetherPortals/listeners/MVNPPlayerListener.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,14 @@ public void onPlayerPortal(PlayerPortalEvent event) {
6464
return;
6565
}
6666

67+
Player player = event.getPlayer();
68+
6769
if (type == PortalType.NETHER) {
6870
try {
6971
Class.forName("org.bukkit.TravelAgent");
7072
event.useTravelAgent(true);
7173
} catch (ClassNotFoundException ignore) {
72-
Logging.fine("TravelAgent not available for PlayerPortalEvent for " + event.getPlayer().getName());
74+
Logging.fine("TravelAgent not available for PlayerPortalEvent for " + player.getName());
7375
}
7476
}
7577

@@ -79,24 +81,24 @@ public void onPlayerPortal(PlayerPortalEvent event) {
7981
if (currentWorld.equalsIgnoreCase(linkedWorld)) {
8082
newTo = null;
8183
} else if (linkedWorld != null) {
82-
newTo = this.linkChecker.findNewTeleportLocation(currentLocation, linkedWorld, event.getPlayer());
84+
newTo = this.linkChecker.findNewTeleportLocation(currentLocation, linkedWorld, player);
8385
} else if (this.nameChecker.isValidNetherName(currentWorld)) {
8486
if (type == PortalType.NETHER) {
85-
newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getNormalName(currentWorld, PortalType.NETHER), event.getPlayer());
87+
newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getNormalName(currentWorld, PortalType.NETHER), player);
8688
} else {
87-
newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getEndName(this.nameChecker.getNormalName(currentWorld, PortalType.NETHER)), event.getPlayer());
89+
newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getEndName(this.nameChecker.getNormalName(currentWorld, PortalType.NETHER)), player);
8890
}
8991
} else if (this.nameChecker.isValidEndName(currentWorld)) {
9092
if (type == PortalType.NETHER) {
91-
newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getNetherName(this.nameChecker.getNormalName(currentWorld, PortalType.ENDER)), event.getPlayer());
93+
newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getNetherName(this.nameChecker.getNormalName(currentWorld, PortalType.ENDER)), player);
9294
} else {
93-
newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getNormalName(currentWorld, PortalType.ENDER), event.getPlayer());
95+
newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getNormalName(currentWorld, PortalType.ENDER), player);
9496
}
9597
} else {
9698
if (type == PortalType.ENDER) {
97-
newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getEndName(currentWorld), event.getPlayer());
99+
newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getEndName(currentWorld), player);
98100
} else {
99-
newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getNetherName(currentWorld), event.getPlayer());
101+
newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getNetherName(currentWorld), player);
100102
}
101103
}
102104

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

113115
if (!event.isCancelled()) {
114116
if (fromWorld.getEnvironment() == World.Environment.THE_END && type == PortalType.ENDER) {
115-
Logging.fine("Player '" + event.getPlayer().getName() + "' will be teleported to the spawn of '" + toWorld.getName() + "' since they used an end exit portal.");
117+
Logging.fine("Player '" + player.getName() + "' will be teleported to the spawn of '" + toWorld.getName() + "' since they used an end exit portal.");
116118
try {
117119
Class.forName("org.bukkit.TravelAgent");
118120
event.getPortalTravelAgent().setCanCreatePortal(false);
119121
} catch (ClassNotFoundException ignore) {
120-
Logging.fine("TravelAgent not available for PlayerPortalEvent for " + event.getPlayer().getName() + ". There may be a portal created at spawn.");
122+
Logging.fine("TravelAgent not available for PlayerPortalEvent for " + player.getName() + ". There may be a portal created at spawn.");
121123
}
122124
if (toWorld.getBedRespawn()
123-
&& event.getPlayer().getBedSpawnLocation() != null
124-
&& event.getPlayer().getBedSpawnLocation().getWorld().getUID() == toWorld.getCBWorld().getUID()) {
125-
event.setTo(event.getPlayer().getBedSpawnLocation());
125+
&& player.getBedSpawnLocation() != null
126+
&& player.getBedSpawnLocation().getWorld().getUID() == toWorld.getCBWorld().getUID()) {
127+
event.setTo(player.getBedSpawnLocation());
126128
} else {
127129
event.setTo(toWorld.getSpawnLocation());
128130
}
@@ -132,20 +134,20 @@ public void onPlayerPortal(PlayerPortalEvent event) {
132134
event.getPortalTravelAgent().setCanCreatePortal(true);
133135
event.setTo(event.getPortalTravelAgent().findOrCreate(event.getTo()));
134136
} catch (ClassNotFoundException ignore) {
135-
Logging.fine("TravelAgent not available for PlayerPortalEvent for " + event.getPlayer().getName() + ". Their destination may not be correct.");
137+
Logging.fine("TravelAgent not available for PlayerPortalEvent for " + player.getName() + ". Their destination may not be correct.");
136138
event.setTo(event.getTo());
137139
}
138140
} else if (toWorld.getEnvironment() == World.Environment.THE_END && type == PortalType.ENDER) {
139-
Location spawnLocation = EndPlatformCreator.getVanillaLocation(event.getTo().getWorld());
141+
Location spawnLocation = EndPlatformCreator.getVanillaLocation(player, event.getTo().getWorld());
140142
event.setTo(spawnLocation);
141-
EndPlatformCreator.createEndPlatform(spawnLocation, plugin.isEndPlatformDropBlocks());
143+
EndPlatformCreator.createEndPlatform(spawnLocation.getWorld(), plugin.isEndPlatformDropBlocks());
142144
}
143145

144146
// Advancements need to be triggered manually
145147
if (type == PortalType.NETHER && event.getTo().getWorld().getEnvironment() == World.Environment.NETHER) {
146-
awardAdvancement(event.getPlayer(), enterNetherAdvancement, ENTER_NETHER_CRITERIA);
148+
awardAdvancement(player, enterNetherAdvancement, ENTER_NETHER_CRITERIA);
147149
} else if (type == PortalType.ENDER && event.getTo().getWorld().getEnvironment() == World.Environment.THE_END) {
148-
awardAdvancement(event.getPlayer(), enterEndAdvancement, ENTER_END_CRITERIA);
150+
awardAdvancement(player, enterEndAdvancement, ENTER_END_CRITERIA);
149151
}
150152
}
151153
}

src/main/java/com/onarandombox/MultiverseNetherPortals/utils/EndPlatformCreator.java

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@
22

33
import com.dumptruckman.minecraft.util.Logging;
44
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
5-
import com.onarandombox.MultiverseNetherPortals.MultiverseNetherPortals;
65
import org.bukkit.Location;
76
import org.bukkit.Material;
87
import org.bukkit.World;
98
import org.bukkit.block.Block;
109
import org.bukkit.block.BlockFace;
10+
import org.bukkit.entity.Entity;
11+
import org.bukkit.entity.Player;
1112

1213
public class EndPlatformCreator {
1314

1415
/**
1516
* Creates an end platform at the specified {@code Block}
1617
*
17-
* @param spawnLocation The {@code Block} that the player will spawn at.
18+
* @param world The world to create the platform in
1819
* @param dropEndBlocks If the platform should drop the broken blocks or delete them
1920
*/
20-
public static void createEndPlatform(Block spawnLocation, boolean dropEndBlocks) {
21-
Logging.fine("Creating an end platform at " + spawnLocation.toString());
21+
public static void createEndPlatform(World world, boolean dropEndBlocks) {
22+
Block spawnLocation = new Location(world, 100, 49, 0).getBlock();
23+
Logging.fine("Creating an end platform at " + spawnLocation);
2224

2325
for (int x = spawnLocation.getX() - 2; x <= spawnLocation.getX() + 2; x++) {
2426
for (int z = spawnLocation.getZ() - 2; z <= spawnLocation.getZ() + 2; z++) {
@@ -35,39 +37,29 @@ public static void createEndPlatform(Block spawnLocation, boolean dropEndBlocks)
3537
for (int yMod = 1; yMod <= 3; yMod++) {
3638
Block block = platformBlock.getRelative(BlockFace.UP, yMod);
3739
if (block.getType() != Material.AIR) {
38-
if (dropEndBlocks) {
39-
block.breakNaturally();
40-
} else {
40+
if (!dropEndBlocks || !block.breakNaturally()) {
4141
block.setType(Material.AIR);
4242
}
43-
44-
Logging.finest("Breaking block at " + platformBlock);
43+
Logging.finest("Breaking block at " + block);
4544
}
4645
}
4746
}
4847
}
4948
}
5049

51-
52-
/**
53-
* Creates an end platform at the specified {@code Location}
54-
* @param spawnLocation The {@code Location} that the player will spawn at.
55-
*/
56-
public static void createEndPlatform(Location spawnLocation, boolean dropEndBlocks) {
57-
createEndPlatform(spawnLocation.getBlock(), dropEndBlocks);
58-
}
59-
6050
/**
6151
* The default vanilla location for the end platform
6252
*/
63-
public static Location getVanillaLocation(World world) {
64-
return new Location(world, 100, 49, 0, 90, 0);
53+
public static Location getVanillaLocation(Entity entity, World world) {
54+
return entity instanceof Player
55+
? new Location(world, 100, 49, 0, 90, 0)
56+
: new Location(world, 100.5, 50, 0.5, 90, 0);
6557
}
6658

6759
/**
6860
* The default vanilla location for the end platform
6961
*/
70-
public static Location getVanillaLocation(MultiverseWorld world) {
71-
return getVanillaLocation(world.getCBWorld());
62+
public static Location getVanillaLocation(Entity entity, MultiverseWorld world) {
63+
return getVanillaLocation(entity, world.getCBWorld());
7264
}
7365
}

0 commit comments

Comments
 (0)