Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/releases/1.21' into releases/1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
Gu-ZT committed Sep 17, 2024
2 parents 6869cab + 121fe39 commit 4f92ceb
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/java/dev/anvilcraft/rg/api/RGRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,21 @@ public static void checkSerialize(@NotNull String str) {
// 使用正则表达式匹配驼峰命名法中的大写字母,并在其前添加下划线,然后将整个字符串转换为小写
return str.replaceAll("([a-z])([A-Z]+)", "$1_$2").toLowerCase();
}

/**
* 设置字段的值
*
* @param value 要设置的字段值
* @throws RGRuleException 当值无法被设置时抛出异常
*/
@SuppressWarnings("unchecked")
public void setFieldValue(T value) {
try {
if (this.validator.validate((T) this.field.get(null), value)) {
this.field.set(null, value);
}
} catch (IllegalAccessException e) {
throw new RGRuleException("Illegal value: %s", value);
}
}
}

0 comments on commit 4f92ceb

Please sign in to comment.