-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
71540f4
commit 7f023d7
Showing
5 changed files
with
167 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,4 +119,5 @@ run/ | |
.console_history | ||
logs | ||
kbc.yml | ||
plugins | ||
plugins | ||
permissions.json |
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
66 changes: 66 additions & 0 deletions
66
src/main/java/snw/kookbc/impl/permissions/UserPermissionSaved.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,66 @@ | ||
/* | ||
* KookBC -- The Kook Bot Client & JKook API standard implementation for Java. | ||
* Copyright (C) 2022 - 2023 KookBC contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package snw.kookbc.impl.permissions; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import com.google.gson.reflect.TypeToken; | ||
import snw.jkook.permissions.PermissionAttachmentInfo; | ||
|
||
import java.util.*; | ||
|
||
public class UserPermissionSaved { | ||
private final String uid; | ||
private final Map<String, Boolean> permissions; | ||
|
||
public UserPermissionSaved(String uid, Map<String, Boolean> permissions) { | ||
this.uid = uid; | ||
this.permissions = permissions; | ||
} | ||
|
||
public UserPermissionSaved(String uid, Set<PermissionAttachmentInfo> attachmentInfos) { | ||
this.uid = uid; | ||
this.permissions = new HashMap<>(); | ||
attachmentInfos.forEach(permissionAttachmentInfo -> { | ||
this.permissions.put(permissionAttachmentInfo.getPermission().toLowerCase(Locale.ENGLISH), permissionAttachmentInfo.getValue()); | ||
}); | ||
} | ||
|
||
public String getUid() { | ||
return uid; | ||
} | ||
|
||
public Map<String, Boolean> getPermissions() { | ||
return permissions; | ||
} | ||
|
||
public static final Gson GSON = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create(); | ||
|
||
public static String toString(UserPermissionSaved... array) { | ||
return GSON.toJson(array); | ||
} | ||
|
||
public static UserPermissionSaved parse(String json) { | ||
return GSON.fromJson(json, UserPermissionSaved.class); | ||
} | ||
|
||
public static List<UserPermissionSaved> parseList(String json) { | ||
return GSON.fromJson(json, new TypeToken<List<UserPermissionSaved>>() { | ||
}); | ||
} | ||
} |