Skip to content

Commit 7ba4b0e

Browse files
authored
Merge pull request #36 from Innectic/feature/group-ladders
Feature/group ladders
2 parents 79e8a58 + 5e012d1 commit 7ba4b0e

File tree

22 files changed

+596
-135
lines changed

22 files changed

+596
-135
lines changed

API/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,11 @@
1010

1111
<artifactId>PermissifyAPI</artifactId>
1212

13+
<dependencies>
14+
<dependency>
15+
<groupId>com.google.code.gson</groupId>
16+
<artifactId>gson</artifactId>
17+
<version>2.8.0</version>
18+
</dependency>
19+
</dependencies>
1320
</project>

API/src/main/java/me/innectic/permissify/api/PermissifyConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
public class PermissifyConstants {
3838
// TODO: Create a language formatter to allow for translating.
3939

40+
public static final int PERMISSIFY_PROFILE_VERSION = 2;
41+
4042
// Chat messages
4143
private static final String PERMISSIFY_PREFIX = "&a&lPermissify> ";
4244

API/src/main/java/me/innectic/permissify/api/database/DatabaseHandler.java

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
package me.innectic.permissify.api.database;
2626

2727
import lombok.Getter;
28-
import lombok.Setter;
29-
import me.innectic.permissify.api.permission.Permission;
30-
import me.innectic.permissify.api.permission.PermissionGroup;
28+
import me.innectic.permissify.api.group.Permission;
29+
import me.innectic.permissify.api.group.group.PermissionGroup;
30+
import me.innectic.permissify.api.group.ladder.AbstractLadder;
3131
import me.innectic.permissify.api.profile.PermissifyProfile;
3232

3333
import java.util.*;
@@ -41,10 +41,12 @@
4141
public abstract class DatabaseHandler {
4242

4343
@Getter protected Map<UUID, List<Permission>> cachedPermissions = new HashMap<>();
44-
@Getter protected List<PermissionGroup> cachedGroups = new ArrayList<>();
44+
@Getter protected Map<String, PermissionGroup> cachedGroups = new HashMap<>();
4545
@Getter protected Optional<PermissionGroup> defaultGroup = Optional.empty();
46+
@Getter protected Map<String, AbstractLadder> cachedLadders = new HashMap<>();
4647
@Getter protected final Optional<ConnectionInformation> connectionInformation;
4748
@Getter protected List<UUID> superAdmins = new ArrayList<>();
49+
// Revisit: Maybe different default formatters?
4850
protected String chatFormat = "{group} {username}: {message}";
4951
protected String whisperFormat = "{senderGroup} {username} > {receiverGroup} {to}: {message}";
5052

@@ -71,6 +73,21 @@ public DatabaseHandler(ConnectionInformation connectionInformation) {
7173
*/
7274
public abstract void reload(List<UUID> onlinePlayers);
7375

76+
/**
77+
* Load all groups
78+
*/
79+
protected abstract void loadGroups();
80+
81+
/**
82+
* Load all ladders
83+
*/
84+
protected abstract void loadLadders();
85+
86+
/**
87+
* Load all super admins
88+
*/
89+
protected abstract void loadSuperAdmins();
90+
7491
/**
7592
* Drop all values from the handler.
7693
*/
@@ -165,7 +182,7 @@ public DatabaseHandler(ConnectionInformation connectionInformation) {
165182
*
166183
* @return the registered permission groups
167184
*/
168-
public abstract List<PermissionGroup> getGroups();
185+
public abstract Map<String, PermissionGroup> getGroups();
169186

170187
/**
171188
* Get all permission groups a player is in.
@@ -239,6 +256,13 @@ public DatabaseHandler(ConnectionInformation connectionInformation) {
239256
*/
240257
public abstract boolean isSuperAdmin(UUID uuid);
241258

259+
/***
260+
* Remove a superadmin.
261+
*
262+
* @param uuid the uuid of the player to remove
263+
*/
264+
public abstract void removeSuperAdmin(UUID uuid);
265+
242266
/**
243267
* Set the format for chat messages
244268
*
@@ -275,4 +299,20 @@ public DatabaseHandler(ConnectionInformation connectionInformation) {
275299
* @param group the new group to become the default.
276300
*/
277301
public abstract void setDefaultGroup(PermissionGroup group);
302+
303+
/**
304+
* Set the ladder of a group.
305+
*
306+
* @param group the name of the group
307+
* @param ladder the ladder to add to the group
308+
*/
309+
public abstract void setGroupLadder(String group, AbstractLadder ladder);
310+
311+
/**
312+
* Get the current ladder of a group.
313+
*
314+
* @param group the name of the group to get the ladder from
315+
* @return the ladder, if present.
316+
*/
317+
public abstract Optional<AbstractLadder> getGroupLadder(String group);
278318
}

API/src/main/java/me/innectic/permissify/api/database/handlers/SQLHandler.java

Lines changed: 178 additions & 70 deletions
Large diffs are not rendered by default.

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2323
* SOFTWARE.
2424
*/
25-
package me.innectic.permissify.api.permission;
25+
package me.innectic.permissify.api.group;
2626

2727
import lombok.AllArgsConstructor;
2828
import lombok.Getter;
@@ -35,7 +35,15 @@
3535
* @since 6/8/2017
3636
*/
3737
@AllArgsConstructor
38-
public class Permission implements Serializable {
38+
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/permission/PermissionGroup.java renamed to API/src/main/java/me/innectic/permissify/api/group/group/PermissionGroup.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@
2222
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2323
* SOFTWARE.
2424
*/
25-
package me.innectic.permissify.api.permission;
25+
package me.innectic.permissify.api.group.group;
2626

2727
import lombok.Getter;
28+
import lombok.NonNull;
2829
import lombok.RequiredArgsConstructor;
2930
import lombok.Setter;
31+
import me.innectic.permissify.api.group.Permission;
32+
import me.innectic.permissify.api.group.ladder.AbstractLadder;
3033

3134
import java.io.Serializable;
3235
import java.util.*;
@@ -36,11 +39,12 @@
3639
* @since 6/14/2017
3740
*/
3841
@RequiredArgsConstructor
39-
public class PermissionGroup implements Serializable {
42+
public class PermissionGroup {
4043
@Getter private final String name;
4144
@Getter private final String chatColor;
4245
@Getter private final String prefix;
4346
@Getter private final String suffix;
47+
@NonNull @Getter @Setter private AbstractLadder ladder;
4448
@Getter private List<Permission> permissions = new ArrayList<>();
4549
@Getter private Map<UUID, Boolean> players = new HashMap<>();
4650

@@ -88,4 +92,17 @@ public boolean isPrimaryGroup(UUID uuid) {
8892
public void setPrimaryGroup(UUID uuid, boolean isPrimary) {
8993
players.put(uuid, isPrimary);
9094
}
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+
}
91108
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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 lombok.Getter;
28+
29+
import java.util.*;
30+
31+
/**
32+
* @author Innectic
33+
* @since 9/1/2017
34+
*/
35+
public abstract class AbstractLadder {
36+
@Getter protected Map<UUID, Integer> players = new HashMap<>();
37+
@Getter protected List<LadderLevel> levels = new ArrayList<>();
38+
39+
public final void reset() {
40+
drop();
41+
registerLadders();
42+
}
43+
44+
private void drop() {
45+
players = new HashMap<>();
46+
levels = new ArrayList<>();
47+
}
48+
49+
public abstract void registerLadders();
50+
51+
public final void addPlayer(UUID uuid, int position) {
52+
players.put(uuid, position);
53+
// TODO: Apply extra permissions
54+
}
55+
56+
public final void removePlayer(UUID uuid) {
57+
if (players.containsKey(uuid)) players.remove(uuid);
58+
// TODO: Remove extra permissions
59+
}
60+
61+
@Override
62+
public String toString() {
63+
return "AbstractLadder [" +
64+
"players=" + players +
65+
", levels=" + levels +
66+
"]";
67+
}
68+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 ladder, Type type, JsonSerializationContext context) {
38+
JsonObject result = new JsonObject();
39+
result.add("type", new JsonPrimitive(ladder.getClass().getSimpleName()));
40+
result.add("data", context.serialize(ladder, ladder.getClass()));
41+
return result;
42+
}
43+
44+
@Override
45+
public AbstractLadder deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
46+
JsonObject jsonObject = json.getAsJsonObject();
47+
String typeName = 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: " + typeName, e);
53+
}
54+
}
55+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 lombok.AllArgsConstructor;
28+
import lombok.Getter;
29+
30+
import java.util.Optional;
31+
32+
/**
33+
* @author Innectic
34+
* @since 9/1/2017
35+
*/
36+
@AllArgsConstructor
37+
public class LadderLevel {
38+
@Getter private int power;
39+
@Getter private Optional<String> displayName;
40+
41+
@Override
42+
public String toString() {
43+
return "LadderLevel [" +
44+
"power=" + power +
45+
", displayName=" + displayName +
46+
"]";
47+
}
48+
}

0 commit comments

Comments
 (0)