|
1 | 1 | package me.yleoft.zHomes.utils; |
2 | 2 |
|
| 3 | +import java.lang.reflect.InvocationTargetException; |
3 | 4 | import java.lang.reflect.Method; |
4 | 5 | import java.util.*; |
5 | 6 |
|
|
15 | 16 | import org.bukkit.OfflinePlayer; |
16 | 17 | import org.bukkit.Sound; |
17 | 18 | import org.bukkit.entity.Player; |
| 19 | +import org.bukkit.event.player.PlayerTeleportEvent; |
18 | 20 |
|
19 | 21 | import static me.yleoft.zAPI.utils.LocationUtils.*; |
20 | 22 |
|
@@ -83,37 +85,46 @@ public void teleportPlayer(Player p, OfflinePlayer t, String home) { |
83 | 85 | lang.sendMsg(p, lang.getCantDimensionalTeleport()); |
84 | 86 | return; |
85 | 87 | } |
86 | | - findNearestSafeLocationAsync(loc, 4, 50, tpLoc -> { |
87 | | - if (tpLoc == null) { |
88 | | - new LanguageUtils.CommandsMSG().sendMsg(p, "Unable to find a safe location"); |
89 | | - return; |
90 | | - } |
91 | | - String homeString = p.getUniqueId() == t.getUniqueId() ? home : t.getName() + ":" + home; |
92 | | - Runnable task = () -> { |
93 | | - Sound sound = getTeleportSound(); |
94 | | - if (zAPI.isFolia()) { |
95 | | - try { |
96 | | - Method teleportAsyncMethod = Player.class.getMethod("teleportAsync", Location.class); |
97 | | - teleportAsyncMethod.invoke(p, tpLoc); |
98 | | - } catch (Exception e) { |
99 | | - throw new RuntimeException("Unable to teleport player", e); |
| 88 | + SchedulerUtils.runTask(loc, new FoliaRunnable() { |
| 89 | + @Override |
| 90 | + public void run() { |
| 91 | + Location tpLoc = findNearestSafeLocation(loc, 4, 50); |
| 92 | + if(tpLoc == null) { |
| 93 | + LanguageUtils.CommandsMSG cmdm = new LanguageUtils.CommandsMSG(); |
| 94 | + cmdm.sendMsg(p, cmdm.getUnableToFindSafeLocation()); |
| 95 | + return; |
| 96 | + } |
| 97 | + String homeString = p.getUniqueId() == t.getUniqueId() ? home : t.getName() + ":" + home; |
| 98 | + Runnable task = () -> { |
| 99 | + Sound sound = getTeleportSound(); |
| 100 | + if (zAPI.isFolia()) { |
| 101 | + try { |
| 102 | + Method teleportAsyncMethod = Player.class.getMethod("teleportAsync", Location.class); |
| 103 | + teleportAsyncMethod.invoke(p, tpLoc); |
| 104 | + SchedulerUtils.runTask(tpLoc, () -> { |
| 105 | + if (sound != null && playSound()) p.playSound(p.getLocation(), sound, 1.0F, 1.0F); |
| 106 | + }); |
| 107 | + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { |
| 108 | + throw new RuntimeException("Unable to teleport player to home", e); |
| 109 | + } |
| 110 | + }else { |
| 111 | + SchedulerUtils.runTaskLater(tpLoc, () -> { |
| 112 | + p.teleport(tpLoc, PlayerTeleportEvent.TeleportCause.PLUGIN); |
| 113 | + SchedulerUtils.runTask(tpLoc, () -> { |
| 114 | + if (sound != null && playSound()) p.playSound(p.getLocation(), sound, 1.0F, 1.0F); |
| 115 | + }); |
| 116 | + }, 1L); |
100 | 117 | } |
101 | | - } else { |
102 | | - SchedulerUtils.runTaskLater(tpLoc, () -> p.teleport(tpLoc), 1L); |
| 118 | + lang.sendMsg(p, lang.getOutput(homeString)); |
| 119 | + }; |
| 120 | + if(doWarmup() && !p.hasPermission(PermissionBypassWarmup()) && warmupTime() > 0) { |
| 121 | + LanguageUtils.TeleportWarmupMSG langWarmup = new LanguageUtils.TeleportWarmupMSG(); |
| 122 | + lang.sendMsg(p, langWarmup.getWarmup(warmupTime())); |
| 123 | + startWarmup(p, langWarmup, lang, homeString, task); |
| 124 | + return; |
103 | 125 | } |
104 | | - |
105 | | - lang.sendMsg(p, lang.getOutput(homeString)); |
106 | | - if (sound != null && playSound()) p.playSound(p.getLocation(), sound, 1.0F, 1.0F); |
107 | | - }; |
108 | | - |
109 | | - if (doWarmup() && !p.hasPermission(PermissionBypassWarmup()) && warmupTime() > 0) { |
110 | | - LanguageUtils.TeleportWarmupMSG warmupMsg = new LanguageUtils.TeleportWarmupMSG(); |
111 | | - lang.sendMsg(p, warmupMsg.getWarmup(warmupTime())); |
112 | | - startWarmup(p, warmupMsg, lang, homeString, task); |
113 | | - return; |
| 126 | + task.run(); |
114 | 127 | } |
115 | | - |
116 | | - task.run(); |
117 | 128 | }); |
118 | 129 | } |
119 | 130 | public void teleportPlayer(Player p, String home) { |
|
0 commit comments