Skip to content

Commit 54c1254

Browse files
committed
This ACTUALLY fixed loading / saving. Git didn't commit it all
1 parent 64d635b commit 54c1254

File tree

9 files changed

+109
-17
lines changed

9 files changed

+109
-17
lines changed

API/src/main/java/me/innectic/permissify/api/group/Permission.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,12 @@
3838
public class Permission {
3939
@Getter private String permission;
4040
@Getter @Setter private boolean granted;
41+
42+
@Override
43+
public String toString() {
44+
return "Permission [" +
45+
"permission=" + permission +
46+
", granted=" + granted +
47+
"]";
48+
}
4149
}

API/src/main/java/me/innectic/permissify/api/group/group/PermissionGroup.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,17 @@ public boolean isPrimaryGroup(UUID uuid) {
9292
public void setPrimaryGroup(UUID uuid, boolean isPrimary) {
9393
players.put(uuid, isPrimary);
9494
}
95+
96+
@Override
97+
public String toString() {
98+
return "PermissionGroup [" +
99+
"name=" + name +
100+
", chatColor=" + chatColor +
101+
", prefix=" + prefix +
102+
", suffix=" + suffix +
103+
", ladder=" + ladder +
104+
", permissions=" + permissions +
105+
", players=" + players +
106+
" ]";
107+
}
95108
}

API/src/main/java/me/innectic/permissify/api/group/ladder/AbstractLadder.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import lombok.Getter;
2828

29-
import java.io.Serializable;
3029
import java.util.*;
3130

3231
/**
@@ -48,4 +47,12 @@ public final void drop() {
4847
}
4948

5049
public abstract void registerLadders();
50+
51+
@Override
52+
public String toString() {
53+
return "AbstractLadder [" +
54+
"players=" + players +
55+
", levels=" + levels +
56+
"]";
57+
}
5158
}
Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,55 @@
1-
package me.innectic.permissify.api.group.ladder;
2-
3-
/**
4-
* @author Innectic
5-
* @since 9/2/2017
6-
*/
7-
public class LadderAdapter {
8-
}
1+
/*
2+
*
3+
* This file is part of Permissify, licensed under the MIT License (MIT).
4+
* Copyright (c) Innectic
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
* SOFTWARE.
24+
*/
25+
package me.innectic.permissify.api.group.ladder;
26+
27+
import com.google.gson.*;
28+
import java.lang.reflect.Type;
29+
30+
/**
31+
* @author Innectic
32+
* @since 8/26/2017
33+
*/
34+
public class LadderAdapter implements JsonSerializer<AbstractLadder>, JsonDeserializer<AbstractLadder> {
35+
36+
@Override
37+
public JsonElement serialize(AbstractLadder src, Type typeOfSrc, JsonSerializationContext context) {
38+
JsonObject result = new JsonObject();
39+
result.add("type", new JsonPrimitive(src.getClass().getSimpleName()));
40+
result.add("data", context.serialize(src, src.getClass()));
41+
return result;
42+
}
43+
44+
@Override
45+
public AbstractLadder deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
46+
JsonObject jsonObject = json.getAsJsonObject();
47+
String type = jsonObject.get("type").getAsString();
48+
JsonElement element = jsonObject.get("data");
49+
try {
50+
return context.deserialize(element, Class.forName("me.innectic.permissify.api.group.ladder.impl." + type));
51+
} catch (ClassNotFoundException e) {
52+
throw new JsonParseException("Unknown element type: " + type, e);
53+
}
54+
}
55+
}

API/src/main/java/me/innectic/permissify/api/group/ladder/LadderLevel.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,22 @@
2727
import lombok.AllArgsConstructor;
2828
import lombok.Getter;
2929

30-
import java.io.Serializable;
3130
import java.util.Optional;
3231

3332
/**
3433
* @author Innectic
3534
* @since 9/1/2017
3635
*/
3736
@AllArgsConstructor
38-
public class LadderLevel implements Serializable {
37+
public class LadderLevel {
3938
@Getter private int power;
4039
@Getter private Optional<String> displayName;
40+
41+
@Override
42+
public String toString() {
43+
return "LadderLevel [" +
44+
"power=" + power +
45+
", displayName=" + displayName +
46+
"]";
47+
}
4148
}

API/src/main/java/me/innectic/permissify/api/group/ladder/impl/DefaultLadder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2222
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2323
* SOFTWARE.
24-
*/
25-
package me.innectic.permissify.api.group.ladder.impl;
24+
*/package me.innectic.permissify.api.group.ladder.impl;
2625

2726
import me.innectic.permissify.api.group.ladder.AbstractLadder;
2827
import me.innectic.permissify.api.group.ladder.LadderLevel;

API/src/main/java/me/innectic/permissify/api/profile/PermissifyProfile.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ public class PermissifyProfile {
5050

5151
@Override
5252
public String toString() {
53-
return "PermissifyProfile {" +
53+
return "PermissifyProfile [" +
5454
"groups=" + groups +
5555
", playerPermissions=" + playerPermissions +
5656
", defaultGroup=" + defaultGroup +
5757
", chatFormat=" + chatFormat +
5858
", whisperFormat=" + whisperFormat +
5959
", superAdmins=" + superAdmins +
6060
", version=" + version +
61-
" }";
61+
" ]";
6262
}
6363
}

API/src/main/java/me/innectic/permissify/api/profile/ProfileSerializer.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@
2525
package me.innectic.permissify.api.profile;
2626

2727
import com.google.gson.Gson;
28+
import com.google.gson.GsonBuilder;
29+
import me.innectic.permissify.api.group.ladder.AbstractLadder;
30+
import me.innectic.permissify.api.group.ladder.LadderAdapter;
31+
import me.innectic.permissify.api.group.ladder.impl.DefaultLadder;
2832

2933
import java.io.*;
34+
import java.lang.reflect.Type;
3035
import java.nio.charset.Charset;
3136
import java.nio.file.Files;
3237
import java.nio.file.Path;
@@ -39,7 +44,13 @@
3944
*/
4045
public class ProfileSerializer {
4146

42-
private Gson gson = new Gson();
47+
private final Gson gson;
48+
49+
public ProfileSerializer() {
50+
GsonBuilder gsonBuilder = new GsonBuilder();
51+
gsonBuilder.registerTypeAdapter(AbstractLadder.class, new LadderAdapter());
52+
gson = gsonBuilder.create();
53+
}
4354

4455
/**
4556
* Serialize a permissify profile into a permissify profile file

Spigot/src/main/java/me/innectic/permissify/spigot/commands/permissify/ProfileCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private CommandResponse handleLoadProfile(CommandSender sender, String[] args) {
6666
if (!PermissifyMain.getInstance().getPermissifyAPI().getDatabaseHandler().isPresent())
6767
return new CommandResponse(PermissifyConstants.UNABLE_TO_SET.replace("<REASON>", "No database handler"), false);
6868

69-
boolean saved = saveProfile(args[0] + "-" + Long.toString(System.currentTimeMillis()) + "-pre-load");
69+
boolean saved = saveProfile(args[0] + "-pre-load");
7070
if (!saved) return new CommandResponse(PermissifyConstants.PROFILE_NOT_SAVED.replace("<PROFILE>", args[0]), false);
7171

7272
DatabaseHandler handler = PermissifyMain.getInstance().getPermissifyAPI().getDatabaseHandler().get();

0 commit comments

Comments
 (0)