Add InfoTool, which can be used to query dom info by click

This commit is contained in:
ZhangYuheng 2024-10-14 14:24:24 +08:00
parent dcf39f4097
commit f1116fa281
7 changed files with 132 additions and 22 deletions

View File

@ -11,7 +11,7 @@ var libraries = listOf<String>()
libraries = libraries + "cn.lunadeer:MinecraftPluginUtils:2.0.7"
group = "cn.lunadeer"
version = "2.13.7-beta"
version = "2.14.0-beta"
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))

View File

@ -57,6 +57,7 @@ public class ConfigManager {
_tp_delay = _file.getInt("Teleport.Delay", 0);
_tp_cool_down = _file.getInt("Teleport.CoolDown", 0);
_tool = _file.getString("Tool", "ARROW");
_info_tool = _file.getString("InfoTool", "STRING");
_economy_enable = _file.getBoolean("Economy.Enable", false);
if (getEconomyEnable()) {
@ -179,6 +180,8 @@ public class ConfigManager {
_file.set("Tool", _tool);
_file.setComments("Tool", List.of(Translation.Config_Comment_ToolName.trans()));
_file.set("InfoTool", _info_tool);
_file.setComments("InfoTool", List.of(Translation.Config_Comment_InfoToolName.trans()));
_file.setComments("Economy", Arrays.asList(Translation.Config_Comment_Economy.trans(), Translation.Config_Comment_VaultRequired.trans()));
_file.set("Economy.Enable", _economy_enable);
@ -396,6 +399,15 @@ public class ConfigManager {
_file.set("Tool", tool);
}
public Material getInfoTool() {
return Material.getMaterial(_info_tool);
}
public void setInfoTool(String info_tool) {
_info_tool = info_tool;
_file.set("InfoTool", info_tool);
}
public Boolean getEconomyEnable() {
return _economy_enable;
}
@ -450,6 +462,10 @@ public class ConfigManager {
XLogger.err(Translation.Config_Check_ToolNameError);
setTool("ARROW");
}
if (Material.getMaterial(_info_tool) == null) {
XLogger.err(Translation.Config_Check_InfoToolNameError);
setInfoTool("STRING");
}
if (getAutoCreateRadius() <= 0 && getAutoCreateRadius() != -1) {
XLogger.err(Translation.Config_Check_AutoCreateRadiusError);
setAutoCreateRadius(10);
@ -509,7 +525,9 @@ public class ConfigManager {
private Boolean _tp_enable;
private Integer _tp_delay;
private Integer _tp_cool_down;
private String _tool;
private String _info_tool;
private Boolean _economy_enable;

View File

@ -826,8 +826,10 @@ public class Translation extends Localization {
public static i18n Config_Check_MessageDisplayError;
@i18nField(defaultValue = "AutoCleanAfterDays 不能等于 0已重置为 180")
public static i18n Config_Check_AutoCleanAfterDaysError;
@i18nField(defaultValue = "工具名称设置错误,已重置为 ARROW")
@i18nField(defaultValue = "Tool 名称设置错误,已重置为 ARROW")
public static i18n Config_Check_ToolNameError;
@i18nField(defaultValue = "InfoTool 名称设置错误,已重置为 STRING")
public static i18n Config_Check_InfoToolNameError;
@i18nField(defaultValue = "%s 的 MinY 不能大于等于 MaxY已重置为 -64 和 320")
public static i18n Config_Check_GroupMinYError;
@i18nField(defaultValue = "%s 的 Size.MaxX 设置过小,已重置为 128")
@ -921,6 +923,8 @@ public class Translation extends Localization {
public static i18n Config_Comment_AutoCleanAfterDays;
@i18nField(defaultValue = "圈地工具名称")
public static i18n Config_Comment_ToolName;
@i18nField(defaultValue = "查询领地信息工具名称")
public static i18n Config_Comment_InfoToolName;
@i18nField(defaultValue = "经济设置")
public static i18n Config_Comment_Economy;
@i18nField(defaultValue = "需要安装 Vault 前置及插件")
@ -965,6 +969,31 @@ public class Translation extends Localization {
@i18nField(defaultValue = "管理领地内的其他成员权限")
public static i18n Flags_admin_Description;
@i18nField(defaultValue = "已选择第一个点: %d %d %d")
public static i18n Tool_SelectFirstPoint;
@i18nField(defaultValue = "已选择第二个点: %d %d %d")
public static i18n Tool_SelectSecondPoint;
@i18nField(defaultValue = "两个点不在同一个世界")
public static i18n Tool_NotSameWorld;
@i18nField(defaultValue = "已选择两个点,可以使用 /dominion create <领地名称> 创建领地")
public static i18n Tool_SelectTwoPoints;
@i18nField(defaultValue = "预计领地创建价格为 %.2f %s")
public static i18n Tool_CreateDominionPrice;
@i18nField(defaultValue = "尺寸: %d x %d x %d")
public static i18n Tool_DominionSize;
@i18nField(defaultValue = "面积: %d")
public static i18n Tool_DominionSquare;
@i18nField(defaultValue = "体积: %d")
public static i18n Tool_DominionVolume;
@i18nField(defaultValue = "高度: %d")
public static i18n Tool_DominionHeight;
@i18nField(defaultValue = "这个方块(%d, %d, %d)不在任何领地内")
public static i18n Tool_LocationNotInDominion;
@i18nField(defaultValue = "这个方块(%d, %d, %d)在领地 %s 内")
public static i18n Tool_LocationInDominion;
@i18nField(defaultValue = "领地主人: %s")
public static i18n Tool_DominionOwner;
public Translation(JavaPlugin plugin) {
super(plugin);

View File

@ -55,6 +55,8 @@ AutoCleanAfterDays: 180
Tool: ARROW
InfoTool: STRING
Economy:
Enable: false
Price: 10.0

View File

@ -67,6 +67,9 @@ AutoCleanAfterDays: 180
# 圈地工具名称
Tool: ARROW
# 查询领地信息工具名称
InfoTool: STRING
# 经济设置
# 需要安装 Vault 前置及插件
Economy:
@ -167,6 +170,10 @@ Timer: false # 性能测试计时器
配置手动圈地时的选取工具。如果配置错误会被设置为默认值“ARROW”箭矢。
### InfoTool
配置查询领地信息工具。如果配置错误会被设置为默认值“STRING”字符串。使用左键配合该物品点击领地内方块时会显示领地信息。
### Economy
经济控制支持,让玩家需要花费金钱圈地。使用此特性需要安装 Vault 经济前置插件。

View File

@ -1,7 +1,9 @@
package cn.lunadeer.dominion.events_v1_20_1;
import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.Dominion;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.managers.Translation;
import cn.lunadeer.dominion.utils.Particle;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.VaultConnect.VaultConnect;
@ -41,7 +43,7 @@ public class SelectPointEvents implements Listener {
if (action == Action.LEFT_CLICK_BLOCK) {
event.setCancelled(true);
Notification.info(player, "已选择第一个点: %d %d %d", block.getX(), block.getY(), block.getZ());
Notification.info(player, Translation.Tool_SelectFirstPoint, block.getX(), block.getY(), block.getZ());
Location loc = block.getLocation();
if (Dominion.config.getLimitVert(player)) {
loc.setY(Dominion.config.getLimitMinY(player));
@ -49,7 +51,7 @@ public class SelectPointEvents implements Listener {
points.put(0, loc);
} else if (action == Action.RIGHT_CLICK_BLOCK) {
event.setCancelled(true);
Notification.info(player, "已选择第二个点: %d %d %d", block.getX(), block.getY(), block.getZ());
Notification.info(player, Translation.Tool_SelectSecondPoint, block.getX(), block.getY(), block.getZ());
Location loc = block.getLocation();
if (Dominion.config.getLimitVert(player)) {
loc.setY(Dominion.config.getLimitMaxY(player) - 1);
@ -66,10 +68,10 @@ public class SelectPointEvents implements Listener {
return;
}
if (!points.get(0).getWorld().equals(points.get(1).getWorld())) {
Notification.warn(player, "两个点不在同一个世界");
Notification.warn(player, Translation.Tool_NotSameWorld);
return;
}
Notification.info(player, "已选择两个点,可以使用 /dominion create <领地名称> 创建领地");
Notification.info(player, Translation.Tool_SelectTwoPoints);
Location loc1 = points.get(0);
Location loc2 = points.get(1);
int minX = Math.min(loc1.getBlockX(), loc2.getBlockX());
@ -82,7 +84,7 @@ public class SelectPointEvents implements Listener {
minX, minY, minZ, maxX, maxY, maxZ);
if (Dominion.config.getEconomyEnable()) {
if (!VaultConnect.instance.economyAvailable()) {
Notification.error(player, "计算价格失败,没有可用的经济插件系统,请联系服主。");
Notification.error(player, Translation.Messages_NoEconomyPlugin);
return;
}
int count;
@ -92,13 +94,38 @@ public class SelectPointEvents implements Listener {
count = dominion.getVolume();
}
float price = count * Dominion.config.getEconomyPrice(player);
Notification.info(player, "预计领地创建价格为 %.2f %s", price, VaultConnect.instance.currencyNamePlural());
Notification.info(player, Translation.Tool_CreateDominionPrice, price, VaultConnect.instance.currencyNamePlural());
}
Particle.showBorder(player, dominion);
Notification.info(player, "尺寸: %d x %d x %d", dominion.getWidthX(), dominion.getHeight(), dominion.getWidthZ());
Notification.info(player, "面积: %d", dominion.getSquare());
Notification.info(player, "高度: %d", dominion.getHeight());
Notification.info(player, "体积: %d", dominion.getVolume());
Notification.info(player, Translation.Tool_DominionSize, dominion.getWidthX(), dominion.getHeight(), dominion.getWidthZ());
Notification.info(player, Translation.Tool_DominionSquare, dominion.getSquare());
Notification.info(player, Translation.Tool_DominionHeight, dominion.getHeight());
Notification.info(player, Translation.Tool_DominionVolume, dominion.getVolume());
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void selectBlockToShowInfo(PlayerInteractEvent event) {
Player player = event.getPlayer();
ItemStack item = player.getInventory().getItemInMainHand();
if (item.getType() != Dominion.config.getInfoTool()) {
return;
}
if (event.getAction() != Action.LEFT_CLICK_BLOCK) {
return;
}
event.setCancelled(true);
Block block = event.getClickedBlock();
if (block == null) {
return;
}
DominionDTO dominion = Cache.instance.getDominionByLoc(block.getLocation());
if (dominion == null) {
Notification.info(player, Translation.Tool_LocationNotInDominion, block.getX(), block.getY(), block.getZ());
} else {
Notification.info(player, Translation.Tool_LocationInDominion, block.getX(), block.getY(), block.getZ(), dominion.getName());
Notification.info(player, Translation.Tool_DominionOwner, Cache.instance.getPlayerName(dominion.getOwner()));
}
}
}

View File

@ -1,7 +1,9 @@
package cn.lunadeer.dominion.events_v1_21;
import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.Dominion;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.managers.Translation;
import cn.lunadeer.dominion.utils.Particle;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.VaultConnect.VaultConnect;
@ -41,7 +43,7 @@ public class SelectPointEvents implements Listener {
if (action == Action.LEFT_CLICK_BLOCK) {
event.setCancelled(true);
Notification.info(player, "已选择第一个点: %d %d %d", block.getX(), block.getY(), block.getZ());
Notification.info(player, Translation.Tool_SelectFirstPoint, block.getX(), block.getY(), block.getZ());
Location loc = block.getLocation();
if (Dominion.config.getLimitVert(player)) {
loc.setY(Dominion.config.getLimitMinY(player));
@ -49,7 +51,7 @@ public class SelectPointEvents implements Listener {
points.put(0, loc);
} else if (action == Action.RIGHT_CLICK_BLOCK) {
event.setCancelled(true);
Notification.info(player, "已选择第二个点: %d %d %d", block.getX(), block.getY(), block.getZ());
Notification.info(player, Translation.Tool_SelectSecondPoint, block.getX(), block.getY(), block.getZ());
Location loc = block.getLocation();
if (Dominion.config.getLimitVert(player)) {
loc.setY(Dominion.config.getLimitMaxY(player) - 1);
@ -66,10 +68,10 @@ public class SelectPointEvents implements Listener {
return;
}
if (!points.get(0).getWorld().equals(points.get(1).getWorld())) {
Notification.warn(player, "两个点不在同一个世界");
Notification.warn(player, Translation.Tool_NotSameWorld);
return;
}
Notification.info(player, "已选择两个点,可以使用 /dominion create <领地名称> 创建领地");
Notification.info(player, Translation.Tool_SelectTwoPoints);
Location loc1 = points.get(0);
Location loc2 = points.get(1);
int minX = Math.min(loc1.getBlockX(), loc2.getBlockX());
@ -82,7 +84,7 @@ public class SelectPointEvents implements Listener {
minX, minY, minZ, maxX, maxY, maxZ);
if (Dominion.config.getEconomyEnable()) {
if (!VaultConnect.instance.economyAvailable()) {
Notification.error(player, "计算价格失败,没有可用的经济插件系统,请联系服主。");
Notification.error(player, Translation.Messages_NoEconomyPlugin);
return;
}
int count;
@ -92,13 +94,38 @@ public class SelectPointEvents implements Listener {
count = dominion.getVolume();
}
float price = count * Dominion.config.getEconomyPrice(player);
Notification.info(player, "预计领地创建价格为 %.2f %s", price, VaultConnect.instance.currencyNamePlural());
Notification.info(player, Translation.Tool_CreateDominionPrice, price, VaultConnect.instance.currencyNamePlural());
}
Particle.showBorder(player, dominion);
Notification.info(player, "尺寸: %d x %d x %d", dominion.getWidthX(), dominion.getHeight(), dominion.getWidthZ());
Notification.info(player, "面积: %d", dominion.getSquare());
Notification.info(player, "高度: %d", dominion.getHeight());
Notification.info(player, "体积: %d", dominion.getVolume());
Notification.info(player, Translation.Tool_DominionSize, dominion.getWidthX(), dominion.getHeight(), dominion.getWidthZ());
Notification.info(player, Translation.Tool_DominionSquare, dominion.getSquare());
Notification.info(player, Translation.Tool_DominionHeight, dominion.getHeight());
Notification.info(player, Translation.Tool_DominionVolume, dominion.getVolume());
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void selectBlockToShowInfo(PlayerInteractEvent event) {
Player player = event.getPlayer();
ItemStack item = player.getInventory().getItemInMainHand();
if (item.getType() != Dominion.config.getInfoTool()) {
return;
}
if (event.getAction() != Action.LEFT_CLICK_BLOCK) {
return;
}
event.setCancelled(true);
Block block = event.getClickedBlock();
if (block == null) {
return;
}
DominionDTO dominion = Cache.instance.getDominionByLoc(block.getLocation());
if (dominion == null) {
Notification.info(player, Translation.Tool_LocationNotInDominion, block.getX(), block.getY(), block.getZ());
} else {
Notification.info(player, Translation.Tool_LocationInDominion, block.getX(), block.getY(), block.getZ(), dominion.getName());
Notification.info(player, Translation.Tool_DominionOwner, Cache.instance.getPlayerName(dominion.getOwner()));
}
}
}