Skip to content

Commit

Permalink
调整代码
Browse files Browse the repository at this point in the history
将部分插件的变量放在一起避免过于分散
  • Loading branch information
stevei5mc committed Apr 4, 2024
1 parent 9d4ff7c commit 6db9fdb
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 199 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
- **如果你有开发能力可以为其提供[PR](https://github.com/stevei5mc/NewTipsVariables/pulls)来增加更多变量或修复问题**

## **使用方法**
> **1、将插件放进`plugins`文件夹**
> **2、需确保安装`Tips`插件后重启服务器**
> **3、`/plugins/NewTipsVariables`文件夹中的`.txt`文件获取相关变量介绍,也可在本页面获取相关的变量介绍**
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)**
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/cn/stevei5mc/NewTipsVariables/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Main extends PluginBase {
private Config configInPlayer;
private Config worldName;
private Config language;
public static boolean deBug = false;
//定义配置文件的一些信息
public static int config1Version = 1; //config.yml
public static int config2Version = 1; //player.yml
Expand Down Expand Up @@ -86,6 +87,7 @@ public void loadVarRes() {
public void deBugMode() {
boolean deBug = this.config.getBoolean("debug", false); //这个功能默认关闭,不在config.yml中,需手动加上
if (deBug) {
deBug =t rue;
String debugPerfix = "§7[§cDEBUG§7] ";
this.getLogger().warning(debugPerfix + "§cdebug模式已开启");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package cn.stevei5mc.NewTipsVariables.variables.supportPlugins;

import tip.utils.Api;
import cn.nukkit.Server;
import cn.nukkit.Player;
import cn.stevei5mc.NewTipsVariables.Main;
import tip.utils.variables.BaseVariable;
import cn.stevei5mc.NewTipsVariables.variables.supportPlugins.loadSupportPlugins;
import healthapi.PlayerHealth;
import net.player.api.Point;
import com.task.utils.tasks.PlayerFile;
import com.task.utils.tasks.taskitems.PlayerTask;
import java.util.LinkedList;
import ore.area.utils.player.PlayerClass;
import ore.area.utils.area.AreaClass;
import ore.area.utils.Tools;
import ore.area.AreaMainClass;
import java.util.LinkedHashMap;

public class SmallasWaterPlugins extends BaseVariable {
public SmallasWaterPlugins(Player player) {
super(player);
}

public void strReplace() {
ruoShuiPlugins();
}

public void ruoShuiPlugins() {
String loadPlugin;
boolean debug = Main.deBug;
String loadSMsg = loadSupportPlugins.loadSuccessMsg;
String loadFMsg = loadSupportPlugins.loadFailureMsg;
//需要加载的变量的插件
loadPlugin = "playerPoints";
if (Server.getInstance().getPluginManager().getPlugin(loadPlugin) != null) {
//存在
addStrReplaceString("{point}", String.format("%.2f", Point.myPoint(player)));
if (debug) {Main.getInstance().getLogger().info(loadSMsg.replace("{0}",loadPlugin));}
} else {
if (debug) {Main.getInstance().getLogger().info(loadFMsg.replace("{0}",loadPlugin));}
}
loadPlugin = "OreArea";
if (Server.getInstance().getPluginManager().getPlugin(loadPlugin) != null) {
//这个代码的是复制TipsVeriable的
PlayerClass playerClass = PlayerClass.getPlayerClass(player.getName());
addStrReplaceString("{orearea-level-this}", playerClass.getMaxAreaLevel() + "");
addStrReplaceString("{orearea-level-next}", playerClass.getMaxAreaLevel() + 1 + "");
AreaClass areaClass = Tools.getDefaultArea(player, 2);
String time = "§c不在范围,无法获取可使用时间";
String reset = "§c不在范围,无法获取刷新时间";
String name = "§c没有解锁矿区";
if(areaClass != null){
if(AreaMainClass.getInstance().useTime.containsKey(player.getName())) {
LinkedHashMap<String,Integer> map = AreaMainClass.getInstance().useTime.get(player.getName());
if(map.containsKey(areaClass.getName())){
int i = Math.round(map.get(areaClass.getName()) /60);
if(i != 0) {
time = "§7" +i + "§2分钟";
}else{
time = "§7" +areaClass.getUseTime() + "§2秒";
}
}
}else{
if(!areaClass.isKey()){
time = "§c未开启";
}else{
if(playerClass.canKey(areaClass.getName())) {
if(areaClass.getUseTime() == -1) {
time = "§7无时限";
}else{
int i = Math.round(areaClass.getUseTime() /60);
if(i != 0) {
time = "§7" +i + "§2分钟";
}else{
time = "§7" +areaClass.getUseTime() + "§2秒";
}
}
}else{
time = "§c未解锁矿区";
}
}

}
if(AreaMainClass.timer.containsKey(areaClass.getName())) {
reset = String.valueOf(AreaMainClass.timer.get(areaClass.getName()));
}else{
reset = "§c未刷新";
}
name = areaClass.getName();
}
addStrReplaceString("{orearea-time-use}", time);
addStrReplaceString("{orearea-time-reset}", reset);
addStrReplaceString("{orearea-name}", name);
if (debug) {Main.getInstance().getLogger().info(loadSMsg.replace("{0}",loadPlugin));}
} else {
if (debug) {Main.getInstance().getLogger().info(loadFMsg.replace("{0}",loadPlugin));}
}
loadPlugin = "RSTask";
if (Server.getInstance().getPluginManager().getPlugin(loadPlugin) != null) {
PlayerFile file = PlayerFile.getPlayerFile(this.player.getName());
LinkedList<PlayerTask> tasks = file.getInviteTasks();
String taskName = "暂无";
if (tasks.size() > 0) {
PlayerTask task = (PlayerTask)tasks.get(0);
if (task != null) {
taskName = task.getTaskName();
}
}

this.addStrReplaceString("{task-name}", taskName);
this.addStrReplaceString("{task-count}", file.getCount() + "");
if (debug) {Main.getInstance().getLogger().info(loadSMsg.replace("{0}",loadPlugin));}
} else {
if (debug) {Main.getInstance().getLogger().info(loadFMsg.replace("{0}",loadPlugin));}
}
loadPlugin = "HealthAPI";
if (Server.getInstance().getPluginManager().getPlugin(loadPlugin) != null) {
PlayerHealth health = PlayerHealth.getPlayerHealth(player);
addStrReplaceString("{h}", String.format("%.1f", health.getHealth()));
addStrReplaceString("{mh}", health.getMaxHealth() + "");
addStrReplaceString("{hb}", String.format("%.2f", health.getHealthPercentage() * 100.0D));
if (debug) {Main.getInstance().getLogger().info(loadSMsg.replace("{0}",loadPlugin));}
} else {
if (debug) {Main.getInstance().getLogger().info(loadFMsg.replace("{0}",loadPlugin));}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,27 @@
import cn.nukkit.Server;
import cn.nukkit.Player;
import cn.stevei5mc.NewTipsVariables.variables.supportPlugins.economyApiVariable;
import cn.stevei5mc.NewTipsVariables.variables.supportPlugins.smallasWater.playerPointsVariable;
import cn.stevei5mc.NewTipsVariables.variables.supportPlugins.smallasWater.OreAreaVariable;
import cn.stevei5mc.NewTipsVariables.variables.supportPlugins.smallasWater.RsTaskVariable;
import cn.stevei5mc.NewTipsVariables.Main;
import cn.stevei5mc.NewTipsVariables.variables.supportPlugins.smallasWater.HealthAPIVariable;
import cn.stevei5mc.NewTipsVariables.variables.supportPlugins.SmallasWaterPlugins;

public class loadSupportPlugins{
//加载相关插件的变量时的提示
public static String debugPerfix = "§7[§cDEBUG§7] ";
public static String loadSuccessMsg = debugPerfix+"§a找到插件§e【§b{0}§e】§a相关变量已加载";
public static String loadFailureMsg = debugPerfix+"§c无法找到插件§e【§b{0}§e】§c相关变量加载失败,请安装相关插件再试";

public class loadSupportPlugins {

public static void loadSupportVariables(Player player) {
boolean debug = Main.getInstance().getConfig().getBoolean("debug", false);
//加载相关插件的变量时的提示
String debugPerfix = "§7[§cDEBUG§7] ";
String loadPlugin;
String loadSuccessMsg = "§a找到插件§e【§b{0}§e】§a相关变量已加载";
String loadFailureMsg = "§c无法找到插件§e【§b{0}§e】§c相关变量加载失败,请安装相关插件再试";
//需要加载的变量的插件
loadPlugin = "playerPoints";
if (Server.getInstance().getPluginManager().getPlugin(loadPlugin) != null) {
//存在
Api.registerVariables("playerPointsVariable", playerPointsVariable.class);
if (debug) {Main.getInstance().getLogger().info(loadSuccessMsg.replace("{0}",loadPlugin));}
} else {
if (debug) {Main.getInstance().getLogger().info(loadFailureMsg.replace("{0}",loadPlugin));}
}
String loadPlugin;
boolean debug = Main.deBug;
loadPlugin = "EconomyAPI";
if (Server.getInstance().getPluginManager().getPlugin(loadPlugin) != null) {
//存在
Api.registerVariables("economyApiVariable", economyApiVariable.class);
if (debug) {Main.getInstance().getLogger().info(loadSuccessMsg.replace("{0}",loadPlugin));}
} else {
if (debug) {Main.getInstance().getLogger().info(loadFailureMsg.replace("{0}",loadPlugin));}
}
loadPlugin = "OreArea";
if (Server.getInstance().getPluginManager().getPlugin(loadPlugin) != null) {
//存在
Api.registerVariables("OreAreaVariable", OreAreaVariable.class);
if (debug) {Main.getInstance().getLogger().info(loadSuccessMsg.replace("{0}",loadPlugin));}
} else {
if (debug) {Main.getInstance().getLogger().info(loadFailureMsg.replace("{0}",loadPlugin));}
}
loadPlugin = "RSTask";
if (Server.getInstance().getPluginManager().getPlugin(loadPlugin) != null) {
Api.registerVariables("RsTaskVariable", RsTaskVariable.class);
if (debug) {Main.getInstance().getLogger().info(loadSuccessMsg.replace("{0}",loadPlugin));}
} else {
if (debug) {Main.getInstance().getLogger().info(loadFailureMsg.replace("{0}",loadPlugin));}
} else if (debug){
Main.getInstance().getLogger().info(loadFailureMsg.replace("{0}",loadPlugin));
}
loadPlugin = "HealthAPI";
if (Server.getInstance().getPluginManager().getPlugin(loadPlugin) != null) {
Api.registerVariables("HealthAPIVariable", HealthAPIVariable.class);
if (debug) {Main.getInstance().getLogger().info(loadSuccessMsg.replace("{0}",loadPlugin));}
} else {
if (debug) {Main.getInstance().getLogger().info(loadFailureMsg.replace("{0}",loadPlugin));}
}
Api.registerVariables("SmallasWaterPlugins", SmallasWaterPlugins.class);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 6db9fdb

Please sign in to comment.