Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add account center, admin actions #38

Merged
merged 106 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
270a52d
Improve tag resolving
RappyTV Jun 8, 2024
4bf933d
Extend PlayerInfo's methods
RappyTV Jun 8, 2024
5c4476f
Add functionality to ban players
RappyTV Jun 8, 2024
393c8e4
Add ban bullet point and activity
RappyTV Jun 8, 2024
9300643
Optimize translations for new ban bullet point
RappyTV Jun 8, 2024
c8fd76d
Bump labygradle
RappyTV Jun 8, 2024
76aecce
Improve ApiHandler
RappyTV Jun 8, 2024
78e3102
Delete old unused request implementations
RappyTV Jun 8, 2024
e1b5d88
Move api and util classes into api module
RappyTV Jun 8, 2024
7a17c42
Add response messages to all Input activities
RappyTV Jun 8, 2024
da28128
Add more bullet points, register all
RappyTV Jun 8, 2024
45a3180
Fix translations of new bullet points
RappyTV Jun 8, 2024
dfd8a0a
Fix translations of new bullet points
RappyTV Jun 8, 2024
27d2793
Improve changeTag condition
RappyTV Jun 9, 2024
b7fb992
Add placeholder body on resetTag request to bypass elysia bug
RappyTV Jun 9, 2024
4ab61cb
Rename report.lss to be used multiple times
RappyTV Jun 9, 2024
148eddb
Comment out account center activity for now
RappyTV Jun 9, 2024
d83a9e6
Optimize imports so builds don't fail
RappyTV Jun 9, 2024
3cea4d8
Resolve own playerdata after clearing cache
RappyTV Jun 9, 2024
346371d
Also allow some bullet points when player does not have a tag
RappyTV Jun 9, 2024
2ba1dd9
Clear cache on some more requests
RappyTV Jun 9, 2024
5030a72
Fix toggleAdmin request (idk why the body problem still occurs)
RappyTV Jun 9, 2024
e12c9dd
Print request exceptions
RappyTV Jun 9, 2024
d45f502
Get ban info, add ApiHandler#unbanPlayer
RappyTV Jun 9, 2024
a54cfca
Remove unused parameter field in ApiHandler#unbanPlayer
RappyTV Jun 9, 2024
34c56aa
Rename BanUUIDActivity
RappyTV Jun 9, 2024
c942cc6
Make ToggleBanBulletPoint and ToggleAdminBulletPoint respect the play…
RappyTV Jun 9, 2024
b9518a8
Always clear cache and add own playerinfo instantly
RappyTV Jun 9, 2024
3a4b59b
Add unban/toggleAdmin translations, remove cacheEmpty string
RappyTV Jun 9, 2024
cd3e005
Bump version
RappyTV Jun 9, 2024
91bd6b2
Use component system only
RappyTV Jun 9, 2024
5afc090
Use getters and setters for ApiRequest field
RappyTV Jun 9, 2024
376c194
Fix wrong color for API Version
RappyTV Jun 9, 2024
412ce84
Remove unused method in TagCache, prevent constructing TagCache
RappyTV Jun 9, 2024
55828c3
Prevent ApiHandler construction
RappyTV Jun 9, 2024
aba6827
Fix /gt cc command functionality
RappyTV Jun 9, 2024
70be260
Remove old account center activity
RappyTV Jun 9, 2024
9cc10dc
Rearrange stuff, add method to fetch tag
RappyTV Jun 9, 2024
6a4c3b1
Add empty lss files for tag preview
RappyTV Jun 9, 2024
8c7ffe9
Add empty tag preview widget
RappyTV Jun 9, 2024
e141947
Add tag preview prototype
RappyTV Jun 10, 2024
60c5a44
Update translations
RappyTV Jun 10, 2024
4e4b77f
Add account center style
RappyTV Jun 10, 2024
298a0df
Rename account center lss
RappyTV Jun 10, 2024
2dd08a0
Add tag preview of live tag
RappyTV Jun 10, 2024
2510533
Fix display of overflowing error components
RappyTV Jun 10, 2024
4c96f8c
Add error translationg
RappyTV Jun 10, 2024
0f4a371
Remove wrong notification in ApiHandler
RappyTV Jun 11, 2024
6a97692
Add config change listeners, add getters for config properties
RappyTV Jun 11, 2024
6ac11b0
Initialize TagPreviewWidget with settings element, add refresh button
RappyTV Jun 11, 2024
9b2cb5e
Move PlayerInfo#getIconName -> PlayerInfo#getIconValue and return Glo…
RappyTV Jun 11, 2024
9b4aac7
Add stage translations
RappyTV Jun 11, 2024
c75acaf
Add refresh button lss
RappyTV Jun 11, 2024
4e8e0e2
Remove unused import
RappyTV Jun 11, 2024
ad35395
Move PlayerInfo#getIcon into GlobalIcon#getIcon
RappyTV Jun 11, 2024
4d028e1
Some confusing fetching and reloading stuff that needs to be changed …
RappyTV Jun 12, 2024
404970a
Fix refetching and changing
RappyTV Jun 18, 2024
ebddb0d
Fix cache preview
RappyTV Jun 18, 2024
3d8abd5
Format runnable
RappyTV Jun 18, 2024
fa12871
Fix how empty tags are displayed
RappyTV Jun 18, 2024
3dc34c3
Fix ApiHandler#setPosition response success boolean
RappyTV Jun 19, 2024
b6d03a9
Add popup when updating tag settings
RappyTV Jun 19, 2024
3639da3
Rearrange config a bit, add IntroducedIn badge to preview widget
RappyTV Jun 19, 2024
9a5c633
Improve background option icon
RappyTV Jun 19, 2024
a33c4b5
Add background option description
RappyTV Jun 19, 2024
0c4725b
Fix ComponentWidgets being split up buggy
RappyTV Jun 19, 2024
8c29d3c
Some subconfig updates
RappyTV Jun 19, 2024
970d8a4
Use correct api url, add method to simplify mixin access
RappyTV Jun 19, 2024
9939b5a
Bump version
RappyTV Jun 20, 2024
4e6e585
Add appeal button to TagPreviewWidget
RappyTV Jun 20, 2024
6070120
Add javadocs to PlayerInfo, add PlayerInfo#Suspension, deprecate old …
RappyTV Jun 20, 2024
250f871
Make PlayerInfo#getTag nullable
RappyTV Jun 20, 2024
bf89335
Refrain from using deprecated methods
RappyTV Jun 20, 2024
4126ff4
Allow null value as "appealable" (temporary), make constructors public
RappyTV Jun 20, 2024
e4602dc
Check if info is null, add notification
RappyTV Jun 20, 2024
48dcead
Move Util#clearCache into TagCache and add consumer which accepts the…
RappyTV Jun 21, 2024
4cc3c98
Make TagPreviewWidget refetchable statically
RappyTV Jun 21, 2024
16fca65
Readd API response when resetting the own tag via config
RappyTV Jun 21, 2024
cae40c2
Use new cache clear method
RappyTV Jun 21, 2024
c07e0f4
Add more error handling to settings update button
RappyTV Jun 21, 2024
ad369c5
Don't instantly refetch self on cache clear, rather extract function
RappyTV Jun 21, 2024
34dcb64
Bump labygradle
RappyTV Jun 21, 2024
fe5df02
Don't put the rc versioning into the addon jar
RappyTV Jun 21, 2024
adc8f95
Appealable boolean is now implemented in the API
RappyTV Jun 21, 2024
9c64c15
Add appealBan function to ApiHandler
RappyTV Jun 21, 2024
0b9368f
Add popup to enter appeal reason
RappyTV Jun 21, 2024
9230801
Use Notification.Type#System instead of #Social so notifications are …
RappyTV Jun 21, 2024
61b8e21
Add button to join the discord
RappyTV Jun 23, 2024
661c926
Resolve self after leaving server
RappyTV Jun 23, 2024
190f273
Change type of ApiRequest body values to object
RappyTV Jun 26, 2024
887d9b5
Add some more nullable and notnull annotations to PlayerInfo
RappyTV Jun 26, 2024
9eacde9
Add api request to edit ban info
RappyTV Jun 26, 2024
893287c
Add bullet point to edit bans
RappyTV Jun 26, 2024
dd0362d
Load empty suspension when ban is null
RappyTV Jun 28, 2024
2a0f2e0
Fix lss display in tag preview
RappyTV Jun 28, 2024
0b5ce04
Don't edit ComponentWidget width because the bug is getting fixed
RappyTV Jun 28, 2024
53e764d
Resolve self after every cache clear
RappyTV Jun 28, 2024
c3b6a1e
Add methods to ApiHandler to link and unlink discord account
RappyTV Jun 29, 2024
392d171
Add subcommands to link and unlink discord account
RappyTV Jun 29, 2024
e3e6fdf
Add code field to responseBody
RappyTV Jun 29, 2024
7010e00
Add translation
RappyTV Jun 29, 2024
eb98b31
Register subcommands on main command
RappyTV Jun 29, 2024
b7b183f
Merge branch 'master' into feat/accountCenter
RappyTV Jul 5, 2024
ebb4930
Optimize Map#of usage in ApiHandler
RappyTV Jul 6, 2024
26cff75
Update date for 1.2.0 revision
RappyTV Jul 6, 2024
bc7b8b3
Remove unused addon property
RappyTV Jul 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
360 changes: 360 additions & 0 deletions api/src/main/java/com/rappytv/globaltags/api/ApiHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,360 @@
package com.rappytv.globaltags.api;

