Skip to content

Commit

Permalink
1.3.4
Browse files Browse the repository at this point in the history
[performCommand]  另一种执行命令的节点
[opPerformCommand] 另一种OP执行命令的节点
limitHide  点击限制次数,没次数后按钮隐藏
  • Loading branch information
handy-git committed Jul 29, 2024
1 parent e60dd5b commit c63e8d9
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 11 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
<groupId>cn.handyplus.menu</groupId>
<name>PlayerMenu</name>
<artifactId>PlayerMenu</artifactId>
<version>1.3.3</version>
<version>1.3.4</version>
<description>一个有点好用的玩家菜单插件</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spigot-api.vesion>1.21-R0.1-SNAPSHOT</spigot-api.vesion>
<placeholderapi.version>2.10.5</placeholderapi.version>
<lombok.version>1.18.32</lombok.version>
<HandyLib.version>3.10.7</HandyLib.version>
<HandyLib.version>3.11.0</HandyLib.version>
<VaultAPI.vesion>1.7</VaultAPI.vesion>
<PlayerPoints.version>3.2.6</PlayerPoints.version>
<PlayerGuild.version>1.5.4</PlayerGuild.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public enum CommandTypeEnum {
SERVER("[server]"),
OPEN("[open]"),
REFRESH("[refresh]"),
PERFORM_COMMAND("[performCommand]"),
OP_PERFORM_COMMAND("[opPerformCommand]"),
;

private final String type;
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/cn/handyplus/menu/inventory/MenuGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import cn.handyplus.menu.hook.PlaceholderApiUtil;
import cn.handyplus.menu.param.MenuButtonParam;
import cn.handyplus.menu.service.MenuItemService;
import cn.handyplus.menu.service.MenuLimitService;
import cn.handyplus.menu.util.ConfigUtil;
import cn.handyplus.menu.util.MenuUtil;
import org.bukkit.OfflinePlayer;
Expand Down Expand Up @@ -117,6 +118,14 @@ private void setFunctionMenu(HandyInventory handyInventory) {
if (StrUtil.isNotEmpty(menuButtonParam.getNotPermission()) && player.hasPermission(menuButtonParam.getNotPermission())) {
continue;
}
// 判断是否限制点击次数
if (menuButtonParam.getId() != null && menuButtonParam.getLimitHide() > 0) {
Integer count = MenuLimitService.getInstance().findCountByPlayerUuid(player.getUniqueId(), menuButtonParam.getId());
if (count >= menuButtonParam.getLimitHide()) {
continue;
}
return;
}
// 物品显示数量
int amount = menuButtonParam.getAmount() > 0 ? menuButtonParam.getAmount() : 1;
if (StrUtil.isNotEmpty(menuButtonParam.getDynamicAmount())) {
Expand Down Expand Up @@ -182,6 +191,7 @@ public static MenuButtonParam getMenuButtonParam(MemorySection memorySection, Of
int point = memorySection.getInt("point");
int money = memorySection.getInt("money");
int limit = memorySection.getInt("limit");
int limitHide = memorySection.getInt("limitHide");
int cd = memorySection.getInt("cd");
int id = memorySection.getInt("id", 0);
String permission = memorySection.getString("permission");
Expand Down Expand Up @@ -212,6 +222,7 @@ public static MenuButtonParam getMenuButtonParam(MemorySection memorySection, Of
menuButtonParam.setPoint(point);
menuButtonParam.setMoney(money);
menuButtonParam.setLimit(limit);
menuButtonParam.setLimitHide(limitHide);
menuButtonParam.setCd(cd);
menuButtonParam.setId(id != 0 ? id : null);
menuButtonParam.setHead(head);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ public void onEvent(InventoryCloseEvent event) throws IOException {
if (limit > 0) {
createMenuItem.put("limit", limit);
}
int limitHide = menuButtonParam.getLimitHide();
if (limitHide > 0) {
createMenuItem.put("limitHide", limitHide);
}
List<String> commands = menuButtonParam.getCommands();
if (CollUtil.isNotEmpty(commands)) {
createMenuItem.put("commands", commands);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ private void executeCommand(Player player, List<String> commands, HandyInventory
case REFRESH:
MenuGui.getInstance().setInventoryDate(handyInventory);
break;
case PERFORM_COMMAND:
PlayerSchedulerUtil.playerPerformCommand(player, content);
break;
case OP_PERFORM_COMMAND:
PlayerSchedulerUtil.playerPerformOpCommand(player, content);
break;
default:
break;
}
Expand Down Expand Up @@ -172,7 +178,10 @@ private void setManuTimeLimit(Player player, MenuButtonParam menuButtonParam) {
* @param menuButtonParam 菜单
*/
private void setManuNumberLimit(Player player, MenuButtonParam menuButtonParam) {
if (menuButtonParam.getId() == null || menuButtonParam.getLimit() < 1) {
if (menuButtonParam.getId() == null) {
return;
}
if (menuButtonParam.getLimit() < 1 && menuButtonParam.getLimitHide() < 1) {
return;
}
MenuLimit menuLimit = new MenuLimit();
Expand All @@ -194,13 +203,12 @@ private void setManuNumberLimit(Player player, MenuButtonParam menuButtonParam)
*/
private boolean check(Player player, MenuButtonParam menuButtonParam) {
// 判断点击次数处理
int limit = menuButtonParam.getLimit();
if (limit > 0) {
Integer count = MenuLimitService.getInstance().findCountByPlayerUuid(player.getUniqueId(), menuButtonParam.getId());
if (count >= limit) {
MessageUtil.sendMessage(player, BaseUtil.getMsgNotColor("noLimit"));
return true;
}
if (this.clickLimit(player, menuButtonParam.getId(), menuButtonParam.getLimit())) {
return true;
}
// 判断点击次数处理
if (this.clickLimit(player, menuButtonParam.getId(), menuButtonParam.getLimitHide())) {
return true;
}
// 判断点击时间
int cd = menuButtonParam.getCd();
Expand Down Expand Up @@ -260,6 +268,25 @@ private boolean check(Player player, MenuButtonParam menuButtonParam) {
return false;
}

/**
* 点击次数判断
*
* @param player 玩家
* @param limit 次数
* @return true 不满足
*/
private boolean clickLimit(Player player, Integer menuItemId, int limit) {
if (limit <= 0) {
return false;
}
Integer count = MenuLimitService.getInstance().findCountByPlayerUuid(player.getUniqueId(), menuItemId);
if (count >= limit) {
MessageUtil.sendMessage(player, BaseUtil.getMsgNotColor("noLimit"));
return true;
}
return false;
}

/**
* 商店判断
*
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/cn/handyplus/menu/param/MenuButtonParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ public class MenuButtonParam {
*/
private int limit;

/**
* 限制点击次数并在没有次数后隐藏按钮
*
* @since 1.3.4
*/
private int limitHide;

/**
* 限制点击时间 (秒)
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: PlayerMenu
main: cn.handyplus.menu.PlayerMenu
version: 1.3.3
version: 1.3.4
author: handy
api-version: 1.13
website: https://ricedoc.handyplus.cn/wiki/PlayerMenu/log/
Expand Down

0 comments on commit c63e8d9

Please sign in to comment.