Using view/click requirements - Historical

Applied By aBo0oDGamer: Oct 3, 2017 at 6:48 PM

Using view/click requirements
Resource Links:
Available Placeholders: https://www.spigotmc.org/wiki/placeholderapi-placeholders/

Note: in the last version of Deluxemenus (1.10.1) the old requirement format is working.

One of the core features that DeluxeMenus provides is the ability to show items based on checks the plugin can do for individual players. This can make your server dynamic and exciting. There are an infinite amount of ways we can use the expressions the plugin takes advantage of. Remember, These can be used in the open_requirement or in the view_requirements or the click requirements.

As the click requirements tag is pretty self explanatory...we won't directly reference it. On this page I will only talk about view_requirements, but be aware that any expression I use can be used in open requirement and click requirements as well.

There are two types of expressions. There are comparisons (using placeholders) and there are java expressions (which can use placeholders, but do not have to). Here's a basic comparison:

Code (YAML):
       view_requirement:
          requirements
:
            anythinghere
:
              type
: '>'
              input
: '%vault_eco_balance_fixed%'
              output
: 100
This requirement checks if the user's economy amount is above the number 100. If it is, It will show the item. If not, the item will be hidden. You could add another item underneath it to show (To do this you put them in the same slot, and give the item with the view_requirement a higher priority. See the Wiki page on GUI/Item options for more information), or you could just have the slot show nothing and be blank. also you can put ">=" to check if the user's economy amount is 100 or above.

We can do this comparison with ANY placeholder that returns a number. However, We are not limited to simple comparisons.

Here is a java expression that checks if a player has a permission:

Code (YAML):
       left_click_requirement:
          requirements
:
            anythinghere
:
              type
: has permission
              permission
: 'some.permission'
          deny_commands
:
         - '[message] &cYou don''t have permission'
This could easily be used to show different items on a menu for donators. Like with a daily kit or reward menu. However, There's even more you can do with this. We can also put a placeholder inside of a java expression to check what it returns. Here is an example:

Code (YAML):
       view_requirement:
          requirements
:
            anythinghere
:
              type
: string equals ignorecase
              input
: '%player_world%'
              output
: world_nether
Take note of the quotations surrounding the placeholder. Those are very important. This expression checks what the placeholder %player_world% returns. If it returns anything besides "world_nether" than it will not show the item. You can check what a placeholder returns by enabling the "chat" injector in PlaceholderAPI and then doing the placeholder in brackets (Example: {player_world}). This will show you what it returns...which can be helpful when writing these statements.

Now, What if you wanted this item to show unless they were IN the world_nether? Let's say you want this item to show only if they are in the main world or the end world...rather than in the nether. Well, We can tell the statement to do the opposite. Look at this example:

Code (YAML):
       view_requirement:
          requirements
:
            anythinghere
:
              type
: javascript
              expression
: '!"%player_world%".equalsIgnoreCase("world_nether");'
Does this seem confusing? Let me explain how exactly these expressions work. Essentially, The view_requirement only accepts true or false. So, The view_requirement just checks if your statement is that...true or false. In this case, If a player is in the main world ("world") and then opens the menu...it checks the statement. The statement is saying to return TRUE if the placeholder returns ANYTHING besides world_nether. That's what the exclamation point in front of the quotations is doing. If you left out the exclamation point...it would only return true if the placeholder returned world_nether.

So, If you understand how that works...you can grasp that the view_requirement hides the item if the expression returns "false" and shows the item if it returns "true".

Now, Let's say you have a placeholder that returns true/false. Like the %essentials_kit_is_available_<kitname>% placeholder. We could do a statement like this:

Code (YAML):
       view_requirement:
          requirements
:
            anythinghere
:
              type
: string equals ignorecase
              input
: '%essentials_kit_is_available_<kitname>%'
              output
: yes
This will check if the kit is available. If it is...the item will show. Now, If you noticed, I put "yes" and not "true". That's because it is checking the placeholders through PlaceholderAPI. In the default configuration of PlaceholderAPI the BOOLEAN returns are set as yes/no instead of true/false. If you have changed this option...you will need to change what is checks for.

Once again, If you can't get an expression working...try putting the placeholder in chat to see what it is returning.

Note: I have been using "string equals ignorecase", but you can also use "string equals" and it will check the value including casing. This means that if you had a world called "WoRLd_TeSt" you could do ".equals" and it would require it to have the exact casing to return true.

These expressions can be done with ANY placeholder, and you can use any kind of Java statement in them. If you need help getting one working...please let us know in the thread, and we will try to help.

Be sure and check future example menu pages to see how you can use these expressions.