Skip to content

Commit

Permalink
添加移除变量的方法
Browse files Browse the repository at this point in the history
  • Loading branch information
lt-name committed Dec 27, 2022
1 parent 30d0a18 commit 5c4d3ed
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main/java/com/smallaswater/npc/variable/VariableManage.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static void addVariable(@NotNull String name, @NotNull Class<? extends Ba
RsNPC.getInstance().getLogger().warning("有插件注册了一个弃用的变量类!名字:" + name + " 类:" + variableClass + " 这可能会导致一些安全问题!");
try {
BaseVariable variable = variableClass.newInstance();
VariableManage.VARIABLE_CLASS.put(name, variable);
VARIABLE_CLASS.put(name, variable);
} catch (Exception e) {
RsNPC.getInstance().getLogger().error("添加变量时出错", e);
}
Expand All @@ -51,12 +51,19 @@ public static void addVariable(@NotNull String name, @NotNull Class<? extends Ba
public static void addVariableV2(@NotNull String name, @NotNull Class<? extends BaseVariableV2> variableClass) {
try {
BaseVariableV2 variable = variableClass.getDeclaredConstructor().newInstance();
VariableManage.VARIABLE_V2_CLASS.put(name, variable);
VARIABLE_V2_CLASS.put(name, variable);
} catch (Exception e) {
RsNPC.getInstance().getLogger().error("添加变量时出错", e);
}
}

public static void removeVariable(@NotNull String name) {
VARIABLES.remove(name);
VARIABLES_SUPPLIER.remove(name);
VARIABLE_CLASS.remove(name);
VARIABLE_V2_CLASS.remove(name);
}

public static String stringReplace(IPlayer player, @NotNull String inString, @NotNull RsNpcConfig rsNpcConfig) {
if (player == null) {
player = new OfflinePlayer(Server.getInstance(), "RsNPCFakePlayer");
Expand Down

0 comments on commit 5c4d3ed

Please sign in to comment.