Skip to content

Commit

Permalink
对配置文件进行支持
Browse files Browse the repository at this point in the history
对配置文件进行支持
  • Loading branch information
stevei5mc authored Feb 7, 2024
2 parents ac05c53 + e7dbbe4 commit 14e474d
Show file tree
Hide file tree
Showing 12 changed files with 294 additions and 127 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
target/*
config.yml.md
target/*
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
> **1、将插件放进`plugins`文件夹**
> **2、需确保安装`Tips`插件后重启服务器**
> **3、在`/plugins/NewTipsVariables`文件夹中的`.txt`文件获取相关变量介绍,也可在本页面获取相关的变量介绍**
## **[配置文件使用说明](config-info.md)**
## 变量介绍
### 文字相关的变量
|变量名|对应内容|变量名|对应内容|变量名|对应内容|变量名|对应内容|
Expand Down
2 changes: 1 addition & 1 deletion SupportPluginsVariables.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[返回](README.md)
[返回](README.md) [配置文件说明](config-info.md)
# NewTipsVariables(变量文档)
> **支持的插件篇**
> **按插件的英文字母排序**
Expand Down
76 changes: 76 additions & 0 deletions config-info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
[返回](README.md) [支持的插件](SupportPluginsVariables.md)
# **配置文件使用说明**
> **若未在此说明中写配置项出则代表该配置项还没有支持**
## **[config.yml](src/main/resources/config.yml)**
> **主配置文件**
### **是否释放新的变量说明文档**
```
save-variables-doc: true
```
> **1、该配置项启用后,服务器每次启动后都会生成新的变量文档**
> **2、若关闭后,就算删除变量文档也不会生成新的变量文档**
> **3、该配置项默认启用**
## **[server.yml](src/main/resources/server.yml)**
> **服务器相关变量配置文件**
```
TPS:
low_color: "§c"
medium_value: 9
medium_color: "§e"
high_value: 15
high_color: "§a"
```
> **1、```color```设置显示的颜色,```low``````medium``````high```为显示的范围**
> **2、```value```是一个范围值,```medium``````high```为可设置的范围值,```low```值只能为```0```**
## **[player.yml](src/main/resources/player.yml)**
> **玩家相关变量配置文件**
```
Device:
OS:
Android: "安卓"
iOS: "苹果"
macOS: "苹果但是电脑"
Fire_OS: "Fire_OS"
Gear_VR: "Gear_VR"
HoloLens: "HoloLens"
Windows_10: "Windows 10"
Windows: "Windows"
Dedicated: "Dedicated"
tvOS: "tvOS"
PlayStation: "PlayStation"
Switch: "Switch"
Xbox: "Xbox"
Windows_Phone: "windows但是手机"
Unknown: "未知的系统"
UIProfile:
classic: "classic ui"
pocket: "pocket ui"
Unknown: "Unknown ui
```
> 1、**```OS```玩家的设备系统**
> 2、**```UIProfile```玩家的设备UI**
```
ping:
low_color: "§a"
medium_value: 80
medium_color: "§e"
high_value: 120
high_color: "§c"
HP:
symbols: "§7/"
low_color: "§c"
medium_value: 9
medium_color: "§e"
high_value: 15
high_color: "§a"
Food:
symbols: "§7/"
low_color: "§c"
medium_value: 9
medium_color: "§e"
high_value: 15
high_color: "§a"
```
> **1、```color```设置显示的颜色,```low``````medium``````high```为显示的范围**
> **2、```value```是一个范围值,```medium``````high```为可设置的范围值,```low```值只能为```0```**
> **3、```symbols```是用来设置分割符号的,例如: ```HP: 20/20```**
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-beta3</version>
<version>1.0.0-beta6</version>

<repositories>
<repository>
Expand Down
54 changes: 46 additions & 8 deletions src/main/java/cn/stevei5mc/NewTipsVariables/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,25 @@
import cn.stevei5mc.NewTipsVariables.variables.tipsServerConfig;
import cn.stevei5mc.NewTipsVariables.variables.supportPlugins.loadSupportPlugins;
import cn.nukkit.Player;
import cn.nukkit.utils.Config;

public class Main extends PluginBase {
public static Player player;

private static Main instance;
private static Config config;
private static Config configInServer;
private static Config configInPlayer;
public static Main getInstance() {
return instance;
}

public void onLoad() {
instance = this;
this.loadConfigRes();//加载配置文件
this.loadVarRes();//加载变量文档
}

public void onEnable() {
this.loadresource();//先把资源文件给加载了
//判断需要的前置插件是否存在
if (this.getServer().getPluginManager().getPlugin("Tips") != null) {
//存在则加载该插件
Expand All @@ -34,12 +47,24 @@ public void onDisable() {
this.getLogger().info("§6感谢你的使用");
}

public void loadresource() {
public void loadConfigRes() {
this.getDataFolder().mkdirs(); //创建插件文件夹
//每次都加载最新的变量信息
this.saveResource("base-variables.txt","/base-variables.txt",true);
this.saveResource("SupportPluginsVariables.txt","SupportPluginsVariables.txt",true);
this.getLogger().info("§a变量说明文件加载成功");
this.saveDefaultConfig();
this.saveResource("server.yml",false);
this.saveResource("player.yml",false);
this.config = new Config(this.getDataFolder() + "/config.yml", Config.YAML);
this.configInServer = new Config(this.getDataFolder() + "/server.yml", Config.YAML);
this.configInPlayer = new Config(this.getDataFolder() + "/player.yml", Config.YAML);
}

public void loadVarRes() {
boolean saveVariablesDoc = this.config.getBoolean("save-variables-doc");
if (saveVariablesDoc == true) {
//为true时就每次都加载最新的变量信息
this.saveResource("base-variables.txt",true);
this.saveResource("SupportPluginsVariables.txt",true);
this.getLogger().info("§a变量说明文件加载成功");
}
}

public void tipsvariables() {
Expand All @@ -56,5 +81,18 @@ public void loadover() {
this.getLogger().warning("§c警告:");
this.getLogger().warning("§c本插件为免费且开源的一款插件,如果你是付费获取到的那么你就被骗了");
this.getLogger().info("§a开源链接和使用方法: §bhttps://github.com/stevei5mc/NewTipsVariables");
}
}

@Override
public Config getConfig() {
return this.config;
}

public Config getConfigInServer() {
return this.configInServer;
}

public Config getConfigInPlayer() {
return this.configInPlayer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cn.nukkit.Player;
import cn.nukkit.Server;
import tip.utils.variables.BaseVariable;
import cn.stevei5mc.NewTipsVariables.Main;

public class tipsPlayerConfig extends BaseVariable {
public tipsPlayerConfig(Player player) {
Expand All @@ -20,79 +21,120 @@ public void playerVarConfig() {
addStrReplaceString("{Player-Food}", this.getPlayerFood(player));
addStrReplaceString("{Player-Health}", this.getPlayerHealth(player));
}

//这下面的内容是要从config.yml获取内容的,但是现在还不行

/*这ui档案应该只有classic ui和pocket ui这两种UI(测试出来的)
Unknown UI是为了保险起见加上去的*/
private String playerUiString(int uiprofile) {
String classicUi = Main.getInstance().getConfigInPlayer().getString("Device.UIProfile.classic");
String pocketUi = Main.getInstance().getConfigInPlayer().getString("Device.UIProfile.pocket");
String unknownUi = Main.getInstance().getConfigInPlayer().getString("Device.UIProfile.Unknown");
switch (uiprofile) {
case 0: return "classic ui";
case 1: return "pocket ui";
default: return "Unknown UI";
case 0: return classicUi;
case 1: return pocketUi;
default: return unknownUi;
}
}

