From 38b2f558f0091d6ff1d3bd7de39f72b673836715 Mon Sep 17 00:00:00 2001 From: Taskeren Date: Thu, 23 Jan 2020 15:43:50 +0800 Subject: [PATCH 1/2] No More IndexOutOfBoundsException --- .../command/interfaces/DiscussCommand.java | 5 ++-- .../command/interfaces/EverywhereCommand.java | 5 ++-- .../icq/command/interfaces/GroupCommand.java | 5 ++-- .../command/interfaces/PrivateCommand.java | 5 ++-- .../cc/moecraft/icq/utils/HyArrayList.java | 25 +++++++++++++++++++ 5 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 src/main/java/cc/moecraft/icq/utils/HyArrayList.java diff --git a/src/main/java/cc/moecraft/icq/command/interfaces/DiscussCommand.java b/src/main/java/cc/moecraft/icq/command/interfaces/DiscussCommand.java index b1a22c15..8f288667 100644 --- a/src/main/java/cc/moecraft/icq/command/interfaces/DiscussCommand.java +++ b/src/main/java/cc/moecraft/icq/command/interfaces/DiscussCommand.java @@ -3,8 +3,7 @@ import cc.moecraft.icq.event.events.message.EventDiscussMessage; import cc.moecraft.icq.user.Group; import cc.moecraft.icq.user.GroupUser; - -import java.util.ArrayList; +import cc.moecraft.icq.utils.HyArrayList; /** * 讨论组指令 @@ -23,5 +22,5 @@ public interface DiscussCommand extends IcqCommand * @param args 指令参数 ( 不包含指令名 ) * @return 发送回去的消息 ( 当然也可以手动发送然后返回空 ) */ - String discussMessage(EventDiscussMessage event, GroupUser sender, Group discuss, String command, ArrayList args); + String discussMessage(EventDiscussMessage event, GroupUser sender, Group discuss, String command, HyArrayList args); } diff --git a/src/main/java/cc/moecraft/icq/command/interfaces/EverywhereCommand.java b/src/main/java/cc/moecraft/icq/command/interfaces/EverywhereCommand.java index 33f898f8..f11db5f6 100644 --- a/src/main/java/cc/moecraft/icq/command/interfaces/EverywhereCommand.java +++ b/src/main/java/cc/moecraft/icq/command/interfaces/EverywhereCommand.java @@ -2,8 +2,7 @@ import cc.moecraft.icq.event.events.message.EventMessage; import cc.moecraft.icq.user.User; - -import java.util.ArrayList; +import cc.moecraft.icq.utils.HyArrayList; /** * 此类由 Hykilpikonna 在 2018/05/26 创建! @@ -24,5 +23,5 @@ public interface EverywhereCommand extends IcqCommand * @param args 指令参数 ( 不包含指令名 ) * @return 发送回去的消息 ( 当然也可以手动发送然后返回空 ) */ - String run(EventMessage event, User sender, String command, ArrayList args); + String run(EventMessage event, User sender, String command, HyArrayList args); } diff --git a/src/main/java/cc/moecraft/icq/command/interfaces/GroupCommand.java b/src/main/java/cc/moecraft/icq/command/interfaces/GroupCommand.java index 7d6b8340..b019930a 100644 --- a/src/main/java/cc/moecraft/icq/command/interfaces/GroupCommand.java +++ b/src/main/java/cc/moecraft/icq/command/interfaces/GroupCommand.java @@ -3,8 +3,7 @@ import cc.moecraft.icq.event.events.message.EventGroupMessage; import cc.moecraft.icq.user.Group; import cc.moecraft.icq.user.GroupUser; - -import java.util.ArrayList; +import cc.moecraft.icq.utils.HyArrayList; /** * 群聊指令 @@ -23,5 +22,5 @@ public interface GroupCommand extends IcqCommand * @param args 指令参数 ( 不包含指令名 ) * @return 发送回去的消息 ( 当然也可以手动发送然后返回空 ) */ - String groupMessage(EventGroupMessage event, GroupUser sender, Group group, String command, ArrayList args); + String groupMessage(EventGroupMessage event, GroupUser sender, Group group, String command, HyArrayList args); } diff --git a/src/main/java/cc/moecraft/icq/command/interfaces/PrivateCommand.java b/src/main/java/cc/moecraft/icq/command/interfaces/PrivateCommand.java index e66401d0..8682a1ee 100644 --- a/src/main/java/cc/moecraft/icq/command/interfaces/PrivateCommand.java +++ b/src/main/java/cc/moecraft/icq/command/interfaces/PrivateCommand.java @@ -2,8 +2,7 @@ import cc.moecraft.icq.event.events.message.EventPrivateMessage; import cc.moecraft.icq.user.User; - -import java.util.ArrayList; +import cc.moecraft.icq.utils.HyArrayList; /** * 私聊指令 @@ -21,5 +20,5 @@ public interface PrivateCommand extends IcqCommand * @param args 指令参数 ( 不包含指令名 ) * @return 发送回去的消息 ( 当然也可以手动发送然后返回空 ) */ - String privateMessage(EventPrivateMessage event, User sender, String command, ArrayList args); + String privateMessage(EventPrivateMessage event, User sender, String command, HyArrayList args); } diff --git a/src/main/java/cc/moecraft/icq/utils/HyArrayList.java b/src/main/java/cc/moecraft/icq/utils/HyArrayList.java new file mode 100644 index 00000000..efdc4792 --- /dev/null +++ b/src/main/java/cc/moecraft/icq/utils/HyArrayList.java @@ -0,0 +1,25 @@ +package cc.moecraft.icq.utils; + +import java.util.ArrayList; +import java.util.Collection; + +public class HyArrayList extends ArrayList { + + public HyArrayList() { + super(); + } + + public HyArrayList(int initialCapacity) { + super(initialCapacity); + } + + public HyArrayList(Collection coll) { + super(coll); + } + + @Override + public E get(int index) { + return index >= size() ? null : super.get(index); + } + +} From 4fca89bb6f92487f3adfedce3e673a753c178827 Mon Sep 17 00:00:00 2001 From: Taskeren Date: Fri, 24 Jan 2020 14:14:40 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=BF=98=E5=8E=9FPicqBotX=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cc/moecraft/icq/command/interfaces/DiscussCommand.java | 5 +++-- .../moecraft/icq/command/interfaces/EverywhereCommand.java | 5 +++-- .../cc/moecraft/icq/command/interfaces/GroupCommand.java | 5 +++-- .../cc/moecraft/icq/command/interfaces/PrivateCommand.java | 5 +++-- src/main/java/cc/moecraft/icq/utils/HyArrayList.java | 4 ++++ 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/cc/moecraft/icq/command/interfaces/DiscussCommand.java b/src/main/java/cc/moecraft/icq/command/interfaces/DiscussCommand.java index 8f288667..b1a22c15 100644 --- a/src/main/java/cc/moecraft/icq/command/interfaces/DiscussCommand.java +++ b/src/main/java/cc/moecraft/icq/command/interfaces/DiscussCommand.java @@ -3,7 +3,8 @@ import cc.moecraft.icq.event.events.message.EventDiscussMessage; import cc.moecraft.icq.user.Group; import cc.moecraft.icq.user.GroupUser; -import cc.moecraft.icq.utils.HyArrayList; + +import java.util.ArrayList; /** * 讨论组指令 @@ -22,5 +23,5 @@ public interface DiscussCommand extends IcqCommand * @param args 指令参数 ( 不包含指令名 ) * @return 发送回去的消息 ( 当然也可以手动发送然后返回空 ) */ - String discussMessage(EventDiscussMessage event, GroupUser sender, Group discuss, String command, HyArrayList args); + String discussMessage(EventDiscussMessage event, GroupUser sender, Group discuss, String command, ArrayList args); } diff --git a/src/main/java/cc/moecraft/icq/command/interfaces/EverywhereCommand.java b/src/main/java/cc/moecraft/icq/command/interfaces/EverywhereCommand.java index f11db5f6..33f898f8 100644 --- a/src/main/java/cc/moecraft/icq/command/interfaces/EverywhereCommand.java +++ b/src/main/java/cc/moecraft/icq/command/interfaces/EverywhereCommand.java @@ -2,7 +2,8 @@ import cc.moecraft.icq.event.events.message.EventMessage; import cc.moecraft.icq.user.User; -import cc.moecraft.icq.utils.HyArrayList; + +import java.util.ArrayList; /** * 此类由 Hykilpikonna 在 2018/05/26 创建! @@ -23,5 +24,5 @@ public interface EverywhereCommand extends IcqCommand * @param args 指令参数 ( 不包含指令名 ) * @return 发送回去的消息 ( 当然也可以手动发送然后返回空 ) */ - String run(EventMessage event, User sender, String command, HyArrayList args); + String run(EventMessage event, User sender, String command, ArrayList args); } diff --git a/src/main/java/cc/moecraft/icq/command/interfaces/GroupCommand.java b/src/main/java/cc/moecraft/icq/command/interfaces/GroupCommand.java index b019930a..7d6b8340 100644 --- a/src/main/java/cc/moecraft/icq/command/interfaces/GroupCommand.java +++ b/src/main/java/cc/moecraft/icq/command/interfaces/GroupCommand.java @@ -3,7 +3,8 @@ import cc.moecraft.icq.event.events.message.EventGroupMessage; import cc.moecraft.icq.user.Group; import cc.moecraft.icq.user.GroupUser; -import cc.moecraft.icq.utils.HyArrayList; + +import java.util.ArrayList; /** * 群聊指令 @@ -22,5 +23,5 @@ public interface GroupCommand extends IcqCommand * @param args 指令参数 ( 不包含指令名 ) * @return 发送回去的消息 ( 当然也可以手动发送然后返回空 ) */ - String groupMessage(EventGroupMessage event, GroupUser sender, Group group, String command, HyArrayList args); + String groupMessage(EventGroupMessage event, GroupUser sender, Group group, String command, ArrayList args); } diff --git a/src/main/java/cc/moecraft/icq/command/interfaces/PrivateCommand.java b/src/main/java/cc/moecraft/icq/command/interfaces/PrivateCommand.java index 8682a1ee..e66401d0 100644 --- a/src/main/java/cc/moecraft/icq/command/interfaces/PrivateCommand.java +++ b/src/main/java/cc/moecraft/icq/command/interfaces/PrivateCommand.java @@ -2,7 +2,8 @@ import cc.moecraft.icq.event.events.message.EventPrivateMessage; import cc.moecraft.icq.user.User; -import cc.moecraft.icq.utils.HyArrayList; + +import java.util.ArrayList; /** * 私聊指令 @@ -20,5 +21,5 @@ public interface PrivateCommand extends IcqCommand * @param args 指令参数 ( 不包含指令名 ) * @return 发送回去的消息 ( 当然也可以手动发送然后返回空 ) */ - String privateMessage(EventPrivateMessage event, User sender, String command, HyArrayList args); + String privateMessage(EventPrivateMessage event, User sender, String command, ArrayList args); } diff --git a/src/main/java/cc/moecraft/icq/utils/HyArrayList.java b/src/main/java/cc/moecraft/icq/utils/HyArrayList.java index efdc4792..5c18dc79 100644 --- a/src/main/java/cc/moecraft/icq/utils/HyArrayList.java +++ b/src/main/java/cc/moecraft/icq/utils/HyArrayList.java @@ -17,6 +17,10 @@ public HyArrayList(Collection coll) { super(coll); } + public static HyArrayList of(Collection list) { + return new HyArrayList<>(list); + } + @Override public E get(int index) { return index >= size() ? null : super.get(index);