mirror of
https://github.com/CarmJos/EasyPlugin.git
synced 2026-06-05 00:58:17 +08:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9d97837a24 | |||
| 2efdc5f5a6 | |||
| 19f25db0b7 |
+1
-1
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<version>1.5.6</version>
|
||||
<version>1.5.8</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<properties>
|
||||
|
||||
@@ -162,9 +162,14 @@ public class ColorParser {
|
||||
startColor.getBlue() + bStep * i * bDirection
|
||||
)).toArray(String[]::new);
|
||||
|
||||
return IntStream.range(0, characters.length)
|
||||
.mapToObj(i -> colorText(characters[i], extraFormats.get(i), buildHexColor(hexes[i])))
|
||||
.collect(Collectors.joining());
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String extra = null;
|
||||
for (int i = 0; i < characters.length; i++) {
|
||||
extra = buildExtraFormat(extra, extraFormats.get(i));
|
||||
String s = colorText(characters[i], extra, buildHexColor(hexes[i]));
|
||||
sb.append(s);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
protected static String gradientText(@NotNull String text, @Nullable String startHex, @Nullable String endHex) {
|
||||
@@ -205,4 +210,13 @@ public class ColorParser {
|
||||
.collect(Collectors.joining("", '§' + "x", ""));
|
||||
}
|
||||
|
||||
protected static String buildExtraFormat(String current, String extra) {
|
||||
if (extra != null) current = (current == null ? "" : current) + extra;
|
||||
return isResetCode(current) ? null : current;
|
||||
}
|
||||
|
||||
protected static boolean isResetCode(String input) {
|
||||
return input != null && (input.toLowerCase().endsWith("&r") || input.toLowerCase().endsWith("§r"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,7 +15,7 @@ public class ColorParseTest {
|
||||
System.out.println(parseGradientColor("&<#AAAAAA>我真的&<#BBBBBB>爱死&<#111111>你&<#FFFFFF>!"));
|
||||
|
||||
// 测试穿插
|
||||
System.out.println(parse("&<#AAAAAA>&l我&r真&b的&<#BBBBBB>&o爱死&<#111111>你&<#FFFFFF>了&r!"));
|
||||
System.out.println(parse("&<#AAAAAA>&l&m我真的&o尊的&r真的&<#BBBBBB>&o爱死&<#111111>你&<#FFFFFF>了&r!"));
|
||||
System.out.println(parse("&<#AAAAAA>&l我&r真&(#666666)的&<#BBBBBB>&o爱死&<#111111>你&<#FFFFFF>了&r!"));
|
||||
System.out.println(parse("&r正常的颜色理应&c&l不受影响&r。"));
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<version>1.5.6</version>
|
||||
<version>1.5.8</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<properties>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.5.6</version>
|
||||
<version>1.5.8</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.5.6</version>
|
||||
<version>1.5.8</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.5.6</version>
|
||||
<version>1.5.8</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<version>1.5.6</version>
|
||||
<version>1.5.8</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<properties>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.5.6</version>
|
||||
<version>1.5.8</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<version>1.5.6</version>
|
||||
<version>1.5.8</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<properties>
|
||||
|
||||
@@ -63,7 +63,11 @@ public abstract class UserDataManager<K, U extends UserData<K>> {
|
||||
return key.toString();
|
||||
}
|
||||
|
||||
public abstract @NotNull U empty(@NotNull K key);
|
||||
public abstract @NotNull U emptyUser(@NotNull K key);
|
||||
|
||||
public @NotNull U errorUser(@NotNull K key) {
|
||||
return emptyUser(key);
|
||||
}
|
||||
|
||||
protected abstract @Nullable U loadData(@NotNull K key) throws Exception;
|
||||
|
||||
@@ -108,7 +112,7 @@ public abstract class UserDataManager<K, U extends UserData<K>> {
|
||||
U data = loadData(key);
|
||||
if (data == null) {
|
||||
getPlugin().debug("数据库内不存在用户 " + identifier + " 的数据,视作新档案。");
|
||||
return empty(key);
|
||||
return emptyUser(key);
|
||||
} else {
|
||||
getPlugin().debug("加载用户 " + identifier + " 的数据完成,耗时 " + (System.currentTimeMillis() - s1) + " ms.");
|
||||
return data;
|
||||
@@ -116,7 +120,7 @@ public abstract class UserDataManager<K, U extends UserData<K>> {
|
||||
} catch (Exception ex) {
|
||||
getPlugin().error("加载用户 " + serializeKey(key) + " 数据失败,请检查相关配置!");
|
||||
ex.printStackTrace();
|
||||
return empty(key);
|
||||
return errorUser(key);
|
||||
}
|
||||
|
||||
}, executor).thenApply((data) -> {
|
||||
@@ -223,22 +227,23 @@ public abstract class UserDataManager<K, U extends UserData<K>> {
|
||||
return loadGroup(allKeys, (v) -> false);
|
||||
}
|
||||
|
||||
public @NotNull CompletableFuture<Integer> saveAll() {
|
||||
CompletableFuture<Integer> future = CompletableFuture.completedFuture(0);
|
||||
if (getDataCache().isEmpty()) return future;
|
||||
|
||||
for (U value : getDataCache().values()) {
|
||||
future = future.thenCombine(save(value), (before, result) -> before + (result ? 1 : 0));
|
||||
public void saveAll() {
|
||||
if (getDataCache().isEmpty()) return;
|
||||
for (U u : getDataCache().values()) {
|
||||
try {
|
||||
saveData(u);
|
||||
} catch (Exception e) {
|
||||
getPlugin().error("保存用户 " + serializeKey(u.getKey()) + " 数据失败,请检查相关配置!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return future;
|
||||
}
|
||||
|
||||
public @NotNull CompletableFuture<Integer> unloadAll() {
|
||||
return saveAll().thenApply(result -> {
|
||||
getDataCache().clear();
|
||||
return result;
|
||||
});
|
||||
public int unloadAll(boolean save) {
|
||||
if (save) saveAll();
|
||||
int size = getDataCache().size();
|
||||
getDataCache().clear();
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.5.6</version>
|
||||
<version>1.5.8</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.5.6</version>
|
||||
<version>1.5.8</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.5.6</version>
|
||||
<version>1.5.8</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.5.6</version>
|
||||
<version>1.5.8</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.5.6</version>
|
||||
<version>1.5.8</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.5.6</version>
|
||||
<version>1.5.8</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.5.6</version>
|
||||
<version>1.5.8</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
Reference in New Issue
Block a user