generated from LabyMod/addon-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from RappyLabyAddons/feat/syncRequests
Implement Async requests to reduce lag
- Loading branch information
Showing
11 changed files
with
198 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
core/src/main/java/com/rappytv/globaltags/api/requests/InfoGetRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.rappytv.globaltags.api.requests; | ||
|
||
import com.rappytv.globaltags.api.ApiRequest; | ||
import com.rappytv.globaltags.api.RequestBody; | ||
import java.util.UUID; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class InfoGetRequest extends ApiRequest { | ||
|
||
private String tag; | ||
private String position; | ||
|
||
public InfoGetRequest(UUID uuid, String key) { | ||
super("GET", "/players/" + uuid, key); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<Void> sendAsyncRequest() { | ||
return super.sendAsyncRequest().thenRun(() -> { | ||
if(isSuccessful()) { | ||
this.tag = responseBody.tag; | ||
this.position = responseBody.position; | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public RequestBody getBody() { | ||
return null; | ||
} | ||
|
||
public String getTag() { | ||
return tag; | ||
} | ||
public String getPosition() { | ||
return position; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
core/src/main/java/com/rappytv/globaltags/api/requests/PositionSetRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.rappytv.globaltags.api.requests; | ||
|
||
import com.rappytv.globaltags.api.ApiRequest; | ||
import com.rappytv.globaltags.api.RequestBody; | ||
import net.labymod.api.Laby; | ||
import net.labymod.api.client.entity.player.tag.PositionType; | ||
|
||
public class PositionSetRequest extends ApiRequest { | ||
|
||
private final PositionType position; | ||
|
||
public PositionSetRequest(String key, PositionType type) { | ||
super("POST", "/players/" + Laby.labyAPI().getUniqueId() + "/position", key); | ||
this.position = type; | ||
} | ||
|
||
@Override | ||
public RequestBody getBody() { | ||
return new RequestBody(position); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
core/src/main/java/com/rappytv/globaltags/api/requests/TagSetRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.rappytv.globaltags.api.requests; | ||
|
||
import com.rappytv.globaltags.api.ApiRequest; | ||
import com.rappytv.globaltags.api.RequestBody; | ||
import net.labymod.api.Laby; | ||
|
||
public class TagSetRequest extends ApiRequest { | ||
|
||
private final String key; | ||
|
||
public TagSetRequest(String token, String key) { | ||
super("POST", "/players/" + Laby.labyAPI().getUniqueId(), token); | ||
this.key = key; | ||
} | ||
|
||
@Override | ||
public RequestBody getBody() { | ||
return new RequestBody(key); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
core/src/main/java/com/rappytv/globaltags/api/requests/VersionGetRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.rappytv.globaltags.api.requests; | ||
|
||
import com.rappytv.globaltags.api.ApiRequest; | ||
import com.rappytv.globaltags.api.RequestBody; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class VersionGetRequest extends ApiRequest { | ||
|
||
private String version; | ||
|
||
public VersionGetRequest() { | ||
super("GET", "/", null); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<Void> sendAsyncRequest() { | ||
return super.sendAsyncRequest().thenRun(() -> { | ||
if(isSuccessful()) version = responseBody.version; | ||
}); | ||
} | ||
|
||
@Override | ||
public RequestBody getBody() { | ||
return null; | ||
} | ||
|
||
public String getVersion() { | ||
return version; | ||
} | ||
} |
Oops, something went wrong.