|
38 | 38 |
|
39 | 39 | public class BukkitMCEntity extends BukkitMCMetadatable implements MCEntity { |
40 | 40 |
|
41 | | - Entity e; |
42 | | - private static volatile Boolean isPaperTeleportFlag = null; |
43 | | - private static final Object IS_PAPER_TELEPORT_FLAG_LOCK = new Object(); |
| 41 | + private static final boolean USE_RETAIN_PASSENGERS; |
| 42 | + |
| 43 | + static { |
| 44 | + boolean useRetainPassengers = false; |
| 45 | + try { |
| 46 | + Class<?> clz = Class.forName("io.papermc.paper.entity.TeleportFlag$EntityState"); |
| 47 | + if(clz.getAnnotation(Deprecated.class) == null) { |
| 48 | + useRetainPassengers = true; |
| 49 | + } |
| 50 | + } catch(ClassNotFoundException ignored) {} |
| 51 | + USE_RETAIN_PASSENGERS = useRetainPassengers; |
| 52 | + } |
| 53 | + |
| 54 | + private final Entity e; |
44 | 55 |
|
45 | 56 | public BukkitMCEntity(Entity e) { |
46 | 57 | super(e); |
@@ -254,30 +265,13 @@ public boolean teleport(MCLocation location) { |
254 | 265 |
|
255 | 266 | @Override |
256 | 267 | public boolean teleport(MCLocation location, MCTeleportCause cause) { |
257 | | - @SuppressWarnings("LocalVariableHidesMemberVariable") |
258 | | - Boolean isPaperTeleportFlag = BukkitMCEntity.isPaperTeleportFlag; |
259 | | - if(isPaperTeleportFlag == null) { |
260 | | - synchronized(IS_PAPER_TELEPORT_FLAG_LOCK) { |
261 | | - isPaperTeleportFlag = BukkitMCEntity.isPaperTeleportFlag; |
262 | | - if(isPaperTeleportFlag == null) { |
263 | | - try { |
264 | | - // 1.19.3 |
265 | | - Class.forName("io.papermc.paper.entity.TeleportFlag$EntityState"); |
266 | | - BukkitMCEntity.isPaperTeleportFlag = isPaperTeleportFlag = true; |
267 | | - } catch(ClassNotFoundException ex) { |
268 | | - BukkitMCEntity.isPaperTeleportFlag = isPaperTeleportFlag = false; |
269 | | - } |
270 | | - } |
271 | | - } |
272 | | - } |
273 | | - Location l = ((BukkitMCLocation) location).asLocation(); |
| 268 | + Location l = (Location) location.getHandle(); |
274 | 269 | TeleportCause c = TeleportCause.valueOf(cause.name()); |
275 | | - if(isPaperTeleportFlag) { |
276 | | - // Paper requires a third parameter to maintain consistent behavior when teleporting |
277 | | - // entities with passengers. |
| 270 | + if(USE_RETAIN_PASSENGERS) { |
| 271 | + // Paper requires a third parameter to maintain consistent behavior when teleporting entities with passengers. |
| 272 | + // TeleportFlag.EntityState added in 1.19.3 but RETAIN_PASSENGERS was made default in 1.21.10. |
278 | 273 | TeleportFlag teleportFlag = TeleportFlag.EntityState.RETAIN_PASSENGERS; |
279 | | - // Paper only method: |
280 | | - // e.teleport(l, c, teleportFlag); |
| 274 | + // Paper only method: e.teleport(l, c, teleportFlag); |
281 | 275 | return ReflectionUtils.invokeMethod(Entity.class, e, "teleport", |
282 | 276 | new Class[] { |
283 | 277 | org.bukkit.Location.class, |
|
0 commit comments