|
33 | 33 | import org.mvplugins.multiverse.core.command.MVCommandManager;
|
34 | 34 | import org.mvplugins.multiverse.core.config.CoreConfig;
|
35 | 35 | import org.mvplugins.multiverse.core.destination.DestinationsProvider;
|
| 36 | +import org.mvplugins.multiverse.core.dynamiclistener.EventRunnable; |
36 | 37 | import org.mvplugins.multiverse.core.dynamiclistener.annotations.DefaultEventPriority;
|
| 38 | +import org.mvplugins.multiverse.core.dynamiclistener.annotations.EventClass; |
37 | 39 | import org.mvplugins.multiverse.core.dynamiclistener.annotations.EventMethod;
|
38 | 40 | import org.mvplugins.multiverse.core.dynamiclistener.annotations.EventPriorityKey;
|
39 | 41 | import org.mvplugins.multiverse.core.economy.MVEconomist;
|
@@ -195,59 +197,64 @@ private Option<Location> getMostAccurateRespawnLocation(LoadedMultiverseWorld mv
|
195 | 197 | return Option.of(mvWorld.getSpawnLocation());
|
196 | 198 | }
|
197 | 199 |
|
198 |
| - @EventMethod |
| 200 | + @EventClass("org.spigotmc.event.player.PlayerSpawnLocationEvent") |
199 | 201 | @EventPriorityKey("mvcore-player-spawn-location")
|
200 |
| - void playerSpawnLocation(PlayerSpawnLocationEvent event) { |
201 |
| - Player player = event.getPlayer(); |
202 |
| - MultiverseWorld world = getWorldManager().getLoadedWorld(player.getWorld()).getOrNull(); |
203 |
| - if (world == null) { |
204 |
| - Logging.finer("Player joined in a world that is not managed by Multiverse."); |
205 |
| - return; |
206 |
| - } |
207 |
| - if (!player.hasPlayedBefore()) { |
208 |
| - handleFirstSpawn(event); |
209 |
| - } else { |
210 |
| - handleJoinLocation(event); |
211 |
| - } |
212 |
| - this.handleGameModeAndFlight(player, event.getSpawnLocation().getWorld()); |
213 |
| - } |
| 202 | + EventRunnable playerSpawnLocation() { |
| 203 | + return new EventRunnable<PlayerSpawnLocationEvent>() { |
| 204 | + @Override |
| 205 | + public void onEvent(PlayerSpawnLocationEvent event) { |
| 206 | + Player player = event.getPlayer(); |
| 207 | + MultiverseWorld world = getWorldManager().getLoadedWorld(player.getWorld()).getOrNull(); |
| 208 | + if (world == null) { |
| 209 | + Logging.finer("Player joined in a world that is not managed by Multiverse."); |
| 210 | + return; |
| 211 | + } |
| 212 | + if (!player.hasPlayedBefore()) { |
| 213 | + handleFirstSpawn(event); |
| 214 | + } else { |
| 215 | + handleJoinLocation(event); |
| 216 | + } |
| 217 | + handleGameModeAndFlight(player, event.getSpawnLocation().getWorld()); |
| 218 | + } |
214 | 219 |
|
215 |
| - private void handleFirstSpawn(PlayerSpawnLocationEvent event) { |
216 |
| - if (!config.getFirstSpawnOverride()) { |
217 |
| - Logging.finer("FirstSpawnOverride is disabled"); |
218 |
| - // User has disabled the feature in config |
219 |
| - return; |
220 |
| - } |
221 |
| - Logging.fine("Moving NEW player to(firstspawnoverride): %s", config.getFirstSpawnLocation()); |
222 |
| - destinationsProvider.parseDestination(config.getFirstSpawnLocation()) |
223 |
| - .map(destination -> destination.getLocation(event.getPlayer()) |
224 |
| - .peek(event::setSpawnLocation) |
225 |
| - .onEmpty(() -> Logging.warning("The destination in FirstSpawnLocation in config is invalid"))) |
226 |
| - .onFailure(failure -> { |
227 |
| - Logging.warning("Invalid destination in FirstSpawnLocation in config: %s"); |
228 |
| - Logging.warning(failure.getFailureMessage().formatted(getLocales())); |
229 |
| - }); |
230 |
| - } |
| 220 | + private void handleFirstSpawn(PlayerSpawnLocationEvent event) { |
| 221 | + if (!config.getFirstSpawnOverride()) { |
| 222 | + Logging.finer("FirstSpawnOverride is disabled"); |
| 223 | + // User has disabled the feature in config |
| 224 | + return; |
| 225 | + } |
| 226 | + Logging.fine("Moving NEW player to(firstspawnoverride): %s", config.getFirstSpawnLocation()); |
| 227 | + destinationsProvider.parseDestination(config.getFirstSpawnLocation()) |
| 228 | + .map(destination -> destination.getLocation(event.getPlayer()) |
| 229 | + .peek(event::setSpawnLocation) |
| 230 | + .onEmpty(() -> Logging.warning("The destination in FirstSpawnLocation in config is invalid"))) |
| 231 | + .onFailure(failure -> { |
| 232 | + Logging.warning("Invalid destination in FirstSpawnLocation in config: %s"); |
| 233 | + Logging.warning(failure.getFailureMessage().formatted(getLocales())); |
| 234 | + }); |
| 235 | + } |
231 | 236 |
|
232 |
| - private void handleJoinLocation(PlayerSpawnLocationEvent event) { |
233 |
| - if (!config.getEnableJoinDestination()) { |
234 |
| - Logging.finer("JoinDestination is disabled"); |
235 |
| - // User has disabled the feature in config |
236 |
| - return; |
237 |
| - } |
238 |
| - if (config.getJoinDestination().isBlank()) { |
239 |
| - Logging.warning("Joindestination is enabled but no destination has been specified in config!"); |
240 |
| - return; |
241 |
| - } |
242 |
| - Logging.finer("JoinDestination is " + config.getJoinDestination()); |
243 |
| - destinationsProvider.parseDestination(config.getJoinDestination()) |
244 |
| - .map(destination -> destination.getLocation(event.getPlayer()) |
245 |
| - .peek(event::setSpawnLocation) |
246 |
| - .onEmpty(() -> Logging.warning("The destination in JoinDestination in config is invalid"))) |
247 |
| - .onFailure(failure -> { |
248 |
| - Logging.warning("Invalid destination in JoinDestination in config: %s"); |
249 |
| - Logging.warning(failure.getFailureMessage().formatted(getLocales())); |
250 |
| - }); |
| 237 | + private void handleJoinLocation(PlayerSpawnLocationEvent event) { |
| 238 | + if (!config.getEnableJoinDestination()) { |
| 239 | + Logging.finer("JoinDestination is disabled"); |
| 240 | + // User has disabled the feature in config |
| 241 | + return; |
| 242 | + } |
| 243 | + if (config.getJoinDestination().isBlank()) { |
| 244 | + Logging.warning("Joindestination is enabled but no destination has been specified in config!"); |
| 245 | + return; |
| 246 | + } |
| 247 | + Logging.finer("JoinDestination is " + config.getJoinDestination()); |
| 248 | + destinationsProvider.parseDestination(config.getJoinDestination()) |
| 249 | + .map(destination -> destination.getLocation(event.getPlayer()) |
| 250 | + .peek(event::setSpawnLocation) |
| 251 | + .onEmpty(() -> Logging.warning("The destination in JoinDestination in config is invalid"))) |
| 252 | + .onFailure(failure -> { |
| 253 | + Logging.warning("Invalid destination in JoinDestination in config: %s"); |
| 254 | + Logging.warning(failure.getFailureMessage().formatted(getLocales())); |
| 255 | + }); |
| 256 | + } |
| 257 | + }; |
251 | 258 | }
|
252 | 259 |
|
253 | 260 | /**
|
|
0 commit comments