7
7
package world .bentobox .bentobox .listeners .teleports ;
8
8
9
9
10
+ import java .util .Objects ;
10
11
import java .util .UUID ;
11
12
12
13
import org .bukkit .Bukkit ;
@@ -77,8 +78,29 @@ public void onEntityPortal(EntityPortalEvent event)
77
78
event .setCancelled (true );
78
79
return ;
79
80
}
80
- // Trigger event processor.
81
- this .portalProcess (event , event .getTo ().getWorld ().getEnvironment ());
81
+
82
+ // Check which teleportation is happening.
83
+
84
+ World .Environment source = fromWorld .getEnvironment ();
85
+ World .Environment destination = event .getTo ().getWorld ().getEnvironment ();
86
+
87
+ if (World .Environment .NETHER == source && World .Environment .NORMAL == destination ||
88
+ World .Environment .NORMAL == source && World .Environment .NETHER == destination )
89
+ {
90
+ // Nether to overworld or opposite
91
+ this .portalProcess (event , World .Environment .NETHER );
92
+ }
93
+ else if (World .Environment .THE_END == source && World .Environment .NORMAL == destination ||
94
+ World .Environment .NORMAL == source && World .Environment .THE_END == destination )
95
+ {
96
+ // end to overworld or opposite
97
+ this .portalProcess (event , World .Environment .THE_END );
98
+ }
99
+ else
100
+ {
101
+ // unknown teleportation
102
+ this .portalProcess (event , event .getTo ().getWorld ().getEnvironment ());
103
+ }
82
104
}
83
105
84
106
@@ -224,32 +246,24 @@ private void portalProcess(EntityPortalEvent event, World.Environment environmen
224
246
}
225
247
this .inTeleport .add (event .getEntity ().getUniqueId ());
226
248
227
- // Get target world.
228
- World toWorld ;
229
-
230
- if (environment .equals (World .Environment .NORMAL ))
231
- {
232
- toWorld = overWorld ;
233
- }
234
- else
235
- {
236
- toWorld = this .getNetherEndWorld (overWorld , environment );
237
- }
238
-
239
- if (!overWorld .equals (toWorld ) && !this .isIslandWorld (overWorld , environment ))
249
+ if (fromWorld .equals (overWorld ) && !this .isIslandWorld (overWorld , environment ))
240
250
{
241
251
// This is not island world. Use standard nether or end world teleportation.
242
- this .handleToStandardNetherOrEnd (event , overWorld , toWorld );
252
+ this .handleToStandardNetherOrEnd (event , overWorld , environment );
243
253
return ;
244
254
}
245
-
246
- if (!overWorld .equals (fromWorld ) && !this .isIslandWorld (overWorld , environment ))
255
+
256
+ if (!fromWorld .equals (overWorld ) && !this .isIslandWorld (overWorld , environment ))
247
257
{
248
258
// If entering a portal in the other world, teleport to a portal in overworld if
249
259
// there is one
250
- this .handleFromStandardNetherOrEnd (event , overWorld , toWorld . getEnvironment () );
260
+ this .handleFromStandardNetherOrEnd (event , overWorld , environment );
251
261
return ;
252
262
}
263
+
264
+ // To the nether/end or overworld.
265
+ World toWorld = !fromWorld .getEnvironment ().equals (environment ) ?
266
+ this .getNetherEndWorld (overWorld , environment ) : overWorld ;
253
267
254
268
// Set the destination location
255
269
// If portals cannot be created, then destination is the spawn point, otherwise it's the vector
@@ -286,7 +300,7 @@ private void portalProcess(EntityPortalEvent event, World.Environment environmen
286
300
// Let the server teleport
287
301
return ;
288
302
}
289
-
303
+
290
304
if (environment .equals (World .Environment .THE_END ))
291
305
{
292
306
// Prevent death from hitting the ground while calculating location.
@@ -324,10 +338,11 @@ private void portalProcess(EntityPortalEvent event, World.Environment environmen
324
338
* Handle teleport to standard nether or end
325
339
* @param event - EntityPortalEvent
326
340
* @param overWorld - over world
327
- * @param toWorld - to world
341
+ * @param environment - to target environment
328
342
*/
329
- private void handleToStandardNetherOrEnd (EntityPortalEvent event , World overWorld , World toWorld )
343
+ private void handleToStandardNetherOrEnd (EntityPortalEvent event , World overWorld , World . Environment environment )
330
344
{
345
+ World toWorld = Objects .requireNonNull (this .getNetherEndWorld (overWorld , environment ));
331
346
Location spawnPoint = toWorld .getSpawnLocation ();
332
347
333
348
// If going to the nether and nether portals are active then just teleport to approx location
@@ -345,7 +360,7 @@ private void handleToStandardNetherOrEnd(EntityPortalEvent event, World overWorl
345
360
toWorld .setSpawnLocation (100 , 50 , 0 );
346
361
}
347
362
348
- if (this .isAllowedOnServer (toWorld . getEnvironment () ))
363
+ if (this .isAllowedOnServer (environment ))
349
364
{
350
365
// To Standard Nether or end
351
366
event .setTo (spawnPoint );
0 commit comments