Tidy patches & rename RemovedConfig to TransferringConfig
This commit is contained in:
@@ -7,7 +7,6 @@ Co-authored by: violetc <58360096+s-yh-china@users.noreply.github.com>
|
||||
As part of: Leaves (https://github.com/LeavesMC/Leaves/blob/master/leaves-api/paper-patches/features/0008-Fix-SculkCatalyst-exp-skip.patch)
|
||||
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
|
||||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/event/entity/PlayerDeathEvent.java b/src/main/java/org/bukkit/event/entity/PlayerDeathEvent.java
|
||||
index ab7584873e46020148bceecbd42a43055684e6a0..f33ab20313310a113d6c88e0fc1fe1666218061e 100644
|
||||
--- a/src/main/java/org/bukkit/event/entity/PlayerDeathEvent.java
|
||||
|
||||
@@ -129,23 +129,23 @@
|
||||
+ final Object currentValue = field.get(null);
|
||||
+
|
||||
+ if (!configFileInstance.contains(fullConfigKeyName)){
|
||||
+ for (RemovedConfig removedConfig : field.getAnnotationsByType(RemovedConfig.class)) {
|
||||
+ final String oldConfigKeyName = String.join(".", removedConfig.category()) + "." + removedConfig.name();
|
||||
+ for (TransferringConfig transferringConfig : field.getAnnotationsByType(TransferringConfig.class)) {
|
||||
+ final String oldConfigKeyName = String.join(".", transferringConfig.category()) + "." + transferringConfig.name();
|
||||
+ Object oldValue = configFileInstance.get(oldConfigKeyName);
|
||||
+ if (oldValue != null) {
|
||||
+ boolean success = true;
|
||||
+ if (removedConfig.transfer()) {
|
||||
+ if (transferringConfig.transfer()) {
|
||||
+ try {
|
||||
+ Object oldValueTransferred = ((BasicTransferLogic)removedConfig.transferLogic().getDeclaredConstructor().newInstance()).transform(oldValue);
|
||||
+ Object oldValueTransferred = ((BasicTransferLogic) transferringConfig.transferLogic().getDeclaredConstructor().newInstance()).transform(oldValue);
|
||||
+ configFileInstance.add(fullConfigKeyName, oldValueTransferred);
|
||||
+ } catch (Exception e) {
|
||||
+ success = false;
|
||||
+ logger.error("Failed to transfer removed config {}!", removedConfig.name());
|
||||
+ logger.error("Failed to transfer removed config {}!", transferringConfig.name());
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ if (success) {
|
||||
+ removeConfig(oldConfigKeyName, removedConfig.category());
|
||||
+ removeConfig(oldConfigKeyName, transferringConfig.category());
|
||||
+ }
|
||||
+ final String comments = configInfo.comments();
|
||||
+
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/me/earthme/luminol/config/RemovedConfig.java
|
||||
+++ b/src/main/java/me/earthme/luminol/config/TransferringConfig.java
|
||||
@@ -1,0 +_,20 @@
|
||||
+package me.earthme.luminol.config;
|
||||
+
|
||||
+import java.lang.annotation.*;
|
||||
+
|
||||
+@Retention(RetentionPolicy.RUNTIME)
|
||||
+@Repeatable(RemovedConfig.List.class)
|
||||
+public @interface RemovedConfig {
|
||||
+@Repeatable(TransferringConfig.List.class)
|
||||
+public @interface TransferringConfig {
|
||||
+ String name() default "";
|
||||
+
|
||||
+ String[] category() default "";
|
||||
@@ -18,6 +18,6 @@
|
||||
+
|
||||
+ @Retention(RetentionPolicy.RUNTIME)
|
||||
+ @interface List {
|
||||
+ RemovedConfig[] value();
|
||||
+ TransferringConfig[] value();
|
||||
+ }
|
||||
+}
|
||||
Reference in New Issue
Block a user