Skip to content
This repository was archived by the owner on Feb 19, 2019. It is now read-only.

Commit 1dc2239

Browse files
committed
Created Color Value Type
1 parent 1345e65 commit 1dc2239

File tree

7 files changed

+123
-8
lines changed

7 files changed

+123
-8
lines changed

src/main/java/clientapi/value/Values.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ private Values() {}
5959
define(MultiValue.class, ResolverData.create(new MultiTypeResolver(), String.class));
6060
define(StringValue.class, ResolverData.create(new StringTypeResolver(), String.class));
6161
define(EnumValue.class, ResolverData.create(new EnumTypeResolver(), Enum.class));
62+
define(ColorValue.class, ResolverData.create(new ColorTypeResolver(), Integer.class, Integer.TYPE));
6263
}
6364

6465
/**
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2018 ImpactDevelopment
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package clientapi.value.annotation;
18+
19+
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Retention;
21+
import java.lang.annotation.RetentionPolicy;
22+
import java.lang.annotation.Target;
23+
24+
/**
25+
* Annotation used to mark fields as Color Values
26+
*
27+
* @author Brady
28+
* @since 4/11/2018 11:26 AM
29+
*/
30+
@Retention(RetentionPolicy.RUNTIME)
31+
@Target(ElementType.FIELD)
32+
@ValueDefinition
33+
public @interface ColorValue {}

src/main/java/clientapi/value/type/BooleanType.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ public BooleanType(String name, String parent, String id, String description, Ob
3636
super(name, parent, id, description, object, field);
3737
}
3838

39-
@Override
40-
public final void onEnable() {}
41-
42-
@Override
43-
public final void onDisable() {}
44-
4539
@Override
4640
public final void setState(boolean state) {
4741
this.setValue(state);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2018 ImpactDevelopment
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package clientapi.value.type;
18+
19+
import clientapi.value.Value;
20+
import clientapi.value.annotation.ColorValue;
21+
22+
import java.lang.reflect.Field;
23+
24+
/**
25+
* Basic type for Color values
26+
*
27+
* @see ColorValue
28+
*
29+
* @author Brady
30+
* @since 4/11/2018 11:27 AM
31+
*/
32+
public final class ColorType extends Value<Integer> {
33+
34+
public ColorType(String name, String parent, String id, String description, Object object, Field field) {
35+
super(name, parent, id, description, object, field);
36+
}
37+
}

src/main/java/clientapi/value/type/EnumType.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@
1717
package clientapi.value.type;
1818

1919
import clientapi.value.Value;
20+
import clientapi.value.annotation.EnumValue;
2021
import org.apache.commons.lang3.ArrayUtils;
2122

2223
import java.lang.reflect.Field;
2324

2425
/**
26+
* Basic type for Enum values
27+
*
28+
* @see EnumValue
29+
*
2530
* @author Brady
2631
* @since 12/1/2017 7:12 PM
2732
*/

src/main/java/clientapi/value/type/resolve/ResolverData.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public final boolean isResolvable(Class<?> type) {
6767
return true;
6868

6969
// Otherwise, find a type that matches
70-
for (Class<?> rType : resolvableTypes)
71-
if (rType.isAssignableFrom(type))
70+
for (Class<?> resolvableType : resolvableTypes)
71+
if (resolvableType.isAssignableFrom(type))
7272
return true;
7373

7474
return false;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2018 ImpactDevelopment
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package clientapi.value.type.resolve.impl;
18+
19+
import clientapi.util.ReflectionUtils;
20+
import clientapi.util.annotation.Label;
21+
import clientapi.value.type.ColorType;
22+
import clientapi.value.type.resolve.TypeResolver;
23+
24+
import java.lang.reflect.Field;
25+
26+
/**
27+
* Default implementation of {@code TypeResolver} used to parse {@code ColorType} fields
28+
*
29+
* @author Brady
30+
* @since 4/11/2018 11:27 AM
31+
*/
32+
public final class ColorTypeResolver implements TypeResolver<ColorType> {
33+
34+
@Override
35+
public final ColorType resolve(Object parent, Field field) {
36+
Label label = field.getAnnotation(Label.class);
37+
Integer value = (Integer) ReflectionUtils.getField(parent, field);
38+
if (value == null)
39+
value = 0xFFFFFFFF;
40+
41+
ColorType type = new ColorType(label.name(), label.parent(), label.id(), label.description(), parent, field);
42+
type.setValue(value);
43+
return type;
44+
}
45+
}

0 commit comments

Comments
 (0)