1818
1919package com .volmit .adapt .content .adaptation .rift ;
2020
21+ import com .volmit .adapt .Adapt ;
2122import com .volmit .adapt .api .adaptation .SimpleAdaptation ;
2223import com .volmit .adapt .util .*;
2324import lombok .NoArgsConstructor ;
4041
4142public class RiftBlink extends SimpleAdaptation <RiftBlink .Config > {
4243 private final Map <Player , Long > lastJump = new HashMap <>();
44+ private final Map <Player , Boolean > canBlink = new HashMap <>();
45+
46+ private final double jumpVelocity = -0.0784000015258789 ;
4347
4448 public RiftBlink () {
4549 super ("rift-blink" );
@@ -80,12 +84,10 @@ public void on(PlayerToggleFlightEvent e) {
8084 if (hasAdaptation (p ) && p .getGameMode ().equals (GameMode .SURVIVAL )) {
8185 e .setCancelled (true );
8286 p .setAllowFlight (false );
83-
8487 if (lastJump .get (p ) != null && M .ms () - lastJump .get (p ) <= getCooldownDuration ()) {
8588 return ;
8689 }
8790 if (p .isSprinting ()) {
88-
8991 Location loc = p .getLocation ().clone ();
9092 Location locOG = p .getLocation ().clone ();
9193 Vector dir = loc .getDirection ();
@@ -94,22 +96,18 @@ public void on(PlayerToggleFlightEvent e) {
9496 loc .add (dir );
9597 double cd = dist * 2 ;
9698 loc .subtract (0 , dist , 0 );
97-
9899 while (!isSafe (loc ) && cd -- > 0 ) {
99100 loc .add (0 , 1 , 0 );
100101 }
101-
102102 if (!isSafe (loc )) {
103103 p .getWorld ().playSound (p .getLocation (), Sound .BLOCK_CONDUIT_DEACTIVATE , 1f , 1.24f );
104104 lastJump .put (p , M .ms ());
105105 return ;
106106 }
107-
108107 if (getPlayer (p ).getData ().getSkillLines ().get ("rift" ).getAdaptations ().get ("rift-resist" ) != null &&
109108 getPlayer (p ).getData ().getSkillLines ().get ("rift" ).getAdaptations ().get ("rift-resist" ).getLevel () > 0 ) {
110109 RiftResist .riftResistStackAdd (p , 10 , 5 );
111110 }
112-
113111 if (getConfig ().showParticles ) {
114112
115113 vfxParticleLine (locOG , loc , Particle .REVERSE_PORTAL , 50 , 8 , 0.1D , 1D , 0.1D , 0D , null , false , l -> l .getBlock ().isPassable ());
@@ -119,12 +117,9 @@ public void on(PlayerToggleFlightEvent e) {
119117 J .s (() -> p .teleport (loc .add (0 , 1 , 0 ), PlayerTeleportEvent .TeleportCause .PLUGIN ));
120118 J .s (() -> p .setVelocity (v .multiply (3 )), 2 );
121119 });
122-
123120 lastJump .put (p , M .ms ());
124-
125121 p .getWorld ().playSound (p .getLocation (), Sound .ENTITY_ENDERMAN_TELEPORT , 0.50f , 1.0f );
126122 vfxLevelUp (p );
127-
128123 }
129124 }
130125 }
@@ -136,14 +131,12 @@ public boolean isSafe(Location l) {
136131 @ EventHandler
137132 public void on (PlayerMoveEvent e ) {
138133 Player p = e .getPlayer ();
139- if (hasAdaptation (p ) && p .getGameMode ().equals (GameMode .SURVIVAL )) {
140-
141-
134+ boolean isJumping = p .getVelocity ().getY () > jumpVelocity ;
135+ if (isJumping && !canBlink .containsKey (p ) && hasAdaptation (p ) && p .getGameMode ().equals (GameMode .SURVIVAL ) && p .isSprinting ()) {
142136 if (lastJump .get (p ) != null && M .ms () - lastJump .get (p ) <= getCooldownDuration ()) {
143137 p .setAllowFlight (false );
144138 return ;
145139 }
146-
147140 Location loc = p .getLocation ().clone ();
148141 Vector dir = loc .getDirection ();
149142 double dist = getBlinkDistance (getLevel (p ));
@@ -155,12 +148,18 @@ public void on(PlayerMoveEvent e) {
155148 while (!isSafe (loc ) && cd -- > 0 ) {
156149 loc .add (0 , 1 , 0 );
157150 }
158- if (!isSafe (loc )) {
159- return ;
160- } else if (isSafe (loc )) {
161- p .setAllowFlight (p .getFallDistance () < 4.5 && p .isSprinting ());
162- }
163151
152+ if (isSafe (loc )) {
153+ canBlink .put (p , true );
154+ p .setAllowFlight (true );
155+ Adapt .info ("Allowing flight for " + p .getName () + "" );
156+ J .a (() -> {
157+ p .setAllowFlight (false );
158+ p .setFlying (false );
159+ Adapt .info ("Disabling flight for " + p .getName () + "" );
160+ canBlink .remove (p );
161+ }, 13 );
162+ }
164163 }
165164 }
166165
0 commit comments