22
33import net .kyori .adventure .key .Key ;
44import net .swofty .commons .StringUtility ;
5+ import net .swofty .commons .UnderstandableProxyServer ;
56import org .tinylog .Logger ;
67import net .kyori .adventure .sound .Sound ;
78import net .minestom .server .coordinate .Pos ;
@@ -35,7 +36,6 @@ public class ActionPlayerLaunchPads implements HypixelEventClass {
3536 private static final ScheduledExecutorService scheduler = Executors .newScheduledThreadPool (1 );
3637 private static final Set <UUID > notifiedPlayers = ConcurrentHashMap .newKeySet ();
3738
38-
3939 @ HypixelEvent (node = EventNodes .PLAYER , requireDataLoaded = true , isAsync = true )
4040 public void run (PlayerMoveEvent event ) {
4141 SkyBlockPlayer player = (SkyBlockPlayer ) event .getPlayer ();
@@ -56,6 +56,7 @@ public void run(PlayerMoveEvent event) {
5656 player .setInLaunchpad (true );
5757
5858 boolean accepted = pad .getShouldAllow ().apply (player );
59+ String rejectionMessage = pad .getRejectionMessage ();
5960 if (!accepted && player .getRank ().isStaff ()) {
6061 accepted = true ;
6162 player .getLogHandler ().debug ("As a staff member, you have bypassed the launchpad requirement." );
@@ -76,84 +77,73 @@ public void run(PlayerMoveEvent event) {
7677 ));
7778 player .playSound (Sound .sound (Key .key ("entity.generic.explode" ), Sound .Source .PLAYER , 1 , 1 ));
7879
80+ ServerType targetServerType = pad .getTargetServerType ();
81+ ProxyInformation proxyInfo = new ProxyInformation ();
82+
83+ List <UnderstandableProxyServer > informations =
84+ proxyInfo .getServerInformation (targetServerType ).join ();
85+ if (informations .isEmpty ()) {
86+ accepted = false ;
87+ rejectionMessage = "§cThere are no " + StringUtility .toNormalCase (targetServerType .name ()) + " servers available at the moment. Please try again later." ;
88+ }
89+
7990 if (!accepted ) {
8091 player .setVelocity (player .getPosition ().direction ().mul (-30 ).withY (5 ));
81- player .sendMessage (pad . getRejectionMessage () );
92+ player .sendMessage (rejectionMessage );
8293 player .setInLaunchpad (false );
8394 return ;
8495 }
8596
86- // Check server availability before starting animation
87- ServerType targetServerType = pad .getTargetServerType ();
88- ProxyInformation proxyInfo = new ProxyInformation ();
89- proxyInfo .getServerInformation (targetServerType ).thenAccept (servers -> {
90- if (servers == null || servers .isEmpty ()) {
91- player .setInLaunchpad (false );
92- if (!notifiedPlayers .contains (player .getUuid ())) {
93- notifiedPlayers .add (player .getUuid ());
94- player .sendMessage ("§cThere are no " + StringUtility .toNormalCase (targetServerType .name ()) + " servers available at the moment. Please try again later." );
97+ Pos originalPosition = player .getPosition ();
98+ player .playSound (Sound .sound (Key .key ("entity.firework_rocket.launch" ), Sound .Source .PLAYER , 1 , 1 ));
99+
100+ LivingEntity armorStand = new LivingEntity (EntityType .ARMOR_STAND );
101+ armorStand .getEntityMeta ().setInvisible (true );
102+ armorStand .getEntityMeta ().setHasNoGravity (true );
103+ armorStand .setInstance (player .getInstance (), player .getPosition ());
104+ armorStand .addPassenger (player );
105+
106+ List <Pos > curve = MathUtility .bezierCurve (player .getPosition (), pad .getDestination (), SEGMENTS );
107+ long timeToSleep = 3000 / SEGMENTS ;
108+
109+ // Use ScheduledExecutorService to run the launch trajectory with delays
110+ AtomicInteger index = new AtomicInteger (0 );
111+ ScheduledFuture <?>[] taskHolder = new ScheduledFuture <?>[1 ];
112+ taskHolder [0 ] = scheduler .scheduleAtFixedRate (() -> {
113+ int currentIndex = index .getAndIncrement ();
114+ if (currentIndex >= curve .size ()) {
115+ // Cancel the task
116+ if (taskHolder [0 ] != null ) {
117+ taskHolder [0 ].cancel (false );
95118 }
96- return ;
97- }
98-
99- notifiedPlayers .remove (player .getUuid ());
100119
101- Pos originalPosition = player .getPosition ();
102- player .playSound (Sound .sound (Key .key ("entity.firework_rocket.launch" ), Sound .Source .PLAYER , 1 , 1 ));
103-
104- LivingEntity armorStand = new LivingEntity (EntityType .ARMOR_STAND );
105- armorStand .getEntityMeta ().setInvisible (true );
106- armorStand .getEntityMeta ().setHasNoGravity (true );
107- armorStand .setInstance (player .getInstance (), player .getPosition ());
108- armorStand .addPassenger (player );
109-
110- List <Pos > curve = MathUtility .bezierCurve (player .getPosition (), pad .getDestination (), SEGMENTS );
111- long timeToSleep = 3000 / SEGMENTS ;
112-
113- // Use ScheduledExecutorService to run the launch trajectory with delays
114- AtomicInteger index = new AtomicInteger (0 );
115- ScheduledFuture <?>[] taskHolder = new ScheduledFuture <?>[1 ];
116- taskHolder [0 ] = scheduler .scheduleAtFixedRate (() -> {
117- int currentIndex = index .getAndIncrement ();
118- if (currentIndex >= curve .size ()) {
119- // Cancel the task
120- if (taskHolder [0 ] != null ) {
121- taskHolder [0 ].cancel (false );
120+ player .setInLaunchpad (false );
121+ notifiedPlayers .remove (player .getUuid ());
122+
123+ // Execute the after finished callback
124+ player .sendMessage ("Done" );
125+ pad .getAfterFinished ().accept (player );
126+
127+ // Check after a delay if player is still on this server (transfer failed)
128+ scheduler .schedule (() -> {
129+ // If player is still on the same server and instance, teleport them back
130+ if (player .getInstance () != null && player .getInstance ().equals (armorStand .getInstance ())) {
131+ player .teleport (originalPosition );
132+ player .sendMessage ("§cFailed to connect to the server. You have been teleported back." );
133+ }
134+ try {
135+ armorStand .remove ();
136+ } catch (Exception e ) {
122137 }
138+ }, 2 , TimeUnit .SECONDS );
123139
124- player .setInLaunchpad (false );
125- notifiedPlayers .remove (player .getUuid ());
126-
127- // Execute the after finished callback
128- player .sendMessage ("Done" );
129- pad .getAfterFinished ().accept (player );
130-
131- // Check after a delay if player is still on this server (transfer failed)
132- scheduler .schedule (() -> {
133- // If player is still on the same server and instance, teleport them back
134- if (player .getInstance () != null && player .getInstance ().equals (armorStand .getInstance ())) {
135- player .teleport (originalPosition );
136- player .sendMessage ("§cFailed to connect to the server. You have been teleported back." );
137- }
138- try {
139- armorStand .remove ();
140- } catch (Exception e ) {
141- }
142- }, 2 , TimeUnit .SECONDS );
143-
144- return ;
145- }
140+ return ;
141+ }
146142
147- Pos pos = curve .get (currentIndex );
148- Vec toGoTo = pos .asVec ();
149- Vec direction = toGoTo .sub (player .getPosition ().asVec ()).normalize ();
150- armorStand .setVelocity (direction .mul (50 , 5 , 50 ));
151- }, 0 , timeToSleep , TimeUnit .MILLISECONDS );
152- }).exceptionally (ex -> {
153- Logger .error (ex , "Error checking server availability for launch pad" );
154- player .setInLaunchpad (false );
155- player .sendMessage ("§cAn error occurred while checking server availability. Please try again later." );
156- return null ;
157- });
143+ Pos pos = curve .get (currentIndex );
144+ Vec toGoTo = pos .asVec ();
145+ Vec direction = toGoTo .sub (player .getPosition ().asVec ()).normalize ();
146+ armorStand .setVelocity (direction .mul (50 , 5 , 50 ));
147+ }, 0 , timeToSleep , TimeUnit .MILLISECONDS );
158148 }
159149}
0 commit comments