diff --git a/mirai-core/src/main/java/net/mamoe/mirai/Robot.java b/mirai-core/src/main/java/net/mamoe/mirai/Robot.java index 9ee465ae8..890daf7db 100644 --- a/mirai-core/src/main/java/net/mamoe/mirai/Robot.java +++ b/mirai-core/src/main/java/net/mamoe/mirai/Robot.java @@ -12,7 +12,7 @@ public class Robot { private final int qq; private final String password; - private final RobotNetworkHandler handler ; + private final RobotNetworkHandler handler; /** * Ref list @@ -20,7 +20,7 @@ public class Robot { @Getter private final List owners; - public boolean isOwnBy(String ownerName){ + public boolean isOwnBy(String ownerName) { return owners.contains(ownerName); } @@ -29,28 +29,28 @@ public class Robot { this( data.getIntOrThrow("account", () -> new Exception("can not parse QQ account")), data.getStringOrThrow("password", () -> new Exception("can not parse QQ password")), - data.getAsOrDefault("owners",new ArrayList<>()) + data.getAsOrDefault("owners", ArrayList::new) ); } - public Robot(int qq, String password, List owners){ + public Robot(int qq, String password, List owners) { this.qq = qq; this.password = password; this.owners = Collections.unmodifiableList(owners); - this.handler = new RobotNetworkHandler(this.qq,this.password); + this.handler = new RobotNetworkHandler(this.qq, this.password); } - public void connect(){ + public void connect() { } - public void onPacketReceive(){ + public void onPacketReceive() { } diff --git a/mirai-core/src/main/java/net/mamoe/mirai/network/RobotNetworkHandler.kt b/mirai-core/src/main/java/net/mamoe/mirai/network/RobotNetworkHandler.kt index 594fad924..88796bd9d 100644 --- a/mirai-core/src/main/java/net/mamoe/mirai/network/RobotNetworkHandler.kt +++ b/mirai-core/src/main/java/net/mamoe/mirai/network/RobotNetworkHandler.kt @@ -18,7 +18,7 @@ import java.net.InetSocketAddress import java.util.* /** - * A robotNetworkHandler account. + * A RobotNetworkHandler is used to connect with Tencent servers. * * @author Him188moe */ diff --git a/mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiConfigSection.java b/mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiConfigSection.java index a7c150919..196ddd59a 100644 --- a/mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiConfigSection.java +++ b/mirai-core/src/main/java/net/mamoe/mirai/utils/config/MiraiConfigSection.java @@ -1,10 +1,11 @@ package net.mamoe.mirai.utils.config; + import org.jetbrains.annotations.Nullable; -import java.util.IllegalFormatException; import java.util.LinkedHashMap; import java.util.Map; import java.util.concurrent.Callable; +import java.util.function.Supplier; public class MiraiConfigSection extends MiraiSynchronizedLinkedListMap { @@ -12,18 +13,18 @@ public class MiraiConfigSection extends MiraiSynchronizedLinkedListMap map){ - super(map); + public MiraiConfigSection(Map copyOfMap) { + super(new LinkedHashMap<>(copyOfMap)); } public int getInt(String key){ - return Integer.valueOf(this.get(key).toString()); + return Integer.parseInt(this.get(key).toString()); } public int getIntOrDefault(String key, int defaultV){ Object result = this.getOrDefault(key, null); try { - return result == null ? defaultV : Integer.valueOf(result.toString()); + return result == null ? defaultV : Integer.parseInt(result.toString()); }catch (NumberFormatException ignored){ return defaultV; } @@ -35,20 +36,20 @@ public class MiraiConfigSection extends MiraiSynchronizedLinkedListMap extends MiraiSynchronizedLinkedListMap extends MiraiSynchronizedLinkedListMap extends MiraiSynchronizedLinkedListMap extends MiraiSynchronizedLinkedListMap D getAsOrDefault(String key, D defaultV){ return (D)this.getOrDefault(key,defaultV); } + + @SuppressWarnings("unchecked") + public D getAsOrDefault(String key, Supplier supplier) { + D d = (D) this.get(key); + if (d != null) { + return d; + } + return supplier.get(); + } + + @SuppressWarnings("unchecked") + public D getAs(String key) { + return (D) this.get(key); + } }