add max size configuration

This commit is contained in:
zhangyuheng 2024-02-07 19:31:41 +08:00
parent fa8244e6aa
commit 8d62c34a66
3 changed files with 53 additions and 1 deletions

View File

@ -1,5 +1,6 @@
package cn.lunadeer.dominion.controllers;
import cn.lunadeer.dominion.Dominion;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.utils.Notification;
import cn.lunadeer.dominion.utils.Time;
@ -15,7 +16,7 @@ import static cn.lunadeer.dominion.controllers.Apis.notOwner;
public class DominionController {
public static List<DominionDTO> all(Player owner){
public static List<DominionDTO> all(Player owner) {
return DominionDTO.selectAll(owner.getUniqueId());
}
@ -62,6 +63,17 @@ public class DominionController {
Notification.error(owner, "禁止跨世界操作");
return null;
}
int x_length = Math.abs((int) (loc1.getX() - loc2.getX()));
int y_length = Math.abs((int) (loc1.getY() - loc2.getY()));
int z_length = Math.abs((int) (loc1.getZ() - loc2.getZ()));
if (x_length < 4 || y_length < 4 || z_length < 4) {
Notification.error(owner, "领地的任意一边长度不得小于4");
return null;
}
if (x_length > Dominion.config.getMaxX() || y_length > Dominion.config.getMaxY() || z_length > Dominion.config.getMaxZ()) {
Notification.error(owner, "领地尺寸不能超过 " + Dominion.config.getMaxX() + " x " + Dominion.config.getMaxY() + " x " + Dominion.config.getMaxZ());
return null;
}
DominionDTO dominion = new DominionDTO(owner.getUniqueId(), name, owner.getWorld().getName(),
(int) Math.min(loc1.getX(), loc2.getX()), (int) Math.min(loc1.getY(), loc2.getY()),
(int) Math.min(loc1.getZ(), loc2.getZ()), (int) Math.max(loc1.getX(), loc2.getX()),

View File

@ -21,6 +21,9 @@ public class ConfigManager {
_db_user = _file.getString("Database.User", "postgres");
_db_pass = _file.getString("Database.Pass", "postgres");
_auto_create_radius = _file.getInt("AutoCreateRadius", 10);
_max_x = _file.getInt("MaxX", 128);
_max_y = _file.getInt("MaxY", 64);
_max_z = _file.getInt("MaxZ", 128);
}
public Boolean isDebug() {
@ -64,6 +67,36 @@ public class ConfigManager {
return _db_pass;
}
public Integer getMaxX() {
return _max_x;
}
public void setMaxX(Integer max_x) {
_max_x = max_x;
_file.set("MaxX", max_x);
_plugin.saveConfig();
}
public Integer getMaxY() {
return _max_y;
}
public void setMaxY(Integer max_y) {
_max_y = max_y;
_file.set("MaxY", max_y);
_plugin.saveConfig();
}
public Integer getMaxZ() {
return _max_z;
}
public void setMaxZ(Integer max_z) {
_max_z = max_z;
_file.set("MaxZ", max_z);
_plugin.saveConfig();
}
public Integer getAutoCreateRadius() {
return _auto_create_radius;
}
@ -86,4 +119,8 @@ public class ConfigManager {
private String _db_name;
private Integer _auto_create_radius;
private Integer _max_x;
private Integer _max_y;
private Integer _max_z;
}

View File

@ -6,5 +6,8 @@ Database:
Pass: dominion
AutoCreateRadius: 10
MaxX: 128
MaxY: 64
MaxZ: 128
Debug: false