Skip to content

Commit 9dbb45d

Browse files
committed
add: CommandSender session with specific plugin name clear
1 parent aa7f704 commit 9dbb45d

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/main/java/top/focess/qq/api/command/CommandSender.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package top.focess.qq.api.command;
22

3+
import com.google.common.collect.Lists;
34
import com.google.common.collect.Maps;
45
import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf;
56
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -9,10 +10,12 @@
910
import top.focess.qq.api.bot.Friend;
1011
import top.focess.qq.api.bot.Member;
1112
import top.focess.qq.api.bot.Stranger;
13+
import top.focess.qq.api.plugin.Plugin;
1214
import top.focess.qq.api.util.IOHandler;
1315
import top.focess.qq.api.util.session.Session;
1416
import top.focess.qq.core.listeners.ChatListener;
1517

18+
import java.util.List;
1619
import java.util.Map;
1720
import java.util.Objects;
1821

@@ -278,4 +281,15 @@ public Bot getBot() {
278281
public boolean isStranger() {
279282
return isStranger;
280283
}
284+
285+
public static void clear(Plugin plugin) {
286+
SESSIONS.values().stream().map(Session::getValues).forEach(map ->{
287+
List<String> keys = Lists.newArrayList();
288+
map.forEach((key,value) -> {
289+
if (key.startsWith(plugin.getName() + ":"))
290+
keys.add(key);
291+
});
292+
keys.forEach(map::remove);
293+
});
294+
}
281295
}

src/main/java/top/focess/qq/core/plugin/PluginClassLoader.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@ public static File disablePlugin0(Plugin plugin) {
310310
if (FocessQQ.getUdpSocket() != null)
311311
FocessQQ.getUdpSocket().unregister(plugin);
312312
}
313+
CommandSender.clear(plugin);
314+
FocessQQ.getLogger().debugLang("clear-command-sender-session",plugin.getName());
313315
CLASS_PLUGIN_MAP.remove(plugin.getClass());
314316
NAME_PLUGIN_MAP.remove(plugin.getName());
315317
File ret = null;

src/main/resources/lang.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,5 @@ register-default-special-argument-handlers: Register default special argument ha
188188
exec-command-empty-command: The command is empty
189189
exec-command-error-command: Exec cannot execute command named itself
190190
section-exception: Section %s exception, %s
191+
clear-command-sender-session: Clear command sender session with plugin %s
191192

0 commit comments

Comments
 (0)