import com.rappytv.globaltags.types.GlobalIcon;
import com.rappytv.globaltags.types.PlayerInfo;
import com.rappytv.globaltags.types.PlayerInfo.Suspension;
import com.rappytv.globaltags.util.TagCache;
import com.rappytv.globaltags.util.Util;
import net.labymod.api.Laby;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.component.format.NamedTextColor;
import net.labymod.api.client.entity.player.tag.PositionType;
import net.labymod.api.util.io.web.request.Request.Method;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.function.Consumer;

@SuppressWarnings("unused")
public class ApiHandler {

private static final Map<String, Object> emptyBody = Map.of("body", "placeholder body");

private ApiHandler() {}

public static void getVersion(Consumer<String> consumer) {
ApiRequest request = new ApiRequest(
Method.GET,
"/",
null
) {
@Override
public Map<String, Object> getBody() {
return null;
}
};
request.sendAsyncRequest((response) -> consumer.accept(request.responseBody.version));
}

public static void getInfo(Consumer<PlayerInfo> consumer) {
getInfo(Laby.labyAPI().getUniqueId(), consumer);
}

public static void getInfo(UUID uuid, Consumer<PlayerInfo> consumer) {
ApiRequest request = new ApiRequest(
Method.GET,
"/players/" + uuid,
Util.getSessionToken()
) {
@Override
public Map<String, Object> getBody() {
return null;
}
};
request.sendAsyncRequest((response) -> {
if(!request.isSuccessful()) {
consumer.accept(null);
return;
}
consumer.accept(new PlayerInfo(
uuid,
request.responseBody.tag,
request.responseBody.position,
request.responseBody.icon,
request.responseBody.admin,
request.responseBody.ban
));
});
}

public static void setTag(String tag, Consumer<ApiResponse> consumer) {
setTag(Laby.labyAPI().getUniqueId(), tag, consumer);
}

public static void setTag(UUID uuid, String tag, Consumer<ApiResponse> consumer) {
ApiRequest request = new ApiRequest(
Method.POST,
"/players/" + uuid,
Util.getSessionToken()
) {
@Override
public Map<String, Object> getBody() {
return Map.of("tag", tag);
}
};
request.sendAsyncRequest((response -> {
if(!request.isSuccessful()) {
consumer.accept(new ApiResponse(false, request.getError()));
return;
}
TagCache.clear();
TagCache.resolveSelf((info) -> consumer.accept(new ApiResponse(true, request.getMessage())));
}));
}

public static void setPosition(PositionType position, Consumer<ApiResponse> consumer) {
setPosition(Laby.labyAPI().getUniqueId(), position, consumer);
}

public static void setPosition(UUID uuid, PositionType position, Consumer<ApiResponse> consumer) {
ApiRequest request = new ApiRequest(
Method.POST,
"/players/" + uuid + "/position",
Util.getSessionToken()
) {
@Override
public Map<String, Object> getBody() {
return Map.of("position", position.name().split("_")[0]);
}
};
request.sendAsyncRequest((response) -> {
if(!request.isSuccessful()) {
consumer.accept(new ApiResponse(false, request.getError()));
return;
}
TagCache.clear();
TagCache.resolveSelf((info) -> consumer.accept(new ApiResponse(true, request.getMessage())));
});
}

public static void setIcon(GlobalIcon icon, Consumer<ApiResponse> consumer) {
setIcon(Laby.labyAPI().getUniqueId(), icon, consumer);
}

public static void setIcon(UUID uuid, GlobalIcon icon, Consumer<ApiResponse> consumer) {
ApiRequest request = new ApiRequest(
Method.POST,
"/players/" + uuid + "/icon",
Util.getSessionToken()
) {
@Override
public Map<String, Object> getBody() {
return Map.of("icon", icon.name());
}
};
request.sendAsyncRequest((response) -> {
if(!request.isSuccessful()) {
consumer.accept(new ApiResponse(false, request.getError()));
return;
}
TagCache.clear();
TagCache.resolveSelf((info) -> consumer.accept(new ApiResponse(true, request.getMessage())));
});
}

public static void resetTag(Consumer<ApiResponse> consumer) {
resetTag(Laby.labyAPI().getUniqueId(), consumer);
}

public static void resetTag(UUID uuid, Consumer<ApiResponse> consumer) {
ApiRequest request = new ApiRequest(
Method.DELETE,
"/players/" + uuid,
Util.getSessionToken()
) {
@Override
public Map<String, Object> getBody() {
// https://github.com/elysiajs/elysia/issues/495
return emptyBody;
}
};
request.sendAsyncRequest((response) -> {
if(!request.isSuccessful()) {
consumer.accept(new ApiResponse(false, request.getError()));
return;
}
TagCache.clear();
TagCache.resolveSelf((info) -> consumer.accept(new ApiResponse(true, request.getMessage())));
});
}

public static void reportPlayer(UUID uuid, String reason, Consumer<ApiResponse> consumer) {
ApiRequest request = new ApiRequest(
Method.POST,
"/players/" + uuid + "/report",
Util.getSessionToken()
) {
@Override
public Map<String, Object> getBody() {
return Map.of("reason", reason);
}
};
request.sendAsyncRequest((response) -> {
if(!request.isSuccessful()) {
consumer.accept(new ApiResponse(false, request.getError()));
return;
}
consumer.accept(new ApiResponse(true, request.getMessage()));
});
}

public static void banPlayer(UUID uuid, String reason, Consumer<ApiResponse> consumer) {
ApiRequest request = new ApiRequest(
Method.POST,
"/players/" + uuid + "/ban",
Util.getSessionToken()
) {
@Override
public Map<String, Object> getBody() {
return Map.of("reason", reason);
}
};
request.sendAsyncRequest((response) -> {
if(!request.isSuccessful()) {
consumer.accept(new ApiResponse(false, request.getError()));
return;
}
TagCache.clear();
TagCache.resolveSelf((info) -> consumer.accept(new ApiResponse(true, request.getMessage())));
});
}

public static void unbanPlayer(UUID uuid, Consumer<ApiResponse> consumer) {
ApiRequest request = new ApiRequest(
Method.DELETE,
"/players/" + uuid + "/ban",
Util.getSessionToken()
) {
@Override
public Map<String, Object> getBody() {
// https://github.com/elysiajs/elysia/issues/495
return emptyBody;
}
};
request.sendAsyncRequest((response) -> {
if(!request.isSuccessful()) {
consumer.accept(new ApiResponse(false, request.getError()));
return;
}
TagCache.clear();
TagCache.resolveSelf((info) -> consumer.accept(new ApiResponse(true, request.getMessage())));
});
}

public static void editBan(UUID uuid, Suspension suspension, Consumer<ApiResponse> consumer) {
ApiRequest request = new ApiRequest(
Method.PUT,
"/players/" + uuid + "/ban",
Util.getSessionToken()
) {
@Override
public Map<String, Object> getBody() {
Objects.requireNonNull(suspension.getReason(), "Reason must not be null");
return Map.of("reason", suspension.getReason(), "appealable", suspension.isAppealable());
}
};
request.sendAsyncRequest((response) -> {
if(!request.isSuccessful()) {
consumer.accept(new ApiResponse(false, request.getError()));
return;
}
TagCache.clear();
TagCache.resolveSelf((info) -> consumer.accept(new ApiResponse(true, request.getMessage())));
});
}

public static void appealBan(String reason, Consumer<ApiResponse> consumer) {
ApiRequest request = new ApiRequest(
Method.POST,
"/players/" + Laby.labyAPI().getUniqueId() + "/ban/appeal",
Util.getSessionToken()
) {
@Override
public Map<String, Object> getBody() {
return Map.of("reason", reason);
}
};
request.sendAsyncRequest((response) -> {
if(!request.isSuccessful()) {
consumer.accept(new ApiResponse(false, request.getError()));
return;
}
consumer.accept(new ApiResponse(true, request.getMessage()));
});
}

public static void toggleAdmin(UUID uuid, Consumer<ApiResponse> consumer) {
ApiRequest request = new ApiRequest(
Method.POST,
"/players/" + uuid + "/admin",
Util.getSessionToken()
) {
@Override
public Map<String, Object> getBody() {
// https://github.com/elysiajs/elysia/issues/495
return emptyBody;
}
};
request.sendAsyncRequest((response) -> {
if(!request.isSuccessful()) {
consumer.accept(new ApiResponse(false, request.getError()));
return;
}
TagCache.clear();
TagCache.resolveSelf((info) -> consumer.accept(new ApiResponse(true, request.getMessage())));
});
}

public static void linkDiscord(Consumer<ApiResponse> consumer) {
ApiRequest request = new ApiRequest(
Method.POST,
"/players/" + Laby.labyAPI().getUniqueId() + "/connections/discord",
Util.getSessionToken()
) {
@Override
public Map<String, Object> getBody() {
// https://github.com/elysiajs/elysia/issues/495
return emptyBody;
}
};
request.sendAsyncRequest((response) -> {
if(!request.isSuccessful()) {
consumer.accept(new ApiResponse(false, request.getError()));
return;
}
TagCache.clear();
TagCache.resolveSelf((info) -> consumer.accept(new ApiResponse(true, request.responseBody.code)));
});
}

public static void unlinkDiscord(Consumer<ApiResponse> consumer) {
ApiRequest request = new ApiRequest(
Method.DELETE,
"/players/" + Laby.labyAPI().getUniqueId() + "/connections/discord",
Util.getSessionToken()
) {
@Override
public Map<String, Object> getBody() {
// https://github.com/elysiajs/elysia/issues/495
return emptyBody;
}
};
request.sendAsyncRequest((response) -> {
if(!request.isSuccessful()) {
consumer.accept(new ApiResponse(false, request.getError()));
return;
}
TagCache.clear();
TagCache.resolveSelf((info) -> consumer.accept(new ApiResponse(true, request.getMessage())));
});
}

public static class ApiResponse {

private final boolean successful;
private final Component message;

public ApiResponse(boolean successful, String message) {
this.successful = successful;
this.message = Component.text(message, successful ? NamedTextColor.GREEN : NamedTextColor.RED);
}

public boolean isSuccessful() {
return successful;
}

public Component getMessage() {
return message;
}
}
}
Loading
Loading