Skip to content
This repository was archived by the owner on May 23, 2025. It is now read-only.

Commit cbae168

Browse files
committed
chore: 优化
1 parent 7e581a6 commit cbae168

28 files changed

+123
-126
lines changed

src/main/java/io/github/minecraftchampions/dodoopenjava/debug/DebugLogger.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class DebugLogger {
2020
* @param result result
2121
*/
2222
public void log(@NonNull Result result) {
23-
log("{} 调用api结果: {}", getBotAuthorization(), result);
23+
log("{} 调用api结果: {}", botAuthorization, result);
2424
}
2525

2626
/**
@@ -29,14 +29,14 @@ public void log(@NonNull Result result) {
2929
* @param event event
3030
*/
3131
public void log(@NonNull Event event) {
32-
log("{} 监听事件: {}", getBotAuthorization(), event);
32+
log("{} 监听事件: {}", botAuthorization, event);
3333
}
3434

35-
public void log(@NonNull String str,Object... params) {
35+
public static void log(@NonNull String str, Object... params) {
3636
log.debug(str,params);
3737
}
3838

39-
public void log(@NonNull String str) {
39+
public static void log(@NonNull String str) {
4040
log.debug(str);
4141
}
4242
}

src/main/java/io/github/minecraftchampions/dodoopenjava/debug/Result.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public class Result implements Comparable<Result> {
9999

100100
public JSONObject getData() {
101101
if (isFailure()) {
102-
log.error("调用Dodo开放平台api时出错,错误消息:{};状态code:{};错误数据:{}", getMessage(), getStatusCode(), getData());
102+
log.error("调用Dodo开放平台api时出错,错误消息:{};状态code:{};错误数据:{}", message, statusCode, getData());
103103
return new JSONObject();
104104
}
105105
return jsonObjectData;
@@ -200,7 +200,7 @@ public <T> T ifFailure(@NonNull Function<Result, T> function) {
200200

201201
@Override
202202
public String toString() {
203-
return "Request:" + getRequestData() + "\n" + "Result:" + getData();
203+
return "Request:" + requestData + "\n" + "Result:" + getData();
204204
}
205205

206206
@Override

src/main/java/io/github/minecraftchampions/dodoopenjava/event/EventManager.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@
2222
import java.lang.reflect.InvocationTargetException;
2323
import java.lang.reflect.Method;
2424
import java.lang.reflect.Modifier;
25+
import java.util.*;
2526
import java.util.AbstractMap.SimpleEntry;
26-
import java.util.ArrayList;
27-
import java.util.List;
28-
import java.util.Map;
29-
import java.util.Set;
3027
import java.util.concurrent.CompletableFuture;
3128
import java.util.concurrent.ConcurrentHashMap;
3229

@@ -109,11 +106,10 @@ public synchronized void unregisterAllListeners() {
109106
*/
110107
public void unregisterListeners(@NonNull Listener listener) {
111108
synchronized (handlers) {
112-
Set<Class<? extends Event>> set = handlers.keySet();
113-
for (Class<? extends Event> clazz : set) {
114-
List<SimpleEntry<Method, Object>> list = handlers.get(clazz).stream().
109+
for (List<SimpleEntry<Method, Object>> simpleEntries : handlers.values()) {
110+
List<SimpleEntry<Method, Object>> list = simpleEntries.stream().
115111
filter(e -> e.getKey().getDeclaringClass() == listener.getClass()).toList();
116-
handlers.get(clazz).removeAll(list);
112+
simpleEntries.removeAll(list);
117113
}
118114
}
119115
}
@@ -157,8 +153,8 @@ public void fireEvent(@NonNull Event event) throws RuntimeException {
157153
throw new RuntimeException("未知的Event");
158154
}
159155
synchronized (handlers) {
160-
if (DodoOpenJava.DEBUG_LOGGER_MAP.containsKey(getBot().getAuthorization())) {
161-
DodoOpenJava.DEBUG_LOGGER_MAP.get(getBot().getAuthorization()).log(event);
156+
if (DodoOpenJava.DEBUG_LOGGER_MAP.containsKey(bot.getAuthorization())) {
157+
DodoOpenJava.DEBUG_LOGGER_MAP.get(bot.getAuthorization()).log(event);
162158
}
163159
fireEvent(event, handlers);
164160
}

src/main/java/io/github/minecraftchampions/dodoopenjava/event/WebHookEventTrigger.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*/
3030
@Slf4j
3131
public class WebHookEventTrigger extends AbstractEventTrigger {
32-
boolean isConnect = false;
32+
boolean isConnect;
3333

3434
public WebHookEventTrigger(@NonNull Bot bot, @NonNull String secretKey,
3535
@NonNull String password, @NonNull File file) {
@@ -70,7 +70,7 @@ public WebHookEventTrigger(@NonNull Bot bot, @NonNull String path, @NonNull Stri
7070

7171
private final HttpServerProvider provider = HttpServerProvider.provider();
7272

73-
private HttpsServer server = null;
73+
private HttpsServer server;
7474

7575
/**
7676
* 启动监听
@@ -82,7 +82,7 @@ public synchronized void start() {
8282
return;
8383
}
8484
server = provider.createHttpsServer(new InetSocketAddress(port), 1000);
85-
server.createContext(getPath(), new Handler());
85+
server.createContext(path, new Handler());
8686
server.setExecutor(new ThreadPoolExecutor(3, 10, 3,
8787
TimeUnit.SECONDS, new LinkedBlockingDeque<>(3),
8888
Executors.defaultThreadFactory(), new ThreadPoolExecutor.DiscardOldestPolicy()));
@@ -143,7 +143,7 @@ public synchronized void start() {
143143
*/
144144
@Override
145145
public synchronized void close() {
146-
if (server == null || isConnect()) {
146+
if (server == null || isConnect) {
147147
return;
148148
}
149149
server.stop(0);
@@ -169,7 +169,7 @@ public class Handler implements HttpHandler {
169169
@Override
170170
public void handle(HttpExchange httpExchange) {
171171
try {
172-
InputStream ss = httpExchange.getRequestBody();
172+
httpExchange.getRequestBody();
173173
String requestMethod = httpExchange.getRequestMethod();
174174
Headers responseHeaders = httpExchange.getResponseHeaders();
175175
responseHeaders.set("Content-Type", "application/json;charset=utf-8");

src/main/java/io/github/minecraftchampions/dodoopenjava/event/WebSocketEventTrigger.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public boolean isConnect() {
3030
return mWebSocket != null && mWebSocket.isOpen();
3131
}
3232

33-
public WebSocketClient mWebSocket = null;
33+
public WebSocketClient mWebSocket;
3434

3535
public static final long PING_INTERVAL = 20 * 1000;
3636

@@ -39,7 +39,7 @@ public WebSocketEventTrigger(Bot bot) {
3939
this.bot = bot;
4040
}
4141

42-
private int reacquireCount = 0;
42+
private int reacquireCount;
4343

4444
private final int reacquireMaxCount = 100;
4545

src/main/java/io/github/minecraftchampions/dodoopenjava/event/events/v2/member/MemberLeaveEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public MemberLeaveEvent(JSONObject json) {
104104
* @param type 类型
105105
* @return 类型
106106
*/
107-
public String intLeaveTypeToLeaveType(Integer type) {
107+
public static String intLeaveTypeToLeaveType(Integer type) {
108108
return switch (type) {
109109
case 1 -> "主动";
110110
case 2 -> "被踢";

src/main/java/io/github/minecraftchampions/dodoopenjava/impl/BotImpl.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import lombok.NonNull;
1818
import lombok.RequiredArgsConstructor;
1919
import lombok.extern.slf4j.Slf4j;
20-
import org.json.JSONObject;
2120

2221
import java.util.Objects;
2322

@@ -31,7 +30,7 @@
3130
@Slf4j
3231
public class BotImpl implements Bot {
3332
public String toString() {
34-
return getClientId();
33+
return clientId;
3534
}
3635

3736
/**
@@ -105,7 +104,7 @@ public synchronized void registerListener(@NonNull Listener listener) {
105104
if (!eventTrigger.isConnect()) {
106105
eventTrigger.start();
107106
}
108-
getEventManager().registerListener(listener);
107+
eventManager.registerListener(listener);
109108
}
110109

111110
/**
@@ -121,7 +120,7 @@ public synchronized void removeEventTrigger() {
121120

122121
@Override
123122
public Island getIsland(@NonNull String islandSourceId) {
124-
Result result = getApi().getIslandApi().getIslandList();
123+
Result result = api.getIslandApi().getIslandList();
125124
if (result.isFailure()) {
126125
log.error("获取频道信息失败, 错误消息:{};状态code:{};错误数据:{}", result.getMessage(), result.getStatusCode(), result.getData());
127126
return null;
@@ -220,7 +219,7 @@ public void disable() {
220219
*/
221220
@Override
222221
public String getName() {
223-
return this.getApi().getBotApi().getBotInfo().getData().getString("nickName");
222+
return this.api.getBotApi().getBotInfo().getData().getString("nickName");
224223
}
225224

226225
/**
@@ -230,7 +229,7 @@ public String getName() {
230229
*/
231230
@Override
232231
public String getDodoSourceId() {
233-
return this.getApi().getBotApi().getBotInfo().getData().getString("dodoSourceId");
232+
return this.api.getBotApi().getBotInfo().getData().getString("dodoSourceId");
234233
}
235234

236235
/**
@@ -240,8 +239,7 @@ public String getDodoSourceId() {
240239
*/
241240
@Override
242241
public String getAvatarUrl() {
243-
JSONObject jsonObject = new JSONObject();
244-
return this.getApi().getBotApi().getBotInfo().getData().getString("avatarUrl");
242+
return this.api.getBotApi().getBotInfo().getData().getString("avatarUrl");
245243
}
246244

247245
/**

src/main/java/io/github/minecraftchampions/dodoopenjava/impl/ChannelImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ public String getGroupName() {
6868

6969
@Override
7070
public Result delete() {
71-
return bot.getApi().getChannelApi().deleteChannel(getIslandSourceId(), getChannelId());
71+
return bot.getApi().getChannelApi().deleteChannel(islandSourceId, channelId);
7272
}
7373

7474
@Override
7575
public Island getIsland() {
76-
return new IslandImpl(getIslandSourceId(), bot);
76+
return new IslandImpl(islandSourceId, bot);
7777
}
7878
}

0 commit comments

Comments
 (0)