Skip to content

Commit

Permalink
配置文件新增支持配置圈地最小限制 #28
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdeZhang committed Sep 30, 2024
1 parent ed6dc7c commit be496aa
Show file tree
Hide file tree
Showing 9 changed files with 301 additions and 102 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "cn.lunadeer"
version = "2.10.2-beta"
version = "2.11.0-beta"

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,20 +727,28 @@ private static boolean sizeNotValid(AbstractOperator operator, int x1, int y1, i
int x_length = x2 - x1;
int y_length = y2 - y1;
int z_length = z2 - z1;
if (x_length < 4 || y_length < 4 || z_length < 4) {
operator.setResponse(FAIL.addMessage(Translation.Messages_SizeShouldBeGreaterThan4));
if (x_length < Dominion.config.getLimitSizeMinX(operator.getPlayer())) {
operator.setResponse(FAIL.addMessage(Translation.Messages_SizeXShouldBeGreaterThan, Dominion.config.getLimitSizeMinX(operator.getPlayer())));
return true;
}
if (x_length > Dominion.config.getLimitSizeX(operator.getPlayer()) && Dominion.config.getLimitSizeX(operator.getPlayer()) > 0) {
operator.setResponse(FAIL.addMessage(Translation.Messages_SizeXShouldBeLessThan, Dominion.config.getLimitSizeX(operator.getPlayer())));
if (y_length < Dominion.config.getLimitSizeMinY(operator.getPlayer())) {
operator.setResponse(FAIL.addMessage(Translation.Messages_SizeYShouldBeGreaterThan, Dominion.config.getLimitSizeMinY(operator.getPlayer())));
return true;
}
if (y_length > Dominion.config.getLimitSizeY(operator.getPlayer()) && Dominion.config.getLimitSizeY(operator.getPlayer()) > 0) {
operator.setResponse(FAIL.addMessage(Translation.Messages_SizeYShouldBeLessThan, Dominion.config.getLimitSizeY(operator.getPlayer())));
if (z_length < Dominion.config.getLimitSizeMinZ(operator.getPlayer())) {
operator.setResponse(FAIL.addMessage(Translation.Messages_SizeZShouldBeGreaterThan, Dominion.config.getLimitSizeMinZ(operator.getPlayer())));
return true;
}
if (z_length > Dominion.config.getLimitSizeZ(operator.getPlayer()) && Dominion.config.getLimitSizeZ(operator.getPlayer()) > 0) {
operator.setResponse(FAIL.addMessage(Translation.Messages_SizeZShouldBeLessThan, Dominion.config.getLimitSizeZ(operator.getPlayer())));
if (x_length > Dominion.config.getLimitSizeMaxX(operator.getPlayer()) && Dominion.config.getLimitSizeMaxX(operator.getPlayer()) > 0) {
operator.setResponse(FAIL.addMessage(Translation.Messages_SizeXShouldBeLessThan, Dominion.config.getLimitSizeMaxX(operator.getPlayer())));
return true;
}
if (y_length > Dominion.config.getLimitSizeMaxY(operator.getPlayer()) && Dominion.config.getLimitSizeMaxY(operator.getPlayer()) > 0) {
operator.setResponse(FAIL.addMessage(Translation.Messages_SizeYShouldBeLessThan, Dominion.config.getLimitSizeMaxY(operator.getPlayer())));
return true;
}
if (z_length > Dominion.config.getLimitSizeMaxZ(operator.getPlayer()) && Dominion.config.getLimitSizeMaxZ(operator.getPlayer()) > 0) {
operator.setResponse(FAIL.addMessage(Translation.Messages_SizeZShouldBeLessThan, Dominion.config.getLimitSizeMaxZ(operator.getPlayer())));
return true;
}
if (y2 > Dominion.config.getLimitMaxY(operator.getPlayer())) {
Expand Down
60 changes: 45 additions & 15 deletions core/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,21 @@ public void reload() {
_group_title_suffix = _file.getString("GroupTitle.Suffix", "&#ffffff]");

GroupLimit defaultGroup = new GroupLimit();
defaultGroup.setLimitSizeX(_file.getInt("Limit.SizeX", 128), null);
defaultGroup.setLimitSizeY(_file.getInt("Limit.SizeY", 64), null);
defaultGroup.setLimitSizeZ(_file.getInt("Limit.SizeZ", 128), null);
if (_file.contains("Limit.SizeX")) { // todo: should be removed in the future
defaultGroup.setLimitSizeMaxX(_file.getInt("Limit.SizeX", 128), null);
defaultGroup.setLimitSizeMaxY(_file.getInt("Limit.SizeY", 64), null);
defaultGroup.setLimitSizeMaxZ(_file.getInt("Limit.SizeZ", 128), null);
defaultGroup.setLimitSizeMinX(4, null);
defaultGroup.setLimitSizeMinY(4, null);
defaultGroup.setLimitSizeMinZ(4, null);
} else {
defaultGroup.setLimitSizeMaxX(_file.getInt("Limit.Size.MaxX", 128), null);
defaultGroup.setLimitSizeMaxY(_file.getInt("Limit.Size.MaxY", 64), null);
defaultGroup.setLimitSizeMaxZ(_file.getInt("Limit.Size.MaxZ", 128), null);
defaultGroup.setLimitSizeMinX(_file.getInt("Limit.Size.MinX", 4), null);
defaultGroup.setLimitSizeMinY(_file.getInt("Limit.Size.MinY", 4), null);
defaultGroup.setLimitSizeMinZ(_file.getInt("Limit.Size.MinZ", 4), null);
}
defaultGroup.setLimitMinY(_file.getInt("Limit.MinY", -64), null);
defaultGroup.setLimitMaxY(_file.getInt("Limit.MaxY", 320), null);
defaultGroup.setLimitAmount(_file.getInt("Limit.Amount", 10), null);
Expand Down Expand Up @@ -133,12 +145,18 @@ public void saveAll() {
_file.setInlineComments("Limit.MinY", List.of(Translation.Config_Comment_MinY.trans()));
_file.set("Limit.MaxY", groupLimits.get("default").getLimitMaxY(null));
_file.setInlineComments("Limit.MaxY", List.of(Translation.Config_Comment_MaxY.trans()));
_file.set("Limit.SizeX", groupLimits.get("default").getLimitSizeX(null));
_file.setInlineComments("Limit.SizeX", List.of(Translation.Config_Comment_SizeX.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans()));
_file.set("Limit.SizeY", groupLimits.get("default").getLimitSizeY(null));
_file.setInlineComments("Limit.SizeY", List.of(Translation.Config_Comment_SizeY.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans()));
_file.set("Limit.SizeZ", groupLimits.get("default").getLimitSizeZ(null));
_file.setInlineComments("Limit.SizeZ", List.of(Translation.Config_Comment_SizeZ.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans()));
_file.set("Limit.Size.MaxX", groupLimits.get("default").getLimitSizeMaxX(null));
_file.setInlineComments("Limit.Size.MaxX", List.of(Translation.Config_Comment_SizeMaxX.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans()));
_file.set("Limit.Size.MaxY", groupLimits.get("default").getLimitSizeMaxY(null));
_file.setInlineComments("Limit.Size.MaxY", List.of(Translation.Config_Comment_SizeMaxY.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans()));
_file.set("Limit.Size.MaxZ", groupLimits.get("default").getLimitSizeMaxZ(null));
_file.setInlineComments("Limit.Size.MaxZ", List.of(Translation.Config_Comment_SizeMaxZ.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans()));
_file.set("Limit.Size.MinX", groupLimits.get("default").getLimitSizeMinX(null));
_file.setInlineComments("Limit.Size.MinX", List.of(Translation.Config_Comment_SizeMinX.trans()));
_file.set("Limit.Size.MinY", groupLimits.get("default").getLimitSizeMinY(null));
_file.setInlineComments("Limit.Size.MinY", List.of(Translation.Config_Comment_SizeMinY.trans()));
_file.set("Limit.Size.MinZ", groupLimits.get("default").getLimitSizeMinZ(null));
_file.setInlineComments("Limit.Size.MinZ", List.of(Translation.Config_Comment_SizeMinZ.trans()));
_file.set("Limit.Amount", groupLimits.get("default").getLimitAmount(null));
_file.setInlineComments("Limit.Amount", List.of(Translation.Config_Comment_Amount.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans()));
_file.set("Limit.Depth", groupLimits.get("default").getLimitDepth(null));
Expand Down Expand Up @@ -249,16 +267,28 @@ public String getDbPass() {
return _db_pass;
}

public Integer getLimitSizeX(Player player) {
return groupLimits.get(getPlayerGroup(player)).getLimitSizeX(player.getWorld());
public Integer getLimitSizeMaxX(Player player) {
return groupLimits.get(getPlayerGroup(player)).getLimitSizeMaxX(player.getWorld());
}

public Integer getLimitSizeMaxY(Player player) {
return groupLimits.get(getPlayerGroup(player)).getLimitSizeMaxY(player.getWorld());
}

public Integer getLimitSizeMaxZ(Player player) {
return groupLimits.get(getPlayerGroup(player)).getLimitSizeMaxZ(player.getWorld());
}

public Integer getLimitSizeMinX(Player player) {
return groupLimits.get(getPlayerGroup(player)).getLimitSizeMinX(player.getWorld());
}

public Integer getLimitSizeY(Player player) {
return groupLimits.get(getPlayerGroup(player)).getLimitSizeY(player.getWorld());
public Integer getLimitSizeMinY(Player player) {
return groupLimits.get(getPlayerGroup(player)).getLimitSizeMinY(player.getWorld());
}

public Integer getLimitSizeZ(Player player) {
return groupLimits.get(getPlayerGroup(player)).getLimitSizeZ(player.getWorld());
public Integer getLimitSizeMinZ(Player player) {
return groupLimits.get(getPlayerGroup(player)).getLimitSizeMinZ(player.getWorld());
}

public Integer getAutoCreateRadius() {
Expand Down
120 changes: 93 additions & 27 deletions core/src/main/java/cn/lunadeer/dominion/managers/GroupLimit.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,21 @@ private GroupLimit(File filePath) {
WorldSetting defaultSetting = new WorldSetting(filePath.getName());
defaultSetting.min_y = config.getInt("MinY", -64);
defaultSetting.max_y = config.getInt("MaxY", 320);
defaultSetting.size_x = config.getInt("SizeX", 128);
defaultSetting.size_y = config.getInt("SizeY", 64);
defaultSetting.size_z = config.getInt("SizeZ", 128);
if (config.contains("SizeX")) { // todo: should be removed in the future
defaultSetting.size_max_x = config.getInt("SizeX", 128);
defaultSetting.size_max_y = config.getInt("SizeY", 64);
defaultSetting.size_max_z = config.getInt("SizeZ", 128);
defaultSetting.size_min_x = 4;
defaultSetting.size_min_y = 4;
defaultSetting.size_min_z = 4;
} else {
defaultSetting.size_max_x = config.getInt("Size.MaxX", 128);
defaultSetting.size_max_y = config.getInt("Size.MaxY", 64);
defaultSetting.size_max_z = config.getInt("Size.MaxZ", 128);
defaultSetting.size_min_x = config.getInt("Size.MinX", 4);
defaultSetting.size_min_y = config.getInt("Size.MinY", 4);
defaultSetting.size_min_z = config.getInt("Size.MinZ", 4);
}
defaultSetting.amount = config.getInt("Amount", 10);
defaultSetting.depth = config.getInt("Depth", 3);
defaultSetting.vert = config.getBoolean("Vert", false);
Expand Down Expand Up @@ -68,27 +80,51 @@ public Integer getLimitMaxY(@Nullable World world) {
}
}

public Integer getLimitSizeX(@Nullable World world) {
public Integer getLimitSizeMaxX(@Nullable World world) {
if (world == null || !world_limits.containsKey(world.getName())) {
return world_limits.get("default").size_max_x;
} else {
return world_limits.get(world.getName()).size_max_x;
}
}

public Integer getLimitSizeMaxY(@Nullable World world) {
if (world == null || !world_limits.containsKey(world.getName())) {
return world_limits.get("default").size_max_y;
} else {
return world_limits.get(world.getName()).size_max_y;
}
}

public Integer getLimitSizeMaxZ(@Nullable World world) {
if (world == null || !world_limits.containsKey(world.getName())) {
return world_limits.get("default").size_max_z;
} else {
return world_limits.get(world.getName()).size_max_z;
}
}

public Integer getLimitSizeMinX(@Nullable World world) {
if (world == null || !world_limits.containsKey(world.getName())) {
return world_limits.get("default").size_x;
return world_limits.get("default").size_min_x;
} else {
return world_limits.get(world.getName()).size_x;
return world_limits.get(world.getName()).size_min_x;
}
}

public Integer getLimitSizeY(@Nullable World world) {
public Integer getLimitSizeMinY(@Nullable World world) {
if (world == null || !world_limits.containsKey(world.getName())) {
return world_limits.get("default").size_y;
return world_limits.get("default").size_min_y;
} else {
return world_limits.get(world.getName()).size_y;
return world_limits.get(world.getName()).size_min_y;
}
}

public Integer getLimitSizeZ(@Nullable World world) {
public Integer getLimitSizeMinZ(@Nullable World world) {
if (world == null || !world_limits.containsKey(world.getName())) {
return world_limits.get("default").size_z;
return world_limits.get("default").size_min_z;
} else {
return world_limits.get(world.getName()).size_z;
return world_limits.get(world.getName()).size_min_z;
}
}

Expand Down Expand Up @@ -145,27 +181,51 @@ public void setLimitMaxY(Integer max_y, @Nullable World world) {
}
}

public void setLimitSizeX(Integer size_x, @Nullable World world) {
public void setLimitSizeMaxX(Integer size_x, @Nullable World world) {
if (world == null || !world_limits.containsKey(world.getName())) {
world_limits.get("default").size_max_x = size_x;
} else {
world_limits.get(world.getName()).size_max_x = size_x;
}
}

public void setLimitSizeMaxY(Integer size_y, @Nullable World world) {
if (world == null || !world_limits.containsKey(world.getName())) {
world_limits.get("default").size_max_y = size_y;
} else {
world_limits.get(world.getName()).size_max_y = size_y;
}
}

public void setLimitSizeMaxZ(Integer size_z, @Nullable World world) {
if (world == null || !world_limits.containsKey(world.getName())) {
world_limits.get("default").size_max_z = size_z;
} else {
world_limits.get(world.getName()).size_max_z = size_z;
}
}

public void setLimitSizeMinX(Integer size_x, @Nullable World world) {
if (world == null || !world_limits.containsKey(world.getName())) {
world_limits.get("default").size_x = size_x;
world_limits.get("default").size_min_x = size_x;
} else {
world_limits.get(world.getName()).size_x = size_x;
world_limits.get(world.getName()).size_min_x = size_x;
}
}

public void setLimitSizeY(Integer size_y, @Nullable World world) {
public void setLimitSizeMinY(Integer size_y, @Nullable World world) {
if (world == null || !world_limits.containsKey(world.getName())) {
world_limits.get("default").size_y = size_y;
world_limits.get("default").size_min_y = size_y;
} else {
world_limits.get(world.getName()).size_y = size_y;
world_limits.get(world.getName()).size_min_y = size_y;
}
}

public void setLimitSizeZ(Integer size_z, @Nullable World world) {
public void setLimitSizeMinZ(Integer size_z, @Nullable World world) {
if (world == null || !world_limits.containsKey(world.getName())) {
world_limits.get("default").size_z = size_z;
world_limits.get("default").size_min_z = size_z;
} else {
world_limits.get(world.getName()).size_z = size_z;
world_limits.get(world.getName()).size_min_z = size_z;
}
}

Expand Down Expand Up @@ -251,12 +311,18 @@ private void saveAll() {
this.config.setInlineComments("MinY", List.of(Translation.Config_Comment_MinY.trans()));
this.config.set("MaxY", world_limits.get("default").max_y);
this.config.setInlineComments("MaxY", List.of(Translation.Config_Comment_MaxY.trans()));
this.config.set("SizeX", world_limits.get("default").size_x);
this.config.setInlineComments("SizeX", List.of(Translation.Config_Comment_SizeX.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans()));
this.config.set("SizeY", world_limits.get("default").size_y);
this.config.setInlineComments("SizeY", List.of(Translation.Config_Comment_SizeY.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans()));
this.config.set("SizeZ", world_limits.get("default").size_z);
this.config.setInlineComments("SizeZ", List.of(Translation.Config_Comment_SizeZ.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans()));
this.config.set("Size.MaxX", world_limits.get("default").size_max_x);
this.config.setInlineComments("Size.MaxX", List.of(Translation.Config_Comment_SizeMaxX.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans()));
this.config.set("Size.MaxY", world_limits.get("default").size_max_y);
this.config.setInlineComments("Size.MaxY", List.of(Translation.Config_Comment_SizeMaxY.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans()));
this.config.set("Size.MaxZ", world_limits.get("default").size_max_z);
this.config.setInlineComments("Size.MaxZ", List.of(Translation.Config_Comment_SizeMaxZ.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans()));
this.config.set("Size.MinX", world_limits.get("default").size_min_x);
this.config.setInlineComments("Size.MinX", List.of(Translation.Config_Comment_SizeMinX.trans()));
this.config.set("Size.MinY", world_limits.get("default").size_min_y);
this.config.setInlineComments("Size.MinY", List.of(Translation.Config_Comment_SizeMinY.trans()));
this.config.set("Size.MinZ", world_limits.get("default").size_min_z);
this.config.setInlineComments("Size.MinZ", List.of(Translation.Config_Comment_SizeMinZ.trans()));
this.config.set("Amount", world_limits.get("default").amount);
this.config.setInlineComments("Amount", List.of(Translation.Config_Comment_Amount.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans()));
this.config.set("Depth", world_limits.get("default").depth);
Expand Down
Loading

0 comments on commit be496aa

Please sign in to comment.