Skip to content

Commit

Permalink
管理员可通过游戏内TUI实现领地系统配置
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdeZhang committed May 10, 2024
1 parent 2136953 commit 1eb31e2
Show file tree
Hide file tree
Showing 13 changed files with 578 additions and 95 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
- 采用 TUI 方式进行权限配置交互,简单快捷;
- 支持基础价格系统;
- 领地区域可视化;
- 管理员可在游戏内使用TUI配置领地系统;

## 支持版本

Expand All @@ -44,7 +45,6 @@
## TODO

- WebUI
- Admin TUI

## 建议与反馈

Expand Down
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.lunadeer</groupId>
<artifactId>Dominion</artifactId>
<version>1.22.2-beta</version>
<version>1.23.8-beta</version>
<packaging>jar</packaging>

<name>Dominion</name>
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/cn/lunadeer/dominion/Commands.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package cn.lunadeer.dominion;

import cn.lunadeer.dominion.commands.DominionFlag;
import cn.lunadeer.dominion.commands.DominionOperate;
import cn.lunadeer.dominion.commands.Operator;
import cn.lunadeer.dominion.commands.PlayerPrivilege;
import cn.lunadeer.dominion.commands.*;
import cn.lunadeer.dominion.controllers.PlayerController;
import cn.lunadeer.dominion.dtos.PlayerDTO;
import cn.lunadeer.dominion.tuis.*;
import cn.lunadeer.dominion.tuis.Apis;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
Expand Down Expand Up @@ -149,6 +147,9 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
case "config":
DominionConfig.show(sender, args);
break;
case "set_config":
SetConfig.handler(sender, args);
break;
default:
return false;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/cn/lunadeer/dominion/Dominion.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public void onEnable() {
if (config.getEconomyEnable()) {
vault = new VaultConnect(this);
if (vault.getEconomy() == null) {
XLogger.err("你没有安装 Vault 前置插件,无法使用经济功能。");
config.setEconomyEnable(false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,9 @@ public static void teleportToDominion(CommandSender sender, String[] args) {
return;
}
}

Notification.info(player, "传送将在 " + Dominion.config.getTpDelay() + " 秒后执行");
if (Dominion.config.getTpDelay() > 0) {
Notification.info(player, "传送将在 " + Dominion.config.getTpDelay() + " 秒后执行");
}
Cache.instance.NextTimeAllowTeleport.put(player.getUniqueId(), now.plusSeconds(Dominion.config.getTpCoolDown()));
Dominion.scheduler.region.runDelayed(Dominion.instance, (instance) -> {
if (player.isOnline()) {
Expand Down
254 changes: 254 additions & 0 deletions src/main/java/cn/lunadeer/dominion/commands/SetConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
package cn.lunadeer.dominion.commands;

import cn.lunadeer.dominion.Dominion;
import cn.lunadeer.dominion.tuis.DominionConfig;
import cn.lunadeer.dominion.utils.Notification;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import static cn.lunadeer.dominion.commands.Apis.notOpOrConsole;

public class SetConfig {

public static void handler(CommandSender sender, String[] args) {
if (notOpOrConsole(sender)) return;
if (args.length < 2) {
Notification.error(sender, "参数错误");
return;
}
switch (args[1]) {
case "auto_create_radius":
setAutoCreateRadius(sender, args);
break;
case "limit_max_y":
setLimitMaxY(sender, args);
break;
case "limit_min_y":
setLimitMinY(sender, args);
break;
case "limit_size_x":
setLimitSizeX(sender, args);
break;
case "limit_size_z":
setLimitSizeZ(sender, args);
break;
case "limit_size_y":
setLimitSizeY(sender, args);
break;
case "limit_amount":
setLimitAmount(sender, args);
break;
case "limit_depth":
setLimitDepth(sender, args);
break;
case "limit_vert":
setLimitVert(sender, args);
break;
case "limit_op_bypass":
setLimitOpBypass(sender, args);
break;
case "tp_enable":
setTpEnable(sender, args);
break;
case "tp_delay":
setTpDelay(sender, args);
break;
case "tp_cool_down":
setTpCoolDown(sender, args);
break;
case "economy_enable":
setEconomyEnable(sender, args);
break;
case "economy_price":
setEconomyPrice(sender, args);
break;
case "economy_only_xz":
setEconomyOnlyXZ(sender, args);
break;
case "economy_refund":
setEconomyRefund(sender, args);
break;
default:
Notification.error(sender, "未知参数");
}
}

public static void refreshPageOrNot(CommandSender sender, String[] args) {
if (args.length == 4) {
int page = Integer.parseInt(args[3]);
String[] newArgs = new String[2];
newArgs[0] = "config";
newArgs[1] = String.valueOf(page);
DominionConfig.show(sender, newArgs);
}
}

private static void setAutoCreateRadius(CommandSender sender, String[] args) {
int size = Integer.parseInt(args[2]);
if (size < 2) {
Dominion.config.setAutoCreateRadius(2);
Notification.error(sender, "自动创建半径不能小于2");
} else {
Dominion.config.setAutoCreateRadius(size);
}
refreshPageOrNot(sender, args);
}

private static void adjustSizeY() {
if (Dominion.config.getLimitVert()) {
Dominion.config.setLimitSizeY(Dominion.config.getLimitMaxY() - Dominion.config.getLimitMinY() + 1);
}
}

private static void setLimitMaxY(CommandSender sender, String[] args) {
int maxY = Integer.parseInt(args[2]);
if (maxY <= Dominion.config.getLimitMinY()) {
Notification.error(sender, "最高Y坐标限制不能小于最低Y坐标限制");
return;
}
Dominion.config.setLimitMaxY(maxY);
adjustSizeY();
refreshPageOrNot(sender, args);
}

private static void setLimitMinY(CommandSender sender, String[] args) {
int minY = Integer.parseInt(args[2]);
if (minY >= Dominion.config.getLimitMaxY()) {
Notification.error(sender, "最低Y坐标限制不能大于最高Y坐标限制");
return;
}
Dominion.config.setLimitMinY(minY);
adjustSizeY();
refreshPageOrNot(sender, args);
}

private static void setLimitSizeX(CommandSender sender, String[] args) {
int sizeX = Integer.parseInt(args[2]);
if (sizeX != -1 && sizeX < 4) {
Dominion.config.setLimitSizeX(4);
Notification.error(sender, "X轴(东西)最大尺寸不能小于4");
} else {
Dominion.config.setLimitSizeX(sizeX);
}
refreshPageOrNot(sender, args);
}

private static void setLimitSizeZ(CommandSender sender, String[] args) {
int sizeZ = Integer.parseInt(args[2]);
if (sizeZ != -1 && sizeZ < 4) {
Dominion.config.setLimitSizeZ(4);
Notification.error(sender, "Z轴(南北)最大尺寸不能小于4");
return;
} else {
Dominion.config.setLimitSizeZ(sizeZ);
}
refreshPageOrNot(sender, args);
}

private static void setLimitSizeY(CommandSender sender, String[] args) {
int sizeY = Integer.parseInt(args[2]);
if (sizeY != -1 && sizeY < 4) {
Dominion.config.setLimitSizeY(4);
Notification.error(sender, "Y轴(垂直)最大尺寸不能小于4");
} else {
Dominion.config.setLimitSizeY(sizeY);
}
refreshPageOrNot(sender, args);
}

private static void setLimitAmount(CommandSender sender, String[] args) {
int amount = Integer.parseInt(args[2]);
if (amount != -1 && amount < 0) {
Dominion.config.setLimitAmount(0);
Notification.error(sender, "每个玩家领地数量限制不能小于0");
} else {
Dominion.config.setLimitAmount(amount);
}
refreshPageOrNot(sender, args);
}

private static void setLimitDepth(CommandSender sender, String[] args) {
int depth = Integer.parseInt(args[2]);
if (depth != -1 && depth < 0) {
Dominion.config.setLimitDepth(0);
Notification.error(sender, "领地深度限制不能小于0");
} else {
Dominion.config.setLimitDepth(depth);
}
refreshPageOrNot(sender, args);
}

private static void setLimitVert(CommandSender sender, String[] args) {
boolean limitVert = Boolean.parseBoolean(args[2]);
Dominion.config.setLimitVert(limitVert);
adjustSizeY();
refreshPageOrNot(sender, args);
}

private static void setLimitOpBypass(CommandSender sender, String[] args) {
boolean limitOpBypass = Boolean.parseBoolean(args[2]);
Dominion.config.setLimitOpBypass(limitOpBypass);
refreshPageOrNot(sender, args);
}

private static void setTpEnable(CommandSender sender, String[] args) {
boolean tpEnable = Boolean.parseBoolean(args[2]);
Dominion.config.setTpEnable(tpEnable);
refreshPageOrNot(sender, args);
}

private static void setTpDelay(CommandSender sender, String[] args) {
int tpDelay = Integer.parseInt(args[2]);
if (tpDelay < 0) {
Dominion.config.setTpDelay(0);
Notification.error(sender, "传送延迟不能小于0");
} else {
Dominion.config.setTpDelay(tpDelay);
}
refreshPageOrNot(sender, args);
}

private static void setTpCoolDown(CommandSender sender, String[] args) {
int tpCoolDown = Integer.parseInt(args[2]);
if (tpCoolDown < 0) {
Dominion.config.setTpCoolDown(0);
Notification.error(sender, "传送冷却时间不能小于0");
} else {
Dominion.config.setTpCoolDown(tpCoolDown);
}
refreshPageOrNot(sender, args);
}

private static void setEconomyEnable(CommandSender sender, String[] args) {
boolean economyEnable = Boolean.parseBoolean(args[2]);
Dominion.config.setEconomyEnable(economyEnable);
refreshPageOrNot(sender, args);
}

private static void setEconomyPrice(CommandSender sender, String[] args) {
float economyPrice = Float.parseFloat(args[2]);
if (economyPrice < 0) {
Dominion.config.setEconomyPrice(0.0f);
Notification.error(sender, "每方块单价不能小于0");
} else {
Dominion.config.setEconomyPrice(economyPrice);
}
refreshPageOrNot(sender, args);
}

private static void setEconomyOnlyXZ(CommandSender sender, String[] args) {
boolean economyOnlyXZ = Boolean.parseBoolean(args[2]);
Dominion.config.setEconomyOnlyXZ(economyOnlyXZ);
refreshPageOrNot(sender, args);
}

private static void setEconomyRefund(CommandSender sender, String[] args) {
float economyRefund = Float.parseFloat(args[2]);
if (economyRefund < 0) {
Dominion.config.setEconomyRefund(0.0f);
Notification.error(sender, "领地退款比例不能小于0");
} else {
Dominion.config.setEconomyRefund(economyRefund);
}
}
}
Loading

0 comments on commit 1eb31e2

Please sign in to comment.