1. Configuration and Example/1.3 Scripts

 


Basic Scripts


If and Else statements :

Available syntax :

 $Script$%if%Var1>Var2 (compare integers(numbers)) (greater than)
 $Script$%if%Var1<Var2 (integers) (less than)
 $Script$%if%Var1>=Var2
 $Script$%if%Var1<=Var2 

 $Script$%if%Var1!=Var2 (String & integers) (not equal)
 $Script$%if%Var1==Var2 (String & integers) (equals)


$Script$%if%Var1.contains=Var2   
$Script$%if%Var1.notcontains=Var2
(.contains and .notcontains automatically check if it's a string or a list and adapt accordingly. Check Example below)

$Script$%if%Var1.args.length>2
(counts the length of a text variable splitting it by " " space. "Hello, how are you?" = 4)

$Script$%if%Var1.string.length>10
(counts the length of a string, char by char. "MyCommand" = 9)


$Script$%if%$arg1.isanumber
(True or false. If the string is a number return true)

if the result of every line is false, negative, you can use the ELSE statement :

 $Script$%else%

or more if(s), but no more than one "else". The ELSE statement have to be the last one in every script, or it doesn't work as intended.

 

$Script$%while% (works as an if, and support all the %if% comparison options), works only in the command type RUN_COMMAND_TASK, and do what he say. While something is "true" repeat indefinitely until the statement become false and the cicle interrupts.

 

Special statement for the PLAYERDATA (/mycmd-playerdata) features, are listed here below. 

P.S. The else statement doesn't works with PlayerData script lines.

 $Script$%PlayerData%var1>var2
 $Script$%PlayerData%var1<var2
 $Script$%PlayerData%var1==var2
 $Script$%PlayerData%var1!=var2
 $Script$%PlayerData%var1=var2 (SET string and integer)
 $Script$%PlayerData%var1-var2  (return always 0 if the variable go under the zero after the operation.)
 $Script$%PlayerData%var1+var2
 $Script$%PlayerData%var1*var2 (multiplication)
 $Script$%PlayerData%var1/var2 (division)
 #Same ad above, but edit another player datas. (Support all the operation above =/+/- ecc)
 $Script$%PlayerDataFor%$PlayerName%var1=var2  (PlayerName can be anything, also $arg1)
 $Script$%PlayerData%listname.addlist=stringtoadd (To be used with Lists)
 $Script$%PlayerData%listname.removelist=stringtoremove (To be used with Lists)
$Script$%PlayerData%array1.contains=string2 (To be used with Lists)
To manipulate CUSTOM VARIABLES (/mycmd-variables) (return always true) $Script$%Variable%var1+var2 $Script$%Variable%var1-var2 $Script$%Variable%var1=var2

And TEMPORARY Variables :

 

%TempVariable%VarName=v2
%TempVariable%VarName+v2
%TempVariable%VarName-v2
%TempVariable%VarName.tolowercase

%TempVariable% can use other %TempVariable% as source.

 

TempVars:
- '%TempVariable%$pname=$player'
- '%TempVariable%$test4=[Replace]%player_ping_$pname%'
- '$text$ 4 = $test4 

 Using [Replace] before the papi placeholder as in the example above, will replace first the tempvariable, and then the papi one.

 


Examples :
In the example below, we compare the typed word "$arg1" with something. In this case, if "$arg1" is mypassword , you will get "Right" as result in your chat. How you can see, you can use multiple if in sequence. Just put attention to put the ELSE statement for last. If all the ifs are false, the ELSE statement is performed .

password_example:
  command: /password
  type: RUN_COMMAND
  runcmd:
  - $Script$%if%$arg1==mypassword
  - $text$Right!
  - $Script$%if%$arg1==420
  - $text$&aBLAZE IT
  - $Script$%else%
  - $text$Password not correct

Another example, but in this case we're using the $health variabile. This will check if the player have the full health before execute "something".

health_script_example:
  command: /fullhealth
  type: RUN_COMMAND
  runcmd:
  - $Script$%if%$health==20.0
  - do something
  - $Script$%else%
  - $text$Heal yourself first.


Here some examples with $Script$%PlayerData% , (this work like an if statement).

Example with custom credits :

/mycmd-playerdata set PlayerName credits 50

In the example below, you can see how the command work. First line check if the player have 50 credits. If yes, let's remove 50 credits from the player and then execute something. In this way, the player sender type again the command, and dont have more credits, he get the error-message instead.

scripttext1:
  command: /testscript1
  type: RUN_COMMAND
  runcmd:
  - $Script$%PlayerData%credits>50 #Check if the player have 50 credits
  - $Script$%PlayerData%credits-50 #Remove 50 credits from the player
  - /dosomething
  error-message: "You need at least 50 credits for execute this command."


One time commands :
You can use the playerdata feature for many uses, like the one here below. Check first if the playerdata value yourcommandname exist, if not, proceed executing something and set an new value in the playerdata. If the player re-execute the command, the variable yourcommandname is equals to used and the command doesn't work anymore.

 

one_time_command:
 command: /onetime
 type: RUN_COMMAND
 runcmd:
 - "$Script$%if%$PlayerData%one_time_command%!=used"
 - "$text$&aExecuting the command here..."
 - "$Script$%PlayerData%one_time_command=used"
 - "$Script$%else%"
 - "$text$&6You've already used this command."

 

 

Or:

 runcmd:
 - $Script$%PlayerData%yourcommandname!=used
 - /dosomething
 - $Script$%PlayerData%yourcommandname=used
 error-message: "You have already used this command"


Specific code to check if a player have a specific permission:

  • Use "$Script$%if%HasPermission==node.node"
  • Or "$Script$%if%HasNotPermission==perm.node" to negate it

Here, an example of an command, with limited uses, but with 2 specific permission.
(Mix of playerdata, condition and HasPermission function)

'limitedcommand':
  command: /limitedcommand
  type: RUN_COMMAND
  runcmd:
  - '$Script$%if%$PlayerData%limitedcommand_use%<5<and>HasPermission==limitedcommand.limit.5'
  - '$text$ Your Stuff here (for player with the limit to 5)'
  - '$Script$%PlayerData%limitedcommand_use+1'
  - '$Script$%elseif%$PlayerData%limitedcommand_use%<20<and>HasPermission==limitedcommand.limit.20'
  - '$text$ Your Stuff here (for player with the limit to 20)'
  - '$Script$%PlayerData%limitedcommand_use+1'
  - '$Script$%else%'
  - '$text$&3You have reached the usage limit for this command.'
  permission-required: false

In the example above, there is 2 different permission. limitedcommand.limit.5 and limitedcommand.limit.20.
The commands in this command are executed only if all the condition are true.
The first condition is limitedcommand_use < 5 and HasPermission : limitedcommand.limit.5. If both are true execute the code. Instead, if the player have the other permission (limitedcommand.limit.20), the results for this line are aren't both true,so go on the next if.


Some other "scripts" line:


All Fields :

$Script$AddPermission= , $Script$RemovePermission= , $Script$HasEmptyInventory


AddPermission= & RemovePermission= require Vault plugin.

 

 

Playerdata lists (array) and .contains= :

 

Ingame :

/mycmd-playerdata list <add | remove> <player_name> <variable> <content>

 

Script:

$Script$%PlayerData%listname.addlist=stringtoadd

$Script$%PlayerData%listname.removelist=stringtoremove

 

use those 2 lines above to manage a list, and then use .contains= or .notcontains= to check what's inside.

 

The comparator ".contains=" and ".notcontains=" can work on lists, and it looks only for exact results. So if you search for "hello", and in the list there is "hello hello", it return false, you need to search for the exact string line "hello hello".

 

containsexample:
  command: /containsexample
  type: RUN_COMMAND
  runcmd:
  - $Script$%if%$PlayerData%list1%.contains=$multiargs
  - $text$The array list1 contains $multiargs!
  - $Script$%else%
  - $text$Nothing found in this list 

 

.contains= can also be used with normal strings (not list). If you have a long text, you can check if inside it there is that exact word you're looking for.


Script elseif


Example without ifelse : if both ($arg1 and $arg2) are true, execute both commands (/cmd1,/cmd2).

 - $Script$%if%$arg1==true
 - /cmd1
 - $Script$%if%$arg2==true
 - /cmd2
 - ecc ecc..


If the first IF is true and you want deny the execution of the next IF, use ELSEIF :
Example :

 - $Script$%if%$arg1==true
 - /cmd1
 - $Script$%elseif%$arg2==true
 - /cmd2


In this way, if $arg1 is true, and the second ($arg2) is true, the second don't get executed, because the first one already got executed completing the command there.
Of course, if $arg1 is false and the $arg2 is true, the second will get executed.

If both are false, you can use %else% like the exemple here below:

Example :

 - $Script$%if%$arg1==true
 - /cmd1
 - $Script$%elseif%$arg2==true
 - /cmd2
 - $Script$%else%
 - $text$ Nothing Executed, both commands failed the request.

How to use AND (or) OR conditions :


Use and conditions to create more flexible statements.

 $Script$%if% CONDITION1 <and> CONDITION2    <or>  CONDITION1 <and> CONDITION2 <and>  CONDITION3   <or> ecc....ecc.....

Example :
In the exampe here below, the command will get executed only if one of the 2 condition (separated by the ) is true.

  - "$Script$%if%$gamemode==SURVIVAL<and>$world==world_survival<or>$gamemode==CREATIVE<and>$world==world_creative"
  - "/dosomething"
  • How you can see, the first condition is $gamemode==SURVIVAL $world==world_survival
  • The second one is $gamemode==CREATIVE $world==world_creative.
  • Between those two condition there is a

If one of this two condition is true, the command will get executed.

 

Of course, the use of the it involves the fact who both of the statements splitted by the needs to be true in order to get the command executed. So, using the example above $gamemode must be SURVIVAL and the $world needs to be world_survival in order to satisfy the request.

 

 

P.S. You can use unlimited and unlimited in one line.


How to use "Player API" in RUN_COMMAND Type.


Example of use :

heal:
  command: /heal
  type: RUN_COMMAND
  runcmd:
  - '%PlayerOptions%setHealth: 20'
  - '%PlayerOptions%setFoodLevel: 20'
  - '%PlayerOptions%sendMessage: &aHealed!'

or

  runcmd:
  - '%PlayerOptions%clearInventory: true'
  - '%PlayerOptions%teleport: world:0.0:100.0:0.0'
  - '%PlayerOptions%setItemInHand: STONE_SWORD:1'

 

What to use them on another player? Use %PlayerOptionsFor% instead :

 

Replace player_name with the interested playername, can be fixed or $arg1 for example

"%PlayerOptionsFor%player_name%method: value"<strong><br /></strong>

 

Options available :


Boolean (true or false)


setAllowFlight , setBanned , setCanPickupItems , setCustomNameVisible , setFlying , setOp , setSneaking , setSprinting , setWhitelisted

(only true)

leaveVehicle , resetMaxHealth , closeInventory , clearInventory

spawnFirework , compassTracker 

String (text)


setCustomName , setDisplayName , setGameMode , setPlayerListName , kickPlayer , teleport , setBedSpawnLocation , setCompassTarget , setItemInHand , setItemOnCursor , chat , sendMessage , playSound , playEffect , addPotionEffect , removePotionEffect , addScoreboardTag , removeScoreboardTag , setPlayerListHeader , setPlayerListFoote

Integer, Double or Float (numbers)


setHeldItemSlot, setExhaustion , setExp , setFallDistance , setFireTicks , setFlySpeed , setHealth , setFoodLevel ,setLastDamage , setLevel , setMaxHealth , setMaximumAir , setNoDamageTicks , setRemainingAir , setSaturation , setTotalExperience , giveExp , giveExpLevels , damage , setWalkSpeed , setCustomModelData

Location Type teleport , setBedSpawnLocation , setCompassTarget works in this way :


- '%PlayerOptions%teleport: world_name:X:Y:Z'
or
- '%PlayerOptions%teleport: world_name:X:Y:Z:YAW:PITCH'  #Use the yaw and pitch for adjust the player direction and head level

ItemStack Type :


addItem, setItemInHand , setItemOnCursor, setItemInOffHand, setBoots, setChestplate, setHelmet, setLeggings, setItemInHandDisplayedName, setItemInHandLore
- '%PlayerOptions%setItemInHand: MATERIAL_NAME:AMOUNT'
- '%PlayerOptions%addItem: MATERIAL_NAME:AMOUNT'

or: (more information)

  - %PlayerOptions%addItem: MATERIAL_NAME:AMOUNT:ITEM_META: Enchantments;Level : Displayed Name : Lores;line2;line3...

Become :

  - '%PlayerOptions%addItem: STONE_SWORD:1:0:DAMAGE_ALL;1;FIRE_ASPECT;1:&aMega Sword:&bLine 1;Line 2;$random_colorLine 3'
  • Leave the field empty (Like the enchantment part), if you dont need that :
  - '%PlayerOptions%setChestplate: IRON_CHESTPLATE:1:0::ItemName:Description'

If you only need to edit the Name and Lore Use :
runcmd:
- "%PlayerOptions%setItemInHandDisplayedName: $arg1"
- "%PlayerOptions%setItemInHandLore: $arg2"

 

'%PlayerOptions%removeItem: MATERIAL_NAME:AMOUNT'
#works the same as %PlayerOptions%addItem (It will remove only the same exact ItemStack, it doesn't subtract items from a existing one)

'%PlayerOptions%withdrawItems: MATERIAL_NAME:AMOUNT:ITEM_DISPLAYED_NAME'
#This works like the itemcost feature.

'%PlayerOptions%deleteSingleItem: MATERIAL_NAME:AMOUNT:ITEM_DISPLAYED_NAME'
#This will remove a complete ItemStack from the inventory of a desider type. Amount number is superfluous

'%PlayerOptions%deleteAllItems: MATERIAL_NAME:AMOUNT:ITEM_DISPLAYED_NAME'
#This will remove all the ItemStacks of a certain type from the inventory. Amount number is superfluous

Fireworks :


 Type can be : BALL, BALL_LARGE, BURST, CREEPER, STAR

"%PlayerOptions%spawnCustomFirework TYPE R,G,B R,G,B POWER" -> "%PlayerOptions%spawnCustomFirework BALL 255,0,0 0,0,255 3"

 
you can test them with /mycmd playeroptions spawnCustomFirework ...

 

 

 

And other one's :

 

%PlayerOptions%openWorkbench: NAME, %PlayerOptions%openInventory: NAME, %PlayerOptions%openMerchant: ITEM..ecc, %PlayerOptions%openEnchanting, %PlayerOptions%setCursorOpenInventory: ITEM

 

 

Kit Example

 

Enchantments :

'%PlayerOptions%addEnchantment: ENCHANT_NAME:LEVEL'
'%PlayerOptions%removeEnchantment: ENCHANT_NAME'

Potions :

  - %PlayerOptions%addPotionEffect: POTION_NAME:TIME_IN_TICKS:LEVEL
  - %PlayerOptions%addPotionEffect: SPEED:100:0

 

Effect list : http://jd.bukkit.org/rb/apidocs/org/bukkit/Effect.html Spigot : https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Effect.html

%PlayerOptions%playEffect: EFFECT_NAME:INT_DATA
%PlayerOptions%playEffect: RECORD_PLAY:2260

Sounds list : Bukkit link : http://jd.bukkit.org/rb/apidocs/org/bukkit/Sound.html Spigot: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Sound.html

%PlayerOptions%playSound: SOUND_NAME:VOLUME:BYTE_DATA
%PlayerOptions%playSound: NOTE_BASS:1.0F:1

%PlayerOptions%spawnParticle: PARTICLE_NAME:INTENSITY

While statement example with RUN_COMMAND_TASK


taskexample:
  command: /taskexample
  type: RUN_COMMAND_TASK
  runcmd:
  - "$Script$%while%$health>=10"
  - "$text$Your health is > 10 ($health)"
  - "/dosomething"
  task_run_immediately: true
  task_repeat_every_sec: 1
  task_run_n_times: -1
  task_run_when_offline: true
  task_show_debug: false

In this example, while the health is > 10, do something. If at the next execution the health is < 10, interrupt the cicle.