Skip to content

Commit

Permalink
Merge pull request #61 from anlingyi/release
Browse files Browse the repository at this point in the history
1.6.2-beta
  • Loading branch information
anlingyi authored Aug 6, 2022
2 parents 13a8b75 + 25c7763 commit ee84684
Show file tree
Hide file tree
Showing 80 changed files with 3,110 additions and 1,038 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# XEChat-Idea

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

目前已实现:

**游戏类**

* 五子棋(支持2人联机、人机对战,内置"人工制杖")
* 斗地主(支持2~3人联机、人机对战)
* 不贪吃蛇

**工具类**

* 阅读(作者 @[MINIPuffer](https://github.com/MINIPuffer) ,感谢PR😊)
* 天气查询(基于[和风天气](https://dev.qweather.com/),作者 @[猎隼丶止戈](https://github.com/nn200433) ,感谢PR😊)

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

![](https://oss.xeblog.cn/prod/33a4f79174f2470da66fc7e7f0a36fad.png)
![](https://oss.xeblog.cn/prod/2f78edccf9c947d5827c3be0e8887b94.png)

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

Expand Down
2 changes: 1 addition & 1 deletion xechat-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>cn.xeblog</groupId>
<artifactId>xechat-commons</artifactId>
<version>1.6.1-beta</version>
<version>1.6.2-beta</version>
<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.util.ReferenceCountUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

Expand All @@ -13,6 +15,7 @@
* @author anlingyi
* @date 2021/8/28 6:11 下午
*/
@Slf4j
public class ProtostuffDecoder extends ByteToMessageDecoder {

private final Class clazz;
Expand All @@ -36,8 +39,16 @@ protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteB
} else {
// 读取完整的数据
byte[] data = new byte[length];
byteBuf.readRetainedSlice(length).readBytes(data);
list.add(ProtostuffUtils.deserialize(data, clazz));
ByteBuf body = null;
try {
body = byteBuf.readRetainedSlice(length);
body.readBytes(data);
list.add(ProtostuffUtils.deserialize(data, clazz));
} catch (Exception e) {
log.error("解码异常", e);
} finally {
ReferenceCountUtil.release(body);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ public class CreateGameRoomDTO implements Serializable {
*/
private int nums;

/**
* 游戏模式
*/
private String gameMode;

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public class GameRoom implements Serializable {
*/
private int nums;

/**
* 游戏模式
*/
private String gameMode;

/**
* 房主
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public enum MsgType {
* 游戏开始
*/
GAME_START,
/**
* 玩家已开始游戏
*/
PLAYER_GAME_STARTED,
/**
* 游戏结束
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public enum Game {
GOBANG("五子棋", false),
LANDLORDS("斗地主", false),
READ("阅读", false);
NON_GLUTTONOUS_SNAKE("不贪吃蛇", false);

/**
* 游戏名称
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,7 @@ public void add(K key, Class<? extends V> clazz) {

public void addByAnnotation(String packageName, Class<? extends Annotation> annotationClass) {
Set<Class<?>> classes;
if (this.jarPath == null) {
classes = ClassUtil.scanPackageByAnnotation(packageName, annotationClass);
} else {
classes = ClassUtils.scan(this.jarPath, packageName, annotationClass);
}

classes = ClassUtils.scan(this.jarPath, packageName, annotationClass);
if (!CollectionUtil.isEmpty(classes)) {
classes.forEach(clazz -> {
add(AnnotationUtil.getAnnotationValue(clazz, annotationClass), (Class<? extends V>) clazz);
Expand Down
77 changes: 59 additions & 18 deletions xechat-commons/src/main/java/cn/xeblog/commons/util/ClassUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.xeblog.commons.util;

import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.StrUtil;

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

public static Set<Class<?>> scan(String path, String pkg, Class<? extends Annotation> annotationClass) {
return scan(path, pkg, annotationClass, null);
}

public static Set<Class<?>> scanSubClass(String path, String pkg, Class superClass) {
return scan(path, pkg, null, superClass);
}

public static Set<Class<?>> scan(String path, String pkg, Class<? extends Annotation> annotationClass, Class superClass) {
Set<Class<?>> classes = new HashSet<>();
String pkgPath = null;
if (StrUtil.isNotBlank(pkg)) {
pkgPath = pkg.replace(".", "/");
}

try {
JarFile jar = new JarFile(path);
Enumeration<JarEntry> entryEnumeration = jar.entries();
while (entryEnumeration.hasMoreElements()) {
JarEntry entry = entryEnumeration.nextElement();
String clazzName = entry.getName();
if (pkgPath != null && !clazzName.startsWith(pkgPath)) {
continue;
}
if (path == null) {
classes = ClassUtil.scanPackage(pkg, (clazz) -> {
if (!isAnnotationPresent(clazz, annotationClass)) {
return false;
}
if (!isSubClass(clazz, superClass)) {
return false;
}

if (clazzName.endsWith(".class")) {
clazzName = clazzName.substring(0, clazzName.length() - 6);
clazzName = clazzName.replace("/", ".");
try {
Class<?> clazz = Class.forName(clazzName);
if (annotationClass != null && !clazz.isAnnotationPresent(annotationClass)) {
continue;
}
return true;
});
} else {
JarFile jar = new JarFile(path);
Enumeration<JarEntry> entryEnumeration = jar.entries();
while (entryEnumeration.hasMoreElements()) {
JarEntry entry = entryEnumeration.nextElement();
String clazzName = entry.getName();
if (pkgPath != null && !clazzName.startsWith(pkgPath)) {
continue;
}

if (clazzName.endsWith(".class")) {
clazzName = clazzName.substring(0, clazzName.length() - 6);
clazzName = clazzName.replace("/", ".");
try {
Class<?> clazz = Class.forName(clazzName);
if (!isAnnotationPresent(clazz, annotationClass)) {
continue;
}
if (!isSubClass(clazz, superClass)) {
continue;
}

classes.add(clazz);
} catch (Throwable e) {
classes.add(clazz);
} catch (Throwable e) {
}
}
}
}
Expand All @@ -62,4 +87,20 @@ public static Set<Class<?>> scan(String path, String pkg, Class<? extends Annota
return classes;
}

public static boolean isAnnotationPresent(Class clazz, Class<? extends Annotation> annotationClass) {
if (clazz == null || annotationClass == null) {
return true;
}

return clazz.isAnnotationPresent(annotationClass);
}

public static boolean isSubClass(Class clazz, Class superClass) {
if (clazz == null || superClass == null) {
return true;
}

return superClass.isAssignableFrom(clazz) && !superClass.equals(clazz);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ public static String amOrPm(int a) {
if (a > 6 && a < 12) {
return "上午";
}
if (a == 13) {
if (a == 12) {
return "中午";
}
if (a > 13 && a <= 18) {
if (a >= 13 && a <= 18) {
return "下午";
} else {
return "晚上";
Expand Down
4 changes: 2 additions & 2 deletions xechat-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'cn.xeblog'
version '1.6.1-beta'
version '1.6.2-beta'

sourceCompatibility = 11
targetCompatibility = 11
Expand All @@ -20,7 +20,7 @@ repositories {
}

ext {
xechatCommonsVersion = '1.6.1-beta'
xechatCommonsVersion = '1.6.2-beta'
lombokVersion = '1.18.24'
}

Expand Down
Loading

0 comments on commit ee84684

Please sign in to comment.