Skip to content

Commit

Permalink
Merge pull request #15 from ELDEpendenci/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
eric2788 authored Mar 30, 2022
2 parents a378e84 + ede2c58 commit f2a78a9
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 73 deletions.
22 changes: 19 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ jobs:
- name: Checkout Source Code
id: checkout-source
uses: actions/checkout@v2
- name: Set up JDK 11
- name: Set up JDK 16
id: setup-java
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 16
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Delete tag and release
Expand All @@ -39,7 +39,7 @@ jobs:
tag_name: ${{ env.version }}
release_name: Release ${{ github.repository }}-${{ env.version }}
body: |
(寫下你的更新)
版本更新請到[這裏](https://eric2788.gitbook.io/eldependenci-mvc/references/update/v0.1.3)查看。
draft: false
prerelease: false
- name: Upload Release jar
Expand All @@ -56,3 +56,19 @@ jobs:
with:
use-maven: true
javadocs: javadocs

publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v2
with:
java-version: '16'
distribution: 'adopt'
- name: Publish package
run: mvn --batch-mode deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9 changes: 8 additions & 1 deletion ELDependenci-MVC-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ELDependenci-MVC-Module</artifactId>
<artifactId>eldependenci-mvc-module</artifactId>
<groupId>org.eldependenci</groupId>
<version>0.1.3</version>
</parent>
Expand Down Expand Up @@ -43,6 +43,13 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

public static <C> PersistentDataType<?, C> getPersistentDataType(Class<C> type){
public static <C> PersistentDataType<?, C> getPersistentDataType(Class<C> type) {
if (type.isInterface()) throw new IllegalStateException("type cannot be interface");
if (PRIMITIVE_MAP.containsKey(type)) return (PersistentDataType<?, C>) PRIMITIVE_MAP.get(type);
return (PersistentDataType<?, C>) GENERIC_DATA_TYPE;
}
public static PersistentDataType<byte[], Object> getPersistentDataType(){

public static PersistentDataType<byte[], Object> getPersistentDataType() {
return GENERIC_DATA_TYPE;
}

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

public static Map<String, Object> reflectToMap(Object model) {
try {
return OBJECT_MAPPER.convertValue(model, new TypeReference<>() {});
}catch (Exception e){
return OBJECT_MAPPER.convertValue(model, new TypeReference<>() {
});
} catch (Exception e) {
return Map.of();
}
}

public static <T> T mapToObject(Map<String, Object> map, Class<T> beanClass) {
T obj;
try {
obj = beanClass.getConstructor().newInstance();
}catch (InvocationTargetException | InstantiationException e) {
obj = beanClass.getConstructor().newInstance();
} catch (InvocationTargetException | InstantiationException e) {
throw new IllegalStateException(e);
} catch (IllegalAccessException e) {
throw new IllegalStateException("The no arg constructor is private of type: "+beanClass);
throw new IllegalStateException("The no arg constructor is private of type: " + beanClass);
} catch (NoSuchMethodException e) {
throw new IllegalStateException("Cannot find no arg constructor on type: "+beanClass);
throw new IllegalStateException("Cannot find no arg constructor on type: " + beanClass);
}
Field[] fields = beanClass.getDeclaredFields();
for (Field field : fields) {
int mod = field.getModifiers();
if (Modifier.isFinal(mod) || Modifier.isStatic(mod) || field.isAnnotationPresent(JsonIgnore.class)){
if (Modifier.isFinal(mod) || Modifier.isStatic(mod) || field.isAnnotationPresent(JsonIgnore.class)) {
continue;
}
field.setAccessible(true);
Object value = map.get(field.getName());
if (value instanceof Map<?, ?> && field.getType() != Map.class){
if (value instanceof Map<?, ?> && field.getType() != Map.class) {
Map<String, Object> m = (Map<String, Object>) value;
value = mapToObject(m, field.getType());
}
if (value == null && field.isAnnotationPresent(Nonnull.class)){
if (value == null && field.isAnnotationPresent(NotNull.class)) {
throw new IllegalStateException("property assigned @Nonnull but setting null value.");
}
try {
field.set(obj, value);
}catch (IllegalAccessException e) {
LOGGER.warn("Error while setting field "+field.getName()+" to "+value+", type: "+field.getType(), e);
} catch (IllegalAccessException e) {
LOGGER.warn("Error while setting field " + field.getName() + " to " + value + ", type: " + field.getType(), e);
}
}
return obj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.jetbrains.annotations.Nullable;

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

private final static Map<Class<? extends Number>, MathCalculate<? extends Number>> valueMap = new ConcurrentHashMap<>();
private static <N extends Number> void addNumberType(Class<N> type, MathCalculate<N> math){

private static <N extends Number> void addNumberType(Class<N> type, MathCalculate<N> math) {
valueMap.put(type, math);
}

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

addNumberType(Byte.class, new MathCalculate<>(
(a, b) -> (byte)(a + b),
(a, b) -> (byte)(a - b),
(a, b) -> (byte) (a + b),
(a, b) -> (byte) (a - b),
Number::byteValue,
(value, max) -> value > max,
(value, min) -> value < min,
Expand Down Expand Up @@ -157,7 +158,8 @@ public void callBack(AsyncChatEvent event) {
String msg = ((TextComponent) event.message()).content();
try {
T value = math.parseNum.apply(msg);
if (math.smallerThan.apply(value, min) || math.biggerThan.apply(value, max)) throw new NumberFormatException();
if (math.smallerThan.apply(value, min) || math.biggerThan.apply(value, max))
throw new NumberFormatException();
this.updateValue(value);
} catch (NumberFormatException e) {
event.getPlayer().sendMessage(errorMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import com.ericlam.mc.eldgui.view.View;
import com.ericlam.mc.eldgui.view.ViewDescriptor;
import org.bukkit.Material;

import javax.annotation.Nullable;
import org.jetbrains.annotations.Nullable;


@ViewDescriptor(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.ericlam.mc.eldgui.event;

import org.bukkit.event.inventory.InventoryEvent;
import org.jetbrains.annotations.Nullable;

import javax.annotation.Nullable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.ericlam.mc.eldgui.event;

import org.bukkit.event.inventory.InventoryEvent;
import org.jetbrains.annotations.Nullable;

import javax.annotation.Nullable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

Expand Down
2 changes: 1 addition & 1 deletion eldependenci-mvc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ELDependenci-MVC-Module</artifactId>
<artifactId>eldependenci-mvc-module</artifactId>
<groupId>org.eldependenci</groupId>
<version>0.1.3</version>
</parent>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.ericlam.mc.eldgui;

import javax.annotation.Nullable;
import org.jetbrains.annotations.Nullable;

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

/**
* 透過 key 獲取數據
*
* @param key 鍵
* @param <T> 數據類型
* @return 數據,可爲 null
*/
@Nullable
<T> T getAttribute(String key);
@Nullable <T> T getAttribute(String key);

/**
* 透過 key 提取數據並在 Session 中刪除
*
* @param key 鍵
* @param <T> 數據類型
* @return 數據,可爲 null
*/
@Nullable
<T> T pollAttribute(String key);
@Nullable <T> T pollAttribute(String key);

/**
* 設置數據到 Session
* @param key 鍵
*
* @param key 鍵
* @param value 數值
*/
void setAttribute(String key, Object value);



}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.ericlam.mc.eldgui.component;

import org.bukkit.inventory.ItemStack;

import javax.annotation.Nullable;
import org.jetbrains.annotations.Nullable;

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

/**
* 設置屬性
*
* @param itemStack 物品
* @param key 鍵
* @param value 數值
* @param key
* @param value 數值
*/
void setAttribute(ItemStack itemStack, String key, Object value);

/**
* 設置 該 pattern 内所有物品的屬性
*
* @param pattern pattern
* @param key 鍵
* @param value 數值
* @param key
* @param value 數值
*/
void setAttribute(char pattern, String key, Object value);

/**
* 獲取物品的屬性
*
* @param item 物品
* @param key 鍵
* @param <C> 獲取類型
* @param key
* @param <C> 獲取類型
* @return 數值
*/
@Nullable
<C> C getAttribute(ItemStack item, String key);
@Nullable <C> C getAttribute(ItemStack item, String key);

}
Loading

0 comments on commit f2a78a9

Please sign in to comment.