Skip to content

Commit f2a78a9

Browse files
authored
Merge pull request #15 from ELDEpendenci/develop
Develop
2 parents a378e84 + ede2c58 commit f2a78a9

File tree

11 files changed

+92
-73
lines changed

11 files changed

+92
-73
lines changed

.github/workflows/publish.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ jobs:
1919
- name: Checkout Source Code
2020
id: checkout-source
2121
uses: actions/checkout@v2
22-
- name: Set up JDK 11
22+
- name: Set up JDK 16
2323
id: setup-java
2424
uses: actions/setup-java@v1
2525
with:
26-
java-version: 11
26+
java-version: 16
2727
- name: Build with Maven
2828
run: mvn -B package --file pom.xml
2929
- name: Delete tag and release
@@ -39,7 +39,7 @@ jobs:
3939
tag_name: ${{ env.version }}
4040
release_name: Release ${{ github.repository }}-${{ env.version }}
4141
body: |
42-
(寫下你的更新)
42+
版本更新請到[這裏](https://eric2788.gitbook.io/eldependenci-mvc/references/update/v0.1.3)查看。
4343
draft: false
4444
prerelease: false
4545
- name: Upload Release jar
@@ -56,3 +56,19 @@ jobs:
5656
with:
5757
use-maven: true
5858
javadocs: javadocs
59+
60+
publish:
61+
runs-on: ubuntu-latest
62+
permissions:
63+
contents: read
64+
packages: write
65+
steps:
66+
- uses: actions/checkout@v2
67+
- uses: actions/setup-java@v2
68+
with:
69+
java-version: '16'
70+
distribution: 'adopt'
71+
- name: Publish package
72+
run: mvn --batch-mode deploy
73+
env:
74+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

ELDependenci-MVC-plugin/pom.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns="http://maven.apache.org/POM/4.0.0"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<parent>
6-
<artifactId>ELDependenci-MVC-Module</artifactId>
6+
<artifactId>eldependenci-mvc-module</artifactId>
77
<groupId>org.eldependenci</groupId>
88
<version>0.1.3</version>
99
</parent>
@@ -43,6 +43,13 @@
4343
<groupId>org.apache.maven.plugins</groupId>
4444
<artifactId>maven-shade-plugin</artifactId>
4545
</plugin>
46+
<plugin>
47+
<groupId>org.apache.maven.plugins</groupId>
48+
<artifactId>maven-deploy-plugin</artifactId>
49+
<configuration>
50+
<skip>true</skip>
51+
</configuration>
52+
</plugin>
4653
</plugins>
4754
</build>
4855

ELDependenci-MVC-plugin/src/main/java/com/ericlam/mc/eldgui/PersistDataUtils.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.slf4j.Logger;
1313
import org.slf4j.LoggerFactory;
1414

15-
import javax.annotation.Nonnull;
1615
import java.io.IOException;
1716
import java.lang.reflect.Field;
1817
import java.lang.reflect.InvocationTargetException;
@@ -33,12 +32,13 @@ public class PersistDataUtils {
3332
public static final PersistentDataType<String, Map> MAP_DATA_TYPE = new MapDataType();
3433
private static final Map<Class<?>, PersistentDataType<?, ?>> PRIMITIVE_MAP = new ConcurrentHashMap<>();
3534

36-
public static <C> PersistentDataType<?, C> getPersistentDataType(Class<C> type){
35+
public static <C> PersistentDataType<?, C> getPersistentDataType(Class<C> type) {
3736
if (type.isInterface()) throw new IllegalStateException("type cannot be interface");
3837
if (PRIMITIVE_MAP.containsKey(type)) return (PersistentDataType<?, C>) PRIMITIVE_MAP.get(type);
3938
return (PersistentDataType<?, C>) GENERIC_DATA_TYPE;
4039
}
41-
public static PersistentDataType<byte[], Object> getPersistentDataType(){
40+
41+
public static PersistentDataType<byte[], Object> getPersistentDataType() {
4242
return GENERIC_DATA_TYPE;
4343
}
4444

@@ -118,42 +118,43 @@ public static class GenericDataType implements PersistentDataType<byte[], Object
118118

119119
public static Map<String, Object> reflectToMap(Object model) {
120120
try {
121-
return OBJECT_MAPPER.convertValue(model, new TypeReference<>() {});
122-
}catch (Exception e){
121+
return OBJECT_MAPPER.convertValue(model, new TypeReference<>() {
122+
});
123+
} catch (Exception e) {
123124
return Map.of();
124125
}
125126
}
126127

127128
public static <T> T mapToObject(Map<String, Object> map, Class<T> beanClass) {
128129
T obj;
129130
try {
130-
obj = beanClass.getConstructor().newInstance();
131-
}catch (InvocationTargetException | InstantiationException e) {
131+
obj = beanClass.getConstructor().newInstance();
132+
} catch (InvocationTargetException | InstantiationException e) {
132133
throw new IllegalStateException(e);
133134
} catch (IllegalAccessException e) {
134-
throw new IllegalStateException("The no arg constructor is private of type: "+beanClass);
135+
throw new IllegalStateException("The no arg constructor is private of type: " + beanClass);
135136
} catch (NoSuchMethodException e) {
136-
throw new IllegalStateException("Cannot find no arg constructor on type: "+beanClass);
137+
throw new IllegalStateException("Cannot find no arg constructor on type: " + beanClass);
137138
}
138139
Field[] fields = beanClass.getDeclaredFields();
139140
for (Field field : fields) {
140141
int mod = field.getModifiers();
141-
if (Modifier.isFinal(mod) || Modifier.isStatic(mod) || field.isAnnotationPresent(JsonIgnore.class)){
142+
if (Modifier.isFinal(mod) || Modifier.isStatic(mod) || field.isAnnotationPresent(JsonIgnore.class)) {
142143
continue;
143144
}
144145
field.setAccessible(true);
145146
Object value = map.get(field.getName());
146-
if (value instanceof Map<?, ?> && field.getType() != Map.class){
147+
if (value instanceof Map<?, ?> && field.getType() != Map.class) {
147148
Map<String, Object> m = (Map<String, Object>) value;
148149
value = mapToObject(m, field.getType());
149150
}
150-
if (value == null && field.isAnnotationPresent(Nonnull.class)){
151+
if (value == null && field.isAnnotationPresent(NotNull.class)) {
151152
throw new IllegalStateException("property assigned @Nonnull but setting null value.");
152153
}
153154
try {
154155
field.set(obj, value);
155-
}catch (IllegalAccessException e) {
156-
LOGGER.warn("Error while setting field "+field.getName()+" to "+value+", type: "+field.getType(), e);
156+
} catch (IllegalAccessException e) {
157+
LOGGER.warn("Error while setting field " + field.getName() + " to " + value + ", type: " + field.getType(), e);
157158
}
158159
}
159160
return obj;

ELDependenci-MVC-plugin/src/main/java/com/ericlam/mc/eldgui/component/NumInputField.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import org.bukkit.entity.Player;
1010
import org.bukkit.event.inventory.ClickType;
1111
import org.bukkit.event.inventory.InventoryClickEvent;
12+
import org.jetbrains.annotations.Nullable;
1213

13-
import javax.annotation.Nullable;
1414
import java.util.List;
1515
import java.util.Map;
1616
import java.util.Objects;
@@ -22,7 +22,8 @@
2222
public final class NumInputField<T extends Number> extends AbstractComponent implements Clickable, Listenable<AsyncChatEvent> {
2323

2424
private final static Map<Class<? extends Number>, MathCalculate<? extends Number>> valueMap = new ConcurrentHashMap<>();
25-
private static <N extends Number> void addNumberType(Class<N> type, MathCalculate<N> math){
25+
26+
private static <N extends Number> void addNumberType(Class<N> type, MathCalculate<N> math) {
2627
valueMap.put(type, math);
2728
}
2829

@@ -73,8 +74,8 @@ private static <N extends Number> void addNumberType(Class<N> type, MathCalculat
7374
));
7475

7576
addNumberType(Byte.class, new MathCalculate<>(
76-
(a, b) -> (byte)(a + b),
77-
(a, b) -> (byte)(a - b),
77+
(a, b) -> (byte) (a + b),
78+
(a, b) -> (byte) (a - b),
7879
Number::byteValue,
7980
(value, max) -> value > max,
8081
(value, min) -> value < min,
@@ -157,7 +158,8 @@ public void callBack(AsyncChatEvent event) {
157158
String msg = ((TextComponent) event.message()).content();
158159
try {
159160
T value = math.parseNum.apply(msg);
160-
if (math.smallerThan.apply(value, min) || math.biggerThan.apply(value, max)) throw new NumberFormatException();
161+
if (math.smallerThan.apply(value, min) || math.biggerThan.apply(value, max))
162+
throw new NumberFormatException();
161163
this.updateValue(value);
162164
} catch (NumberFormatException e) {
163165
event.getPlayer().sendMessage(errorMessage);

ELDependenci-MVC-plugin/src/main/java/com/ericlam/mc/eldgui/demo/user/UserUpdateView.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
import com.ericlam.mc.eldgui.view.View;
99
import com.ericlam.mc.eldgui.view.ViewDescriptor;
1010
import org.bukkit.Material;
11-
12-
import javax.annotation.Nullable;
11+
import org.jetbrains.annotations.Nullable;
1312

1413

1514
@ViewDescriptor(

ELDependenci-MVC-plugin/src/main/java/com/ericlam/mc/eldgui/event/MethodParseManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.ericlam.mc.eldgui.event;
22

33
import org.bukkit.event.inventory.InventoryEvent;
4+
import org.jetbrains.annotations.Nullable;
45

5-
import javax.annotation.Nullable;
66
import java.lang.annotation.Annotation;
77
import java.lang.reflect.Method;
88
import java.lang.reflect.Type;

ELDependenci-MVC-plugin/src/main/java/com/ericlam/mc/eldgui/event/MethodParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.ericlam.mc.eldgui.event;
22

33
import org.bukkit.event.inventory.InventoryEvent;
4+
import org.jetbrains.annotations.Nullable;
45

5-
import javax.annotation.Nullable;
66
import java.lang.annotation.Annotation;
77
import java.lang.reflect.Type;
88

eldependenci-mvc/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns="http://maven.apache.org/POM/4.0.0"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<parent>
6-
<artifactId>ELDependenci-MVC-Module</artifactId>
6+
<artifactId>eldependenci-mvc-module</artifactId>
77
<groupId>org.eldependenci</groupId>
88
<version>0.1.3</version>
99
</parent>
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.ericlam.mc.eldgui;
22

3-
import javax.annotation.Nullable;
3+
import org.jetbrains.annotations.Nullable;
44

55
/**
66
* 玩家在打開界面到關閉界面時的數據容器,用於在各個 Controller 之間傳遞資料用
@@ -9,29 +9,29 @@ public interface UISession {
99

1010
/**
1111
* 透過 key 獲取數據
12+
*
1213
* @param key 鍵
1314
* @param <T> 數據類型
1415
* @return 數據,可爲 null
1516
*/
16-
@Nullable
17-
<T> T getAttribute(String key);
17+
@Nullable <T> T getAttribute(String key);
1818

1919
/**
2020
* 透過 key 提取數據並在 Session 中刪除
21+
*
2122
* @param key 鍵
2223
* @param <T> 數據類型
2324
* @return 數據,可爲 null
2425
*/
25-
@Nullable
26-
<T> T pollAttribute(String key);
26+
@Nullable <T> T pollAttribute(String key);
2727

2828
/**
2929
* 設置數據到 Session
30-
* @param key 鍵
30+
*
31+
* @param key 鍵
3132
* @param value 數值
3233
*/
3334
void setAttribute(String key, Object value);
3435

3536

36-
3737
}
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package com.ericlam.mc.eldgui.component;
22

33
import org.bukkit.inventory.ItemStack;
4-
5-
import javax.annotation.Nullable;
4+
import org.jetbrains.annotations.Nullable;
65

76
/**
87
* 物品屬性編輯器
@@ -20,28 +19,30 @@ public interface AttributeController {
2019

2120
/**
2221
* 設置屬性
22+
*
2323
* @param itemStack 物品
24-
* @param key 鍵
25-
* @param value 數值
24+
* @param key
25+
* @param value 數值
2626
*/
2727
void setAttribute(ItemStack itemStack, String key, Object value);
2828

2929
/**
3030
* 設置 該 pattern 内所有物品的屬性
31+
*
3132
* @param pattern pattern
32-
* @param key 鍵
33-
* @param value 數值
33+
* @param key
34+
* @param value 數值
3435
*/
3536
void setAttribute(char pattern, String key, Object value);
3637

3738
/**
3839
* 獲取物品的屬性
40+
*
3941
* @param item 物品
40-
* @param key 鍵
41-
* @param <C> 獲取類型
42+
* @param key
43+
* @param <C> 獲取類型
4244
* @return 數值
4345
*/
44-
@Nullable
45-
<C> C getAttribute(ItemStack item, String key);
46+
@Nullable <C> C getAttribute(ItemStack item, String key);
4647

4748
}

0 commit comments

Comments
 (0)