//获取玩家的饱食度状态
public static String getPlayerFood(Player player) {
String playerFood = "§a15";
if (player.getFoodData().getLevel() >= 0) {
playerFood = "§c" + player.getFoodData().getLevel();
String playerFoodSymbols = Main.getInstance().getConfigInPlayer().getString("Food.symbols");
String playerFoodLowColor = Main.getInstance().getConfigInPlayer().getString("Food.low_color");
int playerFoodMediumValue = Main.getInstance().getConfigInPlayer().getInt("Food.medium_value");
String playerFoodMediumColor = Main.getInstance().getConfigInPlayer().getString("Food.medium_color");
int playerFoodHgihValue = Main.getInstance().getConfigInPlayer().getInt("Food.high_value");
String playerFoodHgihColor = Main.getInstance().getConfigInPlayer().getString("Food.high_color");
String playerFood = playerFoodHgihColor + playerFoodHgihValue;
float foodValue = player.getFoodData().getLevel();
int foodMaxValue = player.getFoodData().getMaxLevel();
//最低值为0
if (foodValue >= 0) {
playerFood = playerFoodLowColor + foodValue + playerFoodSymbols + playerFoodLowColor + foodMaxValue;
}
if (player.getFoodData().getLevel() >= 9) {
playerFood = "§e" + player.getFoodData().getLevel();
if (foodValue >= playerFoodMediumValue) {
playerFood = playerFoodMediumColor + foodValue + playerFoodSymbols + playerFoodMediumColor + foodMaxValue;
}
if (player.getFoodData().getLevel() >= 15) {
playerFood = "§a" + player.getFoodData().getLevel();
if (foodValue >= playerFoodHgihValue) {
playerFood = playerFoodHgihColor + foodValue + playerFoodSymbols + playerFoodHgihColor + foodMaxValue;
}
return playerFood;
}

//获取玩家的生命值状态
public static String getPlayerHealth(Player player) {
String playerFood = "§a15";
if (player.getHealth() >= 0) {
playerFood = "§c" + player.getHealth();
String playerHealthSymbols = Main.getInstance().getConfigInPlayer().getString("HP.symbols");
String playerHealthLowColor = Main.getInstance().getConfigInPlayer().getString("HP.low_color");
int playerHealthMediumValue = Main.getInstance().getConfigInPlayer().getInt("HP.medium_value");
String playerHealthMediumColor = Main.getInstance().getConfigInPlayer().getString("HP.medium_color");
int playerHealthHgihValue = Main.getInstance().getConfigInPlayer().getInt("HP.high_value");
String playerHealthHgihColor = Main.getInstance().getConfigInPlayer().getString("HP.high_color");
String playerHealth = playerHealthHgihColor + playerHealthHgihValue;
float healthValue = player.getHealth();
int healthMaxValue = player.getMaxHealth();
//最低值为0
if (healthValue >= 0) {
playerHealth = playerHealthLowColor + healthValue + playerHealthSymbols + playerHealthLowColor + healthMaxValue;
}
if (player.getHealth() >= 9) {
playerFood = "§e" + player.getHealth();
if (healthValue >= playerHealthMediumValue) {
playerHealth = playerHealthMediumColor + healthValue + playerHealthSymbols + playerHealthMediumColor + healthMaxValue;
}
if (player.getHealth() >= 15) {
playerFood = "§a" + player.getHealth();
if (healthValue >= playerHealthHgihValue) {
playerHealth = playerHealthHgihColor + healthValue + playerHealthSymbols + playerHealthHgihColor + healthMaxValue;
}
return playerFood;
return playerHealth;
}

private String mapDeviceOSToString(int os) {
String osAndroid = Main.getInstance().getConfigInPlayer().getString("Device.OS.Android");
String osIOS = Main.getInstance().getConfigInPlayer().getString("Device.OS.iOS");
String osMacOS = Main.getInstance().getConfigInPlayer().getString("Device.OS.macOS");
String osFireOS = Main.getInstance().getConfigInPlayer().getString("Device.OS.Fire_OS");
String osGearVR = Main.getInstance().getConfigInPlayer().getString("Device.OS.Gear_VR");
String osHoloLens = Main.getInstance().getConfigInPlayer().getString("Device.OS.HoloLens");
String osWindows10 = Main.getInstance().getConfigInPlayer().getString("Device.OS.Windows_10");
String osWindows = Main.getInstance().getConfigInPlayer().getString("Device.OS.Windows");
String osDedicated = Main.getInstance().getConfigInPlayer().getString("Device.OS.Dedicated");
String osTvOS = Main.getInstance().getConfigInPlayer().getString("Device.OS.tvOS");
String osPlayStation = Main.getInstance().getConfigInPlayer().getString("Device.OS.PlayStation");
String osSwitch = Main.getInstance().getConfigInPlayer().getString("Device.OS.Switch");
String osXbox = Main.getInstance().getConfigInPlayer().getString("Device.OS.Xbox");
String osWindowsPhone = Main.getInstance().getConfigInPlayer().getString("Device.OS.Windows_Phone");
String osUnknown = Main.getInstance().getConfigInPlayer().getString("Device.OS.Unknown");
switch (os) {
case 1: return "Android";
case 2: return "iOS";
case 3: return "macOS";
case 4: return "Fire OS";
case 5: return "Gear VR";
case 6: return "HoloLens";
case 7: return "Windows 10";
case 8: return "Windows";
case 9: return "Dedicated";
case 10: return "tvOS";
case 11: return "PlayStation";
case 12: return "Switch";
case 13: return "Xbox";
case 14: return "Windows Phone";
case 1: return osAndroid;
case 2: return osIOS;
case 3: return osMacOS;
case 4: return osFireOS;
case 5: return osGearVR;
case 6: return osHoloLens;
case 7: return osWindows10;
case 8: return osWindows;
case 9: return osDedicated;
case 10: return osTvOS;
case 11: return osPlayStation;
case 12: return osSwitch;
case 13: return osXbox;
case 14: return osWindowsPhone;
default: return osUnknown;
}
return "Unknown";
}

public static String getPlayerPing(Player player) {
String playerMS = "§a0";
if (player.getPing() >= 0) {
playerMS = "§a" + player.getPing();
String playerPingLowColor = Main.getInstance().getConfigInPlayer().getString("ping.low_color");
int playerPingMediumValue = Main.getInstance().getConfigInPlayer().getInt("ping.medium_value");
String playerPingMediumColor = Main.getInstance().getConfigInPlayer().getString("ping.medium_color");
int playerPingHgihValue = Main.getInstance().getConfigInPlayer().getInt("ping.high_value");
String playerPingHgihColor = Main.getInstance().getConfigInPlayer().getString("ping.high_color");
String playerMS = playerPingHgihColor + playerPingHgihValue;
int pingValue = player.getPing();
//最低值为0
if (pingValue >= 0) {
playerMS = playerPingLowColor + pingValue;
}
if (player.getPing() >= 80) {
playerMS = "§e" + player.getPing();
if (pingValue >= playerPingMediumValue) {
playerMS = playerPingMediumColor + pingValue;
}
if (player.getPing() >= 120) {
playerMS = "§c" + player.getPing();
if (pingValue >= playerPingHgihValue) {
playerMS = playerPingHgihColor + pingValue;
}
return playerMS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cn.nukkit.Player;
import cn.nukkit.Server;
import tip.utils.variables.BaseVariable;
import cn.stevei5mc.NewTipsVariables.Main;

public class tipsServerConfig extends BaseVariable {
public tipsServerConfig(Player player) {
Expand All @@ -17,18 +18,23 @@ public void serverVarConfig() {
addStrReplaceString("{Server-Tps}", this.getServerTps(player));
}

//这下面的内容是要从config.yml获取内容的,但是现在还不行

public static String getServerTps(Player player) {
String serverTps = "§a15";
if (Server.getInstance().getTicksPerSecond() >= 0) {
serverTps = "§c" + Server.getInstance().getTicksPerSecond();
String serverTpslowColor = Main.getInstance().getConfigInServer().getString("TPS.low_color");
int serverTpsMediumValue = Main.getInstance().getConfigInServer().getInt("TPS.medium_value");
String serverTpsMediumColor = Main.getInstance().getConfigInServer().getString("TPS.medium_color");
int serverTpsHgihValue = Main.getInstance().getConfigInServer().getInt("TPS.high_value");
String serverTpsHgihColor = Main.getInstance().getConfigInServer().getString("TPS.high_color");
String serverTps = serverTpsHgihColor + serverTpsHgihValue;
float tpsValue = Server.getInstance().getTicksPerSecond();
//最低值为0
if (tpsValue >= 0) {
serverTps = serverTpslowColor + tpsValue;
}
if (Server.getInstance().getTicksPerSecond() >= 9) {
serverTps = "§e" + Server.getInstance().getTicksPerSecond();
if (tpsValue >= serverTpsMediumValue) {
serverTps = serverTpsMediumColor + tpsValue;
}
if (Server.getInstance().getTicksPerSecond() >= 15) {
serverTps = "§a" + Server.getInstance().getTicksPerSecond();
if (tpsValue >= serverTpsHgihValue) {
serverTps = serverTpsHgihColor + tpsValue;
}
return serverTps;
}
Expand Down
Loading

0 comments on commit 14e474d

Please sign in to comment.