Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.0.0-beta8 #7

Merged
merged 14 commits into from
Apr 21, 2024
4 changes: 3 additions & 1 deletion .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ jobs:
uses: actions/upload-artifact@v1
with:
name: ${{ steps.get_info.outputs.repository_name }}-Pr_check-Build-${{ github.run_number}}
path: staging
path: staging
- name: 批准PR
uses: hmarr/auto-approve-action@v4.0.0
4 changes: 2 additions & 2 deletions .github/workflows/tagpush.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
tag: ${{ steps.get_info.outputs.VERSION }}
name: ${{ steps.get_info.outputs.VERSION }}
token: ${{ secrets.GITHUB_TOKEN }}
bodyFile: ./changelogs/${{ steps.get_info.outputs.VERSION }}.md
bodyFile: ./docs/changelogs/${{ steps.get_info.outputs.VERSION }}.md
artifacts: ./target/${{ steps.get_info.outputs.repository_name }}-${{ steps.get_info.outputs.VERSION }}.jar
# 这个暂时没有用
# - name: 发布至minebbs
Expand All @@ -45,5 +45,5 @@ jobs:
# token: ${{ secrets.MINEBBSKEY }}
# title: ${{ steps.get_info.outputs.VERSION }}
# new_version: ${{ steps.get_info.outputs.VERSION }}
# description_file: ./changelogs/${{ steps.get_info.outputs.VERSION }}.md
# description_file: ./docs/changelogs/${{ steps.get_info.outputs.VERSION }}.md
# file_url: 'https://github.com/${{ github.repository }}/releases/latest'
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
![GitHub issues](https://img.shields.io/github/issues/stevei5mc/NewTipsVariables?style=plastic&color=linkGreen)
![GitHub pull requests](https://img.shields.io/github/issues-pr/stevei5mc/NewTipsVariables?style=plastic)
> **该插件可以为Tips添加更多的变量内容,更多变量敬请期待**
## 使用方法
## **使用方法**
> **1、将插件放进`plugins`文件夹**
> **2、需确保安装`Tips`插件后重启服务器**
> **3、在`/plugins/NewTipsVariables`文件夹中的`.txt`文件获取相关变量介绍,也可在本页面获取相关的变量介绍**
### **[配置文件使用说明](./docs/config-info.md)**
### **变量介绍**
**[文字相关变量](./docs/text-variables.md) [玩家相关变量](./docs/player-variables.md) [服务器相关变量](./docs/server-variables.md) [支持的插件](./docs/SupportPluginsVariables.md)**
**[文字相关变量](./docs/text-variables.md) [玩家相关变量](./docs/player-variables.md) [服务器相关变量](./docs/server-variables.md) [支持的插件](./docs/SupportPluginsVariables.md)**
## **命令与权限节点**
|命令|权限节点|权限介绍|默认权限|
|:-:|:-:|:-:|:-:|
|/newtipsariables|newtipsariables.admin|主命令|OP|
|/newtipsariables reload|newtipsariables.admin.reload|重载配置文件|OP|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>cn.stevei5mc</groupId>
<artifactId>NewTipsVariables</artifactId>
<version>1.0.0-beta7</version>
<version>1.0.0-beta8</version>

<repositories>
<repository>
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/cn/stevei5mc/NewTipsVariables/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import cn.stevei5mc.NewTipsVariables.variables.supportPlugins.loadSupportPlugins;
import cn.nukkit.Player;
import cn.nukkit.utils.Config;
import cn.stevei5mc.NewTipsVariables.command.NewTipsVariablesCommand;
import cn.stevei5mc.NewTipsVariables.utils.configUtils;

public class Main extends PluginBase {
public static Player player;
Expand All @@ -20,6 +22,11 @@ public class Main extends PluginBase {
private Config configInPlayer;
private Config worldName;
private Config language;
//定义配置文件的一些信息
public static int config1Version = 1; //config.yml
public static int config2Version = 1; //player.yml
public static int config3Version = 1; //server.yml

public static Main getInstance() {
return instance;
}
Expand All @@ -34,6 +41,8 @@ public void onEnable() {
//判断需要的前置插件是否存在
if (this.getServer().getPluginManager().getPlugin("Tips") != null) {
//存在则加载该插件
this.getServer().getCommandMap().register("", new NewTipsVariablesCommand());
configUtils.configUtils();
this.deBugMode();//用于加载debug信息
this.tipsvariables();//加载变量部分
this.loadover();//加载完成显示的内容
Expand Down Expand Up @@ -113,4 +122,9 @@ public Config getWorldName() {
public Config getLanguage() {
return this.language;
}

//重载配置
public void reload() {
loadConfigRes();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package cn.stevei5mc.NewTipsVariables.command;

import cn.stevei5mc.NewTipsVariables.Main;
import cn.nukkit.command.Command;
import cn.nukkit.command.CommandSender;
import cn.nukkit.command.data.CommandParameter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.concurrent.ConcurrentHashMap;

/**
* @author SmallasWater
*/
public abstract class BaseCommand extends Command {

private final ArrayList<BaseSubCommand> subCommand = new ArrayList<>();
private final ConcurrentHashMap<String, Integer> subCommands = new ConcurrentHashMap<>();
protected final Main main = Main.getInstance();

public BaseCommand(String name, String description) {
super(name.toLowerCase(), description);
}

/**
* 判断权限
* @param sender 玩家
* @return 是否拥有权限
*/
public boolean hasPermission(CommandSender sender) {
return sender.hasPermission(this.getPermission());
}

@Override
public boolean execute(CommandSender sender, String s, String[] args) {
if(this.hasPermission(sender)) {
if(args.length > 0) {
String subCommand = args[0].toLowerCase();
if (subCommands.containsKey(subCommand)) {
BaseSubCommand command = this.subCommand.get(this.subCommands.get(subCommand));
if (command.canUser(sender)) {
return command.execute(sender, s, args);
}else if (sender.isPlayer()) {
sender.sendMessage("你没有权限使用此命令!");
}else {
sender.sendMessage("请在游戏内使用此命令!");
}
}else {
this.sendHelp(sender);
}
}else {
this.sendHelp(sender);
}
return true;
}else {
sender.sendMessage("你没有权限使用此命令!");
}
return true;
}

/**
* 发送帮助
* @param sender 玩家
* */
public abstract void sendHelp(CommandSender sender);

protected void addSubCommand(BaseSubCommand cmd) {
this.subCommand.add(cmd);
int commandId = (this.subCommand.size()) - 1;
this.subCommands.put(cmd.getName().toLowerCase(), commandId);
for (String alias : cmd.getAliases()) {
this.subCommands.put(alias.toLowerCase(), commandId);
}
}

protected void loadCommandBase() {
this.commandParameters.clear();
for(BaseSubCommand subCommand : this.subCommand) {
LinkedList<CommandParameter> parameters = new LinkedList<>();
parameters.add(CommandParameter.newEnum(subCommand.getName(), new String[]{subCommand.getName()}));
parameters.addAll(Arrays.asList(subCommand.getParameters()));
this.commandParameters.put(subCommand.getName(), parameters.toArray(new CommandParameter[0]));
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package cn.stevei5mc.NewTipsVariables.command;

import cn.stevei5mc.NewTipsVariables.Main;
import cn.nukkit.command.CommandSender;
import cn.nukkit.command.data.CommandParameter;


/**
* @author SmallasWater
*/
public abstract class BaseSubCommand {

private final String name;
protected final Main main = Main.getInstance();

protected BaseSubCommand(String name) {
this.name = name.toLowerCase();
}

/**
* @param sender CommandSender
* @return boolean
*/
public abstract boolean canUser(CommandSender sender);

/**
* 获取名称
* @return string
*/
public String getName(){
return name;
}

/**
* 获取别名
* @return string[]
*/
public abstract String[] getAliases();

/**
* 命令响应
* @param sender the sender - CommandSender
* @param args The arrugements - String[]
* @param label label..
* @return true if true
*/
public abstract boolean execute(CommandSender sender, String label, String[] args);

/**
* 指令参数.
* @return 提示参数
* */
public abstract CommandParameter[] getParameters();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cn.stevei5mc.NewTipsVariables.command;

import cn.stevei5mc.NewTipsVariables.command.newTipsVariables.ReloadCommand;
import cn.nukkit.Player;
import cn.nukkit.command.CommandSender;

/**
* @author lt_name
*/
public class NewTipsVariablesCommand extends BaseCommand {

public NewTipsVariablesCommand() {
super("NewTipsVariables", "NewTipsVariables管理命令");
this.setPermission("newtipsariables.admin");
this.addSubCommand(new ReloadCommand("reload"));

this.loadCommandBase();
}

@Override
public void sendHelp(CommandSender sender) {
sender.sendMessage("§a/newtipsariables reload §e重载配置文件");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package cn.stevei5mc.NewTipsVariables.command.newTipsVariables;

import cn.stevei5mc.NewTipsVariables.command.BaseSubCommand;
import cn.nukkit.command.CommandSender;
import cn.nukkit.command.data.CommandParameter;

/**
* @author LT_Name
*/
public class ReloadCommand extends BaseSubCommand {

public ReloadCommand(String name) {
super(name);
}

@Override
public boolean canUser(CommandSender sender) {
return sender.hasPermission("newtipsariables.admin.reload");
}

@Override
public String[] getAliases() {
return new String[0];
}

@Override
public boolean execute(CommandSender sender, String label, String[] args) {
this.main.reload();
sender.sendMessage("重载配置完成!");
return true;
}

@Override
public CommandParameter[] getParameters() {
return new CommandParameter[0];
}
}
37 changes: 37 additions & 0 deletions src/main/java/cn/stevei5mc/NewTipsVariables/utils/configUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package cn.stevei5mc.NewTipsVariables.utils;

import cn.stevei5mc.NewTipsVariables.Main;

public class configUtils {
public static void configUtils() {
int cv1 = Main.getInstance().getConfig().getInt("version");
int cv2 = Main.getInstance().getConfigInPlayer().getInt("version");
int cv3 = Main.getInstance().getConfigInServer().getInt("version");
boolean checkConfig = Main.getInstance().getConfig().getBoolean("updata.in-config.check");
if (checkConfig) {
if (Main.config1Version > cv1) {
Main.getInstance().getLogger().warning("§econfig.yml 版本不是最新版");
} else if (Main.config1Version < cv1) {
Main.getInstance().getLogger().error("§cconfig.yml 版本出现了错误");
} else {
Main.getInstance().getLogger().info("§aconfig.yml 版本是最新版");
}

if (Main.config2Version > cv2) {
Main.getInstance().getLogger().warning("§eplayer.yml 版本不是最新版");
} else if (Main.config2Version < cv2) {
Main.getInstance().getLogger().error("§cplayer.yml 版本出现了错误");
} else {
Main.getInstance().getLogger().info("§aplayer.yml 版本是最新版");
}

if (Main.config3Version > cv3) {
Main.getInstance().getLogger().warning("§eserver.yml 版本不是最新版");
} else if (Main.config3Version < cv3) {
Main.getInstance().getLogger().error("§cserver.yml 版本出现了错误");
} else {
Main.getInstance().getLogger().info("§aserver.yml 版本是最新版");
}
}
}
}
12 changes: 10 additions & 2 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
name: NewTipsVariables
main: cn.stevei5mc.NewTipsVariables.Main
version: '1.0.0-beta7'
version: '1.0.0-beta8'
author: stevei5mc
api: ["1.0.14"]
api: ["1.0.14"]

permissions:
newtipsariables.admin:
description: "NewTipsVariables插件管理员权限"
default: op
newtipsariables.admin.reload:
description: "NewTipsVariables插件重载权限"
default: op
Loading