@@ -57,29 +57,36 @@ public void walk(PlayerMoveEvent e) {
5757 //System.out.println("Link is 1");
5858 link = links .get (0 );
5959 //System.out.println(link.getMat() + " | " + link.getTrailName());
60- } else if (links != null ) {
60+ } else if (links != null ) {
6161 //System.out.println("Link amount > 1");
6262 container = new CustomBlockData (block , main );
63- String [] blockTrailName = container .get (trailNameKey , PersistentDataType .STRING ).split (":" );
64- Integer id = null ;
65- try {
66- id = Integer .parseInt (blockTrailName [1 ]);
67- } catch (Exception ignored ){}
68- for (Link lnk : links ) {
69- Integer closestId = null ;
70- if (lnk .getTrailName ().equals (blockTrailName [0 ])) {
71- //System.out.println("Link was found!");
72- if ((id == null || lnk .identifier () == id ) || (link == null && lnk .identifier () > id )){
73- link = lnk ;
74- break ;
63+ if (!container .has (trailNameKey , PersistentDataType .STRING )) {
64+ Link minLink = null ;
65+ for (Link link1 : links ) {
66+ if (minLink == null || link1 .identifier () < minLink .identifier ()) minLink = link1 ;
67+ }
68+ link = minLink ;
69+ } else {
70+ String [] blockTrailName = container .get (trailNameKey , PersistentDataType .STRING ).split (":" );
71+ Integer id = null ;
72+ try {
73+ id = Integer .parseInt (blockTrailName [1 ]);
74+ } catch (Exception ignored ) {
75+ }
76+ link = links .get (0 );
77+ for (Link lnk : links ) {
78+ if (lnk .getTrailName ().equals (blockTrailName [0 ])) {
79+ if (id != null && lnk .identifier () == id ) {
80+ link = lnk ;
81+ break ;
82+ }
83+ if (lnk .identifier () < link .identifier ()) link = lnk ;
7584 }
76- else if (link != null && lnk .identifier () > id ) break ;
77- else link = lnk ;
7885 }
7986 }
8087 }
8188 Player p = e .getPlayer ();
82- System .out .println (p .getWalkSpeed ());
89+ // System.out.println(p.getWalkSpeed());
8390
8491 //System.out.println(p.getWalkSpeed());
8592
@@ -119,7 +126,7 @@ public void run() {
119126 for (Map .Entry <UUID , Booster > entry : speedBoostedPlayers .entrySet ()) {
120127 Player player = entry .getValue ().getPlayer ();
121128 //System.out.println("boosting: "+player);
122- if (entry .getValue ().immediately ) player .setWalkSpeed (entry .getValue ().targetSpeed );
129+ if (entry .getValue ().immediately ) player .setWalkSpeed (entry .getValue ().targetSpeed );
123130 else if (entry .getValue ().getTargetSpeed () > player .getWalkSpeed ())
124131 player .setWalkSpeed (Math .min (player .getWalkSpeed () + main .getConfigManager ().speedBoostStep , entry .getValue ().getTargetSpeed ()));
125132 else
@@ -138,7 +145,6 @@ else if (entry.getValue().getTargetSpeed() > player.getWalkSpeed())
138145 }
139146
140147 if ((main .getConfigManager ().sneakBypass && e .getPlayer ().isSneaking ()) || link == null ) return ;
141- //System.out.println("asd");
142148 if ((!main .getConfigManager ().usePermission && main .getToggles ().isDisabled (p .getUniqueId ().toString ())) || (main .getConfigManager ().usePermission && !p .hasPermission ("trails.create-trails" ))) {
143149 return ;
144150 }
@@ -214,9 +220,9 @@ private void makePath(Player p, Block block, Link link) {
214220 Integer walked = container .get (walksKey , PersistentDataType .INTEGER );
215221 if (walked == null ) walked = 0 ;
216222 //System.out.println(walked);
217- if (walked >= link .decayNumber ()) {
223+ if (walked >= link .decayNumber () && link . getNext () != null ) {
218224 container .set (walksKey , PersistentDataType .INTEGER , 0 );
219- container .set (trailNameKey , PersistentDataType .STRING , link .getTrailName ()+ ":" + link .identifier ());
225+ container .set (trailNameKey , PersistentDataType .STRING , link .getTrailName () + ":" + link . getNext () .identifier ());
220226 try {
221227 this .changeNext (p , block , link );
222228 } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e ) {
0 commit comments