From 33e2aa773f790544293068f9b5223dd7ba3ed40e Mon Sep 17 00:00:00 2001 From: eric2788 Date: Wed, 30 Mar 2022 20:50:55 +0800 Subject: [PATCH 1/2] upload repo to github maven pkg --- .github/workflows/publish.yml | 22 +++++++++++++-- ELDependenci-MVC-plugin/pom.xml | 9 +++++- eldependenci-mvc/pom.xml | 2 +- pom.xml | 49 ++++++++++++++------------------- 4 files changed, 49 insertions(+), 33 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 311ec2c..2641dec 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -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 @@ -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 @@ -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 }} diff --git a/ELDependenci-MVC-plugin/pom.xml b/ELDependenci-MVC-plugin/pom.xml index b0ec2dd..5aa1715 100644 --- a/ELDependenci-MVC-plugin/pom.xml +++ b/ELDependenci-MVC-plugin/pom.xml @@ -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"> - ELDependenci-MVC-Module + eldependenci-mvc-module org.eldependenci 0.1.3 @@ -43,6 +43,13 @@ org.apache.maven.plugins maven-shade-plugin + + org.apache.maven.plugins + maven-deploy-plugin + + true + + diff --git a/eldependenci-mvc/pom.xml b/eldependenci-mvc/pom.xml index 59d9ae7..17af3e5 100644 --- a/eldependenci-mvc/pom.xml +++ b/eldependenci-mvc/pom.xml @@ -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"> - ELDependenci-MVC-Module + eldependenci-mvc-module org.eldependenci 0.1.3 diff --git a/pom.xml b/pom.xml index faad1cd..9d85cdb 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.eldependenci - ELDependenci-MVC-Module + eldependenci-mvc-module pom 0.1.3 @@ -19,24 +19,16 @@ https://papermc.io/repo/repository/maven-public/ - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - chu77 - https://nexus.chu77.xyz/repository/plugins/ + github + https://maven.pkg.github.com/ELDependenci/eldependenci - com.destroystokyo.paper - paper-api - - + org.eldependenci eldependenci-framework @@ -45,18 +37,6 @@ - - org.spigotmc - spigot-api - 1.16.5-R0.1-SNAPSHOT - provided - - - com.destroystokyo.paper - paper-api - 1.16.5-R0.1-SNAPSHOT - provided - io.papermc.paper paper-api @@ -66,13 +46,13 @@ org.eldependenci eldependenci-framework - 0.1.4 + 0.1.5 provided org.eldependenci eldependenci-addon - 0.1.3 + 0.1.5 provided @@ -146,8 +126,8 @@ maven-compiler-plugin 3.8.1 - 11 - 11 + 16 + 16 UTF-8 @@ -164,6 +144,11 @@ + + org.apache.maven.plugins + maven-deploy-plugin + 3.0.0-M2 + @@ -179,4 +164,12 @@ + + + github + https://maven.pkg.github.com/ELDependenci/eldependenci-mvc + false + + + \ No newline at end of file From ede2c58d9ca4b144db39dab5e2f73464bbfabd72 Mon Sep 17 00:00:00 2001 From: eric2788 Date: Wed, 30 Mar 2022 20:56:44 +0800 Subject: [PATCH 2/2] fix nullable --- .../ericlam/mc/eldgui/PersistDataUtils.java | 29 ++++++++++--------- .../mc/eldgui/component/NumInputField.java | 12 ++++---- .../mc/eldgui/demo/user/UserUpdateView.java | 3 +- .../mc/eldgui/event/MethodParseManager.java | 2 +- .../ericlam/mc/eldgui/event/MethodParser.java | 2 +- .../java/com/ericlam/mc/eldgui/UISession.java | 14 ++++----- .../eldgui/component/AttributeController.java | 21 +++++++------- 7 files changed, 43 insertions(+), 40 deletions(-) diff --git a/ELDependenci-MVC-plugin/src/main/java/com/ericlam/mc/eldgui/PersistDataUtils.java b/ELDependenci-MVC-plugin/src/main/java/com/ericlam/mc/eldgui/PersistDataUtils.java index 01f7c24..10bda22 100644 --- a/ELDependenci-MVC-plugin/src/main/java/com/ericlam/mc/eldgui/PersistDataUtils.java +++ b/ELDependenci-MVC-plugin/src/main/java/com/ericlam/mc/eldgui/PersistDataUtils.java @@ -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; @@ -33,12 +32,13 @@ public class PersistDataUtils { public static final PersistentDataType MAP_DATA_TYPE = new MapDataType(); private static final Map, PersistentDataType> PRIMITIVE_MAP = new ConcurrentHashMap<>(); - public static PersistentDataType getPersistentDataType(Class type){ + public static PersistentDataType getPersistentDataType(Class type) { if (type.isInterface()) throw new IllegalStateException("type cannot be interface"); if (PRIMITIVE_MAP.containsKey(type)) return (PersistentDataType) PRIMITIVE_MAP.get(type); return (PersistentDataType) GENERIC_DATA_TYPE; } - public static PersistentDataType getPersistentDataType(){ + + public static PersistentDataType getPersistentDataType() { return GENERIC_DATA_TYPE; } @@ -118,8 +118,9 @@ public static class GenericDataType implements PersistentDataType 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(); } } @@ -127,33 +128,33 @@ public static Map reflectToMap(Object model) { public static T mapToObject(Map map, Class 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 m = (Map) 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; diff --git a/ELDependenci-MVC-plugin/src/main/java/com/ericlam/mc/eldgui/component/NumInputField.java b/ELDependenci-MVC-plugin/src/main/java/com/ericlam/mc/eldgui/component/NumInputField.java index ccfb498..082efc0 100644 --- a/ELDependenci-MVC-plugin/src/main/java/com/ericlam/mc/eldgui/component/NumInputField.java +++ b/ELDependenci-MVC-plugin/src/main/java/com/ericlam/mc/eldgui/component/NumInputField.java @@ -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; @@ -22,7 +22,8 @@ public final class NumInputField extends AbstractComponent implements Clickable, Listenable { private final static Map, MathCalculate> valueMap = new ConcurrentHashMap<>(); - private static void addNumberType(Class type, MathCalculate math){ + + private static void addNumberType(Class type, MathCalculate math) { valueMap.put(type, math); } @@ -73,8 +74,8 @@ private static void addNumberType(Class 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, @@ -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); diff --git a/ELDependenci-MVC-plugin/src/main/java/com/ericlam/mc/eldgui/demo/user/UserUpdateView.java b/ELDependenci-MVC-plugin/src/main/java/com/ericlam/mc/eldgui/demo/user/UserUpdateView.java index 49e2ea1..ceaf168 100644 --- a/ELDependenci-MVC-plugin/src/main/java/com/ericlam/mc/eldgui/demo/user/UserUpdateView.java +++ b/ELDependenci-MVC-plugin/src/main/java/com/ericlam/mc/eldgui/demo/user/UserUpdateView.java @@ -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( diff --git a/ELDependenci-MVC-plugin/src/main/java/com/ericlam/mc/eldgui/event/MethodParseManager.java b/ELDependenci-MVC-plugin/src/main/java/com/ericlam/mc/eldgui/event/MethodParseManager.java index b46bab9..ffb14e4 100644 --- a/ELDependenci-MVC-plugin/src/main/java/com/ericlam/mc/eldgui/event/MethodParseManager.java +++ b/ELDependenci-MVC-plugin/src/main/java/com/ericlam/mc/eldgui/event/MethodParseManager.java @@ -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; diff --git a/ELDependenci-MVC-plugin/src/main/java/com/ericlam/mc/eldgui/event/MethodParser.java b/ELDependenci-MVC-plugin/src/main/java/com/ericlam/mc/eldgui/event/MethodParser.java index 3fc4726..6836f24 100644 --- a/ELDependenci-MVC-plugin/src/main/java/com/ericlam/mc/eldgui/event/MethodParser.java +++ b/ELDependenci-MVC-plugin/src/main/java/com/ericlam/mc/eldgui/event/MethodParser.java @@ -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; diff --git a/eldependenci-mvc/src/main/java/com/ericlam/mc/eldgui/UISession.java b/eldependenci-mvc/src/main/java/com/ericlam/mc/eldgui/UISession.java index 8ad69f2..0ada82c 100644 --- a/eldependenci-mvc/src/main/java/com/ericlam/mc/eldgui/UISession.java +++ b/eldependenci-mvc/src/main/java/com/ericlam/mc/eldgui/UISession.java @@ -1,6 +1,6 @@ package com.ericlam.mc.eldgui; -import javax.annotation.Nullable; +import org.jetbrains.annotations.Nullable; /** * 玩家在打開界面到關閉界面時的數據容器,用於在各個 Controller 之間傳遞資料用 @@ -9,29 +9,29 @@ public interface UISession { /** * 透過 key 獲取數據 + * * @param key 鍵 * @param 數據類型 * @return 數據,可爲 null */ - @Nullable - T getAttribute(String key); + @Nullable T getAttribute(String key); /** * 透過 key 提取數據並在 Session 中刪除 + * * @param key 鍵 * @param 數據類型 * @return 數據,可爲 null */ - @Nullable - T pollAttribute(String key); + @Nullable T pollAttribute(String key); /** * 設置數據到 Session - * @param key 鍵 + * + * @param key 鍵 * @param value 數值 */ void setAttribute(String key, Object value); - } diff --git a/eldependenci-mvc/src/main/java/com/ericlam/mc/eldgui/component/AttributeController.java b/eldependenci-mvc/src/main/java/com/ericlam/mc/eldgui/component/AttributeController.java index 0a84059..b7bce59 100644 --- a/eldependenci-mvc/src/main/java/com/ericlam/mc/eldgui/component/AttributeController.java +++ b/eldependenci-mvc/src/main/java/com/ericlam/mc/eldgui/component/AttributeController.java @@ -1,8 +1,7 @@ package com.ericlam.mc.eldgui.component; import org.bukkit.inventory.ItemStack; - -import javax.annotation.Nullable; +import org.jetbrains.annotations.Nullable; /** * 物品屬性編輯器 @@ -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 獲取類型 + * @param key 鍵 + * @param 獲取類型 * @return 數值 */ - @Nullable - C getAttribute(ItemStack item, String key); + @Nullable C getAttribute(ItemStack item, String key); }