EpicBanItemTeam / VirtualChest

A sponge plugin providing virtual chest GUIs for menus like ChestCommands
https://ore.spongepowered.org/zzzz/VirtualChest
GNU Lesser General Public License v3.0
34 stars 12 forks source link

Cooldown #91

Closed ClarkHalf closed 5 years ago

ClarkHalf commented 5 years ago

Can I put cooldown for when I click on a chest item? Example if I want to make a daily kit menu. Every 24 hours he can pick up the kit

ClarkHalf commented 5 years ago

@ustc-zzzz

iMystxc commented 5 years ago

just use nucleus for kits.

ClarkHalf commented 5 years ago

I used the kits as an example, but I want to use it in other menus =/

ustc-zzzz commented 5 years ago

In fact there is a best practice based on the features provided by VirtualChest and LuckPerms since LP could set a temporary permission which will expire several hours later. The explanation is a bit long, let me explain it in several parts.

ustc-zzzz commented 5 years ago

For example, if you want to give one diamond to the player per hour while you do not give more than one in 1h, what you can do is:

  1. Determine a permission string whose default value is false for players (the permission string we use here is virtualchest.temp.diamond as an example).
  2. Check the permission (for example, player.hasPermission('virtualchest.temp.diamond')) by setting the value of the Requirements option.
    • If it is false, show the item you want and then set the PrimaryAction as you want and append a command executed by console (starting with lp), which sets the temp permission (for example, console: lp user %player_name% permission settemp virtualchest.temp.diamond true 1h) in the value of Command option.
    • If it is true, show an item which tells the player the PrimaryAction is not available.

Here is an example:

Slot1 = [{
    Requirements = "player.hasPermission('virtualchest.temp.diamond')"
    Item {
        Count = 1
        UnsafeDamage = 0
        ItemType = "minecraft:barrier"
        DisplayName = "You cannot take more than one diamond in 1h"
    }
    PrimaryAction {
        KeepInventoryOpen = false
        Command = "tell: You cannot take more than one diamond in 1h!"
    }
}, {
    Item {
        Count = 1
        UnsafeDamage = 0
        ItemType = "minecraft:diamond"
        DisplayName = "Give you a diamond (take one at most in 1h)"
    }
    PrimaryAction {
        KeepInventoryOpen = false
        Command = """console: give %player_name% minecraft:diamond;
                     console: lp user %player_name% permission settemp virtualchest.temp.diamond true 1h"""
    }
}]