Code Duplication    Length = 21-28 lines in 2 locations

common/src/main/java/net/labymod/serverapi/Addons.java 1 location

@@ 18-45 (lines=28) @@
15
     * @param jsonObject the json object of the message
16
     * @return a list containing the message's addons
17
     */
18
    public static List<Addon> getAddons( JsonObject jsonObject ) {
19
        if ( !jsonObject.has( "addons" ) || !jsonObject.get( "addons" ).isJsonArray() )
20
            return new ArrayList<>();
21
22
        List<Addon> addons = new ArrayList<>();
23
24
        for ( JsonElement arrayElement : jsonObject.get( "addons" ).getAsJsonArray() ) {
25
            if ( !arrayElement.isJsonObject() )
26
                continue;
27
28
            JsonObject arrayObject = arrayElement.getAsJsonObject();
29
30
            if ( !arrayObject.has( "uuid" ) || !arrayObject.get( "uuid" ).isJsonPrimitive() || !arrayObject.get( "uuid" ).getAsJsonPrimitive().isString()
31
                    || !arrayObject.has( "name" ) || !arrayObject.get( "name" ).isJsonPrimitive() || !arrayObject.get( "name" ).getAsJsonPrimitive().isString() )
32
                continue;
33
34
            UUID uuid = null;
35
36
            try {
37
                uuid = UUID.fromString( arrayObject.get( "uuid" ).getAsString() );
38
            } catch ( IllegalArgumentException ex ) {
39
                continue;
40
            }
41
42
            addons.add( new Addon( uuid, arrayObject.get( "name" ).getAsString() ) );
43
        }
44
45
        return addons;
46
    }
47
}
48

common/src/main/java/net/labymod/serverapi/Addon.java 1 location

@@ 33-53 (lines=21) @@
30
     * @param jsonObject the json object of the message
31
     * @return a list containing the message's addons
32
     */
33
    @Deprecated
34
    public static List<Addon> getAddons( JsonObject jsonObject ) {
35
        if ( !jsonObject.has( "addons" ) || !jsonObject.get( "addons" ).isJsonArray() )
36
            return Collections.emptyList();
37
38
        List<Addon> addons = new ArrayList<>();
39
40
        for ( JsonElement arrayElement : jsonObject.get( "addons" ).getAsJsonArray() ) {
41
            if ( !arrayElement.isJsonObject() )
42
                continue;
43
44
            JsonObject arrayObject = arrayElement.getAsJsonObject();
45
46
            if ( !arrayObject.has( "uuid" ) || !arrayObject.get( "uuid" ).isJsonPrimitive() || !arrayObject.get( "uuid" ).getAsJsonPrimitive().isString()
47
                    || !arrayObject.has( "name" ) || !arrayObject.get( "name" ).isJsonPrimitive() || !arrayObject.get( "name" ).getAsJsonPrimitive().isString() )
48
            continue;
49
50
            addons.add( new Addon( UUID.fromString( arrayObject.get( "uuid" ).getAsString() ), arrayObject.get( "name" ).getAsString() ) );
51
        }
52
53
        return addons;
54
    }
55
56
}