Skip to content

Commit ee84684

Browse files
authored
Merge pull request #61 from anlingyi/release
1.6.2-beta
2 parents 13a8b75 + 25c7763 commit ee84684

80 files changed

Lines changed: 3110 additions & 1038 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# XEChat-Idea
22

3-
> Version 1.6.1-beta
3+
> Version 1.6.2-beta
44
55
> 基于Netty的IDEA即时聊天插件:让你能够在IDEA里实现聊天、下棋、斗地主!(理论上支持JetBrains全系列开发工具🙂)
66
@@ -32,14 +32,20 @@
3232

3333
目前已实现:
3434

35+
**游戏类**
36+
3537
* 五子棋(支持2人联机、人机对战,内置"人工制杖")
3638
* 斗地主(支持2~3人联机、人机对战)
39+
* 不贪吃蛇
40+
41+
**工具类**
42+
3743
* 阅读(作者 @[MINIPuffer](https://github.com/MINIPuffer) ,感谢PR😊)
3844
* 天气查询(基于[和风天气](https://dev.qweather.com/),作者 @[猎隼丶止戈](https://github.com/nn200433) ,感谢PR😊)
3945

4046
[了解更多...](https://xeblog.cn/?tag=xechat-idea)
4147

42-
![](https://oss.xeblog.cn/prod/33a4f79174f2470da66fc7e7f0a36fad.png)
48+
![](https://oss.xeblog.cn/prod/2f78edccf9c947d5827c3be0e8887b94.png)
4349

4450
![](https://oss.xeblog.cn/prod/87397d4da728467e912450f94e41b2ef.jpg)
4551

xechat-commons/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>cn.xeblog</groupId>
88
<artifactId>xechat-commons</artifactId>
9-
<version>1.6.1-beta</version>
9+
<version>1.6.2-beta</version>
1010
<build>
1111
<plugins>
1212
<plugin>

xechat-commons/src/main/java/cn/xeblog/commons/codec/ProtostuffDecoder.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import io.netty.buffer.ByteBuf;
55
import io.netty.channel.ChannelHandlerContext;
66
import io.netty.handler.codec.ByteToMessageDecoder;
7+
import io.netty.util.ReferenceCountUtil;
8+
import lombok.extern.slf4j.Slf4j;
79

810
import java.util.List;
911

@@ -13,6 +15,7 @@
1315
* @author anlingyi
1416
* @date 2021/8/28 6:11 下午
1517
*/
18+
@Slf4j
1619
public class ProtostuffDecoder extends ByteToMessageDecoder {
1720

1821
private final Class clazz;
@@ -36,8 +39,16 @@ protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteB
3639
} else {
3740
// 读取完整的数据
3841
byte[] data = new byte[length];
39-
byteBuf.readRetainedSlice(length).readBytes(data);
40-
list.add(ProtostuffUtils.deserialize(data, clazz));
42+
ByteBuf body = null;
43+
try {
44+
body = byteBuf.readRetainedSlice(length);
45+
body.readBytes(data);
46+
list.add(ProtostuffUtils.deserialize(data, clazz));
47+
} catch (Exception e) {
48+
log.error("解码异常", e);
49+
} finally {
50+
ReferenceCountUtil.release(body);
51+
}
4152
}
4253
}
4354
}

xechat-commons/src/main/java/cn/xeblog/commons/entity/game/CreateGameRoomDTO.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ public class CreateGameRoomDTO implements Serializable {
2626
*/
2727
private int nums;
2828

29+
/**
30+
* 游戏模式
31+
*/
32+
private String gameMode;
33+
2934
}

xechat-commons/src/main/java/cn/xeblog/commons/entity/game/GameRoom.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public class GameRoom implements Serializable {
3131
*/
3232
private int nums;
3333

34+
/**
35+
* 游戏模式
36+
*/
37+
private String gameMode;
38+
3439
/**
3540
* 房主
3641
*/

xechat-commons/src/main/java/cn/xeblog/commons/entity/game/GameRoomMsgDTO.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public enum MsgType {
4848
* 游戏开始
4949
*/
5050
GAME_START,
51+
/**
52+
* 玩家已开始游戏
53+
*/
54+
PLAYER_GAME_STARTED,
5155
/**
5256
* 游戏结束
5357
*/

xechat-commons/src/main/java/cn/xeblog/commons/enums/Game.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
public enum Game {
1515
GOBANG("五子棋", false),
1616
LANDLORDS("斗地主", false),
17-
READ("阅读", false);
17+
NON_GLUTTONOUS_SNAKE("不贪吃蛇", false);
1818

1919
/**
2020
* 游戏名称

xechat-commons/src/main/java/cn/xeblog/commons/factory/AbstractSingletonFactory.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,7 @@ public void add(K key, Class<? extends V> clazz) {
5555

5656
public void addByAnnotation(String packageName, Class<? extends Annotation> annotationClass) {
5757
Set<Class<?>> classes;
58-
if (this.jarPath == null) {
59-
classes = ClassUtil.scanPackageByAnnotation(packageName, annotationClass);
60-
} else {
61-
classes = ClassUtils.scan(this.jarPath, packageName, annotationClass);
62-
}
63-
58+
classes = ClassUtils.scan(this.jarPath, packageName, annotationClass);
6459
if (!CollectionUtil.isEmpty(classes)) {
6560
classes.forEach(clazz -> {
6661
add(AnnotationUtil.getAnnotationValue(clazz, annotationClass), (Class<? extends V>) clazz);

xechat-commons/src/main/java/cn/xeblog/commons/util/ClassUtils.java

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package cn.xeblog.commons.util;
22

3+
import cn.hutool.core.util.ClassUtil;
34
import cn.hutool.core.util.StrUtil;
45

56
import java.io.IOException;
@@ -25,33 +26,57 @@ public static Set<Class<?>> scan(String path, String pkg) {
2526
}
2627

2728
public static Set<Class<?>> scan(String path, String pkg, Class<? extends Annotation> annotationClass) {
29+
return scan(path, pkg, annotationClass, null);
30+
}
31+
32+
public static Set<Class<?>> scanSubClass(String path, String pkg, Class superClass) {
33+
return scan(path, pkg, null, superClass);
34+
}
35+
36+
public static Set<Class<?>> scan(String path, String pkg, Class<? extends Annotation> annotationClass, Class superClass) {
2837
Set<Class<?>> classes = new HashSet<>();
2938
String pkgPath = null;
3039
if (StrUtil.isNotBlank(pkg)) {
3140
pkgPath = pkg.replace(".", "/");
3241
}
3342

3443
try {
35-
JarFile jar = new JarFile(path);
36-
Enumeration<JarEntry> entryEnumeration = jar.entries();
37-
while (entryEnumeration.hasMoreElements()) {
38-
JarEntry entry = entryEnumeration.nextElement();
39-
String clazzName = entry.getName();
40-
if (pkgPath != null && !clazzName.startsWith(pkgPath)) {
41-
continue;
42-
}
44+
if (path == null) {
45+
classes = ClassUtil.scanPackage(pkg, (clazz) -> {
46+
if (!isAnnotationPresent(clazz, annotationClass)) {
47+
return false;
48+
}
49+
if (!isSubClass(clazz, superClass)) {
50+
return false;
51+
}
4352

44-
if (clazzName.endsWith(".class")) {
45-
clazzName = clazzName.substring(0, clazzName.length() - 6);
46-
clazzName = clazzName.replace("/", ".");
47-
try {
48-
Class<?> clazz = Class.forName(clazzName);
49-
if (annotationClass != null && !clazz.isAnnotationPresent(annotationClass)) {
50-
continue;
51-
}
53+
return true;
54+
});
55+
} else {
56+
JarFile jar = new JarFile(path);
57+
Enumeration<JarEntry> entryEnumeration = jar.entries();
58+
while (entryEnumeration.hasMoreElements()) {
59+
JarEntry entry = entryEnumeration.nextElement();
60+
String clazzName = entry.getName();
61+
if (pkgPath != null && !clazzName.startsWith(pkgPath)) {
62+
continue;
63+
}
64+
65+
if (clazzName.endsWith(".class")) {
66+
clazzName = clazzName.substring(0, clazzName.length() - 6);
67+
clazzName = clazzName.replace("/", ".");
68+
try {
69+
Class<?> clazz = Class.forName(clazzName);
70+
if (!isAnnotationPresent(clazz, annotationClass)) {
71+
continue;
72+
}
73+
if (!isSubClass(clazz, superClass)) {
74+
continue;
75+
}
5276

53-
classes.add(clazz);
54-
} catch (Throwable e) {
77+
classes.add(clazz);
78+
} catch (Throwable e) {
79+
}
5580
}
5681
}
5782
}
@@ -62,4 +87,20 @@ public static Set<Class<?>> scan(String path, String pkg, Class<? extends Annota
6287
return classes;
6388
}
6489

90+
public static boolean isAnnotationPresent(Class clazz, Class<? extends Annotation> annotationClass) {
91+
if (clazz == null || annotationClass == null) {
92+
return true;
93+
}
94+
95+
return clazz.isAnnotationPresent(annotationClass);
96+
}
97+
98+
public static boolean isSubClass(Class clazz, Class superClass) {
99+
if (clazz == null || superClass == null) {
100+
return true;
101+
}
102+
103+
return superClass.isAssignableFrom(clazz) && !superClass.equals(clazz);
104+
}
105+
65106
}

xechat-commons/src/main/java/cn/xeblog/commons/util/MoYuTipsUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ public static String amOrPm(int a) {
122122
if (a > 6 && a < 12) {
123123
return "上午";
124124
}
125-
if (a == 13) {
125+
if (a == 12) {
126126
return "中午";
127127
}
128-
if (a > 13 && a <= 18) {
128+
if (a >= 13 && a <= 18) {
129129
return "下午";
130130
} else {
131131
return "晚上";

0 commit comments

Comments
 (0)