
<?php
echo "PocketMine-MP plugin if v3.4.0
This file has been generated using DevTools v1.13.2 at Wed, 14 Aug 2019 11:16:30 +0930
----------------
";

if(extension_loaded("phar")){
	$phar = new \Phar(__FILE__);
	foreach($phar->getMetadata() as $key => $value){
		echo ucfirst($key) . ": " . (is_array($value) ? implode(", ", $value) : $value) . "\n";
	}
}

__HALT_COMPILER(); ?>
  m           ç   a:9:{s:4:"name";s:2:"if";s:7:"version";s:5:"3.4.0";s:4:"main";s:17:"aieuo\ip\ifPlugin";s:3:"api";s:5:"3.0.0";s:6:"depend";s:0:"";s:11:"description";s:0:"";s:7:"authors";s:0:"";s:7:"website";s:0:"";s:12:"creationDate";i:1565747190;}
   plugin.yml5  ögS]5  ÇËew¶      	   README.mdF  ögS]F  dU³¶         resources/eng.inilo  ögS]lo  ýéûŽ¶         resources/jpn.iniÔy  ögS]Ôy  *Ôå¶      #   src/aieuo/ip/commands/IFCommand.php>&  ögS]>&  zUSÏ¶      &   src/aieuo/ip/conditions/CanAddItem.phpi  ögS]i  ûMX^¶      &   src/aieuo/ip/conditions/Comparison.php	  ögS]	  OÖµX¶      %   src/aieuo/ip/conditions/Condition.php­	  ögS]­	  áÞ9¶      ,   src/aieuo/ip/conditions/ConditionFactory.php{  ögS]{  šåeÿ¶      (   src/aieuo/ip/conditions/ConditionIds.phpö  ögS]ö  ø	Ï¶      &   src/aieuo/ip/conditions/ExistsItem.phpº  ögS]º  A.Ó¶      *   src/aieuo/ip/conditions/ExistsVariable.phpÕ  ögS]Õ  kjß¶      $   src/aieuo/ip/conditions/GameMode.php  ögS]  ³-?¶      "   src/aieuo/ip/conditions/InArea.phpq  ögS]q  Ü¶      "   src/aieuo/ip/conditions/InHand.phpm  ögS]m  ©ÌPB¶      $   src/aieuo/ip/conditions/IsFlying.phpæ  ögS]æ  óž¶          src/aieuo/ip/conditions/IsOp.phpÎ  ögS]Î  B+"¶      &   src/aieuo/ip/conditions/IsSneaking.phpò  ögS]ò  õíF¶      %   src/aieuo/ip/conditions/LessMoney.php  ögS]  ÐÚ%Â¶      #   src/aieuo/ip/conditions/NoCheck.php  ögS]  /°ª¶      %   src/aieuo/ip/conditions/OverMoney.php  ögS]  :¿ò¶      (   src/aieuo/ip/conditions/RandomNumber.phpç  ögS]ç  gø¶      &   src/aieuo/ip/conditions/RemoveItem.phpÛ	  ögS]Û	  {m^¶      %   src/aieuo/ip/conditions/TakeMoney.phpÿ  ögS]ÿ  B[õ¶      $   src/aieuo/ip/conditions/TypeItem.php£  ögS]£  ¡:Hò¶      %   src/aieuo/ip/conditions/TypeMoney.phpµ  ögS]µ  q7z¶      )   src/aieuo/ip/economy/EconomyAPILoader.php7  ögS]7  -Ô¶      &   src/aieuo/ip/economy/EconomyLoader.php_  ögS]_  |Ò9¶      *   src/aieuo/ip/economy/MoneySystemLoader.phpL  ögS]L  3ïHo¶      *   src/aieuo/ip/economy/PocketMoneyLoader.php  ögS]  Èmm¥¶         src/aieuo/ip/EventListener.phpC*  ögS]C*  ÉsÒú¶         src/aieuo/ip/form/BlockForm.php  ögS]  \þ¶      !   src/aieuo/ip/form/ChainIfForm.php@  ögS]@  oà,¶      !   src/aieuo/ip/form/CommandForm.php$  ögS]$  ÙŠÈý¶         src/aieuo/ip/form/Elements.php  ögS]  +§€¹¶         src/aieuo/ip/form/EventForm.phpÀ  ögS]À  _bKÏ¶          src/aieuo/ip/form/ExportForm.php­	  ögS]­	  mp\
¶         src/aieuo/ip/form/Form.phpk[  ögS]k[  W°YÕ¶          src/aieuo/ip/form/FormIFForm.phpÂ  ögS]Â  7ês¶          src/aieuo/ip/form/ImportForm.php  ögS]  OÒÙu¶         src/aieuo/ip/IFAPI.php  ögS]  #ê¶         src/aieuo/ip/ifPlugin.php   ögS]   èåMê¶      %   src/aieuo/ip/manager/BlockManager.php,  ögS],  èŠld¶      '   src/aieuo/ip/manager/ChainIfManager.phpg  ögS]g  iuØé¶      '   src/aieuo/ip/manager/CommandManager.phpy  ögS]y  Íjáÿ¶      %   src/aieuo/ip/manager/EventManager.php"  ögS]"  ÷:¶      &   src/aieuo/ip/manager/FormIFManager.php÷!  ögS]÷!  ß«&Ç¶      "   src/aieuo/ip/manager/IFManager.phpT  ögS]T  
å2¶      $   src/aieuo/ip/processes/AddEffect.php  ögS]  Ê¶      )   src/aieuo/ip/processes/AddEnchantment.phpÖ  ögS]Ö  ÛñH¶      "   src/aieuo/ip/processes/AddItem.phpn  ögS]n  Ïš~¶      #   src/aieuo/ip/processes/AddMoney.phpô  ögS]ô  l*Á¶      &   src/aieuo/ip/processes/AddVariable.php  ögS]  dœñË¶      !   src/aieuo/ip/processes/Attack.phpþ	  ögS]þ	  T¬ ¶      +   src/aieuo/ip/processes/BroadcastMessage.php  ögS]  ŽZ¶      &   src/aieuo/ip/processes/Calculation.php}  ögS]}  zÂì¶      "   src/aieuo/ip/processes/Command.phpY  ögS]Y  3r0¶      )   src/aieuo/ip/processes/CommandConsole.php  ögS]  _¬¶      &   src/aieuo/ip/processes/Cooperation.phpö	  ögS]ö	  {)¶      ,   src/aieuo/ip/processes/CooperationRepeat.phpÄ  ögS]Ä  'vŒ¶      )   src/aieuo/ip/processes/DelayedCommand.php2  ögS]2  
2¶      0   src/aieuo/ip/processes/DelayedCommandConsole.php  ögS]  8ý0¶      )   src/aieuo/ip/processes/DeleteVariable.phpÈ  ögS]È  ^º©¶      $   src/aieuo/ip/processes/DoNothing.phpq  ögS]q  äÁó¶      &   src/aieuo/ip/processes/EventCancel.php	  ögS]	  ËO;¶      -   src/aieuo/ip/processes/ExecuteOtherPlayer.php  ögS]  KóF#¶         src/aieuo/ip/processes/Kick.php&  ögS]&  Ö¿(Ð¶      !   src/aieuo/ip/processes/Motion.php
  ögS]
  ñ€÷c¶      "   src/aieuo/ip/processes/Process.phpç
  ögS]ç
  Ý-p¶      )   src/aieuo/ip/processes/ProcessFactory.phpª	  ögS]ª	  že8¶      %   src/aieuo/ip/processes/ProcessIds.php`  ögS]`  û:¶      %   src/aieuo/ip/processes/RemoveItem.php
  ögS]
  Z;â¶      $   src/aieuo/ip/processes/SaveDatas.php&  ögS]&  7%µ¶      #   src/aieuo/ip/processes/SendForm.php  ögS]  |«	¶      &   src/aieuo/ip/processes/SendMessage.php@  ögS]@  ãé¶      *   src/aieuo/ip/processes/SendMessageToOp.php÷  ögS]÷  ªZ?¶      "   src/aieuo/ip/processes/SendTip.php  ögS]  Sìº¶      $   src/aieuo/ip/processes/SendTitle.phpG  ögS]G  ŸHÜU¶      +   src/aieuo/ip/processes/SendVoiceMessage.phpž  ögS]ž  x¶      $   src/aieuo/ip/processes/SetBlocks.php  ögS]  Ä¡Y¶      &   src/aieuo/ip/processes/SetGamemode.phpÔ  ögS]Ô  ®/Å¶      $   src/aieuo/ip/processes/SetHealth.php×	  ögS]×	  °ÐÄÓ¶      &   src/aieuo/ip/processes/SetImmobile.phpä  ögS]ä  gà8¶      "   src/aieuo/ip/processes/SetItem.php  ögS]  ÉÐt¶      '   src/aieuo/ip/processes/SetMaxHealth.php(  ögS](  Y%¶      #   src/aieuo/ip/processes/SetMoney.phpÚ  ögS]Ú  Yóú¶      %   src/aieuo/ip/processes/SetNametag.php  ögS]  !VJK¶      #   src/aieuo/ip/processes/SetScale.phpº	  ögS]º	  ðnëü¶      %   src/aieuo/ip/processes/SetSitting.phpÎ  ögS]Î  é¶      &   src/aieuo/ip/processes/SetSleeping.phpw  ögS]w  ["n¶      $   src/aieuo/ip/processes/TakeMoney.phpú  ögS]ú  ÎIóZ¶      #   src/aieuo/ip/processes/Teleport.phpc  ögS]c  W¶      &   src/aieuo/ip/processes/TypeCommand.phpÏ  ögS]Ï  ¶      #   src/aieuo/ip/processes/TypeItem.phpÌ
  ögS]Ì
  :ä¹¶      &   src/aieuo/ip/processes/TypeMessage.phpE  ögS]E  òMÀ¶      $   src/aieuo/ip/processes/TypeMoney.php  ögS]  6]U¶      '   src/aieuo/ip/processes/TypePosition.php8	  ögS]8	  Aþ¶      (   src/aieuo/ip/processes/UnSetImmobile.phpç  ögS]ç  ÌÀk2¶         src/aieuo/ip/Session.phpe  ögS]e  åÏA¶      (   src/aieuo/ip/task/DelayedCommandTask.phpm  ögS]m  uà¶         src/aieuo/ip/task/KickTask.php8  ögS]8  eF¶         src/aieuo/ip/task/SaveTask.phpí  ögS]í  7È{o¶         src/aieuo/ip/utils/Language.phpê  ögS]ê  Ì=¶         src/aieuo/ip/utils/Messages.php  ögS]  ¬Í	Ù¶      &   src/aieuo/ip/variable/ListVariable.phpº  ögS]º  a¶      (   src/aieuo/ip/variable/NumberVariable.php±	  ögS]±	  u¢L¶      (   src/aieuo/ip/variable/StringVariable.phpú  ögS]ú  ò¯Ê¶      "   src/aieuo/ip/variable/Variable.phpí  ögS]í  Mà§­¶      (   src/aieuo/ip/variable/VariableHelper.php  ögS]   ô1$¶      ---
name: if
main: aieuo\ip\ifPlugin
version: 3.4.0
api: 3.0.0
load: POSTWORLD
author: aieuo
permissions:
  ifplugin.customcommand.op:
    default: op
    description: "ifplugin.customcommand.op"
  ifplugin.customcommand.true:
    default: true
    description: "ifplugin.customcommand.true"
...# if_plugin
https://forum.mcbe.jp/resources/172/

# TODO
- [ ] IFããŸãšããŠåºåã§ããããã«ãã  
- [x] åŠçãšãè¿œå ãããšãã«æ€çŽ¢ã§ããããã«ãã  
- [x] å€æ°ã«åãè¿œå ãã  
- [ ] å€ãæ¯èŒãã ã®åãå³ãããã  
- [x] èšç®ãã ã®åãå³ãããã
language.name=English
language.selected=Selected {%0} as the base language

command.noconsole=Please run command in game

economy.found=Selected {%0} as the economy plugin
economy.notfound=Economy plugin not found

message.if=if
message.match=:
message.else=otherwise

form.delete=delete
form.cancel=cancel
form.error=Â§cinvalid inputÂ§f

input.invalid=Â§c[{%0}] invalid data
input.example='example) {%0}'

condition.nocheck.name=check nothing
condition.nocheck.description=check nothing
condition.nocheck.detail=check nothing

condition.takemoney.name=take money
condition.takemoney.description=take Â§7<amount>Â§f money if can reduce
condition.takemoney.detail='take {%0} money if can reduce'

condition.overmoney.name=money held is higher than specified
condition.overmoney.description=money held is higher than Â§7<amount>Â§f
condition.overmoney.detail='if money held is higher than {%0}'
condition.overmoney.zero=Â§erecommended amount is 1 or moreÂ§f
condition.overmoney.form.amount=\nÂ§7<amount>Â§f please enter price

condition.lessmoney.name=money held is less than specified
condition.lessmoney.description=money held is less than Â§7<amount>Â§f
condition.lessmoney.detail='if money held is less than {%0}'

condition.item.form.zero=Â§ethe number of items seems to be 0Â§f
condition.item.form.invalid='Â§csomething is wrong.(id must be a number and must be 0 or more)Â§f'
condition.item.form.id=\nÂ§7<id>Â§f please enter item id
condition.item.form.count=\nÂ§7<count>Â§f please enter item count

condition.inhand.name=have a specified item in my hand
condition.inhand.description=if the hand has Â§7<count>Â§f or more items with id Â§7<id>Â§f
condition.inhand.detail='if having item(id={%0}:{%1} count>={%2}) in hand'

condition.existsitem.name=contains item specified in the inventory
condition.existsitem.description=if the inventory has Â§7<count>Â§f or more items with id Â§7<id>Â§f
condition.existsitem.detail='if contains item(id={%0}:{%1} count={%2}) in the inventory'

condition.removeitem.name=remove specified item if contains it in the inventory
condition.removeitem.description=remove Â§7<count>Â§f of items Â§7<id>Â§f if the inventory contains it
condition.removeitem.detail='remove item(id={%0}:{%1} count={%2}) if the inventory contains it'
condition.removeitem.all=Â§eremove all specified items from the inventoryÂ§f
condition.removeitem.form.count='\nÂ§7<count>Â§f please enter item count. (please enter 0 or leave blank to remove all)'

condition.canadditem.name=can add item to inventory
condition.canadditem.description=if the inventory has space to add Â§7<count>Â§f items with id Â§7<id>Â§f
condition.canadditem.detail='if can add item(id={%0}:{%1} count={%2}) to inventory'

condition.isop.name=the player is op
condition.isop.description=the player is op
condition.isop.detail=check if the player is op

condition.issneaking.name=the player is sneaking
condition.issneaking.description=the player is sneaking
condition.issneaking.detail=check if the player is sneaking

condition.isflying.name=the player is flying
condition.isflying.description=the player is flying
condition.isflying.detail=check if the player is flying

condition.gamemode.name=the gamemode is specified
condition.gamemode.description=if the player\qs gamemode is Â§7<gamemode>Â§f
condition.gamemode.detail=if the player\qs gamemode is Â§7<gamemode>Â§f
condition.gamemode.notfound=Â§cthe gamemode is not foundÂ§f
condition.gamemode.survival=survival mode
condition.gamemode.creative=creative mode
condition.gamemode.adventure=adventure mode
condition.gamemode.spectator=spectator mode
condition.gamemode.form.gamemode=\nÂ§7<gamemode>Â§f please select gamemode

condition.inarea.name=the player is within the specified area
condition.inarea.description=if the player is in the range Â§7<min> to Â§7<max>Â§r of the Â§7<x|y|z>Â§r axis
condition.inarea.detail1='if the player is in the range '
condition.inarea.detail2='{%0}({%1}~{%2})'
condition.inarea.detail3=''
condition.inarea.form.area='\nÂ§7<{%0}>Â§f please enter the range of {%1}-axis (leave blank if not specified)'

condition.randomnumber.name=the random numbers match
condition.randomnumber.description=if the random number generated in the range of Â§7<min>Â§r to Â§7<max>Â§r matches Â§7<check>Â§7
condition.randomnumber.detail=if the random number generated in the range of {%0} to {%1} is {%2}
condition.randomnumber.form.warning={%0} can not be generated by random numbers in the range of {%1} to {%2}
condition.randomnumber.form.min=\nÂ§7<min>Â§f please enter minimum value
condition.randomnumber.form.max=\nÂ§7<max>Â§f please enter maximum value
condition.randomnumber.form.check=\nÂ§7<check>Â§f please enter a number

condition.comparison.name=compare two values
condition.comparison.description=compare Â§7<value1>Â§r and Â§7<value2>Â§r with Â§7<operator>Â§r
condition.comparison.detail.equal=if {%0} and {%1} are equal
condition.comparison.detail.not_equal=if {%0} and {%1} are not equal
condition.comparison.detail.greater=if {%1} is smaller than {%0}
condition.comparison.detail.less=if {%1} is greater than {%0}
condition.comparison.detail.greater_equal=if {%0} is {%1} or more
condition.comparison.detail.less_equal=if {%0} is {%1} or less
condition.comparison.detail.contains=if {%0} contains {%1}
condition.comparison.detail.not_contains=if {%0} does not contains {%1}
condition.comparison.form.value1=\nÂ§7<value1>Â§f please enter the first value
condition.comparison.form.operator=\nÂ§7<operator>Â§f please select the operator
condition.comparison.form.value2=\nÂ§7<value2>Â§f please enter the second value
condition.comparison.form.equal='the values are equal (value1 == value2)'
condition.comparison.form.not_equal='the values are not equal (value1 != value2)'
condition.comparison.form.greater='value1 is greater than the value2 (value1 > value2)'
condition.comparison.form.less='value1 is less than the value2 (value1 < value2)'
condition.comparison.form.greater_equal='value1 is value2 or more (value1 >= value2)'
condition.comparison.form.less_equal='value1 is value2 or less (value1 <= value2)'
condition.comparison.form.contains=value1 contains value2
condition.comparison.form.not_contains=value1 does not contains value2

condition.existsvariable.name=the variable exists
condition.existsvariable.description=if a variable named Â§7<variable>Â§f exists
condition.existsvariable.detail=if a variable named {%0} exists
condition.existsvariable.form.name=\nÂ§7<variable>Â§f please enter variable\qs name

process.donothing.name=do nothing
process.donothing.description=do nothing
process.donothing.detail=do nothing

process.message.form.message=\nÂ§7<message>Â§f please enter a message to send

process.sendmessage.name=send message to chat field
process.sendmessage.description=send a message Â§7<message>Â§f to chat field
process.sendmessage.detail=send message \dq{%0}\dq to chat field

process.sendtip.name=send message to tip field
process.sendtip.description=send a message Â§7<message>Â§f to tip field
process.sendtip.detail=send a message \dq{%0}\dq to tip field

process.sendtitile.name=send message to title field
process.sendtitile.description=send a message Â§7<message> to title field
process.sendtitile.detail=send a message \dq{%0}\dq to title field

process.broadcastmessage.name=send broadcast message
process.broadcastmessage.description=send a message Â§7<message>Â§f to everyone\qs chat field
process.broadcastmessage.detail=send a message \dq{%0}\dq to everyone\qs chat field

process.sendmessagetoop.name=send message just for op
process.sendmessagetoop.description=send a message Â§7<message>Â§f just for op
process.sendmessagetoop.detail=send a message \dq{%0}\dq just for op

process.sendvoicemessage.name=send message with voice
process.sendvoicemessage.description=send a message Â§7<message>Â§f with voice
process.sendvoicemessage.detail=send a message \dq{%0}\dq with voice

process.sendform.name=send form to player
process.sendform.description=send a form named Â§7<name>Â§f to the player
process.sendform.detail=send a form named \dq{%0}\dq to the player
process.sendform.notfound="Â§c[{%0}] There is no form with that name."
process.sendform.form.name=\nÂ§7<name>Â§f please enter a name of form

process.command.form.command=\nÂ§7<command>Â§f please enter a command

process.command.name=execute command
process.command.description=excute a command Â§7<command>Â§f
process.command.detail=excute a command \dq/{%0}\dq

process.commandconsole.name=execute command from console
process.commandconsole.description=excute a command Â§7<command>Â§f from console
process.commandconsole.detail=excute a command \dq/{%0}\dq from console

process.delayedcommand.name=run command with delay
process.delayedcommand.description=execute command Â§7<command>Â§f Â§7<time>Â§f seconds after being called
process.delayedcommand.detail=execute command /dq/{%1}/dq {%0} seconds after being called
process.delayedcommand.form.command=\nÂ§7<command>Â§f please enter a command
process.delayedcommand.form.time=\nÂ§7<time>Â§f please enter the number of seconds to delay

process.delayedcommandconsole.name=run command from console with delay
process.delayedcommandconsole.description=execute command Â§7<command>Â§f from console Â§7<time>Â§f seconds after being called
process.delayedcommandconsole.detail=execute command /dq/{%1}/dq from console {%0} seconds after being called

process.money.zero=Â§erecommended to enter a price greater than 1Â§f
process.money.form.amount=\nÂ§7<amount>Â§f please enter a price

process.addmoney.name=increase money
process.addmoney.description=increase your money held by Â§7<amount>Â§f
process.addmoney.detail=increase your money held by {%0}

process.takemoney.name=decrease money
process.takemoney.description=decrease your money held by Â§7<amount>Â§f
process.takemoney.detail=decrease your money held by {%0}

process.position.form.position=\nÂ§7<pos>Â§f please enter position separated by commas
process.position.level.notfound=Â§cworld does not exist or is not loadedÂ§f

process.teleport.name=teleport
process.teleport.description=teleport to Â§7<pos>Â§f
process.teleport.detail='teleport to ({%0})'

process.motion.name=add motion
process.motion.description='add (Â§7<x> <y> <z>Â§f) motion to the player'
process.motion.detail='add ({%0} {%1} {%2}) motion to the player'
process.motion.form.x=\nÂ§7<x>Â§f please enter the value to move in the x-axis
process.motion.form.y=\nÂ§7<y>Â§f please enter the value to move in the y-axis
process.motion.form.z=\nÂ§7<z>Â§f please enter the value to move in the z-axis

process.setscale.name=change player\qs size
process.setscale.description=change player\qs size to Â§7<scale>Â§f
process.setscale.detail=change player\qs size to {%0}
process.setscale.form.error=Â§csize must be greater than 0Â§f
process.setscale.form.scale="\nÂ§7<scale>Â§f please enter size. (standard: 1)"

process.calculation.name=calculate two values
process.calculation.description=Â§7<value1>Â§fãšÂ§7<value2>Â§fãèšç®Â§7<opefator>Â§rããçµæã{result}ã«å¥ãã
process.calculation.detail.add={%0}ãš{%1}ãè¶³ã
process.calculation.detail.sub={%0}ãã{%1}ãåŒã
process.calculation.detail.mul={%0}ãš{%1}ãæãã
process.calculation.detail.div={%0}ã{%1}ã§å²ã
process.calculation.detail.mod={%0}ã{%1}ã§å²ã£ãäœã
process.calculation.invalid=Â§c[{%0}]ãã®çµã¿åããã¯äœ¿çšã§ããŸãã
process.calculation.error=Â§c[{%0}] {%1}
process.calculation.form.value1=\nÂ§7<value1>Â§f äžã€ç®ã®å€ãå¥åããŠãã ãã
process.calculation.form.value2=\nÂ§7<operator>Â§f éžãã§ãã ãã
process.calculation.form.operator=\nÂ§7<value2>Â§f äºã€ç®ã®å€ãå¥åããŠãã ãã
process.calculation.form.operator.add='äžã€ç®ã®å€ãšäºã€ç®ã®å€ãè¶³ã (value1 + value2)'
process.calculation.form.operator.sub='äžã€ç®ã®å€ãšäºã€ç®ã®å€ãåŒã (value1 - value2)'
process.calculation.form.operator.mul='äžã€ç®ã®å€ãšäºã€ç®ã®å€ãæãã (value1 * value2)'
process.calculation.form.operator.div='äžã€ç®ã®å€ãäºã€ç®ã§å€ãå²ã (value1 / value2)'
process.calculation.form.operator.mod='äžã€ç®ã®å€ãäºã€ç®ã§å€ãå²ã£ãäœã (value1 % value2)'
process.calculation.form.result='\nÂ§7<result>Â§f çµæãä»£å¥ããå€æ°ã®ååãå¥åããŠãã ãã(ç©ºçœãªãresult)'

process.addvariable.name=add variable
process.addvariable.description=Â§7<name>Â§fãšããååã§Â§7<value>Â§fãšããå€ã®å€æ°ãè¿œå ãã
process.addvariable.detail={%0}ãšããååã§{%1}ãšããå€ã®å€æ°ãè¿œå ãã
process.addvariable.form.name=\nÂ§7<name>Â§f å€æ°ã®ååãå¥åããŠãã ãã
process.addvariable.form.value=\nÂ§7<value>Â§f å€æ°ã®å€ãå¥åããŠãã ãã

process.deletevariable.name=delete variable
process.deletevariable.description=Â§7<name>Â§fãšããååã®å€æ°ãåé€ãã
process.deletevariable.detail={%0}ãšããååã®å€æ°ãåé€ãã
process.deletevariable.form.name=\nÂ§7<name>Â§f å€æ°ã®ååãå¥åããŠãã ãã

process.item.form.zero=Â§eåæ°ã0ã«ãªã£ãŠããŸãÂ§f
process.item.form.invalid='Â§cæ­£ããå¥åã§ããŠããŸãã(idã¯æ°å­ã§0ä»¥äžã®æ°ãå¥åããŠãã ãã)Â§f'
process.item.form.id=\nÂ§7<id>Â§f ã¢ã€ãã ã®idãå¥åããŠãã ãã
process.item.form.count=\nÂ§7<count>Â§f ã¢ã€ãã ã®æ°ãå¥åããŠãã ãã
process.item.form.name='Â§7<name>Â§f ã¢ã€ãã ã«ä»ãããååãå¥åããŠãã ãã(ç©ºçœãªããã®ãŸãŸã®ååã§ã)'

process.additem.name=add items to inventory
process.additem.description=ã€ã³ãã³ããªã«idãÂ§7<id>Â§fã®Â§7<name>Â§fãšããååã®ã¢ã€ãã ãÂ§7<count>Â§fè¿œå ãã
process.additem.detail='ã€ã³ãã³ããªã«({%0}:{%1},{%2})ã{%3}åè¿œå ãã'

process.removeitem.name=remove items from inventory
process.removeitem.description=ã€ã³ãã³ããªããidãÂ§7<id>Â§fã®ã¢ã€ãã ãÂ§7<count>Â§fåé€ãã
process.removeitem.detail='ã€ã³ãã³ããªãã({%0}:{%1},{%2})ã{%3}ååé€ãã'
process.removeitem.removeall=Â§eæå®ããã¢ã€ãã ãã€ã³ãã³ããªãããã¹ãŠåé€ããŸãÂ§f
process.removeitem.form.count='\nÂ§7<count>Â§f ã¢ã€ãã ã®æ°ãå¥åããŠãã ãã(åšãŠæ¶ãå Žåã¯0ãå¥åãããç©ºçœã«ããŠãã ãã)'

process.setitem.name=add items to a specified index in the inventory
process.setitem.description=ã€ã³ãã³ããªã®Â§7<index>Â§fã«idãÂ§7<id>Â§fã®Â§7<name>Â§fãšããååã®ã¢ã€ãã ãÂ§7<count>Â§fè¿œå ãã
process.setitem.detail='ã€ã³ãã³ããªã®{%0}ã«({%1}:{%2},{%3})ã{%4}åè¿œå ãã'
process.setitem.form.index=Â§7<index>Â§f ã¢ã€ãã ãè¿œå ããå Žæãå¥åããŠãã ãã

process.immobile.name=åããªãããã«ãã
process.immobile.description=ãã¬ã€ã€ãŒãåããªãããã«ãã
process.immobile.detail=ãã¬ã€ã€ãŒãåããªãããã«ãã

process.mobile.name=åããããã«ãã
process.mobile.description=ãã¬ã€ã€ãŒãåããããã«ãã
process.mobile.detail=ãã¬ã€ã€ãŒãåããããã«ãã

process.addenchant.name=æã«æã£ãŠãã¢ã€ãã ã«ãšã³ãã£ã³ããè¿œå ãã
process.addenchant.description=æã«æã£ãŠãã¢ã€ãã ã«idãÂ§7<id>Â§fã§åŒ·ããÂ§7<power>Â§fã®ãšã³ãã£ã³ããè¿œå ãã
process.addenchant.detail=æã«æã£ãŠãã¢ã€ãã ã«idã{%0}ã§{%1}ã¬ãã«ã®ãšã³ãã£ã³ããè¿œå ãã
process.addenchant.notfound=Â§cãšã³ãã£ã³ããèŠã€ãããŸããÂ§f
process.addenchant.form.id=\nÂ§7<id>Â§f ãšã³ãã£ã³ãã®ååãidãå¥åããŠãã ãã
process.addenchant.form.power=\nÂ§7<power>Â§f ãšã³ãã£ã³ãã®ã¬ãã«ãå¥åããŠãã ãã

process.addeffect.name="adds effects on players"
process.addeffect.description=ãã¬ã€ã€ãŒã«idãÂ§7<id>Â§fã§åŒ·ããÂ§7<power>Â§fã®ãšãã§ã¯ããÂ§7<time>Â§fç§éäžãã
process.addeffect.detail=idã{%0}ã§åŒ·ãã{%1}ã®ãšãã§ã¯ãã{%2}ç§éäžãã
process.addeffect.notfound=Â§cãšãã§ã¯ããèŠã€ãããŸããÂ§f
process.addeffect.form.id=\nÂ§7<id>Â§f ãšãã§ã¯ãã®ååãidãå¥åããŠãã ãã
process.addeffect.form.power=\nÂ§7<power>Â§f ãšãã§ã¯ãã®åŒ·ããå¥åããŠãã ãã
process.addeffect.form.time=\nÂ§7<time>Â§f ãšãã§ã¯ããäžããæéãå¥åããŠãã ãã

process.setnametag.name=change player display name
process.setnametag.description=è¡šç€ºããååãÂ§7<name>Â§fã«å€ãã
process.setnametag.detail=è¡šç€ºããååã{%0}ã«ãã
process.setnametag.form.name=\nÂ§7<name>Â§f å€ããååãå¥åããŠãã ãã

process.setsleeping.name=sleep
process.setsleeping.description=ãã¬ã€ã€ãŒãÂ§7<pos>Â§fã«å¯ããã
process.setsleeping.detail={%0}ã§å¯ã

process.setsitting.name=sit
process.setsitting.description=ãã¬ã€ã€ãŒãÂ§7<pos>Â§fã«åº§ããã
process.setsitting.detail={%0}ã§åº§ã

process.eventcancel.name=cancel event
process.eventcancel.description=ã€ãã³ããã­ã£ã³ã»ã«ãã
process.eventcancel.detail=ã€ãã³ããã­ã£ã³ã»ã«ãã

process.gamemode.name=change player\qs gamemode
process.gamemode.description=ãã¬ã€ã€ãŒã®ã²ãŒã ã¢ãŒããÂ§7<gamemode>Â§fã«ãã
process.gamemode.detail=ã²ãŒã ã¢ãŒãã{%0}ã«å€æŽãã
process.gamemode.notfound=Â§cã²ãŒã ã¢ãŒããèŠã€ãããŸããÂ§f
process.gamemode.survival=ãµãã€ãã«ã¢ãŒã
process.gamemode.creative=ã¯ãªãšã€ãã£ãã¢ãŒã
process.gamemode.adventure=ã¢ããã³ãã£ãŒã¢ãŒã
process.gamemode.spectator=ã¹ãã¯ãã€ã¿ãŒã¢ãŒã
process.gamemode.form.gamemode=\nÂ§7<gamemode>Â§f ã²ãŒã ã¢ãŒããéžæããŠäžãã

process.cooperation.name=call another ChainIF
process.cooperation.description=Â§7<name>Â§fãšããååã®ãã§ãŒã³ãå®è¡ãã
process.cooperation.detail=ãã§ãŒã³ {%0} ãå®è¡ãã
process.cooperation.notfount=Â§cãã®ååã®ãã§ãŒã³ã¯è¿œå ãããŠããŸããÂ§f
process.cooperation.form.name=\nÂ§7<name>Â§f ååãå¥åããŠãã ãã

process.cooperationrepeat.name=call another ChainIF specified times
process.cooperationrepeat.description=Â§7<name>Â§fãšããååã®IFãÂ§7<count>Â§fåå®è¡ãã
process.cooperationrepeat.detail={%0}ã{%1}åå®è¡ãã
process.cooperationrepeat.form.count=\nÂ§7<count>Â§f å®è¡ããåæ°ãå¥åããŠãã ãã

process.executeotherplayer.name=execute IF as other players
process.executeotherplayer.description=Â§7<player>Â§fã«Â§7<name>Â§fãšããååã®ãã§ãŒã³ãå®è¡ããã
process.executeotherplayer.detail={%0}ã{%1}ã«å®è¡ããã
process.executeotherplayer.offline={%0}ã¯ä»ãµãŒããŒã«ããŸãã
process.executeotherplayer.form.name=\nÂ§7<name>Â§f å®è¡ããIFã®ååãå¥åããŠãã ãã
process.executeotherplayer.form.player=\nÂ§7<player>Â§f ãã¬ã€ã€ãŒã®ååãå¥åããŠãã ãã

process.setblocks.name=fill specified range with block
process.setblocks.description='Â§7<level>Â§fã¯ãŒã«ãã®Â§7<spos>Â§f~Â§7<epos>Â§fã«Â§7<id>Â§fã®ãã­ãã¯ãèš­çœ®ãã'
process.setblocks.detail='{%0}ã®{%1},{%2},{%3}ïœ{%4},{%5},{%6}ã«{%7}:{%8}ãèš­çœ®ãã'
process.setblocks.form.spos=\nÂ§7<spos>Â§f æåã®äœçœ®ã,ã§åºåã£ãŠå¥åããŠãã ãã
process.setblocks.form.epos=\nÂ§7<epos>Â§f æåŸã®äœçœ®ã,ã§åºåã£ãŠå¥åããŠãã ãã
process.setblocks.form.level=\nÂ§7<level>Â§f ã¯ãŒã«ãåãå¥åããŠãã ãã
process.setblocks.form.id=\nÂ§7<id>Â§f èš­çœ®ãããã­ãã¯ã®idãå¥åããŠãã ãã

process.savedatas.name=save IF, variable, and setting data
process.savedatas.description=save IF, variable, and setting data
process.savedatas.detail=save IF, variable, and setting data

process.sethealth.name=set player\qs health
process.sethealth.description=ãã¬ã€ã€ãŒã®äœåãÂ§7<health>Â§fã«ãã
process.sethealth.detail=ãã¬ã€ã€ãŒã®äœåã{%0}ã«ãã
process.sethealth.zero=Â§c[{%0}] äœåã¯1ä»¥äžã«ããŠãã ãã
process.sethealth.form.zero=Â§cäœåã¯1ä»¥äžã«ããŠãã ããÂ§f
process.sethealth.form.health=\nÂ§7<health>Â§f äœåãå¥åããŠãã ãã

process.setmaxhealth.name=set player\qs maximum health
process.setmaxhealth.description=ãã¬ã€ã€ãŒã®æå€§äœåãÂ§7<health>Â§fã«ãã
process.setmaxhealth.detail=ãã¬ã€ã€ãŒã®æå€§äœåã{%0}ã«ãã
process.setmaxhealth.zero=Â§c[{%0}] æå€§äœåã¯1ä»¥äžã«ããŠãã ãã

process.attack.name=deal damage to player
process.attack.description=ãã¬ã€ã€ãŒã«ãã¡ãŒãžãÂ§7<damage>Â§fäžãã
process.attack.detail=ãã¬ã€ã€ãŒã«{%0}ãã¡ãŒãžäžãã
process.attack.error=Â§c[{%0}] æ»æåã¯1ä»¥äžã«ããŠãã ãã
process.attack.form.error=Â§cæ»æåã¯1ä»¥äžã«ããŠãã ããÂ§f
process.attack.form.damage=\nÂ§7<damage>Â§f æ»æåãå¥åããŠãã ãã

process.kick.name=kick the player
process.kick.description=ãã¬ã€ã€ãŒãÂ§7<reason>Â§fã§ã­ãã¯ãã
process.kick.detail=ãã¬ã€ã€ãŒã{%0}ã§ã­ãã¯ãã
process.kick.form.reason=\nÂ§7<reason>Â§f çç±ãå¥åããŠãã ãã

command.if.usage=/if <block | command | event | chain | import | language>
command.if.description=do something when conditions are met or when an event occurs

command.language.usage=Usage: /if language <language name>
command.language.notfound=language {%0} not found. available languages: {%1}

command.block.usage=Usage: /if block <edit|check|del|copy|cancel>
command.block.edit=Touch a block to edit.
command.block.check=Touch a block to check.
command.block.del=Touch a block to delete.
command.block.copy=Touch a block to copy.
command.block.cancel=Cancelled.

command.command.usage=Usage: /if command <add_empty|add|edit|check|del|cancel>
command.command.not_added=The command has not been added yet.
command.command.cancel=Cancelled.

form.back=<return to previous>
form.cancel=<cancel>
form.exit=<exit>
form.cancelled=Â§eCanceled successfully.Â§f
form.changed=Â§bThe change was successful.Â§f
form.insufficient=Â§cInsufficient inputÂ§f
form.selectButton=Â§7please select button

form.action.add=add
form.action.edit=edit
form.action.delete=delete
form.action.check=check
form.action.copy=copy

form.form.selectAction.title=/if
form.form.editIF.title=Edit IF
form.form.editIF.if="ãã~ãç·šéãã"
form.form.editIF.match=æ¡ä»¶ã«åã£ãæãç·šéãã
form.form.editIF.else=æ¡ä»¶ã«åããªãã£ãæãç·šéãã
form.form.editIF.changeName=ååãèš­å®ãã
form.form.editIF.export=ãã¡ã€ã«åºåãã
form.form.editContents.title=IFç·šé > {%0}
form.form.editContents.add=<è¿œå ãã>
form.form.addContents.title=IFç·šé > è¿œå 
form.form.addContents.search=<æ€çŽ¢ãã>
form.form.delete.notExist=Â§cãŸã è¿œå ããŠããªãã®ã§åé€ã§ããŸããÂ§f
form.form.added=Â§bè¿œå ããŸããÂ§f
form.form.added.suspicious=Â§eè¿œå ããŸããããæ­£ããå¥åã§ããŠããªãå¯èœæ§ããããŸãÂ§f
form.form.changed=Â§bå€æŽããŸããÂ§f
form.form.changed.suspicious=Â§eå€æŽããŸããããæ­£ããå¥åã§ããŠããªãå¯èœæ§ããããŸãÂ§f
form.form.confirmDelete.title=åé€
form.form.confirmDelete.content=æ¬åœã«åé€ããŸãã?\nåé€ãããšåã«æ»ããŸãã
form.form.confirmDelete.yes=ã¯ã
form.form.confirmDelete.no=ããã
form.form.delete.success=Â§båé€ããŸããÂ§f
form.form.search.title=IFæ€çŽ¢
form.form.search.label=ååã§æ€çŽ¢ããŸã
form.form.search.input=æ€çŽ¢ããèšèãå¥åããŠãã ãã
form.form.searchResult.title=IFç·šé > è¿œå  > æ€çŽ¢
form.form.setName.title=ååèš­å®
form.form.setName.content0=IFã«ååãèš­å®ããŸã
form.form.setName.content1=ååãå¥åããŠãã ãã
form.form.setName.content2=ååãåé€ãã
form.form.setName.success=Â§bååãèš­å®ããŸããÂ§f
form.form.deleteName.success=Â§eååãåé€ããŸããÂ§f

form.block=block
form.block.action.title=ãã­ãã¯ > æäœéžæ
form.block.action.edit=ç·šéãããã­ãã¯ãè§Šã£ãŠãã ãã
form.block.action.check=ç¢ºèªãããã­ãã¯ãè§Šã£ãŠãã ãã
form.block.action.delete=åé€ãããã­ãã¯ãè§Šã£ãŠãã ãã
form.block.action.copy=ã³ããŒãããã­ãã¯ãè§Šã£ãŠãã ãã

form.command=command

form.event=event

form.formif=form
form.formif.list=ãªã¹ã
form.formif.custom=ã«ã¹ã¿ã 
form.formif.modal=ãã©ãŒã 
form.formif.exist=Â§eãã®ååã®ãã®ã¯æ¢ã«è¿œå ããŠããŸãÂ§f
form.formif.notexist=Â§eãã®ååã®ç©ã¯ãŸã è¿œå ãããŠããŸãã
form.formif.recive=åä¿¡: {%0}
form.formif.recive.input="åä¿¡: {form_data}[{%0}] <- (å¥åå€)"
form.formif.recive.slider="åä¿¡: {form_data}[{%0}] <- (éžæããæ°å€)"
form.formif.recive.dropdown="åä¿¡: {form_data}[{%0}] <- (äžçªäžã0ãšããŠéžæããå Žæã®æ°å€)"
form.formif.action.title=ãã©ãŒã  > æäœéžæ
form.formif.addformif.title=ãã©ãŒã  > è¿œå 
form.formif.addformif.content0={%0}è¿œå ããåå
form.formif.addformif.content1=ãã©ãŒã ã®ã¿ã€ãã«
form.formif.addformif.content2=ãã©ãŒã ã®çš®é¡
form.formif.selectformif.title=ãã©ãŒã  > ãã©ãŒã éžæ
form.formif.selectformif.content0={%0}ãã©ãŒã ã®ååãå¥åããŠãã ãã
form.formif.editformif.title=ãã©ãŒã  > ç·šé
form.formif.editformif.content={%0}Â§7ãã¿ã³ãæŒããŠãã ãã
form.formif.editformif.button.preview=<è¡šç€ºãç¢ºèªãã>
form.formif.editformif.button.edit=<ãã®ãã©ãŒã ã®IFãç·šéãã>
form.formif.editformif.button.title=ã¿ã€ãã«: {%0}
form.formif.editformif.modal.content=åå®¹: {%0}
form.formif.editformif.modal.button1=ãã¿ã³1: {%0}
form.formif.editformif.modal.button2=ãã¿ã³2: {%0}
form.formif.editformif.form.content=åå®¹: {%0}
form.formif.editformif.form.button=ãã¿ã³: {%0}
form.formif.editformif.form.addbutton=<ãã¿ã³ãè¿œå ãã>
form.formif.editformif.custom.content={%0}: {%1}
form.formif.editformif.custom.addparts=<ããŒããè¿œå ãã>
form.formif.selectparts.title=ãã©ãŒã  > ããŒã
form.formif.selectparts.parts.text=ãã­ã¹ã
form.formif.selectparts.parts.title=ã¿ã€ãã«
form.formif.selectparts.parts.content=åå®¹
form.formif.selectparts.parts.button=ãã¿ã³
form.formif.selectparts.parts.button1=ãã¿ã³1
form.formif.selectparts.parts.button2=ãã¿ã³2
form.formif.selectparts.parts.editif=ãã®ãã¿ã³ã«åå¿ããIFãç·šéãã
form.formif.selectparts.addbutton=ãã¿ã³ãè¿œå ãã
form.formif.selectparts.addparts=ããŒããè¿œå ãã
form.formif.selectparts.select_custom_parts=è¿œå ãããã®ãéžæããŠãã ãã
form.formif.iflist.title=ãã©ãŒã  > {%0} > éžæ
form.formif.iflist.add=<è¿œå ãã>
form.formif.iflist.content=Â§7ãã¿ã³ãæŒããŠãã ãã
form.formif.deleted=åé€ããŸãã
form.formif.custom.label="label (æå­ãè¡šç€ºãã)"
form.formif.custom.input="input (æå­ãå¥åãã)"
form.formif.custom.input.placeholder="ãã¬ãŒã¹ãã«ããŒ (äœãå¥åãããŠããªããšãã«è¡šç€ºãããèãæå­)"
form.formif.custom.input.default="ããã©ã«ã (æåããå¥åãããŠããæå­)"
form.formif.custom.toggle="toggle (ãã°ã«ãã¿ã³)"
form.formif.custom.toggle.default="åæå€ (true ã false)"
form.formif.custom.slider="slider (ã¹ã©ã€ããŒ)"
form.formif.custom.slider.max=æå€§å€
form.formif.custom.slider.min=æå°å€
form.formif.custom.slider.default=åæå€
form.formif.custom.slider.step=ç®çã
form.formif.custom.dropdown="dropdown (ãã­ããããŠã³)"
form.formif.custom.dropdown.option="éžæè¢{%0} (ç©ºçœã«ãããšåé€ããŸã)"
form.formif.custom.dropdowm.addOption="--------------------\néžæè¢è¿œå  (,ã§åºåã£ãŠè€æ°å¥åã§ããŸã)"
form.formif.custom.text=ãã­ã¹ã

form.chain=chain

form.import=importlanguage.name=æ¥æ¬èª
language.selected=èšèªã{%0}ã«èš­å®ããŸãã

command.console=ã²ãŒã åã§å®è¡ããŠãã ãã

economy.found={%0}ãèŠã€ããŸãã
economy.notfound=çµæžã·ã¹ãã ãã©ã°ã€ã³ãèŠã€ãããŸãã

message.if=ãã
message.match=ãªã
message.else=æ¡ä»¶ã«åããªãã£ãã

form.delete=åé€ãã
form.cancel=ã­ã£ã³ã»ã«
form.error=Â§cæ­£ããå¥åã§ããŠããŸããÂ§f

input.invalid=Â§c[{%0}] æ­£ããå¥åã§ããŠããŸãã
input.example='äŸ) {%0}'

condition.nocheck.name=äœãç¢ºèªããªã
condition.nocheck.description=äœãç¢ºèªããªã
condition.nocheck.detail=äœãç¢ºèªããªã

condition.takemoney.name=ãéãæžãã
condition.takemoney.description=ãéãÂ§7<amount>Â§fæãããªãæžãã
condition.takemoney.detail='ãéã{%0}æãããªãæžãã'

condition.overmoney.name=ææéãæå®ããéé¡ä»¥äžã
condition.overmoney.description=ææéãÂ§7<amount>Â§fä»¥äžãªã
condition.overmoney.detail='ææéã{%0}ä»¥äžãªã'
condition.overmoney.zero=Â§e1ä»¥äžã®æ°å­ãå¥åããããšãæšå¥šããŸãÂ§f
condition.overmoney.form.amount=\nÂ§7<amount>Â§f å€æ®µãå¥åããŠãã ãã

condition.lessmoney.name=ææéãæå®ããéé¡ä»¥äžã
condition.lessmoney.description=ææéãÂ§7<amount>Â§fä»¥äžãªã
condition.lessmoney.detail='ææéã{%0}ä»¥äžãªã'

condition.item.form.zero=Â§eåæ°ã0ã«ãªã£ãŠããŸãÂ§f
condition.item.form.invalid='Â§cæ­£ããå¥åã§ããŠããŸãã(idã¯æ°å­ã§0ä»¥äžã®æ°ãå¥åããŠãã ãã)Â§f'
condition.item.form.id=\nÂ§7<id>Â§f ã¢ã€ãã ã®idãå¥åããŠãã ãã
condition.item.form.count=\nÂ§7<count>Â§f ã¢ã€ãã ã®æ°ãå¥åããŠãã ãã

condition.inhand.name=æå®ããã¢ã€ãã ãæã«æã£ãŠãã
condition.inhand.description=idãÂ§7<id>Â§fã®ã¢ã€ãã ãÂ§7<count>Â§fåä»¥äžæã«æã£ãŠãããªã
condition.inhand.detail='æã«({%0}:{%1})ã{%2}åãã£ãŠãããªã'

condition.existsitem.name=ã€ã³ãã³ããªã«æå®ããã¢ã€ãã ãå¥ã£ãŠãã
condition.existsitem.description=ã€ã³ãã³ããªã«idãÂ§7<id>Â§fã®ã¢ã€ãã ãÂ§7<count>Â§fåä»¥äžãããªã
condition.existsitem.detail='ã€ã³ãã³ããªã«({%0}:{%1})ã{%2}åãããªã'

condition.removeitem.name=æå®ããã¢ã€ãã ãã€ã³ãã³ããªã«ãããªãåé€ãã
condition.removeitem.description=ã€ã³ãã³ããªããidãÂ§7<id>Â§fã®ã¢ã€ãã ãÂ§7<count>Â§fååé€ã§ãããªãåé€ãã
condition.removeitem.detail='ã€ã³ãã³ããªãã({%0}:{%1})ã{%2}ååé€ã§ãããªãåé€ãã'
condition.removeitem.all=Â§eæå®ããã¢ã€ãã ãã€ã³ãã³ããªãããã¹ãŠåé€ããŸãÂ§f
condition.removeitem.form.count='\nÂ§7<count>Â§f ã¢ã€ãã ã®æ°ãå¥åããŠãã ãã(åšãŠæ¶ãå Žåã¯0ãå¥åãããç©ºçœã«ããŠãã ãã)'

condition.canadditem.name=ã€ã³ãã³ããªã«ã¢ã€ãã ãè¿œå ã§ããã
condition.canadditem.description=ã€ã³ãã³ããªã«idãÂ§7<id>Â§fã®ã¢ã€ãã ãÂ§7<count>Â§fåè¿œå ã§ããã¹ããŒã¹ããããªã
condition.canadditem.detail='ã€ã³ãã³ããªã«({%0}:{%1})ã{%2}åè¿œå ã§ãããªã'

condition.isop.name=ãã¬ã€ã€ãŒãopã
condition.isop.description=ãã¬ã€ã€ãŒãopã
condition.isop.detail=ãã¬ã€ã€ãŒãopã

condition.issneaking.name=ãã¬ã€ã€ãŒãã¹ããŒã¯ããŠããã
condition.issneaking.description=ãã¬ã€ã€ãŒãã¹ããŒã¯ããŠãããªã
condition.issneaking.detail=ãã¬ã€ã€ãŒãã¹ããŒã¯ããŠãããªã

condition.isflying.name=ãã¬ã€ã€ãŒãé£ãã§ããã
condition.isflying.description=ãã¬ã€ã€ãŒãé£ãã§ãããªã
condition.isflying.detail=ãã¬ã€ã€ãŒãé£ãã§ãããªã

condition.gamemode.name=ã²ãŒã ã¢ãŒããæå®ãããã®ã ã£ãã
condition.gamemode.description=ãã¬ãŒã€ãŒã®ã²ãŒã ã¢ãŒããÂ§7<gamemode>Â§fã ã£ãã
condition.gamemode.detail=ã²ãŒã ã¢ãŒãã{%0}ãªã
condition.gamemode.notfound=Â§cã²ãŒã ã¢ãŒããèŠã€ãããŸããÂ§f
condition.gamemode.survival=ãµãã€ãã«ã¢ãŒã
condition.gamemode.creative=ã¯ãªãšã€ãã£ãã¢ãŒã
condition.gamemode.adventure=ã¢ããã³ãã£ãŒã¢ãŒã
condition.gamemode.spectator=ã¹ãã¯ãã€ã¿ãŒã¢ãŒã
condition.gamemode.form.gamemode=\nÂ§7<gamemode>Â§f ã²ãŒã ã¢ãŒããéžæããŠäžãã

condition.inarea.name=æå®ããç¯å²åã«ããã
condition.inarea.description='ãã¬ã€ã€ãŒãÂ§7<x|y|z>Â§rè»žãÂ§7<min>Â§rïœÂ§7<max>Â§rã®ç¯å²ã«ããã'
condition.inarea.detail1=''
condition.inarea.detail2='{%0}è»žã{%1}~{%2}ã®ç¯å²'
condition.inarea.detail3={%0}ã«ãããªã
condition.inarea.form.area='\nÂ§7<{%0}>Â§f {%1}è»žã®ç¯å²ãå¥åããŠãã ãã (æå®ããªãå Žåã¯ç©ºçœã§)'

condition.randomnumber.name=ä¹±æ°ãæå®ãããã®ã ã£ãã
condition.randomnumber.description='Â§7<min>Â§rïœÂ§7<max>Â§rã®ç¯å²ã§çæããä¹±æ°ãÂ§7<check>Â§7ã ã£ãã'
condition.randomnumber.detail='{%0}~{%1}ã®ç¯å²ã®ä¹±æ°ã{%2}ãªã'
condition.randomnumber.form.warning='Â§eæå®ããæ°{%0}ã¯{%1}~{%2}ã®ç¯å²ã®ä¹±æ°ã§çæãããããšã¯ãããŸããÂ§f'
condition.randomnumber.form.min=\nÂ§7<min>Â§f ä¹±æ°ã®ç¯å²ã®æå°å€ãå¥åããŠãã ãã
condition.randomnumber.form.max=\nÂ§7<max>Â§f ä¹±æ°ã®ç¯å²ã®æå€§å€ãå¥åããŠãã ãã
condition.randomnumber.form.check=\nÂ§7<check>Â§f ç¢ºèªããæ°ãå¥åããŠãã ãã

condition.comparison.name=äºã€ã®å€ãæ¯èŒãã
condition.comparison.description=Â§7<value1>Â§rãšÂ§7<value2>Â§rãÂ§7<operator>Â§rãªã
condition.comparison.detail.equal={%0}ãš{%1}ãç­ãããªã
condition.comparison.detail.not_equal={%0}ãš{%1}ãç­ãããªããã
condition.comparison.detail.greater={%0}ãã{%1}ãå°ãããªã
condition.comparison.detail.less={%0}ãã{%1}ãå€§ãããªã
condition.comparison.detail.greater_equal={%0}ã{%1}ä»¥äžãªã
condition.comparison.detail.less_equal={%0}ã{%1}ä»¥äžãªã
condition.comparison.detail.contains={%0}ã®äž­ã«{%1}ãå«ãŸããŠãããªã
condition.comparison.detail.not_contains={%0}ã®äž­ã«{%1}ãå«ãŸããŠããªããªã
condition.comparison.form.value1=\nÂ§7<value1>Â§f äžã€ç®ã®å€ãå¥åããŠãã ãã
condition.comparison.form.operator=\nÂ§7<operator>Â§f éžãã§ãã ãã
condition.comparison.form.value2=\nÂ§7<value2>Â§f äºã€ç®ã®å€ãå¥åããŠãã ãã
condition.comparison.form.equal=äºã€ã®å€ãç­ãã
condition.comparison.form.not_equal=äºã€ã®å€ãç­ãããªã
condition.comparison.form.greater=äžã€ç®ã®å€ãäºã€ç®ã®å€ããå€§ãã
condition.comparison.form.less=äžã€ç®ã®å€ãäºã€ç®ã®å€ããå°ãã
condition.comparison.form.greater_equal=äžã€ç®ã®å€ãäºã€ç®ã®å€ä»¥äž
condition.comparison.form.less_equal=äžã€ç®ã®å€ãäºã€ç®ã®å€ä»¥äž
condition.comparison.form.contains=äžã€ç®ã®å€ã®äž­ã«äºã€ç®ã®å€ãå«ãŸããŠãã
condition.comparison.form.not_contains=äžã€ç®ã®å€ã®äž­ã«äºã€ç®ã®å€ãå«ãŸããŠããªã

condition.existsvariable.name=å€æ°ãå­åšããã
condition.existsvariable.description=å€æ°Â§7<variable>Â§fãå­åšããã
condition.existsvariable.detail={%0}ãšããååã®å€æ°ãå­åšãããªã
condition.existsvariable.form.name=\nÂ§7<variable>Â§f å€æ°ã®ååãå¥åããŠãã ãã

process.donothing.name=äœãããªã
process.donothing.description=äœãããªã
process.donothing.detail=äœãããªã

process.message.form.message=\nÂ§7<message>Â§f éãã¡ãã»ãŒãžãå¥åããŠãã ãã

process.sendmessage.name=ãã£ããæ¬ã«ã¡ãã»ãŒãžãéã
process.sendmessage.description=ãã£ããæ¬ã«ã¡ãã»ãŒãžÂ§7<message>Â§fãéã
process.sendmessage.detail=ãã£ããæ¬ã« {%0} ãšéã

process.sendtip.name=tipæ¬ã«ã¡ãã»ãŒãžãéã
process.sendtip.description=tipæ¬ã«ã¡ãã»ãŒãžÂ§7<message>Â§fãéã
process.sendtip.detail=tipæ¬ã« {%0} ãšéã

process.sendtitile.name=titleæ¬ã«ã¡ãã»ãŒãžãéã
process.sendtitile.description=titleæ¬ã«ã¡ãã»ãŒãžÂ§7<message>Â§fãéã
process.sendtitile.detail=titleæ¬ã« {%0} ãšéã

process.broadcastmessage.name=åšå¡ã«ã¡ãã»ãŒãžãéã
process.broadcastmessage.description=åšå¡ã«ã¡ãã»ãŒãžÂ§7<message>Â§fãéã
process.broadcastmessage.detail=åšå¡ã«{%0}ãšéã

process.sendmessagetoop.name=opã ãã«ã¡ãã»ãŒãžãéã
process.sendmessagetoop.description=opã ãã«ã¡ãã»ãŒãžÂ§7<message>Â§fãéã
process.sendmessagetoop.detail=opã ãã« {%0} ãšéã

process.sendvoicemessage.name=é³å£°ä»ãã®ã¡ãã»ãŒãžãéã
process.sendvoicemessage.description=é³å£°ä»ãã®ã¡ãã»ãŒãžÂ§7<message>Â§fãéã
process.sendvoicemessage.detail='é³å£°ä»ãã®ã¡ãã»ãŒãž({%0})ãéã'

process.sendform.name=ãã©ãŒã ãéä¿¡ãã
process.sendform.description=ãã¬ã€ã€ãŒã«Â§7<name>Â§fãšããååã®ãã©ãŒã ãéä¿¡ãã
process.sendform.detail=ãã¬ã€ã€ãŒã«{%0}ãšããååã®ãã©ãŒã ãéä¿¡ãã
process.sendform.notfound=Â§c[{%0}] ãã®ååã®ãã©ãŒã ã¯å­åšããŸãã
process.sendform.form.name=\nÂ§7<name>Â§f ãã©ãŒã ã®åå

process.command.form.command=\nÂ§7<command>Â§f å®è¡ããã³ãã³ããå¥åããŠãã ãã

process.command.name=ã³ãã³ããå®è¡ãã
process.command.description=ã³ãã³ãÂ§7<command>Â§fãå®è¡ãã
process.command.detail=/{%0}ãå®è¡ãã

process.commandconsole.name=ã³ã³ãœãŒã«ããã³ãã³ããå®è¡ãã
process.commandconsole.description=ã³ã³ãœãŒã«ããã³ãã³ãÂ§7<command>Â§fãå®è¡ãã
process.commandconsole.detail=ã³ã³ãœãŒã«ãã /{%0} ãå®è¡ãã

process.delayedcommand.name=éããŠã³ãã³ããå®è¡ãã
process.delayedcommand.description=Â§7<time>Â§fç§éããŠã³ãã³ãÂ§7<command>Â§fãå®è¡ãã
process.delayedcommand.detail={%0}ç§éããŠ /{%1} ãå®è¡ãã
process.delayedcommand.form.command=\nÂ§7<command>Â§f å®è¡ããã³ãã³ããå¥åããŠãã ãã
process.delayedcommand.form.time=\nÂ§7<time>Â§f éãããç§æ°ãå¥åããŠãã ãã

process.delayedcommandconsole.name=éããŠã³ãã³ããã³ã³ãœãŒã«ããå®è¡ãã
process.delayedcommandconsole.description=Â§7<time>Â§fç§éããŠã³ãã³ãÂ§7<command>Â§fãã³ã³ãœãŒã«ããå®è¡ãã
process.delayedcommandconsole.detail={%0}ç§éããŠ /{%1} ãã³ã³ãœãŒã«ããå®è¡ãã

process.money.zero=Â§e1ä»¥äžã®æ°å­ãå¥åããããšãæšå¥šããŸãÂ§f
process.money.form.amount=\nÂ§7<amount>Â§f å€æ®µãå¥åããŠãã ãã

process.addmoney.name=ææéãå¢ãã
process.addmoney.description=ææéãÂ§7<amount>Â§få¢ãã
process.addmoney.detail=ææéã{%0}å¢ãã

process.takemoney.name=ææéãæžãã
process.takemoney.description=ææéãÂ§7<amount>Â§fæžãã
process.takemoney.detail=ææéã{%0}æžãã

process.setmoney.name=ææéãèš­å®ãã
process.setmoney.description=ææéãÂ§7<amount>Â§fã«èš­å®ãã
process.setmoney.detail=ææéã{%0}ã«èš­å®ãã

process.position.form.position=\nÂ§7<pos>Â§f åº§æšãšã¯ãŒã«ãåã,ã§åºåã£ãŠå¥åããŠãã ãã
process.position.level.notfound=Â§cã¯ãŒã«ããå­åšããªããèª­ã¿èŸŒãŸããŠããŸããÂ§f

process.teleport.name=ãã¬ããŒããã
process.teleport.description=Â§7<pos>Â§fã«ãã¬ããŒããã
process.teleport.detail={%0}ã«ãã¬ããŒããã

process.motion.name=ãã¬ã€ã€ãŒãåãã
process.motion.description='ãã¬ã€ã€ãŒã(Â§7<x> <y> <z>Â§f)ãã­ãã¯åãã'
process.motion.detail='ãã¬ã€ã€ãŒã({%0} {%1} {%2})ãã­ãã¯åãã'
process.motion.form.x=\nÂ§7<x>Â§f xè»žæ¹åã«åããå€ãå¥åããŠãã ãã
process.motion.form.y=\nÂ§7<y>Â§f yè»žæ¹åã«åããå€ãå¥åããŠãã ãã
process.motion.form.z=\nÂ§7<z>Â§f zè»žæ¹åã«åããå€ãå¥åããŠãã ãã

process.setscale.name=ãã¬ã€ã€ãŒã®ãµã€ãºãå€ãã
process.setscale.description=ãã¬ã€ã€ãŒã®ãµã€ãºãÂ§7<scale>Â§fã«ãã
process.setscale.detail=ãã¬ã€ã€ãŒã®ãµã€ãºã{%0}ã«ãã
process.setscale.form.error=Â§cæ­£ããå¥åã§ããŠããŸãã\nå€ã¯0ããå€§ããããŠãã ããÂ§f
process.setscale.form.scale=\nÂ§7<scale>Â§f å€§ãããå¥åããŠãã ãã

process.calculation.name=äºã€ã®å€ãèšç®ãã
process.calculation.description=Â§7<value1>Â§fãšÂ§7<value2>Â§fãèšç®Â§7<opefator>Â§rããçµæã{result}ã«å¥ãã
process.calculation.detail.add={%0}ãš{%1}ãè¶³ã
process.calculation.detail.sub={%0}ãã{%1}ãåŒã
process.calculation.detail.mul={%0}ãš{%1}ãæãã
process.calculation.detail.div={%0}ã{%1}ã§å²ã
process.calculation.detail.mod={%0}ã{%1}ã§å²ã£ãäœã
process.calculation.invalid=Â§c[{%0}]ãã®çµã¿åããã¯äœ¿çšã§ããŸãã
process.calculation.error=Â§c[{%0}] {%1}
process.calculation.form.value1=\nÂ§7<value1>Â§f äžã€ç®ã®å€ãå¥åããŠãã ãã
process.calculation.form.value2=\nÂ§7<operator>Â§f éžãã§ãã ãã
process.calculation.form.operator=\nÂ§7<value2>Â§f äºã€ç®ã®å€ãå¥åããŠãã ãã
process.calculation.form.operator.add='äžã€ç®ã®å€ãšäºã€ç®ã®å€ãè¶³ã (value1 + value2)'
process.calculation.form.operator.sub='äžã€ç®ã®å€ãšäºã€ç®ã®å€ãåŒã (value1 - value2)'
process.calculation.form.operator.mul='äžã€ç®ã®å€ãšäºã€ç®ã®å€ãæãã (value1 * value2)'
process.calculation.form.operator.div='äžã€ç®ã®å€ãäºã€ç®ã§å€ãå²ã (value1 / value2)'
process.calculation.form.operator.mod='äžã€ç®ã®å€ãäºã€ç®ã§å€ãå²ã£ãäœã (value1 % value2)'
process.calculation.form.result='\nÂ§7<result>Â§f çµæãä»£å¥ããå€æ°ã®ååãå¥åããŠãã ãã(ç©ºçœãªãresult)'

process.addvariable.name=å€æ°ãè¿œå ãã
process.addvariable.description=Â§7<name>Â§fãšããååã§Â§7<value>Â§fãšããå€ã®å€æ°ãè¿œå ãã
process.addvariable.detail={%0}ãšããååã§{%1}ãšããå€ã®å€æ°ãè¿œå ãã
process.addvariable.form.name=\nÂ§7<name>Â§f å€æ°ã®ååãå¥åããŠãã ãã
process.addvariable.form.value=\nÂ§7<value>Â§f å€æ°ã®å€ãå¥åããŠãã ãã

process.deletevariable.name=å€æ°ãåé€ãã
process.deletevariable.description=Â§7<name>Â§fãšããååã®å€æ°ãåé€ãã
process.deletevariable.detail={%0}ãšããååã®å€æ°ãåé€ãã
process.deletevariable.form.name=\nÂ§7<name>Â§f å€æ°ã®ååãå¥åããŠãã ãã

process.item.form.zero=Â§eåæ°ã0ã«ãªã£ãŠããŸãÂ§f
process.item.form.invalid='Â§cæ­£ããå¥åã§ããŠããŸãã(idã¯æ°å­ã§0ä»¥äžã®æ°ãå¥åããŠãã ãã)Â§f'
process.item.form.id=\nÂ§7<id>Â§f ã¢ã€ãã ã®idãå¥åããŠãã ãã
process.item.form.count=\nÂ§7<count>Â§f ã¢ã€ãã ã®æ°ãå¥åããŠãã ãã
process.item.form.name='Â§7<name>Â§f ã¢ã€ãã ã«ä»ãããååãå¥åããŠãã ãã(ç©ºçœãªããã®ãŸãŸã®ååã§ã)'

process.additem.name=ã€ã³ãã³ããªã«ã¢ã€ãã ãè¿œå ãã
process.additem.description=ã€ã³ãã³ããªã«idãÂ§7<id>Â§fã®Â§7<name>Â§fãšããååã®ã¢ã€ãã ãÂ§7<count>Â§fè¿œå ãã
process.additem.detail='ã€ã³ãã³ããªã«({%0}:{%1},{%2})ã{%3}åè¿œå ãã'

process.removeitem.name=ã€ã³ãã³ããªããã¢ã€ãã ãåé€ãã
process.removeitem.description=ã€ã³ãã³ããªããidãÂ§7<id>Â§fã®ã¢ã€ãã ãÂ§7<count>Â§fåé€ãã
process.removeitem.detail='ã€ã³ãã³ããªãã({%0}:{%1},{%2})ã{%3}ååé€ãã'
process.removeitem.removeall=Â§eæå®ããã¢ã€ãã ãã€ã³ãã³ããªãããã¹ãŠåé€ããŸãÂ§f
process.removeitem.form.count='\nÂ§7<count>Â§f ã¢ã€ãã ã®æ°ãå¥åããŠãã ãã(åšãŠæ¶ãå Žåã¯0ãå¥åãããç©ºçœã«ããŠãã ãã)'

process.setitem.name=ã€ã³ãã³ããªã®æå®ããå Žæã«ã¢ã€ãã ãè¿œå ãã
process.setitem.description=ã€ã³ãã³ããªã®Â§7<index>Â§fã«idãÂ§7<id>Â§fã®Â§7<name>Â§fãšããååã®ã¢ã€ãã ãÂ§7<count>Â§fè¿œå ãã
process.setitem.detail='ã€ã³ãã³ããªã®{%0}ã«({%1}:{%2},{%3})ã{%4}åè¿œå ãã'
process.setitem.form.index=Â§7<index>Â§f ã¢ã€ãã ãè¿œå ããå Žæãå¥åããŠãã ãã

process.immobile.name=åããªãããã«ãã
process.immobile.description=ãã¬ã€ã€ãŒãåããªãããã«ãã
process.immobile.detail=ãã¬ã€ã€ãŒãåããªãããã«ãã

process.mobile.name=åããããã«ãã
process.mobile.description=ãã¬ã€ã€ãŒãåããããã«ãã
process.mobile.detail=ãã¬ã€ã€ãŒãåããããã«ãã

process.addenchant.name=æã«æã£ãŠãã¢ã€ãã ã«ãšã³ãã£ã³ããè¿œå ãã
process.addenchant.description=æã«æã£ãŠãã¢ã€ãã ã«idãÂ§7<id>Â§fã§åŒ·ããÂ§7<power>Â§fã®ãšã³ãã£ã³ããè¿œå ãã
process.addenchant.detail=æã«æã£ãŠãã¢ã€ãã ã«idã{%0}ã§{%1}ã¬ãã«ã®ãšã³ãã£ã³ããè¿œå ãã
process.addenchant.notfound=Â§cãšã³ãã£ã³ããèŠã€ãããŸããÂ§f
process.addenchant.form.id=\nÂ§7<id>Â§f ãšã³ãã£ã³ãã®ååãidãå¥åããŠãã ãã
process.addenchant.form.power=\nÂ§7<power>Â§f ãšã³ãã£ã³ãã®ã¬ãã«ãå¥åããŠãã ãã

process.addeffect.name=ãšãã§ã¯ããäžãã
process.addeffect.description=ãã¬ã€ã€ãŒã«idãÂ§7<id>Â§fã§åŒ·ããÂ§7<power>Â§fã®ãšãã§ã¯ããÂ§7<time>Â§fç§éäžãã
process.addeffect.detail=idã{%0}ã§åŒ·ãã{%1}ã®ãšãã§ã¯ãã{%2}ç§éäžãã
process.addeffect.notfound=Â§cãšãã§ã¯ããèŠã€ãããŸããÂ§f
process.addeffect.form.id=\nÂ§7<id>Â§f ãšãã§ã¯ãã®ååãidãå¥åããŠãã ãã
process.addeffect.form.power=\nÂ§7<power>Â§f ãšãã§ã¯ãã®åŒ·ããå¥åããŠãã ãã
process.addeffect.form.time=\nÂ§7<time>Â§f ãšãã§ã¯ããäžããæéãå¥åããŠãã ãã

process.setnametag.name=ååãå€ãã
process.setnametag.description=è¡šç€ºããååãÂ§7<name>Â§fã«å€ãã
process.setnametag.detail=è¡šç€ºããååã{%0}ã«ãã
process.setnametag.form.name=\nÂ§7<name>Â§f å€ããååãå¥åããŠãã ãã

process.setsleeping.name=å¯ããã
process.setsleeping.description=ãã¬ã€ã€ãŒãÂ§7<pos>Â§fã«å¯ããã
process.setsleeping.detail={%0}ã§å¯ã

process.setsitting.name=åº§ããã
process.setsitting.description=ãã¬ã€ã€ãŒãÂ§7<pos>Â§fã«åº§ããã
process.setsitting.detail={%0}ã§åº§ã

process.eventcancel.name=ã€ãã³ããã­ã£ã³ã»ã«ãã
process.eventcancel.description=ã€ãã³ããã­ã£ã³ã»ã«ãã
process.eventcancel.detail=ã€ãã³ããã­ã£ã³ã»ã«ãã

process.gamemode.name=ã²ãŒã ã¢ãŒããå€æŽãã
process.gamemode.description=ãã¬ã€ã€ãŒã®ã²ãŒã ã¢ãŒããÂ§7<gamemode>Â§fã«ãã
process.gamemode.detail=ã²ãŒã ã¢ãŒãã{%0}ã«å€æŽãã
process.gamemode.notfound=Â§cã²ãŒã ã¢ãŒããèŠã€ãããŸããÂ§f
process.gamemode.survival=ãµãã€ãã«ã¢ãŒã
process.gamemode.creative=ã¯ãªãšã€ãã£ãã¢ãŒã
process.gamemode.adventure=ã¢ããã³ãã£ãŒã¢ãŒã
process.gamemode.spectator=ã¹ãã¯ãã€ã¿ãŒã¢ãŒã
process.gamemode.form.gamemode=\nÂ§7<gamemode>Â§f ã²ãŒã ã¢ãŒããéžæããŠäžãã

process.cooperation.name=ã»ãã®IFãšé£æºãã
process.cooperation.description=Â§7<name>Â§fãšããååã®ãã§ãŒã³ãå®è¡ãã
process.cooperation.detail=ãã§ãŒã³ {%0} ãå®è¡ãã
process.cooperation.notfount=Â§cãã®ååã®ãã§ãŒã³ã¯è¿œå ãããŠããŸããÂ§f
process.cooperation.form.name=\nÂ§7<name>Â§f ååãå¥åããŠãã ãã

process.cooperationrepeat.name=ã»ãã®IFæå®ããåæ°å®è¡ãã
process.cooperationrepeat.description=Â§7<name>Â§fãšããååã®IFãÂ§7<count>Â§fåå®è¡ãã
process.cooperationrepeat.detail={%0}ã{%1}åå®è¡ãã
process.cooperationrepeat.form.count=\nÂ§7<count>Â§f å®è¡ããåæ°ãå¥åããŠãã ãã

process.executeotherplayer.name=ã»ãã®ãã¬ã€ã€ãŒãšããŠIFãå®è¡ãã
process.executeotherplayer.description=Â§7<player>Â§fã«Â§7<name>Â§fãšããååã®ãã§ãŒã³ãå®è¡ããã
process.executeotherplayer.detail={%0}ã{%1}ã«å®è¡ããã
process.executeotherplayer.offline={%0}ã¯ä»ãµãŒããŒã«ããŸãã
process.executeotherplayer.form.name=\nÂ§7<name>Â§f å®è¡ããIFã®ååãå¥åããŠãã ãã
process.executeotherplayer.form.player=\nÂ§7<player>Â§f ãã¬ã€ã€ãŒã®ååãå¥åããŠãã ãã

process.setblocks.name=æå®ããç¯å²ã«ãã­ãã¯ãèš­çœ®ãã
process.setblocks.description='Â§7<level>Â§fã¯ãŒã«ãã®Â§7<spos>Â§f~Â§7<epos>Â§fã«Â§7<id>Â§fã®ãã­ãã¯ãèš­çœ®ãã'
process.setblocks.detail='{%0}ã®{%1},{%2},{%3}ïœ{%4},{%5},{%6}ã«{%7}:{%8}ãèš­çœ®ãã'
process.setblocks.form.spos=\nÂ§7<spos>Â§f æåã®äœçœ®ã,ã§åºåã£ãŠå¥åããŠãã ãã
process.setblocks.form.epos=\nÂ§7<epos>Â§f æåŸã®äœçœ®ã,ã§åºåã£ãŠå¥åããŠãã ãã
process.setblocks.form.level=\nÂ§7<level>Â§f ã¯ãŒã«ãåãå¥åããŠãã ãã
process.setblocks.form.id=\nÂ§7<id>Â§f èš­çœ®ãããã­ãã¯ã®idãå¥åããŠãã ãã

process.savedatas.name=ããŒã¿ãã»ãŒããã
process.savedatas.description=ããŒã¿ãã»ãŒããã
process.savedatas.detail=ããŒã¿ãã»ãŒããã

process.sethealth.name=äœåãå€æŽãã
process.sethealth.description=ãã¬ã€ã€ãŒã®äœåãÂ§7<health>Â§fã«ãã
process.sethealth.detail=ãã¬ã€ã€ãŒã®äœåã{%0}ã«ãã
process.sethealth.zero=Â§c[{%0}] äœåã¯1ä»¥äžã«ããŠãã ãã
process.sethealth.form.zero=Â§cäœåã¯1ä»¥äžã«ããŠãã ããÂ§f
process.sethealth.form.health=\nÂ§7<health>Â§f äœåãå¥åããŠãã ãã

process.setmaxhealth.name=æå€§äœåãå€æŽãã
process.setmaxhealth.description=ãã¬ã€ã€ãŒã®æå€§äœåãÂ§7<health>Â§fã«ãã
process.setmaxhealth.detail=ãã¬ã€ã€ãŒã®æå€§äœåã{%0}ã«ãã
process.setmaxhealth.zero=Â§c[{%0}] æå€§äœåã¯1ä»¥äžã«ããŠãã ãã

process.attack.name=ãã¡ãŒãžãäžãã
process.attack.description=ãã¬ã€ã€ãŒã«ãã¡ãŒãžãÂ§7<damage>Â§fäžãã
process.attack.detail=ãã¬ã€ã€ãŒã«{%0}ãã¡ãŒãžäžãã
process.attack.error=Â§c[{%0}] æ»æåã¯1ä»¥äžã«ããŠãã ãã
process.attack.form.error=Â§cæ»æåã¯1ä»¥äžã«ããŠãã ããÂ§f
process.attack.form.damage=\nÂ§7<damage>Â§f æ»æåãå¥åããŠãã ãã

process.kick.name=ã­ãã¯ãã
process.kick.description=ãã¬ã€ã€ãŒãÂ§7<reason>Â§fã§ã­ãã¯ãã
process.kick.detail=ãã¬ã€ã€ãŒã{%0}ã§ã­ãã¯ãã
process.kick.form.reason=\nÂ§7<reason>Â§f çç±ãå¥åããŠãã ãã

command.if.usage=/if <block | command | event | chain | import | language>
command.if.description=æ¡ä»¶ã«ãã£ãæãã€ãã³ããèµ·ããæã«äœãããã

command.language.usage=äœ¿ãæ¹: /if language <èšèªå>
command.language.notfound=èšèª {%0} ã¯èŠã€ãããŸããã{%1}ãäœ¿çšã§ããŸã

command.block.usage=Usage: /if block <edit|check|del|copy|cancel>
command.block.edit=ç·šéãããã­ãã¯ãè§Šã£ãŠãã ãã
command.block.check=ç¢ºèªãããã­ãã¯ãè§Šã£ãŠãã ãã
command.block.del=åé€ãããã­ãã¯ãè§Šã£ãŠãã ãã
command.block.copy=ã³ããŒãããã­ãã¯ãè§Šã£ãŠãã ãã
command.block.cancel=ã­ã£ã³ã»ã«ããŸãã

command.command.usage=Usage: /if command <add_empty|add|edit|check|del|cancel>
command.command.not_added=ãã®ã³ãã³ãã¯ãŸã è¿œå ãããŠããŸãã
command.command.cancel=ã­ã£ã³ã»ã«ããŸãã

command.form.usage=Usage: /if form <add | edit | del>

form.back=<ã²ãšã€åã®ç»é¢ã«æ»ã>
form.cancel=<ã­ã£ã³ã»ã«>
form.exit=<çµäº>
form.cancelled=Â§eã­ã£ã³ã»ã«ããŸããÂ§f
form.changed=Â§bå€æŽããŸããÂ§f
form.insufficient=Â§cå¿èŠäºé ãå¥åããŠãã ããÂ§f
form.selectButton=Â§7ãã¿ã³ãæŒããŠãã ãã

form.action.add=è¿œå ãã
form.action.edit=ç·šéãã
form.action.delete=åé€ãã
form.action.check=ç¢ºèªãã
form.action.copy=ã³ããŒãã

form.form.selectAction.title=/if
form.form.editIF.title=IFç·šé
form.form.editIF.if="ãã~ãç·šéãã"
form.form.editIF.match=æ¡ä»¶ã«åã£ãæãç·šéãã
form.form.editIF.else=æ¡ä»¶ã«åããªãã£ãæãç·šéãã
form.form.editIF.changeName=ååãèš­å®ãã
form.form.editIF.export=ãã¡ã€ã«åºåãã
form.form.editContents.title=IFç·šé > {%0}
form.form.editContents.add=<è¿œå ãã>
form.form.addContents.title=IFç·šé > è¿œå 
form.form.addContents.search=<æ€çŽ¢ãã>
form.form.delete.notExist=Â§cãŸã è¿œå ããŠããªãã®ã§åé€ã§ããŸããÂ§f
form.form.added=Â§bè¿œå ããŸããÂ§f
form.form.added.suspicious=Â§eè¿œå ããŸããããæ­£ããå¥åã§ããŠããªãå¯èœæ§ããããŸãÂ§f
form.form.changed=Â§bå€æŽããŸããÂ§f
form.form.changed.suspicious=Â§eå€æŽããŸããããæ­£ããå¥åã§ããŠããªãå¯èœæ§ããããŸãÂ§f
form.form.confirmDelete.title=åé€
form.form.confirmDelete.content=æ¬åœã«åé€ããŸãã?\nåé€ãããšåã«æ»ããŸãã
form.form.confirmDelete.yes=ã¯ã
form.form.confirmDelete.no=ããã
form.form.delete.success=Â§båé€ããŸããÂ§f
form.form.search.title=IFæ€çŽ¢
form.form.search.label=ååã§æ€çŽ¢ããŸã
form.form.search.input=æ€çŽ¢ããèšèãå¥åããŠãã ãã
form.form.searchResult.title=IFç·šé > è¿œå  > æ€çŽ¢
form.form.setName.title=ååèš­å®
form.form.setName.content0=IFã«ååãèš­å®ããŸã
form.form.setName.content1=ååãå¥åããŠãã ãã
form.form.setName.content2=ååãåé€ãã
form.form.setName.success=Â§bååãèš­å®ããŸããÂ§f
form.form.deleteName.success=Â§eååãåé€ããŸããÂ§f

form.block=ãã­ãã¯
form.block.action.title=ãã­ãã¯ > æäœéžæ
form.block.action.edit=ç·šéãããã­ãã¯ãè§Šã£ãŠãã ãã
form.block.action.check=ç¢ºèªãããã­ãã¯ãè§Šã£ãŠãã ãã
form.block.action.delete=åé€ãããã­ãã¯ãè§Šã£ãŠãã ãã
form.block.action.copy=ã³ããŒãããã­ãã¯ãè§Šã£ãŠãã ãã

form.command=ã³ãã³ã

form.event=ã€ãã³ã

form.formif=ãã©ãŒã 
form.formif.list=ãªã¹ã
form.formif.custom=ã«ã¹ã¿ã 
form.formif.modal=ãã©ãŒã 
form.formif.action.formList=ãã©ãŒã äžèŠ§
form.formif.exist=Â§eãã®ååã®ãã®ã¯æ¢ã«è¿œå ããŠããŸãÂ§f
form.formif.notexist=Â§eãã®ååã®ç©ã¯ãŸã è¿œå ãããŠããŸãã
form.formif.recive=åä¿¡: {%0}
form.formif.recive.input="åä¿¡: {form_data}[{%0}] <- (å¥åå€)"
form.formif.recive.slider="åä¿¡: {form_data}[{%0}] <- (éžæããæ°å€)"
form.formif.recive.dropdown="åä¿¡: {form_data}[{%0}] <- (äžçªäžã0ãšããŠéžæããå Žæã®æ°å€)"
form.formif.action.title=ãã©ãŒã  > æäœéžæ
form.formif.addformif.title=ãã©ãŒã  > è¿œå 
form.formif.addformif.content0={%0}è¿œå ããåå
form.formif.addformif.content1=ãã©ãŒã ã®ã¿ã€ãã«
form.formif.addformif.content2=ãã©ãŒã ã®çš®é¡
form.formif.selectformif.title=ãã©ãŒã  > ãã©ãŒã éžæ
form.formif.selectformif.content0={%0}ãã©ãŒã ã®ååãå¥åããŠãã ãã
form.formif.editformif.title=ãã©ãŒã  > ç·šé
form.formif.editformif.content={%0}Â§7ãã¿ã³ãæŒããŠãã ãã
form.formif.editformif.button.preview=<è¡šç€ºãç¢ºèªãã>
form.formif.editformif.button.edit=<ãã®ãã©ãŒã ã®IFãç·šéãã>
form.formif.editformif.button.title=ã¿ã€ãã«: {%0}
form.formif.editformif.modal.content=åå®¹: {%0}
form.formif.editformif.modal.button1=ãã¿ã³1: {%0}
form.formif.editformif.modal.button2=ãã¿ã³2: {%0}
form.formif.editformif.form.content=åå®¹: {%0}
form.formif.editformif.form.button=ãã¿ã³: {%0}
form.formif.editformif.form.addbutton=<ãã¿ã³ãè¿œå ãã>
form.formif.editformif.custom.content={%0}: {%1}
form.formif.editformif.custom.addparts=<ããŒããè¿œå ãã>
form.formif.selectparts.title=ãã©ãŒã  > ããŒã
form.formif.selectparts.parts.text=ãã­ã¹ã
form.formif.selectparts.parts.title=ã¿ã€ãã«
form.formif.selectparts.parts.content=åå®¹
form.formif.selectparts.parts.button=ãã¿ã³
form.formif.selectparts.parts.button1=ãã¿ã³1
form.formif.selectparts.parts.button2=ãã¿ã³2
form.formif.selectparts.parts.editif=ãã®ãã¿ã³ã«åå¿ããIFãç·šéãã
form.formif.selectparts.addbutton=ãã¿ã³ãè¿œå ãã
form.formif.selectparts.addparts=ããŒããè¿œå ãã
form.formif.selectparts.select_custom_parts=è¿œå ãããã®ãéžæããŠãã ãã
form.formif.iflist.title=ãã©ãŒã  > {%0} > éžæ
form.formif.iflist.add=<è¿œå ãã>
form.formif.deleted=åé€ããŸãã
form.formif.custom.label="æå­ãè¡šç€ºãã (label)"
form.formif.custom.label.index=æå­ãè¡šç€ºãã
form.formif.custom.input="æå­ãå¥åãã (input)"
form.formif.custom.input.index="æå­ãå¥åãã"
form.formif.custom.input.placeholder="ãã¬ãŒã¹ãã«ããŒ (äœãå¥åãããŠããªããšãã«è¡šç€ºãããèãæå­)"
form.formif.custom.input.default="ããã©ã«ã (æåããå¥åãããŠããæå­)"
form.formif.custom.toggle="ãã°ã«ãã¿ã³ (toggle)"
form.formif.custom.toggle.index="ãã°ã«ãã¿ã³"
form.formif.custom.toggle.default=åæå€
form.formif.custom.slider="ã¹ã©ã€ããŒ (slider)"
form.formif.custom.slider.index="ã¹ã©ã€ããŒ"
form.formif.custom.slider.max=æå€§å€
form.formif.custom.slider.min=æå°å€
form.formif.custom.slider.default=åæå€
form.formif.custom.slider.step=ç®çã
form.formif.custom.dropdown="ãã­ããããŠã³ (dropdown)"
form.formif.custom.dropdown.index="ãã­ããããŠã³"
form.formif.custom.dropdown.option="éžæè¢{%0} (ç©ºçœã«ãããšåé€ããŸã)"
form.formif.custom.dropdowm.addOption="--------------------\néžæè¢è¿œå  (,ã§åºåã£ãŠè€æ°å¥åã§ããŸã)"
form.formif.custom.text=ãã­ã¹ã
form.formif.formList.title=ãã©ãŒã  > äžèŠ§
form.formif.formList.button="{%0} Â§7({%1})"

form.chain=ãã§ãŒã³

form.import=ãã¡ã€ã«ã€ã³ããŒã<?php

namespace aieuo\ip\commands;

use pocketmine\command\Command;
use pocketmine\command\CommandExecutor;
use pocketmine\command\CommandSender;
use pocketmine\command\PluginCommand;

use aieuo\ip\Session;
use aieuo\ip\form\Form;
use aieuo\ip\utils\Messages;
use aieuo\ip\utils\Language;
use aieuo\ip\manager\IFManager;

class IFCommand extends PluginCommand implements CommandExecutor {

	public function __construct($owner) {
		parent::__construct('if', $owner);
		$this->setPermission('op');
		$this->setDescription(Language::get("command.if.description"));
		$this->setUsage("if <block | command | event | chain | import | language>");
		$this->setExecutor($this);
		$this->owner = $owner;
		$this->form = new Form();
	}

	public function onCommand(CommandSender $sender, Command $cmd, string $label, array $args) : bool {
		if(!$sender->isOp() or $sender->getName() === "CONSOLE") return true;
		$name = $sender->getName();

		if(!isset($args[0])){
			$form = $this->form->getSelectIfTypeForm();
			Form::sendForm($sender, $form, $this->form, "onSelectIfType");
			return true;
		}

		$session = Session::get($sender);
		switch ($args[0]) {
			case "language":
				if(!isset($args[1])) {
					$sender->sendMessage(Language::get("command.language.usage"));
					return true;
				}
				$languages = [];
		        foreach($this->owner->getResources() as $resource) {
                    $filename = $resource->getFilename();
                    if (strrchr($filename, ".") == ".ini") $languages[] = basename($filename, ".ini");
                    if ($filename === $args[1].".ini") {
		                $messages = parse_ini_file($resource->getPathname());
		            }
		        }
		        if(!isset($messages)) {
                    $available = implode(", ", $languages);
                    $sender->sendMessage(Language::get("command.language.notfound", [$args[1], $available]));
		        	return true;
		        }
		        $this->owner->language->setMessages($messages);
		        $this->owner->config->set("language", $args[1]);
		        $sender->sendMessage(Language::get("language.selected", [Language::get("language.name")]));
				break;
			case 'block':
				if(!isset($args[1])) {
	                $form = $this->form->getBlockForm()->getSelectActionForm();
	                Form::sendForm($sender, $form, $this->form->getBlockForm(), "onSelectAction");
	                break;
	            }
				switch ($args[1]) {
					case "edit":
						$sender->sendMessage(Language::get("command.block.edit"));
						break;
					case "check":
						$sender->sendMessage(Language::get("command.block.check"));
						break;
					case "del":
						$sender->sendMessage(Language::get("command.block.del"));
						break;
					case "copy":
						$sender->sendMessage(Language::get("command.block.copy"));
						break;
					case "cancel":
						$session->setValid(false);
						$sender->sendMessage(Language::get("command.block.cancel"));
						return true;
					default:
						$sender->sendMessage(Language::get("command.block.usage"));
						return true;
				}
                $session->setValid()->setIfType(IFManager::BLOCK)->setData("action", $args[1]);
				break;
			case 'command':
				if(!isset($args[1])){
	                $form = $this->form->getCommandForm()->getSelectActionForm();
	                Form::sendForm($sender, $form, $this->form->getCommandForm(), "onSelectAction");
					break;
				}
                $session->setValid()->setIfType(IFManager::COMMAND)->setData("action", $args[1]);
				$manager = $this->owner->getCommandManager();
				switch ($args[1]) {
					case "add":
					case "add_empty":
		                $form = $this->form->getCommandForm()->getAddCommandForm();
		                Form::sendForm($sender, $form, $this->form->getCommandForm(), "onAddCommand");
						break;
					case "edit":
						if(!isset($args[2])) {
			                $form = $this->form->getCommandForm()->getSelectCommandForm();
			                Form::sendForm($sender, $form, $this->form->getCommandForm(), "onSelectCommand");
			                break;
			            }
						if(!$manager->isAdded($args[2])) {
							$sender->sendMessage(Language::get("command.command.not_added"));
							$session->setValid(false);
							break;
						}
        				$session->setData("if_key", $args[2]);
						$datas = $manager->get($args[2]);
						$mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
			            $form = $this->form->getCommandForm()->getEditIfForm($mes);
			            Form::sendForm($sender, $form, $this->form->getCommandForm(), "onEditIf");
						break;
					case "check":
						if(!isset($args[2])) {
			                $form = $this->form->getCommandForm()->getSelectCommandForm();
			                Form::sendForm($sender, $form, $this->form->getCommandForm(), "onSelectCommand");
							break;
						}
						if(!$manager->isAdded($args[2])) {
							$sender->sendMessage(Language::get("command.command.not_added"));
							$session->setValid(false);
							break;
						}
						$datas = $manager->get($args[2]);
						$mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
						$sender->sendMessage($mes);
						$session->setValid(false);
						break;
					case "del":
						if(!isset($args[2])) {
			                $form = $this->form->getCommandForm()->getSelectCommandForm();
			                Form::sendForm($sender, $form, $this->form->getCommandForm(), "onSelectCommand");
							break;
						}
						if(!$manager->isAdded($args[2])) {
							$sender->sendMessage(Language::get("command.command.not_added"));
							$session->setValid(false);
							break;
						}
						$session->setData("if_key", $args[2]);
			            $form = $this->form->getConfirmDeleteForm();
			            Form::sendForm($sender, $form, $this->form, "onDeleteIf");
						break;
					case "cancel":
						$session->setValid(false);
						$sender->sendMessage(Language::get("command.command.cancel"));
						return true;
					default:
						$sender->sendMessage(Language::get("command.command.usage"));
						return true;
				}
				break;
			case 'event':
				$form = $this->form->getEventForm()->getSelectEventForm();
				Form::sendForm($sender, $form, $this->form->getEventForm(), "onSelectEvent");
				break;
			case "chain":
				if(isset($args[1])) {
					$session = Session::get($sender);
					switch ($args[1]) {
						case 'add':
			                $session->setData("action", "add");
			                $form = $this->form->getChainForm()->getAddChainIfForm();
			                Form::sendForm($sender, $form, $this->form->getChainForm(), "onAddChainIf");
							break;
						case 'edit':
                			$session->setData("action", "edit");
			                $form = $this->form->getChainForm()->getEditChainIfForm();
			                Form::sendForm($sender, $form, $this->form->getChainForm(), "onEditChainIf");
							break;
						case 'del':
                			$session->setData("action", "del");
			                $form = $this->form->getChainForm()->getEditChainIfForm();
			                Form::sendForm($sender, $form, $this->form->getChainForm(), "onEditChainIf");
							break;
						case 'list':
			                $form = $this->form->getChainForm()->getChainIfListForm();
			                Form::sendForm($sender, $form, $this->form->getChainForm(), "onChainIfList");
							break;
						default:
			                $form = $this->form->getChainForm()->getSelectActionForm();
			                Form::sendForm($sender, $form, $this->form->getChainForm(), "onselectAction");
							break;
					}
			        $session->setIfType(Session::CHAIN);
			        $session->setValid();
					return true;
				}
                $form = $this->form->getChainForm()->getSelectActionForm();
                Form::sendForm($sender, $form, $this->form->getChainForm(), "onselectAction");
				return true;
            case "form":
                $session->setValid(true)->setIfType(Session::FORM);
                if (!isset($args[1])) {
                    $form = $this->form->getFormIFForm()->getSelectActionForm();
                    Form::sendForm($sender, $form, $this->form->getFormIFForm(), "onSelectAction");
                    break;
                }
                switch ($args[1]) {
                    case "add":
                        $session->setData("action", "add");
                        $form = $this->form->getFormIFForm()->getAddIFformForm();
                        Form::sendForm($sender, $form, $this->form->getFormIFForm(), "onAddIFformForm");
                        break;
                    case "edit":
                    case "del":
                        $session->setData("action", $args[1]);
                        $form = $this->form->getFormIFForm()->getSelectIFformForm();
                        Form::sendForm($sender, $form, $this->form->getFormIFForm(), "onSelectIFformForm");
                        break;
                    default:
                        $sender->sendMessage(Language::get("command.form.usage"));
                        $session->setValid(false);
                        break;
                }
                break;
			case "import":
                $form = $this->form->getImportForm()->getImportListForm();
                Form::sendForm($sender, $form, $this->form->getImportForm(), "onImportList");
                break;
			default:
				$data = $this->form->getSelectIfTypeForm();
				Form::sendForm($sender, $data, $this->form, "onSelectIfType");
				break;
		}
		return true;
	}
}<?php

namespace aieuo\ip\conditions;

use pocketmine\item\Item;

use aieuo\ip\utils\Language;

class CanAddItem extends TypeItem {

	protected $id = self::CAN_ADD_ITEM;
	protected $name = "@condition.canadditem.name";
	protected $description = "@condition.canadditem.description";

	public function getMessage() {
		$item = $this->getItem();
		if(!($item instanceof Item)) return false;
		return Language::get("condition.canadditem.detail", [$item->getId(), $item->getDamage(), $item->getCount()]);
	}

	public function check() {
		$player = $this->getPlayer();
		$item = $this->getItem();
		if(!($item instanceof Item)) {
			$player->sendMessage(Language::get("input.invalid", [$this->getName()]));
			return self::ERROR;
		}
        if($player->getInventory()->canAddItem($item)) return self::MATCHED;
        return self::NOT_MATCHED;
	}
}<?php

namespace aieuo\ip\conditions;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Language;

class Comparison extends Condition {

    protected $id = self::COMPARISON;
    protected $name = "@condition.comparison.name";
    protected $description = "@condition.comparison.description";

    const ERROR = -1;
    const EQUAL = 0;
    const NOT_EQUAL = 1;
    const GREATER = 2;
    const GREATER_EQUAL = 3;
    const LESS = 4;
    const LESS_EQUAL = 5;
    const CONTAINS = 6;
    const NOT_CONTAINS = 7;

    public function getMessage() {
        if ($this->getValues() === false) return false;
        $value1 = $this->getValue1();
        $value2 = $this->getValue2();
        switch ($this->getOperator()) {
            case self::EQUAL:
                $mes = Language::get("condition.comparison.detail.equal", [$value1, $value2]);
                break;
            case self::NOT_EQUAL:
                $mes = Language::get("condition.comparison.detail.not_equal", [$value1, $value2]);
                break;
            case self::GREATER:
                $mes = Language::get("condition.comparison.detail.greater", [$value1, $value2]);
                break;
            case self::LESS:
                $mes = Language::get("condition.comparison.detail.less", [$value1, $value2]);
                break;
            case self::GREATER_EQUAL:
                $mes = Language::get("condition.comparison.detail.greater_equal", [$value1, $value2]);
                break;
            case self::LESS_EQUAL:
                $mes = Language::get("condition.comparison.detail.less_equal", [$value1, $value2]);
                break;
            case self::CONTAINS:
                $mes = Language::get("condition.comparison.detail.contains", [$value1, $value2]);
                break;
            case self::NOT_CONTAINS:
                $mes = Language::get("condition.comparison.detail.not_contains", [$value1, $value2]);
                break;
            default:
                return false;
        }
        return $mes;
    }

    public function getValue1() {
        return $this->getValues()[0];
    }

    public function getValue2() {
        return $this->getValues()[1];
    }

    public function getOperator() {
        return $this->getValues()[2];
    }

    public function setNumbers($value1, $value2, int $ope) {
        $this->setValues([$value1, $value2, $ope]);
    }

    public function parse(string $numbers) {
        if (!preg_match("/(.*)\[ope:([0-9])\](.*)/", $numbers, $matches)) return false;
        $operator = (int)$matches[2];
        $value1 = trim(rtrim($matches[1]));
        if (is_numeric($value1)) $value1 = (int)$value1;
        $value2 = trim(rtrim($matches[3]));
        if (is_numeric($value2)) $value2 = (int)$value2;
        return [$value1, $value2, $operator];
    }

    public function check() {
        $player = $this->getPlayer();
        if ($this->getValues() === false) {
            $player->sendMessage(Language::get("input.invalid", [$this->getName()]));
            return self::ERROR;
        }
        $value1 = $this->getValue1();
        $value2 = $this->getValue2();
        $result = self::NOT_MATCHED;
        switch ($this->getOperator()) {
            case self::EQUAL:
                if ($value1 == $value2) $result = self::MATCHED;
                break;
            case self::NOT_EQUAL:
                if ($value1 != $value2) $result = self::MATCHED;
                break;
            case self::GREATER:
                if ($value1 > $value2) $result = self::MATCHED;
                break;
            case self::LESS:
                if ($value1 < $value2) $result = self::MATCHED;
                break;
            case self::GREATER_EQUAL:
                if ($value1 >= $value2) $result = self::MATCHED;
                break;
            case self::LESS_EQUAL:
                if ($value1 <= $value2) $result = self::MATCHED;
                break;
            case self::CONTAINS:
                if (strpos($value1, $value2) !== false) $result = self::MATCHED;
                break;
            case self::NOT_CONTAINS:
                if (strpos($value1, $value2) === false) $result = self::MATCHED;
                break;
            default:
                $player->sendMessage(Language::get("input.invalid", [$this->getName()]));
                break;
        }
        return $result;
    }


    public function getEditForm(string $default = "", string $mes = "") {
        $values = $this->parse($default);
        $value1 = $default;
        $operator = self::EQUAL;
        $value2 = "";
        if ($values !== false) {
            $value1 = $values[0];
            $operator = $values[2];
            $value2 = $values[1];
        } elseif ($default !== "") {
            $mes .= Language::get("form.error");
        }
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("condition.comparison.form.value1"), Language::get("input.example", ["100"]), $value1),
                Elements::getDropdown(Language::get("condition.comparison.form.operator"), [
                    Language::get("condition.comparison.form.equal"),
                    Language::get("condition.comparison.form.not_equal"),
                    Language::get("condition.comparison.form.greater"),
                    Language::get("condition.comparison.form.less"),
                    Language::get("condition.comparison.form.greater_equal"),
                    Language::get("condition.comparison.form.less_equal"),
                    Language::get("condition.comparison.form.contains"),
                    Language::get("condition.comparison.form.not_contains"),
                ], $operator),
                Elements::getInput(Language::get("condition.comparison.form.value2"), Language::get("input.example", ["100"]), $value2),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        if ($datas[1] === "" or $datas[3] === "") {
            $status = null;
        } elseif ($this->parse($datas[1]."[ope:".$datas[2]."]".$datas[3]) === false) {
            $status = false;
        }
        $contents = $datas[1]."[ope:".$datas[2]."]".$datas[3];
        return ["status" => $status, "contents" => $contents, "delete" => $datas[4], "cancel" => $datas[5]];
    }
}<?php

namespace aieuo\ip\conditions;

use pocketmine\Player;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

use aieuo\ip\utils\Language;

class Condition implements ConditionIds {

	const MATCHED = 0;
	const NOT_MATCHED = 1;
	const NOT_FOUND = 2;
	const ERROR = -1;

	/** @var Player */
	private $player;

	/** @var array */
	private $values = [];

    /** @var int */
    protected $id;
    /** @var string */
    protected $name;
    /** @var string */
    protected $description;
    /** @var string */
    protected $detail;

	public function __construct($player = null) {
		$this->player = $player;
	}

	public static function get($id) {
		return ConditionFactory::get($id);
	}

	public function getId() {
		return $this->id;
	}

	public function getName() {
        if($this->name[0] === "@") {
            return Language::get(substr($this->name, 1));
        }
		return $this->name;
	}

	public function getDescription() {
        if($this->description[0] === "@") {
            return Language::get(substr($this->description, 1));
        }
		return $this->description;
	}

    public function getDetail() {
        if($this->detail[0] === "@") {
            return Language::get(substr($this->detail, 1));
        }
        return $this->detail;
    }

	public function parse(string $str) {
		return $str;
	}

	public function setPlayer(Player $player) : self {
		$this->player = $player;
		return $this;
	}

	public function getPlayer() : Player {
		return $this->player;
	}

	public function setValues($values) : self {
		$this->values = $values;
		return $this;
	}

	public function getValues() {
		return $this->values;
	}

	public function getEditForm(string $default = "", string $mes = "") {
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas){
    	return ["status" => true, "contents" => "", "delete" => $datas[1], "cancel" => $datas[2]];
    }

	public function check() {
		return Ifs::NOT_FOUND;
	}
}<?php

namespace aieuo\ip\conditions;

class ConditionFactory {
	private static $list = [];

	public static function init() {
		self::register(new NoCheck());
		self::register(new TakeMoney());
		self::register(new OverMoney());
		self::register(new LessMoney());
		self::register(new InHand());
		self::register(new ExistsItem());
		self::register(new RemoveItem());
		self::register(new CanAddItem());
		self::register(new IsOp());
		self::register(new IsSneaking());
		self::register(new IsFlying());
		self::register(new GameMode());
		self::register(new InArea());
		self::register(new RandomNumber());
		self::register(new Comparison());
		self::register(new ExistsVariable());
	}
	/**
	 * @param  int $id
	 * @return Condition | null
	 */
	public static function get($id) {
		if(isset(self::$list[$id])) {
			return clone self::$list[$id];
		}
		return new Condition();
	}

	public static function getAll() {
		return self::$list;
	}

	/**
	 * @param  Condition $condition
	 */
	public static function register(Condition $condition) {
		self::$list[$condition->getId()] = clone $condition;
	}
}<?php

namespace aieuo\ip\conditions;

interface ConditionIds {
    const TAKEMONEY = 0;
    const IN_HAND = 1;
    const EXISTS_ITEM = 2;
    const IS_SNEAKING = 3;
    const OVERMONEY = 4;
    const REMOVE_ITEM = 5;
    const GAMEMODE = 6;
    const NO_CHECK = 7;
    const COMPARISON = 8;
    const IS_OP = 9;
    const IS_FLYING = 10;
    const IN_AREA = 11;
    const RANDOM_NUMBER = 12;
    const EXISTS_VARIABLE = 13;
    const LESSMONEY = 14;
    const CAN_ADD_ITEM = 15;
}<?php

namespace aieuo\ip\conditions;

use pocketmine\item\Item;

use aieuo\ip\utils\Language;

class ExistsItem extends TypeItem {

    protected $id = self::EXISTS_ITEM;
    protected $name = "@condition.existsitem.name";
    protected $description = "@condition.existsitem.description";

    public function getMessage() {
        $item = $this->getItem();
        if (!($item instanceof Item)) return false;
        return Language::get("condition.existsitem.detail", [$item->getId(), $item->getDamage(), $item->getCount()]);
    }

    public function check() {
        $player = $this->getPlayer();
        $item = $this->getItem();
        if (!($item instanceof Item)) {
            $player->sendMessage(Language::get("input.invalid", [$this->getName()]));
            return self::ERROR;
        }
        if ($player->getInventory()->contains($item)) return self::MATCHED;
        return self::NOT_MATCHED;
    }
}<?php

namespace aieuo\ip\conditions;

use aieuo\ip\ifPlugin;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Language;

class ExistsVariable extends Condition {

	protected $id = self::EXISTS_VARIABLE;
    protected $name = "@condition.existsvariable.name";
	protected $description = "@condition.existsvariable.description";

	public function getMessage() {
		$name = $this->getVariableName();
		return Language::get("condition.existsvariable.detail", [$name]);
	}

	public function getVariableName() {
		return $this->getValues();
	}

	public function setVariableName(string $variable) {
		$this->setValues($variable);
	}

	public function check() {
		if(ifPlugin::getInstance()->getVariableHelper()->exists($this->getVariableName())) return self::MATCHED;
		return self::NOT_MATCHED;
	}


	public function getEditForm(string $default = "", string $mes = "") {
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("condition.existsvariable.form.name"), Language::get("input.example", ["aieuo"]), $default),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas){
    	$status = true;
    	if($datas[1] === "") $status = null;
    	return ["status" => $status, "contents" => $datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\conditions;

use pocketmine\Server;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Language;

class GameMode extends Condition {

    protected $id = self::GAMEMODE;
    protected $name = "@condition.gamemode.name";
    protected $description = "@condition.gamemode.description";

    private $gamemodes = [
        "condition.gamemode.survival",
        "condition.gamemode.creative",
        "condition.gamemode.adventure",
        "condition.gamemode.spectator"
    ];

    public function getMessage() {
        $gamemode = $this->getGamemode();
        if ($gamemode === false) return false;
        return Language::get("condition.gamemode.detail", [Language::get($this->gamemodes[$gamemode])]);
    }

    public function getGamemode() {
        return $this->getValues();
    }

    public function setGamemode(int $gamemode) {
        $this->setValues($gamemode);
    }

    public function parse(string $gamemode) {
        $intGamemode = Server::getInstance()->getGamemodeFromString($gamemode);
        if ($intGamemode === -1) return false;
        return $intGamemode;
    }

    public function check() {
        $player = $this->getPlayer();
        $gamemode = $this->getGamemode();
        if ($gamemode === false) {
            $player->sendMessage(Language::get("condition.gamemode.notfound"));
            return self::ERROR;
        }
        return $player->getGamemode() === $gamemode ? self::MATCHED : self::NOT_MATCHED;
    }


    public function getEditForm(string $default = "", string $mes = "") {
        if ($default === "") {
            $gamemode = 0;
        } elseif (($gamemode = $this->parse($default)) === false) {
            $mes .= Language::get("condition.gamemode.notfound");
            $gamemode = 0;
        }
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getDropdown(
                    Language::get("condition.gamemode.form.gamemode"),
                    array_map(function ($g) {
                        return Language::get($g);
                    }, $this->gamemodes),
                    $gamemode
                ),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        if ($datas[1] === "") {
            $status = null;
        } else {
            $gamemode = $this->parse((string)$datas[1]);
            if ($gamemode === false) $status = false;
        }
        return ["status" => $status, "contents" => (string)$datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\conditions;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Language;

class InArea extends Condition {

    protected $id = self::IN_AREA;
    protected $name = "@condition.inarea.name";
    protected $description = "@condition.inarea.description";

    public function __construct($player = null, $area = false) {
        parent::__construct($player);
        $this->setValues($area);
    }

    public function getMessage() {
        $areas = $this->getArea();
        if ($areas === false) return false;
        $message = Language::get("condition.inarean.detail1");
        $mes = [];
        foreach ($areas as $axis => $area) {
            $mes[] = Language::get("condition.inarea.detail2", [$axis, $area[0], $area[1]]);
        }
        return $message.Language::get("condition.inarean.detail3", [implode(",", $mes)]);
    }

    public function getArea() {
        return $this->getValues();
    }

    public function setArea(Array $area) {
        $this->setValues($area);
    }

    public function parse(string $areas) {
        if (!preg_match("/([xyz]\(-?[0-9]+\.?[0-9]*,-?[0-9]+\.?[0-9]*\))+/", $areas, $matches)) return false;
        array_shift($matches);
        $areas = [];
        foreach ($matches as $match) {
            if (!preg_match("/([xyz])\((-?[0-9]+\.?[0-9]*),(-?[0-9]+\.?[0-9]*)\)/", $match, $matches1)) continue;
            $min = min((float)$matches1[2], (float)$matches1[3]);
            $max = max((float)$matches1[2], (float)$matches1[3]);
            $areas[$matches1[1]] = [$min, $max];
        }
        return $areas;
    }

    public function check() {
        $player = $this->getPlayer();
        $areas = $this->getArea();
        if ($areas === false) {
            $player->sendMessage(Language::get("input.invalid", [$this->getName()]));
            return self::ERROR;
        }
        foreach ($areas as $axis => $area) {
            if ($player->$axis < $area[0] and $player->$axis > $area[1]) return self::NOT_MATCHED;
        }
        return self::MATCHED;
    }

    public function getEditForm(string $default = "", string $mes = "") {
        $areas = $this->parse($default);
        if ($areas === false) {
            $areas = ["x" => $default, "y" => "", "z" => ""];
            if ($default !== "") $mes .= Language::get("form.error");
        }

        $content = [Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes))];
        foreach (["x", "y", "z"] as $axis) {
            if (!isset($areas[$axis])) $areas[$axis] = "";
            if (is_array(($areas[$axis]))) $areas[$axis] = $areas[$axis][0].",".$areas[$axis][1];
            $content[] = Elements::getInput(
                Language::get("condition.inarea.form.area"),
                Language::get("input.example", ["0,100"]),
                $areas[$axis]
            );
        }
        $content[] = Elements::getToggle(Language::get("form.delete"));
        $content[] = Elements::getToggle(Language::get("form.cancel"));
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => $content
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        $area_str = $datas[1] !== "" ? "x(".$datas[1].")" : "";
        $area_str .= $datas[2] !== "" ? "y(".$datas[2].")" : "";
        $area_str .= $datas[3] !== "" ? "z(".$datas[3].")" : "";
        if ($datas[1] === "" and $datas[2] === "" and $datas[3] === "") {
            $status = null;
        } else {
            $areas = $this->parse($area_str);
            if ($areas == false) $status = false;
        }
        return ["status" => $status, "contents" => $area_str, "delete" => $datas[4], "cancel" => $datas[5]];
    }
}<?php

namespace aieuo\ip\conditions;

use pocketmine\item\Item;

use aieuo\ip\utils\Language;

class InHand extends TypeItem {

    protected $id = self::IN_HAND;
    protected $name = "@condition.inhand.name";
    protected $description = "@condition.inhand.description";

    public function getMessage() {
        $item = $this->getItem();
        if (!($item instanceof Item)) return false;
        return Language::get("condition.isop.detail", [$item->getId(), $item->getDamage(), $item->getCount()]);
    }

    public function check() {
        $player = $this->getPlayer();
        $item = $this->getItem();
        if (!($item instanceof Item)) {
            $player->sendMessage(Language::get("input.invalid", [$this->getName()]));
            return self::ERROR;
        }
        $hand = $player->getInventory()->getItemInHand();
        if ($hand->getId() == $item->getId()
            and $hand->getDamage() == $item->getDamage()
            and $hand->getCount() >= $item->getCount()
        ) {
            return self::MATCHED;
        }
        return self::NOT_MATCHED;
    }
}<?php

namespace aieuo\ip\conditions;

use aieuo\ip\utils\Language;

class IsFlying extends Condition {

	protected $id = self::IS_FLYING;
	protected $name = "@condition.isflying.name";
	protected $description = "@condition.isflying.description";

	public function getMessage() {
		return Language::get("condition.isflying.detail");
	}

	public function check() {
		$player = $this->getPlayer();
		return $player->isFlying() ? self::MATCHED : self::NOT_MATCHED;
	}
}<?php

namespace aieuo\ip\conditions;

use aieuo\ip\utils\Language;

class IsOp extends Condition {

	protected $id = self::IS_OP;
	protected $name = "@condition.isop.name";
	protected $description = "@condition.isop.description";

	public function getMessage() {
		return Language::get("condition.isop.detali");
	}

	public function check() {
		$player = $this->getPlayer();
		return $player->isOp() ? self::MATCHED : self::NOT_MATCHED;
	}
}<?php

namespace aieuo\ip\conditions;

use aieuo\ip\utils\Language;

class IsSneaking extends Condition {

	protected $id = self::IS_SNEAKING;
	protected $name = "@condition.issneaking.name";
	protected $description = "@condition.issneaking.description";

	public function getMessage() {
		return Language::get("condition.issneaking.detail");
	}

	public function check() {
		$player = $this->getPlayer();
		return $player->isSneaking() ? self::MATCHED : self::NOT_MATCHED;
	}
}<?php

namespace aieuo\ip\conditions;

use aieuo\ip\ifPlugin;

use aieuo\ip\utils\Language;
use pocketmine\utils\TextFormat;

class LessMoney extends TypeMoney {

    protected $id = self::LESSMONEY;
    protected $name = "@condition.lessmoney.name";
    protected $description = "@condition.lessmoney.description";

    public function getMessage() {
        return Language::get("condition.lessmoney.detail", [$this->getAmount()]);
    }

    public function check() {
        $player = $this->getPlayer();
        $economy = ifPlugin::getInstance()->getEconomy();
        if ($economy === null) {
            $player->sendMessage(TextFormat::RED.Language::get("economy.notfound"));
            return self::ERROR;
        }
        $mymoney = $economy->getMoney($player->getName());
        if ($mymoney <= $this->getAmount()) return self::MATCHED;
        return self::NOT_MATCHED;
    }
}<?php

namespace aieuo\ip\conditions;

use aieuo\ip\utils\Language;

class NoCheck extends Condition {

	protected $id = self::NO_CHECK;
	protected $name = "@condition.nocheck.name";
	protected $description = "@condition.nocheck.description";

	public function getMessage() {
		return Language::get("condition.nocheck.detail");
	}

	public function check() {
		return self::MATCHED;
	}
}<?php

namespace aieuo\ip\conditions;

use aieuo\ip\ifPlugin;

use aieuo\ip\utils\Language;
use pocketmine\utils\TextFormat;

class OverMoney extends TypeMoney {

    protected $id = self::OVERMONEY;
    protected $name = "@condition.overmoney.name";
    protected $description = "@condition.overmoney.description";

    public function getMessage() {
        return Language::get("condition.overmoney.detail", [$this->getAmount()]);
    }

    public function check() {
        $player = $this->getPlayer();
        $economy = ifPlugin::getInstance()->getEconomy();
        if ($economy === null) {
            $player->sendMessage(TextFormat::RED.Language::get("economy.notfound"));
            return self::ERROR;
        }
        $mymoney = $economy->getMoney($player->getName());
        if ($mymoney >= $this->getAmount()) return self::MATCHED;
        return self::NOT_MATCHED;
    }
}<?php

namespace aieuo\ip\conditions;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Language;

class RandomNumber extends Condition {

	protected $id = self::RANDOM_NUMBER;
    protected $name = "@condition.randomnumber.name";
    protected $description = "@condition.randomnumber.description";

	public function getMessage() {
		if($this->getValues() === false) return false;
		return Language::get("condition.randomnumber.detail", [$this->getMin(), $this->getMax(), $this->getCheck()]);
	}

	public function getMin() {
		return $this->getValues()[0];
	}

	public function getMax() {
		return $this->getValues()[1];
	}

	public function getCheck() {
		return $this->getValues()[2];
	}

	public function setNumbers(int $min, int $max, int $check) {
		$this->setValues([$min, $max, $check]);
	}

	public function parse(string $numbers) {
        if(!preg_match("/(-?[0-9]+),(-?[0-9]+),(-?[0-9]+)/", $numbers, $matches)) return false;
        $min = min((int)$matches[1], (int)$matches[2]);
        $max = max((int)$matches[1], (int)$matches[2]);
        return [$min, $max, (int)$matches[3]];
	}

	public function check() {
		$player = $this->getPlayer();
		if($this->getValues() === false) {
			$player->sendMessage(Language::get("input.invalid", [$this->getName()]));
			return self::ERROR;
		}
        $rand = mt_rand($this->getMin(), $this->getMax());
        if($rand === $this->getCheck()) return self::MATCHED;
        return self::NOT_MATCHED;
	}


	public function getEditForm(string $default = "", string $mes = "") {
		$numbers = $this->parse($default);
		$min = $default;
		$max = "";
		$check = "";
		if($numbers !== false) {
			$min = $numbers[0];
			$max = $numbers[1];
			$check = $numbers[2];
			if($check > $max or $check < $min) {
				$mes .= Language::get("condition.randomnumber.form.warning", [$check, $min, $max]);
			}
		} elseif($default !== "") {
			$mes .= Language::get("form.error");
		}
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("condition.randomnumber.form.min"), Language::get("input.example", ["1"]), $min),
                Elements::getInput(Language::get("condition.randomnumber.form.max"), Language::get("input.example", ["5"]), $max),
                Elements::getInput(Language::get("condition.randomnumber.form.check"), Language::get("input.example", ["3"]), $check),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	$num_str = $datas[1].",".$datas[2].",".$datas[3];
    	if($datas[1] === "" or $datas[2] === "" or $datas[3] === "") {
    		$status = null;
    	} else {
	    	$num = $this->parse($num_str);
	    	if($num === false) $status = false;
	    }
    	return ["status" => $status, "contents" => $num_str, "delete" => $datas[4], "cancel" => $datas[5]];
    }
}<?php

namespace aieuo\ip\conditions;

use pocketmine\item\Item;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Language;

class RemoveItem extends TypeItem {

	protected $id = self::REMOVE_ITEM;
    protected $name = "@condition.removeitem.name";
    protected $description = "@condition.removeitem.description";

	public function getMessage() {
		$item = $this->getItem();
		if(!($item instanceof Item)) return false;
		return Language::get("condition.removeitem.detail", [$item->getId(), $item->getDamage(), $item->getCount()]);
	}

	public function check() {
		$player = $this->getPlayer();
		$item = $this->getItem();
	    if(!($item instanceof Item)) {
			$player->sendMessage(Language::get("input.invalid", [$this->getName()]));
			return self::ERROR;
		}
		if($item->getCount() === 0) {
            $count = 0;
            foreach ($player->getInventory()->getContents() as $item1) {
                if($item1->getId() == $item->getId() and $item1->getDamage() == $item->getDamage()) $count += $item1->getCount();
            }
            if($count == 0) return self::NOT_MATCHED;
            $item->setCount($count);
		}
        if($player->getInventory()->contains($item)) {
            $player->getInventory()->removeItem($item);
            return self::MATCHED;
        }
        return self::NOT_MATCHED;
	}

	public function getEditForm(string $default = "", string $mes = "") {
		$item = $this->parse($default);
		$id = $default;
		$count = "";
		if($item instanceof Item) {
			$id = $item->getId().":".$item->getDamage();
			$count = $item->getCount();
			if($count === 0) $mes .= Language::get("condition.removeitem.all");
		} elseif($default !== "") {
			$mes .= Language::get("condition.item.form.invalid");
		}
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("condition.item.form.id"), Language::get("input.example", ["1:0"]), $id),
                Elements::getInput(Language::get("condition.removeitem.form.count"), Language::get("input.example", ["5"]), $count),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}
}<?php

namespace aieuo\ip\conditions;

use aieuo\ip\ifPlugin;

use aieuo\ip\utils\Language;
use pocketmine\utils\TextFormat;

class TakeMoney extends TypeMoney {

    protected $id = self::TAKEMONEY;
    protected $name = "@condition.takemoney.name";
    protected $description = "@condition.takemoney.description";

    public function getMessage() {
        return Language::get("condition.takemoney.detail", [$this->getAmount()]);
    }

    public function check() {
        $player = $this->getPlayer();
        $economy = ifPlugin::getInstance()->getEconomy();
        if ($economy === null) {
            $player->sendMessage(TextFormat::RED.Language::get("economy.notfound"));
            return self::ERROR;
        }
        $mymoney = $economy->getMoney($player->getName());
        if ($mymoney >= $this->getAmount()) {
            $economy->takeMoney($player->getName(), $this->getAmount());
            return self::MATCHED;
        }
        return self::NOT_MATCHED;
    }
}<?php

namespace aieuo\ip\conditions;

use pocketmine\item\Item;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Language;

class TypeItem extends Condition {
	public function getItem() {
		return $this->getValues();
	}

	public function setItem(Item $item) {
		$this->setValues($item);
	}

	public function parse(string $id) {
		if(!preg_match("/^\s*([0-9]+)\s*:?\s*([0-9]*)\s*:?\s*([0-9]*)\s*$/", $id, $ids)) return false;
		$item = Item::get((int)$ids[1], empty($ids[2]) ? 0 : (int)$ids[2], empty($ids[3]) ? 0 : (int)$ids[3]);
		return $item;
	}

	public function getEditForm(string $default = "", string $mes = "") {
		$item = $this->parse($default);
		$id = $default;
		$count = "";
		if($item instanceof Item) {
			$id = $item->getId().":".$item->getDamage();
			$count = $item->getCount();
			if($count === 0) $mes .= Language::get("condition.item.form.zero");
		} elseif($default !== "") {
			$mes .= Language::get("condition.item.form.invalid");
		}
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("condition.item.form.id"), Language::get("input.example", ["1:0"]), $id),
                Elements::getInput(Language::get("condition.item.form.count"), Language::get("input.example", ["5"]), $count),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
	}

    public function parseFormData(array $datas) {
    	$status = true;
    	$id = explode(":", $datas[1]);
    	if(!isset($id[1])) $id[1] = 0;
    	$ids_str = $id[0].":".$id[1].":".$datas[2];
    	if($datas[1] === "" or $datas[2] === "") {
    		$status = null;
    	} else {
	    	$ids = $this->parse($ids_str);
	    	if($ids === false) $status = false;
	    }
    	return ["status" => $status, "contents" => $ids_str, "delete" => $datas[3], "cancel" => $datas[4]];
    }
}<?php

namespace aieuo\ip\conditions;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Language;

class TypeMoney extends Condition {
    public function __construct($player = null, $amount = 0) {
        parent::__construct($player);
        $this->setValues($amount);
    }

    public function getAmount() {
        return $this->getValues();
    }

    public function setAmount(int $amount) {
        $this->setValues($amount);
    }

    public function parse(string $amount) {
        $amount = (int)mb_convert_kana($amount, "n");
        return $amount;
    }

    public function getEditForm(string $default = "", string $mes = "") {
        $money = $this->parse($default);
        if ($money <= 0) $money = $default;
        if ($money <= 0 and $default !== "") $mes .= Language::get("condition.overmoney.zero");
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)."\n"),
                Elements::getInput(Language::get("condition.overmoney.form.amount"), Language::get("input.example", ["1000"]), $money),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        if ($datas[1] === "") $status = null;
        return ["status" => $status, "contents" => $datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\economy;

class EconomyAPILoader implements EconomyLoader {

    private $plugin;

    public function __construct($plugin) {
        $this->plugin = $plugin;
    }

    public function getPlugin() {
        return $this->plugin;
    }

    public function getMoney(string $name) {
        return (int)$this->getPlugin()->mymoney($name);
    }

    public function addMoney(string $name, int $money) {
        $this->getPlugin()->addMoney($name, $money);
        return true;
    }

    public function takeMoney(string $name, int $money) {
        $this->getPlugin()->reduceMoney($name, $money);
        return true;
    }

    public function setMoney(string $name, int $money) {
        $this->getPlugin()->setMoney($name, $money);
        return true;
    }
}<?php

namespace aieuo\ip\economy;

interface EconomyLoader {
    /**
     * ææéãååŸãã
     * @param  string $name ãã¬ã€ã€ãŒã®åå
     * @return int          ææé
     */
    public function getMoney(string $name);

    /**
     * ææéãå¢ãã
     * @param string $name  ãã¬ã€ã€ãŒã®åå
     * @param int    $money å¢ããé¡
     */
    public function addMoney(string $name, int $money);

    /**
     * ææéãæžãã
     * @param  string $name  ãã¬ã€ã€ãŒã®åå
     * @param  int    $money æžããé¡
     */
    public function takeMoney(string $name, int $money);

    /**
     * ææéãèš­å®ãã
     *
     * @param string $name
     * @param integer $money
     * @return void
     */
    public function setMoney(string $name, int $money);
}<?php

namespace aieuo\ip\economy;

class MoneySystemLoader implements EconomyLoader{

    private $plugin;

    public function __construct($plugin){
        $this->plugin = $plugin;
    }

    public function getPlugin(){
        return $this->plugin;
    }

    public function getMoney(string $name){
        return (int)$this->getPlugin()->getAPI()->get($name);
    }

    public function addMoney(string $name, int $money){
        $this->getPlugin()->getAPI()->increase($name, $money);
        return true;
    }

    public function takeMoney(string $name, int $money){
        $this->getPlugin()->getAPI()->reduce($name, $money);
        return true;
    }

    public function setMoney(string $name, int $money) {
        $this->getPlugin()->getAPI()->set($name, $money);
        return true;
    }
}<?php

namespace aieuo\ip\economy;

class PocketMoneyLoader implements EconomyLoader{

    private $plugin;

    public function __construct($plugin){
        $this->plugin = $plugin;
    }

    public function getPlugin(){
        return $this->plugin;
    }

    public function getMoney(string $name){
        return (int)$this->getPlugin()->getMoney($name);
    }

    public function addMoney(string $name, int $money){
        $mymoney = $this->getMoney($name);
        $this->getPlugin()->setMoney($name, $mymoney + $money);
        return true;
    }

    public function takeMoney(string $name, int $money){
        $mymoney = $this->getMoney($name);
        $this->getPlugin()->setMoney($name, $mymoney - $money);
        return true;
    }

    public function setMoney(string $name, int $money) {
        $this->getPlugin()->setMoney($name, $money);
        return true;
    }
}<?php

namespace aieuo\ip;

use pocketmine\Server;
use pocketmine\event\Listener;
use pocketmine\event\server\DataPacketReceiveEvent;
use pocketmine\network\mcpe\protocol\ModalFormResponsePacket;
use pocketmine\network\mcpe\protocol\InteractPacket;
use pocketmine\Player;
use pocketmine\event\player\PlayerChatEvent;
use pocketmine\event\player\PlayerCommandPreprocessEvent;
use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\event\player\PlayerQuitEvent;
use pocketmine\event\player\PlayerToggleFlightEvent;
use pocketmine\event\block\BlockBreakEvent;
use pocketmine\event\block\BlockPlaceEvent;
use pocketmine\event\entity\EntityDeathEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\event\entity\EntityLevelChangeEvent;
use pocketmine\event\entity\EntityTeleportEvent;
use pocketmine\event\inventory\CraftItemEvent;

use aieuo\ip\form\Form;
use aieuo\ip\utils\Messages;
use aieuo\ip\Session;
use aieuo\ip\processes\SetSitting;

class EventListener implements Listener {
    public function __construct($owner) {
        $this->owner = $owner;
    }

    public function getOwner() {
        return $this->owner;
    }

    public function commandProcess(PlayerCommandPreprocessEvent $event) {
        $this->onEvent($event, "PlayerCommandPreprocessEvent");

        if ($event->isCancelled()) return;
        $cmd = mb_substr($event->getMessage(), 1);
        $manager = $this->getOwner()->getCommandManager();
        if ($manager->isAdded($cmd)) {
            if ($manager->isSubCommand($cmd) and !$manager->isAdded($cmd)) {
                $subcommands = implode(" | ", $manager->getSubcommands($cmd));
                $event->getPlayer()->sendMessage("Usage: /".$manager->getOriginCommand($cmd)." <".$subcommands.">");
                return;
            }
            $datas = $manager->get($cmd);
            if ($datas["permission"] == "ifplugin.customcommand.op" and !$event->getPlayer()->isOp()) return;
            $manager->executeIfMatchCondition(
                $event->getPlayer(),
                $datas["if"],
                $datas["match"],
                $datas["else"],
                [
                    "player" => $event->getPlayer(),
                    "command" => $cmd,
                    "event" => $event
                ]
            );
        }
    }

    public function chat(PlayerChatEvent $event){
        $this->onEvent($event, "PlayerChatEvent");
    }

    public function join(PlayerJoinEvent $event){
        Session::register($event->getPlayer());

        $this->onEvent($event, "PlayerJoinEvent");
    }

    public function craft(CraftItemEvent $event){
        $this->onEvent($event, "CraftItemEvent");
    }

    public function quit(PlayerQuitEvent $event){
        $this->onEvent($event, "PlayerQuitEvent");
    }

    public function toggleFlight(PlayerToggleFlightEvent $event){
        $this->onEvent($event, "PlayerToggleFlightEvent");
    }

    public function blockBreak(BlockBreakEvent $event){
        $this->onEvent($event, "BlockBreakEvent");
    }

    public function blockPlace(BlockPlaceEvent $event){
        $this->onEvent($event, "BlockPlaceEvent");
    }

    public function entityDamage(EntityDamageEvent $event){
        $this->onEvent($event, "EntityDamageEvent");
    }
    public function entityDamageByEntity(EntityDamageByEntityEvent $event){
        $this->onEvent($event, "EntityAttackEvent");
    }
    public function entityDeath(EntityDeathEvent $event){
        $this->onEvent($event, "EntityDeathEvent");

        $player = $event->getEntity();
        if ($player instanceof Player) SetSitting::leave($player);
    }

    public function entityLevelChange(EntityLevelChangeEvent $event){
        $this->onEvent($event, "EntityLevelChangeEvent");

        $player = $event->getEntity();
        if ($player instanceof Player) SetSitting::leave($player);
    }

    public function onEvent($event, $eventname){
        switch ($eventname) {
            case 'CraftItemEvent':
            case 'PlayerInteractEvent':
            case 'PlayerChatEvent':
            case 'PlayerCommandPreprocessEvent':
            case 'PlayerJoinEvent':
            case 'PlayerQuitEvent':
            case 'PlayerToggleFlightEvent':
            case 'BlockBreakEvent':
            case 'BlockPlaceEvent':
                $player = $event->getPlayer();
                break;
            case 'EntityDamageEvent':
            case 'EntityDeathEvent':
            case 'EntityLevelChangeEvent':
                $player = $event->getEntity();
                if (!($player instanceof Player)) return;
                break;
            case "EntityAttackEvent":
                $player = $event->getDamager();
                if (!($player instanceof Player)) return;
                break;
        }
        $manager = $this->getOwner()->getEventManager();
        $datas = $manager->getFromEvent($eventname);
        foreach ($datas as $key => $data) {
            $data = $manager->get($key, ["eventname" => $eventname]);
            $manager->executeIfMatchCondition(
                $player,
                $data["if"],
                $data["match"],
                $data["else"],
                [
                    "player" => $player,
                    "eventname" => $eventname,
                    "event" => $event
                ]
            );
        }
    }

    public function interact(PlayerInteractEvent $event){
        $player = $event->getPlayer();
        if (!isset($this->touch[$player->getName()])) $this->touch[$player->getName()] = 0;
        $tick = Server::getInstance()->getTick();
        if ($tick - $this->touch[$player->getName()] <= 3) {
            return;
        }
        $this->touch[$player->getName()] = $tick;
        $this->onEvent($event, "PlayerInteractEvent");

        $manager = $this->getOwner()->getBlockManager();
        $block = $event->getBlock();
        $pos = $manager->getPosition($block);
        if ($player->isOp()) {
            if (($session = Session::get($player))->isValid()) {
                $type = $session->getData("action");
                $manager = $this->getOwner()->getBlockManager();
                switch ($type) {
                    case 'edit':
                        $session->setData("if_key", $pos);
                        if ($manager->isAdded($pos)) {
                            $datas = $manager->get($pos);
                        } else {
                            $datas = $manager->repairIF([]);
                            $manager->set($pos);
                        }
                        $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
                        $form = (new Form)->getEditIfForm($mes, $datas["name"] ?? null);
                        Form::sendForm($player, $form, new Form(), "onEditIf");
                        return;
                    case 'check':
                        $pos = $manager->getPosition($block);
                        if (!$manager->isAdded($pos)) {
                            $player->sendMessage("ãã®ãã­ãã¯ã«ã¯è¿œå ãããŠããŸãã");
                            return;
                        }
                        $datas = $manager->get($pos);
                        $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
                        $player->sendMessage($mes);
                        break;
                    case 'copy':
                        $pos = $manager->getPosition($block);
                        if (!$manager->isAdded($pos)) {
                            $player->sendMessage("ãã®ãã­ãã¯ã«ã¯è¿œå ãããŠããŸãã");
                            return;
                        }
                        $session->setData("if_key", $pos);
                        $session->setData("action", "paste");
                        $player->sendMessage("è²Œãä»ãããã­ãã¯ãè§Šã£ãŠãã ãã");
                        return;
                    case 'paste':
                        $pos = $manager->getPosition($block);
                        if ($manager->isAdded($pos)) {
                            $player->sendMessage("ãã®ãã­ãã¯ã«ã¯ãã§ã«è¿œå ãããŠããŸã");
                            return;
                        }
                        $manager->set($pos, $manager->get($session->getData("if_key")));
                        $player->sendMessage("è²Œãä»ããŸãã");
                        break;
                    case 'del':
                        $pos = $manager->getPosition($block);
                        if (!$manager->isAdded($pos)) {
                            $player->sendMessage("ãã®ãã­ãã¯ã«ã¯è¿œå ãããŠããŸãã");
                            return;
                        }
                        $session->setData("if_key", $pos);
                        $form = (new Form())->getConfirmDeleteForm();
                        Form::sendForm($player, $form, new Form(), "onDeleteIf");
                        return;
                }
                $session->setValid(false);
                return;
            }
        }
        if ($manager->isAdded($pos)) {
            $datas = $manager->get($pos);
            $manager->executeIfMatchCondition(
                $player,
                $datas["if"],
                $datas["match"],
                $datas["else"],
                [
                    "player" => $player,
                    "block" => $block,
                    "event" => $event
                ]
            );
        }
    }


    public function receive(DataPacketReceiveEvent $event) {
        $pk = $event->getPacket();
        $player = $event->getPlayer();
        $name = $player->getName();
        if (!$player->isOp())return;
        if ($pk instanceof ModalFormResponsePacket) {
            $json = str_replace([",]",",,"], [",\"\"]",",\"\","], $pk->formData);
            $data = json_decode($json);
            Form::onRecive($pk->formId, $player, $data);
        } elseif ($pk instanceof InteractPacket) {
            if ($pk->action === InteractPacket::ACTION_LEAVE_VEHICLE) {
                SetSitting::leave($player);
            }
        }
    }

    public function teleport(EntityTeleportEvent $event) {
        $player = $event->getEntity();
        if ($player instanceof Player) SetSitting::leave($player);
    }
}<?php

namespace aieuo\ip\form;

use aieuo\ip\Session;
use aieuo\ip\form\Form;
use aieuo\ip\utils\Language;

class BlockForm {
    public function getSelectActionForm() {
        $data = [
            "type" => "form",
            "title" => Language::get("form.block.action.title"),
            "content" => Language::get("form.selectButton"),
            "buttons" => [
                Elements::getButton(Language::get("form.action.edit")),
                Elements::getButton(Language::get("form.action.check")),
                Elements::getButton(Language::get("form.action.delete")),
                Elements::getButton(Language::get("form.action.copy")),
                Elements::getButton(Language::get("form.cancel")),
                Elements::getButton(Language::get("form.back"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onSelectAction($player, $data) {
        if ($data === null) return;
        $session = Session::get($player);
        switch ($data) {
            case 0:
                $session->setData("action", "edit");
                $player->sendMessage(Language::get("form.block.action.edit"));
                break;
            case 1:
                $session->setData("action", "check");
                $player->sendMessage(Language::get("form.block.action.check"));
                break;
            case 2:
                $session->setData("action", "del");
                $player->sendMessage(Language::get("form.block.action.delete"));
                break;
            case 3:
                $session->setData("action", "copy");
                $player->sendMessage(Language::get("form.block.action.copy"));
                break;
            case 4:
                $session->setValid(false);
                $player->sendMessage(Language::get("form.cancelled"));
                return;
            case 5:
                $form = (new Form())->getSelectIfTypeForm();
                Form::sendForm($player, $form, new Form(), "onSelectIfType");
                return;
        }
        $session->setIfType(Session::BLOCK);
        $session->setValid();
    }
}<?php

namespace aieuo\ip\form;

use aieuo\ip\ifPlugin;

use aieuo\ip\Session;
use aieuo\ip\form\Form;
use aieuo\ip\utils\Messages;

class ChainIfForm {
    public function getSelectActionForm(){
        $data = [
            "type" => "form",
            "title" => "chain > æäœéžæ",
            "content" => "Â§7ãã¿ã³ãæŒããŠãã ãã",
            "buttons" => [
                Elements::getButton("è¿œå "),
                Elements::getButton("ç·šé"),
                Elements::getButton("åé€"),
                Elements::getButton("äžèŠ§"),
                Elements::getButton("ã­ã£ã³ã»ã«"),
                Elements::getButton("ã²ãšã€åã®ç»é¢ã«æ»ã")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onSelectAction($player, $data) {
        if($data === null) return;
        $session = Session::get($player);
        switch ($data) {
            case 0:
                $session->setData("action", "add");
                $form = $this->getAddChainIfForm();
                Form::sendForm($player, $form, $this, "onAddChainIf");
                break;
            case 1:
                $session->setData("action", "edit");
                $form = $this->getEditChainIfForm();
                Form::sendForm($player, $form, $this, "onEditChainIf");
                break;
            case 2:
                $session->setData("action", "del");
                $form = $this->getEditChainIfForm();
                Form::sendForm($player, $form, $this, "onEditChainIf");
                break;
            case 3:
                $form = $this->getChainIfListForm();
                Form::sendForm($player, $form, $this, "onChainIfList");
                break;
            case 4:
                $session->setValid(false);
                $player->sendMessage("ã­ã£ã³ã»ã«ããŸãã");
                return;
            case 5:
                $form = (new Form())->getSelectIfTypeForm();
                Form::sendForm($player, $form, new Form(), "onSelectIfType");
                return;
        }
        $session->setIfType(Session::CHAIN);
        $session->setValid();
    }

    public function getAddChainIfForm($mes = "") {
        $data = [
            "type" => "custom_form",
            "title" => "chain > è¿œå ",
            "content" => [
                Elements::getInput(($mes !== "" ? $mes."\n" : "")."é£æºæã«äœ¿ãååãå¥åããŠãã ãã", ""),
                Elements::getToggle("ã­ã£ã³ã»ã«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onAddChainIf($player, $data) {
        $session = Session::get($player);
        if($data === null) {
            $session->setValid(false, false);
            return;
        }
        if($data[1]) {
            $form = $this->getSelectActionForm();
            Form::sendForm($player, $form, $this, "onSelectAction");
            return;
        }
        if($data[0] === ""){
            $form = $this->getAddChainIfForm("Â§cå¿èŠäºé ãå¥åããŠãã ããÂ§f");
            Form::sendForm($player, $form, $this, "onAddChainIf");
            $player->sendMessage("å¿èŠäºé ãå¥åããŠãã ãã");
            return;
        }
        $manager = ifPlugin::getInstance()->getChainManager();
        if($manager->isAdded($data[0])) {
            $form = $this->getAddChainIfForm("Â§cãã®ååã¯æ¢ã«äœ¿çšãããŠããŸãÂ§f");
            Form::sendForm($player, $form, $this, "onAddChainIf");
            $player->sendMessage("ãã®ååã¯æ¢ã«äœ¿çšãããŠããŸã");
            return;
        }
        $session->setData("if_key", $data[0]);
        $datas = $manager->repairIF([]);
        $manager->set($data[0], $datas);
        $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
        $form = (new Form)->getEditIfForm($mes, $datas["name"] ?? null);
        Form::sendForm($player, $form, new Form(), "onEditIf");
    }

    public function getEditChainIfForm($mes = "") {
        $data = [
            "type" => "custom_form",
            "title" => "chain > ç·šé",
            "content" => [
                Elements::getInput(($mes !== "" ? $mes."\n" : "")."ç·šéããååãå¥åããŠãã ãã", ""),
                Elements::getToggle("ã­ã£ã³ã»ã«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onEditChainIf($player, $data) {
        $session = Session::get($player);
        if($data === null) {
            $session->setValid(false, false);
            return;
        }
        if($data[1]) {
            $form = $this->getSelectActionForm();
            Form::sendForm($player, $form, $this, "onSelectAction");
            return;
        }
        if($data[0] === ""){
            $form = $this->getAddChainIfForm("Â§cå¿èŠäºé ãå¥åããŠãã ããÂ§f");
            Form::sendForm($player, $form, $this, "onAddChainIf");
            $player->sendMessage("å¿èŠäºé ãå¥åããŠãã ãã");
            return;
        }
        $manager = ifPlugin::getInstance()->getChainManager();
        if(!$manager->isAdded($data[0])) {
            $form = $this->getAddChainIfForm("Â§cãã®ååã®ç©ã¯å­åšããŸããÂ§f");
            Form::sendForm($player, $form, $this, "onAddChainIf");
            $player->sendMessage("ãã®ååã®ç©ã¯å­åšããŸãã");
            return;
        }
        $session->setData("if_key", $data[0]);
        $action = $session->getData("action");
        if($action === "edit") {
            $datas = $manager->repairIF([]);
            $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
            $form = (new Form)->getEditIfForm($mes, $datas["name"] ?? null);
            Form::sendForm($player, $form, new Form(), "onEditIf");
        } elseif($action === "del") {
            $form = (new Form())->getConfirmDeleteForm();
            Form::sendForm($player, $form, new Form(), "onDeleteIf");
        }
    }

    public function getChainIfListForm() {
        $datas = ifPlugin::getInstance()->getChainManager()->getAll();
        $buttons = [Elements::getButton("<ã²ãšã€åã®ããŒãžã«æ»ã>")];
        foreach ($datas as $name => $data) {
            $buttons[] = Elements::getButton($name);
        }
        $data = [
            "type" => "form",
            "title" => "ç·šé",
            "content" => "Â§7ãã¿ã³ãæŒããŠãã ãã",
            "buttons" => $buttons
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onChainIfList($player, $data) {
        $session = Session::get($player);
        if($data === null) {
            $session->setValid(false, false);
            return;
        }
        if($data === 0) {
            $form = $this->getSelectActionForm();
            Form::sendForm($player, $form, $this, "onSelectAction");
            return;
        }
        $manager = ifPlugin::getInstance()->getChainManager();
        $ifs = array_slice($manager->getAll(), $data-1, 1, true);
        $key = key($ifs);
        $datas = current($ifs);
        $session->setData("if_key", $key);
        $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
        $form = (new Form)->getEditIfForm($mes, $datas["name"] ?? null);
        Form::sendForm($player, $form, new Form(), "onEditIf");
    }
}<?php

namespace aieuo\ip\form;

use aieuo\ip\ifPlugin;
use aieuo\ip\Session;
use aieuo\ip\utils\Messages;
use aieuo\ip\form\Form;

class CommandForm {
    public function getSelectActionForm() {
        $data = [
            "type" => "form",
            "title" => "command > æäœéžæ",
            "content" => "Â§7ãã¿ã³ãæŒããŠãã ãã",
            "buttons" => [
                Elements::getButton("è¿œå ãã"),
                Elements::getButton("ã³ãã³ãã ãè¿œå ãã"),
                Elements::getButton("ç·šéãã"),
                Elements::getButton("åé€ãã"),
                Elements::getButton("è¿œå ããã³ãã³ãäžèŠ§"),
                Elements::getButton("ã­ã£ã³ã»ã«ãã"),
                Elements::getButton("ã²ãšã€åã®ç»é¢ã«æ»ã")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onSelectAction($player, $data) {
        if($data === null) return;
        $session = Session::get($player);
        switch ($data) {
            case 0:
                $session->setData("action", "add");
                break;
            case 1:
                $session->setData("action", "add_empty");
                break;
            case 2:
                $session->setData("action", "edit");
                break;
            case 3:
                $session->setData("action", "del");
                break;
            case 4:
                $form = $this->getCommandListForm();
                Form::sendForm($player, $form, $this, "onCommandList");
                return;
            case 5:
                $session->setValid(false);
                $player->sendMessage("ã­ã£ã³ã»ã«ããŸãã");
                return;
            case 6:
                $form = (new Form())->getSelectIfTypeForm();
                Form::sendForm($player, $form, new Form(), "onSelectIfType");
                return;
        }
        switch ($data) {
            case 0:
            case 1:
                $form = $this->getAddCommandForm();
                Form::sendForm($player, $form, $this, "onAddCommand");
                break;
            case 2:
            case 3:
            case 4:
                $form = $this->getSelectCommandForm();
                Form::sendForm($player, $form, $this, "onSelectCommand");
                break;
        }
        $session->setIfType(Session::COMMAND);
        $session->setValid();
    }


    public function getAddCommandForm($mes = "") {
        $data = [
            "type" => "custom_form",
            "title" => "command > ã³ãã³ãè¿œå ",
            "content" => [
                Elements::getInput(($mes !== "" ? $mes."\n" : "")."è¿œå ããã³ãã³ãã®åå", "æåã®/ãå€ããŠ"),
                Elements::getInput("ã³ãã³ãã®èª¬æ"),
                Elements::getDropdown("æš©é", ["opã ã", "åšå¡äœ¿ãã"], 1),
                Elements::getToggle("ã­ã£ã³ã»ã«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onAddCommand($player, $data) {
        $session = Session::get($player);
        if($data === null) {
            $session->setValid(false, false);
            return;
        }
        $manager = ifPlugin::getInstance()->getCommandManager();
        if($data[3]) {
            $form = $this->getSelectActionForm();
            Form::sendForm($player, $form, $this, "onSelectAction");
            return;
        }
        if($data[0] === ""){
            $form = $this->getAddCommandForm("Â§cå¿èŠäºé ãå¥åããŠãã ããÂ§f");
            Form::sendForm($player, $form, $this, "onAddCommand");
            $player->sendMessage("å¿èŠäºé ãå¥åããŠãã ãã");
            return;
        }
        if($manager->exists($data[0])){
            $form = $this->getAddCommandForm("Â§cãã®ã³ãã³ãã¯æ¢ã«äœ¿çšãããŠããŸãÂ§f");
            Form::sendForm($player, $form, $this, "onAddCommand");
            $player->sendMessage("Â§cãã®ã³ãã³ãã¯æ¢ã«äœ¿çšãããŠããŸã");
            return;
        }
        if($manager->isAdded($data[0])){
            $form = $this->getAddCommandForm("Â§eãã®ã³ãã³ãã¯æ¢ã«è¿œå ããŠããŸãÂ§f");
            Form::sendForm($player, $form, $this, "onAddCommand");
            $player->sendMessage("Â§eãã®ã³ãã³ãã¯æ¢ã«è¿œå ããŠããŸã");
            return;
        }
        if($data[1] === "") $data[1] = "ifPluginã§è¿œå ããã³ãã³ãã§ã";
        $manager->set($data[0], [], ["perm" => $data[2] == 0 ? "ifplugin.customcommand.op" : "ifplugin.customcommand.true", "desc" => $data[1], ]);
        $manager->register($data[0], $data[2] == 0 ? "ifplugin.customcommand.op" : "ifplugin.customcommand.true", $data[1]);
        if($session->getData("action") == "add_empty"){
            $player->sendMessage("è¿œå ããŸãã");
            $session->setValid(false);
            return;
        }
        $session->setData("if_key", $data[0]);
        $session->setData("description", $data[1]);
        $session->setData("permission", $data[2] == 0 ? "ifplugin.customcommand.op" : "ifplugin.customcommand.true");
        $datas = $manager->repairIF([]);
        $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
        $form = (new Form)->getEditIfForm($mes, $datas["name"] ?? null);
        Form::sendForm($player, $form, new Form(), "onEditIf");
    }


    public function getSelectCommandForm($mes = "") {
        $data = [
            "type" => "custom_form",
            "title" => "command > ã³ãã³ãéžæ",
            "content" => [
                Elements::getInput(($mes !== "" ? $mes."\n" : "")."ã³ãã³ãã®åå", "æåã®/ãå€ããŠ"),
                Elements::getToggle("ã­ã£ã³ã»ã«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onSelectCommand($player, $data) {
        $session = Session::get($player);
        if($data === null) {
            $session->setValid(false, false);
            return;
        }
        if($data[1]) {
            $form = $this->getSelectActionForm();
            Form::sendForm($player, $form, $this, "onSelectAction");
            return;
        }
        if($data[0] === ""){
            $form = $this->getSelectCommandForm("Â§cå¿èŠäºé ãå¥åããŠãã ããÂ§f");
            Form::sendForm($player, $form, $this, "onSelectCommand");
            $player->sendMessage("å¿èŠäºé ãå¥åããŠãã ãã");
            return;
        }
        $manager = ifPlugin::getInstance()->getCommandManager();
        if(!$manager->isAdded($data[0])){
            $form = $this->getSelectCommandForm("Â§cãã®ã³ãã³ãã¯ãŸã è¿œå ãããŠããŸããÂ§f");
            Form::sendForm($player, $form, $this, "onSelectCommand");
            $player->sendMessage("ãã®ã³ãã³ãã¯ãŸã è¿œå ãããŠããŸãã");
            return;
        }

        $session->setData("if_key", $data[0]);
        $action = $session->getData("action");
        if($action == "edit"){
            $datas = $manager->get($data[0]);
            $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
            $form = (new Form)->getEditIfForm($mes, $datas["name"] ?? null);
            Form::sendForm($player, $form, new Form(), "onEditIf");
        }elseif($action == "del"){
            $form = (new Form())->getConfirmDeleteForm();
            Form::sendForm($player, $form, new Form(), "onDeleteIf");
        }
    }

    public function getCommandListForm() {
        $manager = ifPlugin::getInstance()->getCommandManager();
        $commands = $manager->getAll();
        $buttons = [Elements::getButton("<1ã€åã®ããŒãžã«æ»ã>")];
        foreach ($commands as $command => $value) {
            $buttons[] = Elements::getButton($command);
        }
        $data = [
            "type" => "form",
            "title" => "command > æäœéžæ",
            "content" => "Â§7ãã¿ã³ãæŒããŠãã ãã",
            "buttons" => $buttons
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onCommandList($player, $data) {
        $session = Session::get($player);
        if($data === null) {
            $session->setValid(false, false);
            return;
        }
        if($data === 0) {
            $form = $this->getSelectActionForm();
            Form::sendForm($player, $form, $this, "onSelectAction");
            return;
        }
        $manager = ifPlugin::getInstance()->getCommandManager();
        $command = key(array_slice($manager->getAll(), $data - 1, 1, true));
        $session->setData("if_key", $command);
        $datas = $manager->get($command);
        $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
        $form = (new Form)->getEditIfForm($mes, $datas["name"] ?? null);
        Form::sendForm($player, $form, new Form(), "onEditIf");
    }
}<?php

namespace aieuo\ip\form;

class Elements {
    public static function getLabel($text){
        return [
            "type" => "label",
            "text" => (string)$text
        ];
    }

    public static function getInput($text, $placeholder = "", $default = ""){
        return [
            "type" => "input",
            "text" => (string)$text,
            "default" => (string)$default,
            "placeholder" => (string)$placeholder
        ];
    }

    public static function getToggle($text, $default = false){
        return [
            "type" => "toggle",
            "text" => (string)$text,
            "default" => $default,
        ];
    }

    public static function getDropdown($text, $options = [], $default = 0){
    	return [
            "type" => "dropdown",
            "text" => (string)$text,
            "options" => $options,
            "default" => $default
        ];
    }

    public static function getSlider($text, $min = 0, $max = 0, $default = 0, $step = 1) {
        return [
            "type" => "slider",
            "text" => (string)$text,
            "min" => (int)$min,
            "max" => (int)$max,
            "default" => (int)$default,
            "step" => (int)$step
        ];
    }

    public static function getButton($text){
    	return [
    		"text" => (string)$text
    	];
    }
}<?php

namespace aieuo\ip\form;

use aieuo\ip\ifPlugin;
use aieuo\ip\Session;
use aieuo\ip\utils\Messages;
use aieuo\ip\form\Form;

class EventForm {

	private $events = [
        "PlayerChatEvent" => "ãã¬ã€ã€ãŒããã£ãããããšã",
        "PlayerCommandPreprocessEvent" => "ãã¬ã€ã€ãŒãã³ãã³ããå®è¡ãããšã",
        "PlayerInteractEvent" => "ãã¬ã€ã€ãŒããã­ãã¯ãè§Šã£ããšã",
        "PlayerJoinEvent" => "ãã¬ã€ã€ãŒããµãŒããŒã«åå ãããšã",
        "PlayerQuitEvent" => "ãã¬ã€ã€ãŒããµãŒããŒããéå®€ãããšã",
        "BlockBreakEvent" => "ãã¬ã€ã€ãŒããã­ãã¯ãå£ãããšã",
        "BlockPlaceEvent" => "ãã¬ã€ã€ãŒããã­ãã¯ãçœ®ãããšã",
        "EntityDamageEvent" => "ãã¬ã€ã€ãŒããã¡ãŒãžãåãããšã",
        "EntityAttackEvent" => "ãã¬ã€ã€ãŒãæ»æãããšã",
        "PlayerToggleFlightEvent" => "ãã¬ã€ã€ãŒããã©ã€ç¶æãåãæ¿ãããšã",
        "PlayerDeathEvent" => "ãã¬ã€ã€ãŒãæ­»äº¡ãããšã",
        "EntityLevelChangeEvent" => "ãã¬ã€ã€ãŒãã¯ãŒã«ããç§»åãããšã",
        "CraftItemEvent" => "ãã¬ã€ã€ãŒãã¯ã©ãããããšã",
    ];

    public function getEvents() {
    	return $this->events;
    }

    public function getSelectEventForm(){
    	$buttons = [Elements::getButton("1ã€åã®ããŒãžã«æ»ã")];
    	foreach ($this->getEvents() as $key => $event) {
    		$buttons[] = Elements::getButton($event);
    	}
        $data = [
            "type" => "form",
            "title" => "event > ã€ãã³ãéžæ",
            "content" => "Â§7ãã¿ã³ãæŒããŠãã ãã",
            "buttons" => $buttons
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onSelectEvent($player, $data) {
        $session = Session::get($player);
        if($data === null) {
            $session->setValid(false, false);
            return;
        }
        if($data === 0) {
            $form = (new Form())->getSelectIfTypeForm();
            Form::sendForm($player, $form, new Form(), "onSelectIfType");
            return;
        }
        $eventname = key(array_slice($this->getEvents(), $data-1, 1, true));
        $session->setData("eventname", $eventname);
        $form = $this->getIfListForm($eventname);
        Form::sendForm($player, $form, $this, "onSelectIf");
        $session->setIfType(Session::EVENT);
        $session->setValid();
    }

    public function getIfListForm($event) {
    	$manager = ifPlugin::getInstance()->getEventManager();
    	$datas = $manager->getFromEvent($event);
    	$buttons = [Elements::getButton("<1ã€åã®ããŒãžã«æ»ã>"), Elements::getButton("<è¿œå ãã>")];
    	foreach ($datas as $n => $data) {
    		$buttons[] = Elements::getButton(empty($data["name"]) ? $n : $data["name"]);
    	}
        $data = [
            "type" => "form",
            "title" => "event > $event > éžæ",
            "content" => "Â§7ãã¿ã³ãæŒããŠãã ãã",
            "buttons" => $buttons
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onSelectIf($player, $data) {
        $session = Session::get($player);
        if($data === null) {
            $session->setValid(false, false);
            return;
        }
        if($data === 0) {
			$form = $this->getSelectEventForm();
			Form::sendForm($player, $form, $this, "onSelectEvent");
			return;
        }
        $manager = ifPlugin::getInstance()->getEventManager();
        $eventname = $session->getData("eventname");
        if($data === 1) {
            $key = $manager->addEmpty($eventname);
        	$session->setData("if_key", $key);
	        $datas = $manager->repairIF([]);
	        $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
            $form = (new Form)->getEditIfForm($mes, $datas["name"] ?? null);
	        Form::sendForm($player, $form, new Form(), "onEditIf");
        	return;
        }
        $session->setData("if_key", $data - 2);
        $datas = $manager->get($data - 2, ["eventname" => $eventname]);
        $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
        $form = (new Form)->getEditIfForm($mes, $datas["name"] ?? null);
        Form::sendForm($player, $form, new Form(), "onEditIf");
    }
}<?php

namespace aieuo\ip\form;

use aieuo\ip\ifPlugin;
use aieuo\ip\Session;
use aieuo\ip\utils\Messages;

class ExportForm {
    public function getExportForm($mes = ""){
        $data = [
            "type" => "custom_form",
            "title" => "å±æçšãã¡ã€ã«äœæ",
            "content" => [
                Elements::getInput(($mes === "" ? "" : $mes."\n")."ã¿ã€ãã«"),
                Elements::getInput("äœæè"),
                Elements::getInput("èª¬æ"),
                Elements::getToggle("ã­ã£ã³ã»ã«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onExport($player, $data) {
        $session = Session::get($player);
        if($data === null) {
            $session->setValid(false, false);
            return;
        }
        $type = $session->getIfType();
        $manager = ifPlugin::getInstance()->getManagerBySession($session);
        $options = ifPlugin::getInstance()->getOptionsBySession($session);
        $key = $session->getData("if_key");
        $datas = $manager->get($key, $options);
        if($data[3]) {
            $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
            $form = (new Form())->getEditIfForm($mes, $datas["name"] ?? null);
            Form::sendForm($player, $form, new Form(), "onEditIf");
        	return;
        }
        if($data[0] == "" or $data[1] == "" or $data[2] == "") {
            $form = $this->getExportForm("Â§cå¿èŠäºé ãèšå¥ããŠãã ããÂ§f");
            Form::sendForm($player, $form, $this, "onExport");
            $player->sendMessage("å¿èŠäºé ãå¥åããŠãã ãã");
            return;
        }
        $datas["type"] = $type;
        $datas["options"] = $options;
        $export = [
        	"name" => $data[0],
        	"author" => $data[1],
        	"details" => $data[2],
            "plugin_version" => ifPlugin::VERSION,
        	"ifs" => [
        		$key => $datas
        	]
        ];
        $filename = $data[0]."_".$data[1]."_".$type."_".$key.".json";
        $path = ifPlugin::getInstance()->getDataFolder()."exports/".$filename;
        file_put_contents($path, json_encode($export, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
        $player->sendMessage($filename."ãšããŠä¿å­ããŸãã");
        $session->setValid(false);
    }
}<?php

namespace aieuo\ip\form;

use pocketmine\network\mcpe\protocol\ModalFormRequestPacket;

use aieuo\ip\ifPlugin;
use aieuo\ip\Session;
use aieuo\ip\utils\Messages;

use aieuo\ip\conditions\Condition;
use aieuo\ip\conditions\ConditionFactory;
use aieuo\ip\processes\Process;
use aieuo\ip\processes\ProcessFactory;
use aieuo\ip\utils\Language;

class Form {

    private static $forms = [];

    public static function sendForm($player, $form, $class, $func) {
        while (true) {
            $id = mt_rand(0, 999999999);
            if (!isset(self::$forms[$id])) break;
        }
        self::$forms[$id] = [$class, $func];
        $pk = new ModalFormRequestPacket();
        $pk->formId = $id;
        $pk->formData = $form;
        $player->dataPacket($pk);
    }

    public static function onRecive($id, $player, $datas) {
        if (isset(self::$forms[$id])) {
            call_user_func_array(self::$forms[$id], [$player, $datas]);
            unset(self::$forms[$id]);
        }
    }

//////////////////////////////////////////////////////////////
    public static function encodeJson($data) {
        $json = json_encode($data, JSON_PRETTY_PRINT | JSON_BIGINT_AS_STRING | JSON_UNESCAPED_UNICODE);
        return $json;
    }

//////////////////////////////////////////////////////////////
    public function getBlockForm() {
        return new BlockForm();
    }

    public function getCommandForm() {
        return new CommandForm();
    }

    public function getEventForm() {
        return new EventForm();
    }

    public function getChainForm() {
        return new ChainIfForm();
    }

    public function getFormIFForm() {
        return new FormIFForm();
    }

    public function getExportForm() {
        return new ExportForm();
    }

    public function getImportForm() {
        return new ImportForm();
    }

    public function getSelectIfTypeForm() {
        $data = [
            "type" => "form",
            "title" => Language::get("form.form.selectAction.title"),
            "content" => Language::get("form.selectButton"),
            "buttons" => [
                Elements::getButton(Language::get("form.block")),
                Elements::getButton(Language::get("form.command")),
                Elements::getButton(Language::get("form.event")),
                Elements::getButton(Language::get("form.formif")),
                Elements::getButton(Language::get("form.chain")),
                Elements::getButton(Language::get("form.import")),
                Elements::getButton(Language::get("form.exit"))
            ]
        ];
        $json = self::encodeJson($data);
        return $json;
    }

    public function onSelectIfType($player, $data) {
        if ($data === null) return;
        $session = Session::get($player);
        switch ($data) {
            case 0:
                $session->setIfType(Session::BLOCK);
                $form = $this->getBlockForm()->getSelectActionForm();
                Form::sendForm($player, $form, $this->getBlockForm(), "onSelectAction");
                break;
            case 1:
                $session->setIfType(Session::COMMAND);
                $form = $this->getCommandForm()->getSelectActionForm();
                Form::sendForm($player, $form, $this->getCommandForm(), "onSelectAction");
                break;
            case 2:
                $session->setIfType(Session::EVENT);
                $form = $this->getEventForm()->getSelectEventForm();
                Form::sendForm($player, $form, $this->getEventForm(), "onSelectEvent");
                break;
            case 3:
                $session->setIfType(Session::FORM);
                $form = $this->getFormIFForm()->getSelectActionForm();
                Form::sendForm($player, $form, $this->getFormIFForm(), "onSelectAction");
                break;
            case 4:
                $session->setIfType(Session::CHAIN);
                $form = $this->getChainForm()->getSelectActionForm();
                Form::sendForm($player, $form, $this->getChainForm(), "onSelectAction");
                break;
            case 5:
                $form = $this->getImportForm()->getImportListForm();
                Form::sendForm($player, $form, $this->getImportForm(), "onImportList");
                break;
            case 6:
                $session->setValid(false);
                break;
        }
    }

    public function getEditIfForm($mes, $name = null) {
        $data = [
            "type" => "form",
            "title" => empty($name) ? Language::get("form.form.editIF.title") : $name,
            "content" => $mes,
            "buttons" => [
                Elements::getButton(Language::get("form.form.editIF.if")),
                Elements::getButton(Language::get("form.form.editIF.match")),
                Elements::getButton(Language::get("form.form.editIF.else")),
                Elements::getButton(Language::get("form.action.delete")),
                Elements::getButton(Language::get("form.form.editIF.changeName")),
                Elements::getButton(Language::get("form.form.editIF.export")),
                Elements::getButton(Language::get("form.exit"))
            ]
        ];
        $data = self::encodeJson($data);
        return $data;
    }

    public function onEditIf($player, $data) {
        $session = Session::get($player);
        if ($data === null) {
            $session->setValid(false, false);
            return;
        }
        $manager = ifPlugin::getInstance()->getManagerBySession($session);
        $options = ifPlugin::getInstance()->getOptionsBySession($session);
        $key = $session->getData("if_key");
        $datas = $manager->get($key, $options);
        if ($data == 0) {
            $form = $this->getEditContentsForm($datas["if"], "", "if");
            $session->setData("type", "if");
        } elseif ($data == 1) {
            $form = $this->getEditContentsForm($datas["match"], "", "match");
            $session->setData("type", "match");
        } elseif ($data == 2) {
            $form = $this->getEditContentsForm($datas["else"], "", "else");
            $session->setData("type", "else");
        } elseif ($data == 3) {
            $form = $this->getConfirmDeleteForm();
            Form::sendForm($player, $form, $this, "onDeleteIf");
            return;
        } elseif ($data == 4) {
            $form = $this->getChangeNameForm(isset($datas["name"]) ? $datas["name"] : "");
            Form::sendForm($player, $form, $this, "onChangeName");
            return;
        } elseif ($data == 5) {
            $form = $this->getExportForm()->getExportForm();
            Form::sendForm($player, $form, $this->getExportForm(), "onExport");
            return;
        } else {
            $session->setValid(false);
            return;
        }
        Form::sendForm($player, $form, $this, "onEditIfContents");
    }

    public function getEditContentsForm($datas, $mes = "", $type = "") {
        $data = [
            "type" => "form",
            "title" => Language::get("form.form.editContents.title", [Language::get("form.form.editIF.".$type)]),
            "content" => ($mes === "" ? "" : $mes."\n").Language::get("form.selectButton"),
            "buttons" => []
        ];
        $data["buttons"] = [Elements::getButton(Language::get("form.back")), Elements::getButton(Language::get("form.form.editContents.add"))];
        foreach ($datas as $key => $value) {
            if ($value["id"] < 100) {
                $content = Condition::get($value["id"]);
            } else {
                $content = Process::get($value["id"]);
            }
            $content->setValues($content->parse($value["content"]));
            $message = $content->getMessage();
            $data["buttons"][] = Elements::getButton($message === false ? $content->getDescription() : $message);
        }
        $data = self::encodeJson($data);
        return $data;
    }

    public function onEditIfContents($player, $data) {
        $session = Session::get($player);
        if ($data === null) {
            $session->setValid(false, false);
            return;
        }
        $type = $session->getIfType();
        $manager = ifPlugin::getInstance()->getManagerBySession($session);
        $options = ifPlugin::getInstance()->getOptionsBySession($session);
        $key = $session->getData("if_key");
        $datas = $manager->get($key, $options);
        if ($data == 0) {
            // ã²ãšã€åã®formã«æ»ã
            $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
            $form = $this->getEditIfForm($mes, $datas["name"] ?? null);
            Form::sendForm($player, $form, $this, "onEditIf");
            return;
        }
        if ($data == 1) {
            // æ°ããè¿œå ãã
            $form = $this->getAddContentsForm($session->getData("type"));
            Form::sendForm($player, $form, $this, "onAddContent");
            return;
        }

        // è¿œå ãããŠãããã®ãéžæãã
        $ifData = $datas[$session->getData("type")][$data - 2];
        if ($session->getData("type") == "if") {
            $datas = Condition::get($ifData["id"]);
        } else {
            $datas = Process::get($ifData["id"]);
        }
        $session->setData("contents", $datas);
        $session->setData("num", $data - 2);
        $form = $datas->getEditForm((string)$ifData["content"]);
        Form::sendForm($player, $form, $this, "onUpdateContent");
    }

    public function getAddContentsForm($type, $mes = "") {
        if ($type == "if") {
            $datas = ConditionFactory::getAll();
        } else {
            $datas = ProcessFactory::getAll();
        }
        $buttons[] = Elements::getButton(Language::get("form.back"));
        $buttons[] = Elements::getButton(Language::get("form.form.addContents.search"));
        foreach ($datas as $data) {
            $buttons[] = Elements::getButton($data->getName());
        }
        $data = [
            "type" => "form",
            "title" => Language::get("form.form.addContents.title"),
            "content" => ($mes === "" ? "" : $mes."\n").Language::get("form.selectButton"),
            "buttons" => $buttons
        ];
        $json = self::encodeJson($data);
        return $json;
    }

    public function onAddContent($player, $data) {
        $session = Session::get($player);
        if ($data === null) {
            $session->setValid(false, false);
            return;
        }
        $type = $session->getIfType();
        $manager = ifPlugin::getInstance()->getManagerBySession($session);
        $options = ifPlugin::getInstance()->getOptionsBySession($session);
        if ($data == 0) {
            $key = $session->getData("if_key");
            $datas = $manager->get($key, $options);
            $form = $this->getEditContentsForm($datas[$session->getData("type")], "", $session->getData("type"));
            Form::sendForm($player, $form, $this, "onEditIfContents");
            return;
        }
        if ($data == 1) {
            $form = $this->getSearchForm();
            Form::sendForm($player, $form, $this, "onSearch");
            return;
        }
        $data -= 2;
        if ($session->getData("type") == "if") {
            $all = ConditionFactory::getAll();
            $datas = Condition::get(current(array_slice($all, $data, 1, true))->getId());
        } else {
            $all = ProcessFactory::getAll();
            $datas = Process::get(current(array_slice($all, $data, 1, true))->getId());
        }
        $session->setData("contents", $datas);
        $form = $datas->getEditForm();
        Form::sendForm($player, $form, $this, "onEdit");
    }

    public function onEdit($player, $data) {
        $session = Session::get($player);
        if ($data === null) {
            $session->setValid(false, false);
            return;
        }
        $manager = ifPlugin::getInstance()->getManagerBySession($session);
        $options = ifPlugin::getInstance()->getOptionsBySession($session);
        $content = $session->getData("contents");
        $datas = $content->parseFormData($data);
        if ($datas["cancel"]) {
            $form = $this->getAddContentsForm($session->getData("type"));
            Form::sendForm($player, $form, $this, "onAddContent");
            return;
        }
        if ($datas["delete"]) {
            $player->sendMessage(Language::get("form.form.delete.notExist"));
            $form = $this->getAddContentsForm($session->getData("type"), Language::get("form.form.delete.notExist"));
            Form::sendForm($player, $form, $this, "onAddContent");
            return;
        }
        if ($datas["status"] === null) {
            $form = $content->getEditForm($datas["contents"], Language::get("form.insufficient"));
            Form::sendForm($player, $form, $this, "onEdit");
            return;
        }
        $mes = Language::get("form.form.added");
        if ($datas["status"] === false) $mes = Language::get("form.form.added.suspicious");
        $key = $session->getData("if_key");
        $manager->add($key, $session->getData("type"), $content->getId(), $datas["contents"], $options);
        $contents = $manager->get($key, $options);
        $form = $this->getEditContentsForm($contents[$session->getData("type")], $mes, $session->getData("type"));
        Form::sendForm($player, $form, $this, "onEditIfContents");
        $player->sendMessage($mes);
    }

    public function onUpdateContent($player, $data) {
        $session = Session::get($player);
        if ($data === null) {
            $session->setValid(false, false);
            return;
        }
        $type = $session->getIfType();
        $manager = ifPlugin::getInstance()->getManagerBySession($session);
        $options = ifPlugin::getInstance()->getOptionsBySession($session);
        $content = $session->getData("contents");
        $datas = $content->parseFormData($data);
        if ($datas["cancel"]) {
            $key = $session->getData("if_key");
            $form = $this->getEditContentsForm($manager->get($key, $options)[$session->getData("type")], "", $session->getData("type"));
            Form::sendForm($player, $form, $this, "onEditIfContents");
            return;
        }
        if ($datas["delete"]) {
            $form = $this->getConfirmDeleteForm();
            Form::sendForm($player, $form, $this, "onDeleteContent");
            return;
        }
        if ($datas["status"] === null) {
            $form = $content->getEditForm($datas["contents"], Language::get("form.insufficient"));
            Form::sendForm($player, $form, $this, "onEdit");
            return;
        }

        $mes = Language::get("form.form.changed");
        if ($datas["status"] === false) $mes = Language::get("form.form.changed.suspicious");
        $key = $session->getData("if_key");
        $manager->updateContent($key, $session->getData("type"), $session->getData("num"), $datas["contents"], $options);
        $contents = $manager->get($key, $options);
        $form = $this->getEditContentsForm($contents[$session->getData("type")], $mes, $session->getData("type"));
        Form::sendForm($player, $form, $this, "onEditIfContents");
        $player->sendMessage($mes);
    }

    public function getConfirmDeleteForm() {
        $data = [
            "type" => "modal",
            "title" => Language::get("form.form.confirmDelete.title"),
            "content" => Language::get("form.form.confirmDelete.content"),
            "button1" => Language::get("form.form.confirmDelete.yes"),
            "button2" => Language::get("form.form.confirmDelete.no")
        ];
        $data = self::encodeJson($data);
        return $data;
    }

    public function onDeleteContent($player, $data) {
        $session = Session::get($player);
        if ($data === null) {
            $session->setValid(false, false);
            return;
        }
        $type = $session->getIfType();
        $manager = ifPlugin::getInstance()->getManagerBySession($session);
        $options = ifPlugin::getInstance()->getOptionsBySession($session);

        $key = $session->getData("if_key");
        if ($data) {
            $manager->del($key, $session->getData("type"), $session->getData("num"), $options);
            $form = $this->getEditContentsForm($manager->get($key, $options)[$session->getData("type")], Language::get("form.form.delete.success"), $session->getData("type"));
            Form::sendForm($player, $form, $this, "onEditIfContents");
            $player->sendMessage(Language::get("form.form.delete.success"));
        } else {
            $contents = $manager->get($key, $options);
            $ifData = $contents[$session->getData("type")][$session->getData("num")];
            $form = $manager->get($key, $options)->getEditForm($ifData["contents"], Language::get("form.cancelled"));
            Form::sendForm($player, $form, $this, "onEdit");
            $player->sendMessage(Language::get("form.cancelled"));
        }
    }

    public function onDeleteIf($player, $data) {
        $session = Session::get($player);
        if ($data === null) {
            $session->setValid(false, false);
            return;
        }
        $type = $session->getIfType();
        $manager = ifPlugin::getInstance()->getManagerBySession($session);
        $options = ifPlugin::getInstance()->getOptionsBySession($session);

        if ($data) {
            $manager->remove($session->getData("if_key"), $options);
            $player->sendMessage(Language::get("form.form.delete.success"));
        } else {
            $player->sendMessage(Language::get("form.cancelled"));
        }
        $session->setValid(false);
    }

    public function getSearchForm($mes = "") {
        $data = [
            "type" => "custom_form",
            "title" => Language::get("form.form.search.title"),
            "content" => [
                Elements::getLabel(Language::get("form.form.search.label").(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("form.form.search.input"))
            ]
        ];
        $data = self::encodeJson($data);
        return $data;
    }

    public function onSearch($player, $data) {
        $session = Session::get($player);
        if ($data === null) {
            $session->setValid(false, false);
            return;
        }
        if ($data[1] === "") {
            $form = $this->getSearchForm(Language::get("form.insufficient"));
            Form::sendForm($player, $form, $this, "onSearch");
            return;
        }
        if ($session->getData("type") == "if") {
            $all = ConditionFactory::getAll();
        } else {
            $all = ProcessFactory::getAll();
        }
        $keywords = explode(" ", $data[1]);
        $result = array_filter($all, function ($item) use ($keywords) {
            $contains = true;
            foreach ($keywords as $keyword) {
                if (strpos($item->getName(), $keyword) === false) $contains = false;
            }
            return($contains);
        });
        $session->setData("searchResult", $result);

        $buttons[] = Elements::getButton(Language::get("form.back"));
        foreach ($result as $item) {
            $buttons[] = Elements::getButton($item->getName());
        }
        $data = [
            "type" => "form",
            "title" => Language::get("form.form.searchResult.title"),
            "content" => Language::get("form.selectButton"),
            "buttons" => $buttons
        ];
        Form::sendForm($player, self::encodeJson($data), $this, "onSearchResult");
    }

    public function onSearchResult($player, $data) {
        $session = Session::get($player);
        if ($data === null) {
            $session->setValid(false, false);
            return;
        }
        $type = $session->getIfType();
        $manager = ifPlugin::getInstance()->getManagerBySession($session);
        $options = ifPlugin::getInstance()->getOptionsBySession($session);
        if ($data == 0) {
            $key = $session->getData("if_key");
            $datas = $manager->get($key, $options);
            $form = $this->getEditContentsForm($datas[$session->getData("type")], "", $session->getData("type"));
            Form::sendForm($player, $form, $this, "onEditIfContents");
            return;
        }
        $data -= 1;
        $all = $session->getData("searchResult");
        if ($session->getData("type") == "if") {
            $datas = Condition::get(current(array_slice($all, $data, 1, true))->getId());
        } else {
            $datas = Process::get(current(array_slice($all, $data, 1, true))->getId());
        }
        $session->setData("contents", $datas);
        $form = $datas->getEditForm();
        Form::sendForm($player, $form, $this, "onEdit");
    }

    public function getChangeNameForm($name = "") {
        $data = [
            "type" => "custom_form",
            "title" => Language::get("form.form.setName.title"),
            "content" => [
                Elements::getLabel(Language::get("form.form.setName.content0")),
                Elements::getInput(Language::get("form.form.setName.content1"), "", $name),
                Elements::getToggle(Language::get("form.form.setName.content2")),
                Elements::getToggle(Language::get("form.cancel")),
            ]
        ];
        $data = self::encodeJson($data);
        return $data;
    }

    public function onChangeName($player, $data) {
        $session = Session::get($player);
        if ($data === null) {
            $session->setValid(false, false);
            return;
        }
        $type = $session->getIfType();
        $manager = ifPlugin::getInstance()->getManagerBySession($session);
        $options = ifPlugin::getInstance()->getOptionsBySession($session);
        $key = $session->getData("if_key");
        $datas = $manager->get($key, $options);
        $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
        if ($data[3]) {
            $form = $this->getEditIfForm($mes, $datas["name"] ?? null);
            Form::sendForm($player, $form, $this, "onEditIf");
            return;
        }
        if ($data[2]) {
            $mes = Language::get("form.deleteName.success")."\n".$mes;
            $player->sendMessage(Language::get("form.deleteName.success"));
            $manager->setName($key, "", $options);
        } else {
            $mes = Language::get("form.form.setName.success")."\n".$mes;
            $player->sendMessage(Language::get("form.form.setName.success"));
            $manager->setName($key, $data[1], $options);
        }
        $form = $this->getEditIfForm($mes, $datas["name"] ?? null);
        Form::sendForm($player, $form, $this, "onEditIf");
    }
}<?php

namespace aieuo\ip\form;

use aieuo\ip\ifPlugin;
use aieuo\ip\Session;
use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Messages;
use aieuo\ip\conditions\Condition;
use aieuo\ip\conditions\Comparison;
use aieuo\ip\utils\Language;

class FormIFForm {
    public function getSelectActionForm(){
        $data = [
            "type" => "form",
            "title" => Language::get("form.formif.action.title"),
            "content" => Language::get("form.selectButton"),
            "buttons" => [
                Elements::getButton(Language::get("form.action.add")),
                Elements::getButton(Language::get("form.action.edit")),
                Elements::getButton(Language::get("form.action.delete")),
                Elements::getButton(Language::get("form.formif.action.formList")),
                Elements::getButton(Language::get("form.cancel")),
                Elements::getButton(Language::get("form.back"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onSelectAction($player, $data) {
        if ($data === null) return;
        $session = Session::get($player);
        $session->setValid()->setIfType(Session::FORM);
        switch ($data) {
            case 0:
                $session->setData("action", "add");
                Form::sendForm($player, $this->getAddIFformForm(), $this, "onAddIFformForm");
                return;
            case 1:
                $session->setData("action", "edit");
                break;
            case 2:
                $session->setData("action", "del");
                break;
            case 3:
                Form::sendForm($player, $this->getFormIFListForm(), $this, "onFormIFList");
                return;
            case 4:
                $session->setValid(false);
                $player->sendMessage(Language::get("form.cancelled"));
                return;
            case 5:
                $session->setValid(false);
                $form = (new Form())->getSelectIfTypeForm();
                Form::sendForm($player, $form, new Form(), "onSelectIfType");
                return;
        }
        Form::sendForm($player, $this->getSelectIFformForm(), $this, "onSelectIFformForm");
    }

    public function getAddIFformForm($mes = "") {
        $data = [
            "type" => "custom_form",
            "title" => Language::get("form.formif.addformif.title"),
            "content" => [
                Elements::getInput(Language::get("form.formif.addformif.content0", [$mes !== "" ? $mes."\n" : ""])),
                Elements::getInput(Language::get("form.formif.addformif.content1")),
                Elements::getDropdown(Language::get("form.formif.addformif.content2"), [
                    Language::get("form.formif.list"),
                    Language::get("form.formif.custom"),
                    Language::get("form.formif.modal"),
                ], 0),
                Elements::getToggle(Language::get("form.cancel")),
            ],
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onAddIFformForm($player, $data) {
        $session = Session::get($player);
        if ($data === null) {
            $session->setValid(false, false);
            return;
        }
        $manager = ifPlugin::getInstance()->getFormIFManager();
        if ($data[3]) {
            $form = $this->getSelectActionForm();
            Form::sendForm($player, $form, $this, "onSelectAction");
            return;
        }
        if ($data[0] === "") {
            $form = $this->getAddIFformForm(Language::get("form.insufficient"));
            Form::sendForm($player, $form, $this, "onAddIFformForm");
            $player->sendMessage(Language::get("form.insufficient"));
            return;
        }
        if ($manager->isAdded($data[0])) {
            $form = $this->getAddIFformForm(Language::get("form.formif.exist"));
            Form::sendForm($player, $form, $this, "onAddIFformForm");
            $player->sendMessage(Language::get("form.formif.exist"));
            return;
        }
        $form = ["title" => $data[1] == "" ? $data[0] : $data[1]];
        switch ($data[2]) {
            case 0:
                $form["type"] = "form";
                $form["content"] = "content";
                $form["buttons"] = [];
                break;
            case 1:
                $form["type"] = "custom_form";
                $form["content"] = [];
                break;
            case 2:
                $form["type"] = "modal";
                $form["content"] = "content";
                $form["button1"] = "button1";
                $form["button2"] = "button2";
                break;
        }
        $json = Form::encodeJson($form);
        $session->setData("if_key", $data[0])->setData("form", $form);
        $datas = $manager->repairIF([]);
        $datas["form"] = $json;
        $manager->set($data[0], $datas);
        Form::sendForm($player, $this->getEditIFformForm($form), $this, "onEditIFformForm");
    }

    public function getSelectIFformForm($mes = "") {
        $data = [
            "type" => "custom_form",
            "title" => Language::get("form.formif.selectformif.title"),
            "content" => [
                Elements::getInput(Language::get("form.formif.selectformif.content0", [$mes !== "" ? $mes."\n" : ""])),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onSelectIFformForm($player, $data) {
        $session = Session::get($player);
        if ($data === null) {
            $session->setValid(false, false);
            return;
        }
        if ($data[1]) {
            $form = $this->getSelectActionForm();
            Form::sendForm($player, $form, $this, "onSelectAction");
            return;
        }
        if ($data[0] === "") {
            $form = $this->getSelectIFformForm(Language::get("form.insufficient"));
            Form::sendForm($player, $form, $this, "onSelectIFformForm");
            $player->sendMessage(Language::get("form.insufficient"));
            return;
        }
        $manager = ifPlugin::getInstance()->getFormIFManager();
        if (!$manager->isAdded($data[0])) {
            $form = $this->getSelectIFformForm(Language::get("form.formif.notexist"));
            Form::sendForm($player, $form, $this, "onSelectIFformForm");
            $player->sendMessage(Language::get("form.formif.notexist"));
            return;
        }

        $session->setData("if_key", $data[0]);
        $action = $session->getData("action");
        if ($action == "edit") {
            $form = $manager->getIF($data[0])["form"];
            $session->setData("form", json_decode($form, true));
            Form::sendForm($player, $this->getEditIFformForm(json_decode($form, true)), $this, "onEditIFformForm");
        } elseif ($action == "del") {
            $form = (new Form())->getConfirmDeleteForm();
            Form::sendForm($player, $form, $this, "onDeleteIf");
        }
    }

    public function getEditIFformForm($form, $mes = "") {
        $type = $form["type"];
        $buttons = [
            ["text" => Language::get("form.formif.editformif.button.preview")],
            ["text" => Language::get("form.formif.editformif.button.edit")],
            ["text" => Language::get("form.formif.editformif.button.title", [$form["title"]])],
        ];
        switch ($type) {
            case 'modal':
                $buttons[] = ["text" => Language::get("form.formif.editformif.modal.content", [$form["content"]])];
                $buttons[] = ["text" => Language::get("form.formif.editformif.modal.button1", [$form["button1"]])];
                $buttons[] = ["text" => Language::get("form.formif.editformif.modal.button2", [$form["button2"]])];
                break;
            case "form":
                $buttons[] = ["text" => Language::get("form.formif.editformif.form.content", [$form["content"]])];
                foreach ($form["buttons"] as $button) {
                    $buttons[] = ["text" => Language::get("form.formif.editformif.form.button", [$button["text"]])];
                }
                $buttons[] = ["text" => Language::get("form.formif.editformif.form.addbutton")];
                break;
            case "custom_form":
                foreach ($form["content"] as $content) {
                    $buttons[] = ["text" => Language::get("form.formif.editformif.custom.content", [Language::get("form.formif.custom.".$content["type"].".index"), $content["text"]])];
                }
                $buttons[] = ["text" => Language::get("form.formif.editformif.custom.addparts")];
                break;
        }
        $data = [
            "type" => "form",
            "title" => Language::get("form.formif.editformif.title"),
            "content" => Language::get("form.formif.editformif.content", [$mes !== "" ? $mes."\n" : ""]),
            "buttons" => $buttons
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onEditIFformForm($player, $data) {
        $session = Session::get($player);
        if ($data === null) {
            $session->setValid(false, false);
            return;
        }
        $form = $session->getData("form");
        $manager = ifPlugin::getInstance()->getFormIFManager();
        if ($data === 0) {
            Form::sendForm($player, Form::encodeJson($form), $this, "onPreviewIFform");
            return;
        }
        if ($data === 1) {
            Form::sendForm($player, $this->getIfListForm($session->getData("if_key")), $this, "onSelectIf");
            return;
        }
        $session->setData("form_select_place", $data-2);
        Form::sendForm($player, $this->getSelectPartsForm($form, $data-2), $this, "onSelectParts");
    }

    public function onPreviewIFform($player, $data) {
        $session = Session::get($player);
        $form = $session->getData("form");
        Form::sendForm($player, $this->getEditIFformForm($form), $this, "onEditIFformForm");
    }

    public function getSelectPartsForm($form, $place, $mes = "") {
        $data = [
            "type" => "custom_form",
            "title" => Language::get("form.formif.selectparts.title"),
            "content" => [Elements::getToggle(($mes !== "" ? $mes."\n" : "").Language::get("form.cancel"))],
        ];
        switch ($form["type"]) {
            case 'modal':
                switch ($place) {
                    case 0:
                        $data["content"][] = Elements::getLabel(Language::get("form.formif.selectparts.parts.title"));
                        $data["content"][] = Elements::getInput(Language::get("form.formif.selectparts.parts.text"), "", $form["title"]);
                        break;
                    case 1:
                        $data["content"][] = Elements::getLabel(Language::get("form.formif.selectparts.parts.content"));
                        $data["content"][] = Elements::getInput(Language::get("form.formif.selectparts.parts.text"), "", $form["content"]);
                        break;
                    case 2:
                        $data["content"][] = Elements::getLabel(Language::get("form.formif.selectparts.parts.button1")."\n".Language::get("form.formif.recive", ["{form_data} <- true"]));
                        $data["content"][] = Elements::getInput(Language::get("form.formif.selectparts.parts.text"), "", $form["button1"]);
                        $data["content"][] = Elements::getToggle(Language::get("form.formif.selectparts.parts.editif"));
                        break;
                    case 3:
                        $data["content"][] = Elements::getLabel(Language::get("form.formif.selectparts.parts.button2")."\n".Language::get("form.formif.recive", ["{form_data} <- false"]));
                        $data["content"][] = Elements::getInput(Language::get("form.formif.selectparts.parts.text"), "", $form["button2"]);
                        $data["content"][] = Elements::getToggle(Language::get("form.formif.selectparts.parts.editif"));
                        break;
                }
                break;
            case "form":
                if ($place == 0) {
                    $data["content"][] = Elements::getLabel(Language::get("form.formif.selectparts.parts.title"));
                    $data["content"][] = Elements::getInput(Language::get("form.formif.selectparts.parts.text"), "", $form["title"]);
                    break;
                }
                if ($place == 1) {
                    $data["content"][] = Elements::getLabel(Language::get("form.formif.selectparts.parts.content"));
                    $data["content"][] = Elements::getInput(Language::get("form.formif.selectparts.parts.text"), "", $form["content"]);
                    break;
                }
                $place -= 2;
                if (!isset($form["buttons"][$place])) {
                    $data["content"][] = Elements::getLabel(Language::get("form.formif.selectparts.addbutton"));
                    $data["content"][] = Elements::getInput(Language::get("form.formif.selectparts.parts.text"));
                    $data["content"][] = Elements::getToggle(Language::get("form.formif.selectparts.parts.editif"));
                    break;
                }
                $data["content"][] = Elements::getLabel(Language::get("form.formif.selectparts.parts.button")."\n".Language::get("form.formif.recive", ["{form_data} <- $place"]));
                $data["content"][] = Elements::getInput(Language::get("form.formif.selectparts.parts.text"), "", $form["buttons"][$place]["text"]);
                $data["content"][] = Elements::getToggle(Language::get("form.formif.selectparts.parts.editif"));
                $data["content"][] = Elements::getToggle(Language::get("form.action.delete"));
                break;
            case "custom_form":
                if ($place == 0) {
                    $data["content"][] = Elements::getLabel(Language::get("form.formif.selectparts.parts.title"));
                    $data["content"][] = Elements::getInput(Language::get("form.formif.selectparts.parts.text"), "", $form["title"]);
                    break;
                }
                $place -= 1;
                if (!isset($form["content"][$place])) {
                    $data["content"][] = Elements::getLabel(Language::get("form.formif.selectparts.addparts"));
                    $data["content"][] = Elements::getDropdown(
                        Language::get("form.formif.selectparts.select_custom_parts"),
                        array_map(function ($partsname) {
                            return Language::get("form.formif.custom.".$partsname);
                        }, array_keys($this->getCustomFormParts()))
                    );
                    break;
                }
                $parts = $form["content"][$place];
                $data["content"] = array_merge($data["content"], $this->getCustomFormParts($parts["type"], $parts, $place));
                break;
        }
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onSelectParts($player, $data) {
        $session = Session::get($player);
        if ($data === null) {
            $session->setValid(false, false);
            return;
        }
        $form = $session->getData("form");
        $place = $session->getData("form_select_place");
        if ($data[0]) {
            Form::sendForm($player, $this->getEditIFformForm($form, Language::get("form.cancelled")), $this, "onEditIFformForm");
            return;
        }
        $manager = ifPlugin::getInstance()->getFormIFManager();
        $datas = $manager->getIF($session->getData("if_key"));
        switch ($form["type"]) {
            case 'modal':
                switch ($place) {
                    case 0:
                        $partsname = "title";
                        break;
                    case 1:
                        $partsname = "content";
                        break;
                    case 2:
                        $partsname = "button1";
                        break;
                    case 3:
                        $partsname = "button2";
                        break;
                }
                $form[$partsname] = $data[2];
                if (isset($data[3]) and $data[3]) {
                    $session->setData("form", $form);
                    $datas["form"] = Form::encodeJson($form);
                    $manager->set($session->getData("if_key"), $datas);
                    $responses = array_filter($datas["ifs"], function ($ifs) use ($partsname) {
                        $comparison = false;
                        foreach ($ifs["if"] as $ifdata) {
                            if ($ifdata["id"] === Condition::COMPARISON and ($content = Condition::get(Condition::COMPARISON)->parse($ifdata["content"])) !== false) {
                                if ($content[0] !== "{form_data}" or $content[1] !== Comparison::EQUAL or $content[2] != ($partsname === "button1")) continue;
                                $comparison = true;
                            }
                        }
                        return $comparison;
                    });
                    if (count($responses) === 0) {
                        $session->setData("form_place", count($datas["ifs"]));
                        $options = ifPlugin::getInstance()->getOptionsBySession($session);
                        $manager->add($session->getData("if_key"), "if", Condition::COMPARISON, "{form_data}[ope:0]".($partsname === "button1" ? "true" : "false"), $options);
                        $ifdata = $manager->get($session->getData("if_key"), $options);
                    } else {
                        $ifdata = array_shift($responses);
                        $session->setData("form_place", array_keys($datas["ifs"], $ifdata)[0]);
                    }
                    $mes = Messages::createMessage($ifdata["if"], $ifdata["match"], $ifdata["else"]);
                    $form = (new Form)->getEditIfForm($mes);
                    Form::sendForm($player, $form, new Form(), "onEditIf");
                    return;
                }
                break;
            case "form":
                switch ($place) {
                    case 0:
                        $form["title"] = $data[2];
                        break;
                    case 1:
                        $form["content"] = $data[2];
                        break;
                    default:
                        $place -= 2;
                        $form["buttons"][$place] = ["text" => $data[2]];
                        if (isset($data[4]) and $data[4]) {
                            unset($form["buttons"][$place]);
                            $form["buttons"] = array_merge($form["buttons"]);
                            break;
                        }
                        if ($data[3]) {
                            $session->setData("form", $form);
                            $datas["form"] = Form::encodeJson($form);
                            $manager->set($session->getData("if_key"), $datas);
                            $responses = array_filter($datas["ifs"], function ($ifs) use ($place) {
                                $comparison = false;
                                foreach ($ifs["if"] as $ifdata) {
                                    if ($ifdata["id"] === Condition::COMPARISON and ($content = Condition::get(Condition::COMPARISON)->parse($ifdata["content"])) !== false) {
                                        if ($content[0] !== "{form_data}" or $content[1] !== Comparison::EQUAL or $content[2] !== $place) continue;
                                        $comparison = true;
                                    }
                                }
                                return $comparison;
                            });
                            if (count($responses) === 0) {
                                $session->setData("form_place", count($datas["ifs"]));
                                $options = ifPlugin::getInstance()->getOptionsBySession($session);
                                $manager->add($session->getData("if_key"), "if", Condition::COMPARISON, "{form_data}[ope:0]$place", $options);
                                $ifdata = $manager->get($session->getData("if_key"), $options);
                            } else {
                                $ifdata = array_shift($responses);
                                $session->setData("form_place", array_keys($datas["ifs"], $ifdata)[0]);
                            }
                            $mes = Messages::createMessage($ifdata["if"], $ifdata["match"], $ifdata["else"]);
                            $form = (new Form)->getEditIfForm($mes);
                            Form::sendForm($player, $form, new Form(), "onEditIf");
                            return;
                        }
                        break;
                }
                break;
            case "custom_form":
                switch ($place) {
                    case 0:
                        $form["title"] = $data[2];
                        break;
                    default:
                        $place -= 1;
                        if (!isset($form["content"][$place])) {
                            $partsname = array_keys($this->getCustomFormParts())[$data[2]];
                            $form["content"][] = Elements::{"get".$partsname}($partsname);
                            break;
                        }
                        if ($data[1]) {
                            unset($form["content"][$place]);
                            $form["content"] = array_merge($form["content"]);
                            break;
                        }
                        $parts = $form["content"][$place];
                        switch ($parts["type"]) {
                            case 'label':
                                $form["content"][$place] = Elements::getLabel($data[3]);
                                break;
                            case "input":
                                $form["content"][$place] = Elements::getInput($data[3], $data[4], $data[5]);
                                break;
                            case "toggle":
                                $form["content"][$place] = Elements::getToggle($data[3], $data[4]);
                                break;
                            case "slider":
                                $form["content"][$place] = Elements::getSlider($data[3], (int)$data[4], (int)$data[5], (int)$data[6], (int)$data[7]);
                                break;
                            case "dropdown":
                                $options = $form["content"][$place]["options"];
                                $count = count($options);
                                for ($i=0; $i<$count; $i++) {
                                    $options[$i] = $data[$i+4];
                                }
                                $options = array_merge($options, explode(",", $data[$count+4]));
                                $options = array_filter($options, function ($option) {
                                    return(trim(rtrim($option)) !== "");
                                });
                                $options = array_values($options);
                                $form["content"][$place] = Elements::getDropdown($data[3], $options);
                                break;
                        }
                        break;
                }
                break;
        }
        $session->setData("form", $form);
        $datas["form"] = Form::encodeJson($form);
        $manager->set($session->getData("if_key"), $datas);
        $player->sendMessage(Language::get("form.changed"));
        Form::sendForm($player, $this->getEditIFformForm($form, Language::get("form.changed")), $this, "onEditIFformForm");
    }

    public function getCustomFormParts($name = "", $default = null, $place = null) {
        $parts = [
            "label" => [
                Elements::getToggle(Language::get("form.action.delete")),
                Elements::getLabel(Language::get("form.formif.custom.label")
                    .($place === null ? "" : "\n".Language::get("form.formif.recive", ["{form_data}[$place] <-\"\""]))),
                Elements::getInput(Language::get("form.formif.custom.text"), "", $default["text"] ?? ""),
            ],
            "input" => [
                Elements::getToggle(Language::get("form.action.delete")),
                Elements::getLabel(Language::get("form.formif.custom.input")
                    .($place === null ? "" : "\n".Language::get("form.formif.recive.input", [$place]))),
                Elements::getInput(Language::get("form.formif.custom.text"), "", $default["text"] ?? ""),
                Elements::getInput(Language::get("form.formif.custom.input.placeholder"), "", $default["placeholder"] ?? ""),
                Elements::getInput(Language::get("form.formif.custom.input.default"), "", $default["default"] ?? ""),
            ],
            "toggle" => [
                Elements::getToggle(Language::get("form.action.delete")),
                Elements::getLabel(Language::get("form.formif.custom.toggle")
                    .($place === null ? "" : "\n".Language::get("form.formif.recive", ["{form_data}[$place] <- (true | false)"]))),
                Elements::getInput(Language::get("form.formif.custom.text"), "", $default["text"] ?? ""),
                Elements::getToggle(Language::get("form.formif.custom.toggle.default"), $default["default"] ?? false),
            ],
            "slider" => [
                Elements::getToggle(Language::get("form.action.delete")),
                Elements::getLabel(Language::get("form.formif.custom.slider")
                    .($place === null ? "" : "\n".Language::get("form.formif.recive.slider", [$place]))),
                Elements::getInput(Language::get("form.formif.custom.text"), "", $default["text"] ?? ""),
                Elements::getInput(Language::get("form.formif.custom.slider.min"), "", $default["min"] ?? ""),
                Elements::getInput(Language::get("form.formif.custom.slider.max"), "", $default["max"] ?? ""),
                Elements::getInput(Language::get("form.formif.custom.slider.default"), "", $default["default"] ?? ""),
                Elements::getInput(Language::get("form.formif.custom.slider.step"), "", $default["step"] ?? ""),
            ],
            "dropdown" => [
                Elements::getToggle(Language::get("form.action.delete")),
                Elements::getLabel(Language::get("form.formif.custom.dropdown")
                    .($place === null ? "" : "\n".Language::get("form.formif.recive.dropdown", [$place]))),
                Elements::getInput(Language::get("form.formif.custom.text"), "", $default["text"] ?? ""),
            ],
        ];
        if (isset($default["options"])) {
            foreach ($default["options"] as $i => $option) {
                $parts["dropdown"][] = Elements::getInput(Language::get("form.formif.custom.dropdown.option", [$i]), "", $option);
            }
        }
        $parts["dropdown"][] = Elements::getInput(Language::get("form.formif.custom.dropdowm.addOption"));
        if (empty($name)) return $parts;
        return $parts[$name];
    }

    public function getIfListForm($name) {
        $manager = ifPlugin::getInstance()->getFormIFManager();
        $datas = $manager->getIF($name);
        $buttons = [Elements::getButton(Language::get("form.back")), Elements::getButton(Language::get("form.formif.iflist.add"))];
        foreach ($datas["ifs"] as $n => $data) {
            $buttons[] = Elements::getButton(empty($data["name"]) ? $n : $data["name"]);
        }
        $data = [
            "type" => "form",
            "title" => Language::get("form.formif.iflist.title"),
            "content" => Language::get("form.selectButton"),
            "buttons" => $buttons
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onSelectIf($player, $data) {
        $session = Session::get($player);
        if ($data === null) {
            $session->setValid(false, false);
            return;
        }
        if ($data === 0) {
            $form = $session->getData("form");
            Form::sendForm($player, $this->getEditIFformForm($form), $this, "onEditIFformForm");
            return;
        }
        $manager = ifPlugin::getInstance()->getFormIFManager();
        $datas = $manager->getIF($session->getData("if_key"));
        if ($data === 1) {
            $session->setData("form_place", count($datas["ifs"]));
            $mes = Messages::createMessage([], [], []);
            $form = (new Form)->getEditIfForm($mes);
            Form::sendForm($player, $form, new Form(), "onEditIf");
            return;
        }
        $session->setData("form_place", $data - 2);
        $datas = $datas["ifs"][$data-2];
        $mes = Messages::createMessage($datas["if"], $datas["match"], $datas["else"]);
        $form = (new Form)->getEditIfForm($mes);
        Form::sendForm($player, $form, new Form(), "onEditIf");
    }

    public function onDeleteIf($player, $data) {
        $session = Session::get($player);
        if ($data === null) {
            $session->setValid(false, false);
            return;
        }
        $type = $session->getIfType();
        $manager = ifPlugin::getInstance()->getFormIFManager();

        if ($data) {
            $manager->removeIF($session->getData("if_key"));
            $player->sendMessage(Language::get("form.formif.deleted"));
        } else {
            $player->sendMessage(Language::get("form.cancelled"));
        }
        $session->setValid(false);
    }

    public function getFormIFListForm() {
        $manager = ifPlugin::getInstance()->getFormIFManager();
        $forms = $manager->getAll();
        $buttons = [Elements::getButton(Language::get("form.back"))];
        foreach ($forms as $formName => $value) {
            switch (json_decode($value["form"], true)["type"]) {
                case "form":
                    $formType = Language::get("form.formif.list");
                    break;
                case "modal":
                    $formType = Language::get("form.formif.modal");
                    break;
                case "custom_form":
                    $formType = Language::get("form.formif.custom");
                    break;
                default:
                    $formType = "";
            }
            $buttons[] = Elements::getButton(Language::get("form.formif.formList.button", [$formName, $formType]));
        }
        $data = [
            "type" => "form",
            "title" => Language::get("form.formif.formList.title"),
            "content" => Language::get("form.formif.formList.title"),
            "buttons" => $buttons
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function onFormIFList($player, $data) {
        $session = Session::get($player);
        if ($data === null) {
            $session->setValid(false, false);
            return;
        }
        if ($data === 0) {
            $form = $this->getSelectActionForm();
            Form::sendForm($player, $form, $this, "onSelectAction");
            return;
        }
        $manager = ifPlugin::getInstance()->getFormIFManager();
        $formName = key(array_slice($manager->getAll(), $data - 1, 1, true));
        $form = $manager->getIF($formName)["form"];
        $session->setData("if_key", $formName);
        $session->setData("form", json_decode($form, true));
        Form::sendForm($player, $this->getEditIFformForm(json_decode($form, true)), $this, "onEditIFformForm");
    }
}<?php

namespace aieuo\ip\form;

use aieuo\ip\ifPlugin;
use aieuo\ip\Session;
use aieuo\ip\utils\Messages;

class ImportForm {
	public function getImportListForm($mes = "") {
		$buttons = [Elements::getButton("<ã²ãšã€åã®ããŒãžã«æ»ã>")];
		$files = glob(ifPlugin::getInstance()->getDataFolder()."imports/*.json");
		foreach($files as $file){
			if(is_dir($file)) continue;
			$datas = json_decode(file_get_contents($file), true);
			$buttons[] = Elements::getButton($datas["name"]." | ".$datas["author"]);
		}
		$data = [
			"type" => "form",
			"title" => "ãã¡ã€ã«éžæ",
			"content" => ($mes === "" ? "" : $mes."\n")."Â§7ãã¿ã³ãæŒããŠãã ãã",
			"buttons" => $buttons
		];
		$json = Form::encodeJson($data);
		return $json;
	}

	public function onImportList($player, $data) {
        $session = Session::get($player);
		if($data === null) {
			$session->setValid(false, false);
			return;
		}
		if($data == 0) {
			$data = (new Form())->getSelectIfTypeForm();
			Form::sendForm($player, $data, new Form(), "onSelectIfType");
			return;
		}
		$files = glob(ifPlugin::getInstance()->getDataFolder()."imports/*.json");
		if(!isset($files[$data - 1])) {
			$form = $this->getImportListForm("ãšã©ãŒãçºçããŸãããããäžåºŠéžæããŠãã ãã");
			Form::sendForm($player, $form, $this, "onImportList");
			return;
		}
		$path = $files[$data - 1];
		$session->setData("path", $path);
		$form = $this->getImportForm(json_decode(file_get_contents($path), true));
		Form::sendForm($player, $form, $this, "onImport");
	}

	public function getImportForm($datas) {
		$mes = $datas["name"]."\näœæè: ".$datas["author"]."\n".$datas["details"]."\n";
		foreach ($datas["ifs"] as $key => $value) {
			$mes .= "---------------------------\n";
			$mes .= "Â§l".$key."Â§rÂ§f\n".Messages::createMessage($value["if"], $value["match"], $value["else"])."\n";
		}
		$data = [
			"type" => "custom_form",
			"title" => "ãã¡ã€ã«ã€ã³ããŒã > ".$datas["name"],
			"content" => [
				Elements::getLabel($mes),
				Elements::getToggle("ã­ã£ã³ã»ã«")
			]
		];
		$json = Form::encodeJson($data);
		return $json;
	}

	public function onImport($player, $data) {
        $session = Session::get($player);
		if($data === null) {
			$session->setValid(false, false);
			return;
		}
		if($data[1]) {
			$form = $this->getImportListForm("ã­ã£ã³ã»ã«ããŸãã");
			Form::sendForm($player, $form, $this, "onImportList");
			return;
		}
		$file = json_decode(file_get_contents($session->getData("path")), true);
		$this->importDatas($player, $file);
	}

	public function importDatas($player, $file, $count = 0) {
        $session = Session::get($player);
		foreach ($file["ifs"] as $key => $datas) {
			if($datas["type"] === Session::BLOCK) {
				$manager = ifPlugin::getInstance()->getBlockManager();

				if($manager->isAdded($key) and !isset($session->getData("overwrite")[$key])) {
					$session->setData("file", $file);
					$session->setData("if_key", $key);
					$session->setData("count", $count);
					$form = $this->getConfirmOverwriteForm($key);
					Form::sendForm($player, $form, $this, "onConfirmOverwrite");
					return;
				} elseif($manager->isAdded($key) and !$session->getData("overwrite")[$key]) {
					continue;
				}

				$manager->set($key, [
					"if" => $datas["if"],
					"match" => $datas["match"],
					"else" => $datas["else"],
					"author" => $file["author"]
				]);
				$count ++;
			} elseif($datas["type"] === Session::COMMAND) {
				$manager = ifPlugin::getInstance()->getCommandManager();

				if(!$manager->isAdded($key) and $manager->exists($key)) continue;
				if($manager->isAdded($key) and !isset($session->getData("overwrite")[$key])){
					$session->setData("file", $file);
					$session->setData("if_key", $key);
					$session->setData("count", $count);
					$form = $this->getConfirmOverwriteForm($key);
					Form::sendForm($player, $form, $this, "onConfirmOverwrite");
					return;
				} elseif($manager->isAdded($key) and !$session->getData("overwrite")[$key]) {
					continue;
				}

				$manager->set($key, [
					"if" => $datas["if"],
					"match" => $datas["match"],
					"else" => $datas["else"],
					"author" => $file["author"]
				], [
					"desc" => $datas["description"],
					"perm" => $datas["permission"]
				]);
				$manager->register($key, $datas["description"], $datas["permission"]);
				$count ++;
			} elseif($datas["type"] === Session::EVENT) {
				$manager = ifPlugin::getInstance()->getEventManager();
				$manager->addByEvent($datas["options"]["eventname"], $datas + ["author" => $file["author"]]);
				$count ++;
			} elseif($datas["type"] === Session::CHAIN) {
				$manager = ifPlugin::getInstance()->getChainManager();

				if($manager->isAdded($key) and !isset($session->getData("overwrite")[$key])) {
					$session->setData("file", $file);
					$session->setData("if_key", $key);
					$session->setData("count", $count);
					$form = $this->getConfirmOverwriteForm($key);
					Form::sendForm($player, $form, $this, "onConfirmOverwrite");
					return;
				} elseif($manager->isAdded($key) and !$session->getData("overwrite")[$key]) {
					continue;
				}

				$manager->set($key, [
					"if" => $datas["if"],
					"match" => $datas["match"],
					"else" => $datas["else"],
					"author" => $file["author"]
				]);
				$count ++;
			}
			unset($file["ifs"][$key]);
		}
		$player->sendMessage($count."åã®IFãè¿œå ããŸãã");
		$session->setValid(false);
	}

	public function getConfirmOverwriteForm($name) {
		$data = [
			"type" => "modal",
			"title" => "äžæžã",
			"content" => $name."ã¯æ¢ã«å­åšããŸããäžæžãããŸãã?\näžæžããããšä»¥åã®ç©ã¯åŸ©åã§ããŸããã",
			"button1" => "ã¯ã",
			"button2" => "ããã"
		];
		$data = Form::encodeJson($data);
		return $data;
	}

	public function onConfirmOverwrite($player, $data) {
        $session = Session::get($player);
		if($data === null) {
			$session->setValid(false, false);
			return;
		}
		if($data) {
			if(($overwrite = $session->getData("overwrite")) === "") {
				$session->setData("overwrite", [$session->getData("if_key") => true]);
			} else {
				$overwrite[$session->getData("if_key")] = true;
				$session->setData("overwrite", $overwrite);
			}
			$this->importDatas($player, $session->getData("file"), $session->getData("count"));
		} else {
			if(($overwrite = $session->getData("overwrite")) === "") {
				$session->setData("overwrite", [$session->getData("if_key") => false]);
			} else {
				$overwrite[$session->getData("if_key")] = false;
				$session->setData("overwrite", $overwrite);
			}
			$this->importDatas($player, $session->getData("file"), $session->getData("count"));
		}
	}
}<?php

namespace aieuo\ip;

use pocketmine\Server;
use pocketmine\event\Event;

use aieuo\ip\conditions\Condition;
use aieuo\ip\processes\Process;
use aieuo\ip\variable\StringVariable;
use aieuo\ip\variable\NumberVariable;
use aieuo\ip\variable\ListVariable;

class IFAPI {

    public function checkCondition($player, $datas, $options = []) {
        $matched = true;
        foreach($datas as $data){
            $result = ($co = Condition::get($data["id"]))
                        ->setPlayer($player)
                        ->setValues(
                            $co->parse(
                                ifPlugin::getInstance()
                                  ->getVariableHelper()
                                  ->replaceVariables($data["content"], $this->getReplaceDatas($options))
                            )
                        )->check();
            if($result === Condition::ERROR or $result === Condition::NOT_FOUND) {
                return $result;
            } elseif($result === Condition::NOT_MATCHED) {
                $matched = false;
            }
        }
        return $matched ? Condition::MATCHED : Condition::NOT_MATCHED;
    }

    public function executeProcess($player, $datas, $options) {
        $replaceDatas = $this->getReplaceDatas($options);
        foreach ($datas as $data) {
            $process = Process::get($data["id"]);
            $process->replaceDatas = $replaceDatas;
            if(isset($options["event"]) and $options["event"] instanceof Event) $process->setEvent($options["event"]);
            if($data["id"] === Process::EVENT_CANCEL) {
                $process->setValues($options["event"])->execute();
                continue;
            }
            $process->setPlayer($player)
              ->setValues(
                $process->parse(
                    ifPlugin::getInstance()
                      ->getVariableHelper()
                        ->replaceVariables($data["content"], $replaceDatas)
                )
              )->execute();
        }
    }

    public function executeIfMatchCondition($player, $datas1, $datas2, $datas3, $options = []) {
        $match = $this->checkCondition($player, $datas1, $options);
        switch ($match) {
            case Condition::MATCHED:
                $datas = $datas2;
                break;
            case Condition::NOT_MATCHED:
                $datas = $datas3;
                break;
            case Condition::NOT_FOUND:
                $player->sendMessage("Â§cãšã©ãŒãçºçããŸãã(id: ".$datas["id"]."ãèŠã€ãããŸãã)");
            case Condition::ERROR:
            default:
                return false;
        }
        $this->executeProcess($player, $datas, $options);
        return true;
    }

    public function getReplaceDatas($datas) {
        $player = $datas["player"];
        $server = Server::getInstance();
        $variableHelper = ifPlugin::getInstance()->getVariableHelper();
        $onlines = [];
        foreach ($server->getOnlinePlayers() as $p) {
            $onlines[] = $p->getName();
        }
        $ops = [];
        foreach ($server->getOps()->getAll() as $p => $value) {
            $ops[] = $p;
        }
        $variables = [
            "player" => new StringVariable("player", $player->__toString()),
            "player_name" => new StringVariable("player_name", $player->getName()),
            "nametag" => new StringVariable("nametag", $player->getDisplayName()),
            "player_pos" => new StringVariable("player_pos", $player->x.",".$player->y.",".$player->z.",".$player->level->getFolderName()),
            "player_x" => new NumberVariable("player_x", $player->x),
            "player_y" => new NumberVariable("player_y", $player->y),
            "player_z" => new NumberVariable("player_z", $player->z),
            "player_level" => new StringVariable("player_level", $player->level->getFolderName()),
            "firstplayed" => new NumberVariable("firstplayed", $player->getFirstPlayed()),
            "lastplayed" => new NumberVariable("lastplayed", $player->getLastPlayed()),
            "hand_index" => new NumberVariable("hand_index", $player->getInventory()->getHeldItemIndex()),
            "hand_item" => new StringVariable("hand_item", $player->getInventory()->getItemInHand()->__toString()),
            "hand_name" => new StringVariable("hand_name", $player->getInventory()->getItemInHand()->getName()),
            "hand_id" => new NumberVariable("hand_id", $player->getInventory()->getItemInHand()->getId()),
            "hand_damage" => new NumberVariable("hand_damage", $player->getInventory()->getItemInHand()->getDamage()),
            "hand_count" => new NumberVariable("hand_count", $player->getInventory()->getItemInHand()->getCount()),
            "server_name" => new StringVariable("server_name", $server->getName()),
            "microtime" => new NumberVariable("microtime", microtime(true)),
            "date" => new StringVariable("date", date("m/d h:i:s")),
            "default_level" => new StringVariable("default_level", $server->getDefaultLevel()->getFolderName()),
            "onlines" => new ListVariable("onlines", $onlines),
            "ops" => new ListVariable("ops", $ops)
        ];
        return $variables;
    }
}<?php
namespace aieuo\ip;

use pocketmine\plugin\PluginBase;
use pocketmine\event\Listener;
use pocketmine\utils\Config;

use aieuo\ip\commands\IFCommand;
use aieuo\ip\manager\BlockManager;
use aieuo\ip\manager\CommandManager;
use aieuo\ip\manager\EventManager;
use aieuo\ip\manager\ChainIfManager;
use aieuo\ip\manager\FormIFManager;
use aieuo\ip\economy\EconomyLoader;
use aieuo\ip\economy\EconomyAPILoader;
use aieuo\ip\economy\MoneySystemLoader;
use aieuo\ip\economy\PocketMoneyLoader;
use aieuo\ip\IFAPI;
use aieuo\ip\task\SaveTask;
use aieuo\ip\variable\VariableHelper;

use aieuo\ip\conditions\ConditionFactory;
use aieuo\ip\processes\ProcessFactory;

use aieuo\ip\utils\Language;

class ifPlugin extends PluginBase implements Listener{
    const VERSION = "3.3.0";

    private static $instance;

    private $loaded = false;

    public function onEnable(){
        $this->getServer()->getPluginManager()->registerEvents(new EventListener($this),$this);
        if(!file_exists($this->getDataFolder())) @mkdir($this->getDataFolder(), 0721, true);
        if(!file_exists($this->getDataFolder()."exports")) @mkdir($this->getDataFolder()."exports", 0721, true);
        if(!file_exists($this->getDataFolder()."imports")) @mkdir($this->getDataFolder()."imports", 0721, true);
        $this->config = new Config($this->getDataFolder()."config.yml", Config::YAML, [
            "wait" => 0,
            "save_time" => 10*20*60,
            "language" => "jpn",
        ]);
        $this->config->save();
        $this->wait = $this->config->get("wait");
        $language = $this->config->get("language", "jpn");
        $languages = [];
        foreach($this->getResources() as $resource) {
            $filename = $resource->getFilename();
            if (strrchr($filename, ".") == ".ini") $languages[] = basename($filename, ".ini");
            if ($filename === $language.".ini") {
                $messages = parse_ini_file($resource->getPathname());
            }
        }
        if(!isset($messages)) {
            $this->getLogger()->warning("èšèªãã¡ã€ã«ã®èª­ã¿èŸŒã¿ã«å€±æããŸãã");
            $this->getLogger()->warning(implode(", ", $languages)." ãäœ¿çšã§ããŸã");
            $this->getServer()->getPluginManager()->disablePlugin($this);
            return;
        }
        $this->language = new Language($messages);

        $this->getServer()->getCommandMap()->register("ifPlugin", new IFCommand($this));

        $this->loadEconomySystemPlugin();

        $this->command = new CommandManager($this);
        $this->block = new BlockManager($this);
        $this->event = new EventManager($this);
        $this->chain = new ChainIfManager($this);
        $this->formif = new FormIFManager($this);

        $this->api = new IFAPI();

        $this->variables = new VariableHelper($this);
        $this->variables->loadDataBase();

        $savetime = (int)$this->config->get("save_time", 10*20*60);
        $this->getScheduler()->scheduleRepeatingTask(new SaveTask($this), (int)$savetime);

        self::$instance = $this;

        ConditionFactory::init();
        ProcessFactory::init();

        $this->loaded = true;
    }

    public function onDisable(){
        if(!$this->loaded) return;
        $this->command->save();
        $this->block->save();
        $this->event->save();
        $this->chain->save();
        $this->formif->save();
        $this->variables->save();
        $this->config->save();
    }

    public static function getInstance(): self {
        return self::$instance;
    }

    public function getBlockManager() : BlockManager{
        return $this->block;
    }

    public function getCommandManager() : CommandManager{
        return $this->command;
    }

    public function getEventManager() : EventManager{
        return $this->event;
    }

    public function getChainManager() : ChainIfManager{
        return $this->chain;
    }

    public function getFormIFManager() : FormIFManager{
        return $this->formif;
    }

    public function getAPI() : IFAPI{
        return $this->api;
    }

    public function getVariableHelper() : VariableHelper{
        return $this->variables;
    }

    public function getEconomy() : ?EconomyLoader {
        return $this->economy;
    }

    public function loadEconomySystemPlugin(){
        if(($plugin = $this->getServer()->getPluginManager()->getPlugin("EconomyAPI")) !== null){
            $this->economy = new EconomyAPILoader($plugin);
            $this->getLogger()->info(Language::get("economy.found", ["EconomyAPI"]));
        }elseif(($plugin = $this->getServer()->getPluginManager()->getPlugin("MoneySystem")) !== null){
            $this->economy = new MoneySystemLoader($plugin);
            $this->getLogger()->info(Language::get("economy.found", ["MoneySystem"]));
        }elseif(($plugin = $this->getServer()->getPluginManager()->getPlugin("PocketMoney")) !== null){
            $this->economy = new PocketMoneyLoader($plugin);
            $this->getLogger()->info(Language::get("economy.found", ["PocketMoney"]));
        }else{
            $this->economy = null;
            $this->getLogger()->warning(Language::get("economy.notfound"));
        }
    }

    public function getManagerBySession($session) {
        $type = $session->getIfType();
        if($type === Session::BLOCK) {
            $manager = $this->getBlockManager();
        }elseif($type === Session::COMMAND) {
            $manager = $this->getCommandManager();
        }elseif($type === Session::EVENT) {
            $manager = $this->getEventManager();
        }elseif($type === Session::CHAIN) {
            $manager = $this->getChainManager();
        } elseif ($type === Session::FORM) {
            $manager = $this->getFormIFManager();
        }
        return $manager;
    }

    public function getOptionsBySession($session) {
        $type = $session->getIfType();
        if($type === Session::BLOCK) {
            $options = [];
        }elseif($type === Session::COMMAND) {
            $options = ["desc" => $session->getData("description"), "perm" => $session->getData("permission")];
        }elseif($type === Session::EVENT) {
            $options = ["eventname" => $session->getData("eventname")];
        }elseif($type === Session::CHAIN) {
            $options = [];
        } elseif ($type === Session::FORM) {
            $options = ["place" => $session->getData("form_place")];
        }
        return $options;
    }
}<?php

namespace aieuo\ip\manager;

use pocketmine\block\SignPost;
use pocketmine\tile\Sign;

use aieuo\ip\variable\StringVariable;
use aieuo\ip\variable\NumberVariable;
use aieuo\ip\variable\ListVariable;

class BlockManager extends IFManager {

	public function __construct($owner) {
		parent::__construct($owner ,"blocks");
	}

    public function set($key, $datas = [], $options = []) {
        $datas = $this->repairIF($datas);
        parent::set($key, $datas);
    }

    public function getPosition($block) {
        return $block->x.",".$block->y.",".$block->z.",".$block->level->getFolderName();
    }

    public function getReplaceDatas($datas) {
        $variables = parent::getReplaceDatas($datas);
        $block = $datas["block"];
        $event = $datas["event"];
        $add = [
            "block" => new StringVariable("block", $block->__toString()),
            "block_name" => new StringVariable("block_name", $block->getName()),
            "block_id" => new NumberVariable("block_id", $block->getId()),
            "block_damage" => new NumberVariable("block_damage", $block->getDamage()),
            "block_ids" => new StringVariable("block_ids", $block->getId().":".$block->getDamage()),
            "block_pos" => new StringVariable("block_pos", $block->x.",".$block->y.",".$block->z.",".$block->level->getFolderName()),
            "block_x" => new NumberVariable("block_x", $block->x),
            "block_y" => new NumberVariable("block_y", $block->y),
            "block_z" => new NumberVariable("block_z", $block->z),
            "block_level" => new StringVariable("block_level", $block->level->getFolderName()),
            "touch_face" => new NumberVariable("touch_face", $event->getFace())
        ];
        if($block instanceof SignPost) {
            $sign = $block->level->getTile($block);
            if($sign instanceof Sign) {
                $variables["sign_lines"] = new ListVariable("sign_lines", $sign->getText());
            }
        }
        return array_merge($variables, $add);
    }
}<?php

namespace aieuo\ip\manager;

use aieuo\ip\variable\StringVariable;
use aieuo\ip\variable\NumberVariable;

class ChainIfManager extends IFManager {

	public function __construct($owner) {
		parent::__construct($owner ,"chains");
	}

    public function set($key, $datas = [], $options = []) {
        $datas = $this->repairIF($datas);
        parent::set($key, $datas);
    }

    public function getReplaceDatas($datas) {
        $variables = parent::getReplaceDatas($datas);
        if(isset($datas["count"])) $variables["i"] = new NumberVariable("i", $datas["count"]);
        if(isset($datas["origin"])) {
            $origin = $datas["origin"];
            $add = [
                "origin_name" => new StringVariable("origin_name", $origin->getName()),
                "origin_pos" => new StringVariable("origin_pos", $origin->x.",".$origin->y.",".$origin->z.",".$origin->level->getFolderName()),
                "origin_x" => new NumberVariable("origin_x", $origin->x),
                "origin_y" => new NumberVariable("origin_y", $origin->y),
                "origin_z" => new NumberVariable("origin_z", $origin->z),
                "origin_level" => new StringVariable("origin_level", $origin->level->getFolderName())
            ];
            $variables = array_merge($variables, $add);
        }
        return $variables;
    }
}<?php

namespace aieuo\ip\manager;

use pocketmine\command\PluginCommand;

use aieuo\ip\variable\StringVariable;
use aieuo\ip\variable\ListVariable;

class CommandManager extends IFManager {

    private $command_list = [];

    public function __construct($owner) {
        parent::__construct($owner, "commands");
        $this->registerCommands();
    }

    public function set($key, $datas = [], $options = []) {
        $datas = $this->repairIF($datas);
        if ($options["desc"] === "") $options["desc"] = "ifPluginã§è¿œå ããã³ãã³ãã§ã";
        if ($options["perm"] === "") $options["perm"] = "ifplugin.customcommand.op";
        $datas["description"] = $options["desc"];
        $datas["permission"] = $options["perm"];
        parent::set($key, $datas);
    }

    public function add($key, $type, $id, $content, $args = []) {
        $datas = [];
        if ($this->isAdded($key))$datas = $this->get($key);
        $datas[$type][] = [
            "id" => $id,
            "content" => $content
        ];
        $this->register($key, $args["desc"], $args["perm"]);
        $this->set($key, $datas, $args);
    }

    public function remove($key) {
        $this->unregister($key);
        parent::remove($key);
    }

    public function registerCommands() {
        foreach ($this->getAll() as $command => $value) {
            $permission = $value["permission"];
            switch ($permission) {
                case 'ifplugin.customcommand.op':
                case 'ifplugin.customcommand.true':
                    break;
                case true:
                case 'true':
                case 'default':
                    $permission = "ifplugin.customcommand.true";
                    break;
                default:
                    $permission = "ifplugin.customcommand.op";
                    break;
            }
            if ($this->isSubcommand($command)) $command = $this->getOriginCommand($command);
            if (!$this->exists($command)) {
                $this->register($command, $permission, $value["description"]);
            }
        }
    }

    public function register($command, $permission = null, $description = null) {
        $permission = $permission ?? "ifplugin.customcommand.op";
        $description = $description ?? "ifPluginã§è¿œå ããã³ãã³ãã§ã";
        if ($this->isSubcommand($command)) $command = $this->getOriginCommand($command);
        if (!$this->exists($command)) {
            $newCommand = new PluginCommand($command, $this->getOwner());
            $newCommand->setDescription($description);
            $newCommand->setPermission($permission);
            $this->getServer()->getCommandMap()->register("ifPlugin", $newCommand);
            $this->command_list[$command] = $newCommand;
            return true;
        }
        return false;
    }

    public function unregister($command) {
        $count = count($this->getSubcommands($command));
        if (!$this->isSubcommand($command) and $this->isAdded($command)) $count ++;
        if ($count <= 1) {
            $this->getServer()->getCommandMap()->unregister($this->command_list[$command]);
        }
        unset($this->command_list[$command]);
    }

    public function exists($command) {
        $exist = $this->getServer()->getPluginCommand($command);
        if ($exist === null)return false;
        return true;
    }

    public function isSubcommand($command) {
        $subcommand = false;
        if (strpos($command, " ") !== false)$subcommand = true;
        return $subcommand;
    }

    public function getSubcommands($command) {
        $array = [];
        $command = explode(" ", $command)[0];
        $commands = $this->getAll();
        foreach ($commands as $cmd => $value) {
            $cmds = explode(" ", $cmd);
            if (array_shift($cmds) == $command) {
                if (isset($cmds[0])) {
                    $sub = implode(" ", $cmds);
                    $array[] = $sub;
                }
            }
        }
        return $array;
    }

    public function getOriginCommand($command) {
        if (!$this->isSubcommand($command)) return $command;
        $commands = explode(" ", $command);
        return $commands[0];
    }

    public function getReplaceDatas($datas) {
        $result = parent::getReplaceDatas($datas);
        $command = $datas["command"];
        $cmds = explode(" ", substr($command, 1));
        $result["cmd"] = new StringVariable("cmd", array_shift($cmds));
        $result["args"] = new ListVariable("args", $cmds);
        return $result;
    }
}<?php

namespace aieuo\ip\manager;

use pocketmine\Player;
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\block\SignPost;
use pocketmine\tile\Sign;

use aieuo\ip\variable\StringVariable;
use aieuo\ip\variable\NumberVariable;
use aieuo\ip\variable\ListVariable;

class EventManager extends IFManager {

	public function __construct($owner){
        parent::__construct($owner, "events");
    }

    public function get($key, $args = []){
        $datass = $this->getFromEvent($args["eventname"]);
        if(!isset($datass[$key]))return [];
        $datas = $datass[$key];
        $datas = $this->repairIF($datas);
        return $datas;
    }

    public function add($key, $type, $id, $content, $args = []){
        $datas = $this->getFromEvent($args["eventname"]);
        $datas[$key][$type][] = [
            "id" => $id,
            "content" => $content
        ];
        $this->set($args["eventname"], $datas);
    }

    public function getCount($event){
        $datas = $this->getFromEvent($event);
        return count($datas);
    }

    public function addEmpty($event) {
        $datas = $this->getFromEvent($event);
        $data = [
            "if" => [],
            "match" => [],
            "else" => []
        ];
        $datas[] = $data;
        $this->set($event, $datas);
        return count($datas) -1;
    }

    public function getFromEvent($event){
        $datas = [];
        if(isset(($all = $this->getAll())[$event]))$datas = $all[$event];
        return $datas;
    }

    public function addByEvent($event, $add) {
        $add = $this->repairIF($add);
        $datas = $this->getFromEvent($event);
        $datas[] = $add;
        $this->set($event, $datas);
    }

    public function del($key, $type, $num, $options = []) {
        $datas = $this->getFromEvent($options["eventname"]);
        if(!isset($datas[$key]))return false;
        unset($datas[$key][$type][$num]);
        $datas[$key][$type] = array_merge($datas[$key][$type]);
        $this->set($options["eventname"], $datas);
        return true;
    }

    public function updateContent($key, $type, $num, $new, $options = []) {
        $datas = $this->getFromEvent($options["eventname"]);
        if(!isset($datas[$key]))return false;
        $datas[$key][$type][$num]["content"] = $new;
        $this->set($options["eventname"], $datas);
        return true;
    }

    public function remove($key, $options = []) {
        $datas = $this->getFromEvent($options["eventname"]);
        if(!isset($datas[$key]))return false;
        unset($datas[$key]);
        $datas = array_merge($datas);
        $this->set($options["eventname"], $datas);
        return true;
    }
    public function setName($key, $name, $options = []) {
        $datas = $this->getFromEvent($options["eventname"]);
        if (!isset($datas[$key])) return false;
        $datas[$key]["name"] = $name;
        $this->set($options["eventname"], $datas);
        return true;
    }

    public function getReplaceDatas($datas){
        $result = parent::getReplaceDatas($datas);
        $event = $datas["event"];
        $eventname = $datas["eventname"];
        $variables = [];
        if ($eventname == "PlayerInteractEvent"
            or $eventname == "BlockBreakEvent"
            or $eventname == "BlockPlaceEvent"
        ){
            $block = $event->getBlock();
            $variables["block"] = new StringVariable("block", $block->__toString());
            $variables["block_name"] = new StringVariable("block_name", $block->getName());
            $variables["block_id"] = new NumberVariable("block_id", $block->getId());
            $variables["block_damage"] = new NumberVariable("block_damage", $block->getDamage());
            $variables["block_ids"] = new StringVariable("block_ids", $block->getId().":".$block->getDamage());
            $variables["block_pos"] = new StringVariable("block_pos", $block->x.",".$block->y.",".$block->z.",".$block->level->getFolderName());
            $variables["block_level"] = new StringVariable("block_level", $block->level->getFolderName());
            if($block instanceof SignPost) {
                $sign = $block->level->getTile($block);
                if($sign instanceof Sign) {
                    $variables["sign_lines"] = new ListVariable("sign_lines", $sign->getText());
                }
            }
        }
        if ($eventname == "PlayerChatEvent"
            or $eventname == "PlayerCommandPreprocessEvent"
        ){
            $variables["mes"] = new StringVariable("mes", $event->getMessage());
        }
        if($eventname == "PlayerCommandPreprocessEvent"){
            $args = explode(" ", $variables["mes"]->getValue());
            $variables["cmd"] = new StringVariable("cmd", array_shift($args));
            $variables["args"] = new ListVariable("args", $args);
        }
        if($eventname == "CraftItemEvent"){
            $inputs = $event->getInputs();
            $outputs = $event->getOutputs();
            $inputnames = [];
            $inputids = [];
            foreach ($inputs as $input) {
                $inputnames[] = $input->getName();
                $inputids[] = $input->getId().":".$input->getDamage();
            }
            $outputnames = [];
            $outputids = [];
            foreach ($outputs as $output) {
                $outputnames[] = $output->getName();
                $outputids[] = $output->getId().":".$output->getDamage();
            }
            $variables["input_name"] = new ListVariable("input_name", $inputnames);
            $variables["input_id"] = new ListVariable("input_id", $inputids);
            $variables["output_name"] = new ListVariable("output_name", $outputnames);
            $variables["output_id"] = new ListVariable("output_id", $outputids);
        }
        if($eventname == "EntityDamageEvent"){
            $entity = $event->getEntity();
            $variables["event_damage"] = new NumberVariable("event_damage", $event->getBaseDamage());
            $variables["evant_cause"] = new NumberVariable("evant_cause", $event->getCause());
            if($event instanceof EntityDamageByEntityEvent){
                $damager = $event->getDamager();
                if($damager instanceof Player){
                    $variables["attacker"] = new StringVariable("attacker", $damager->__toString());
                    $variables["attacker_name"] = new StringVariable("attacker_name", $damager->getName());
                    $variables["attacker_pos"] = new StringVariable("attacker_pos", $damager->x.",".$damager->y.",".$damager->z.",".$damager->level->getFolderName());
                    $variables["attacker_x"] = new NumberVariable("attacker_x", $damager->x);
                    $variables["attacker_y"] = new NumberVariable("attacker_y", $damager->y);
                    $variables["attacker_z"] = new NumberVariable("attacker_z", $damager->z);
                    $variables["attacker_level"] = new StringVariable("attacker_level", $damager->level->getFolderName());
                }
            }
        }
        if ($eventname == "EntityAttackEvent") {
            $entity = $event->getEntity();
            $variables["event_damage"] = new NumberVariable("event_damage", $event->getBaseDamage());
            $variables["evant_cause"] = new NumberVariable("evant_cause", $event->getCause());
            if ($event instanceof EntityDamageByEntityEvent) {
                $player = $event->getEntity();
                if ($player instanceof Player) {
                    $variables["target"] = new StringVariable("target", $player->__toString());
                    $variables["target_name"] = new StringVariable("target_name", $player->getName());
                    $variables["target_pos"] = new StringVariable("target_pos", $player->x.",".$player->y.",".$player->z.",".$player->level->getFolderName());
                    $variables["target_x"] = new NumberVariable("target_x", $player->x);
                    $variables["target_y"] = new NumberVariable("target_y", $player->y);
                    $variables["target_z"] = new NumberVariable("target_z", $player->z);
                    $variables["target_level"] = new StringVariable("target_level", $player->level->getFolderName());
                }
            }
        }
        if($eventname == "EntityLevelChangeEvent"){
            $variables["origin_level"] = new StringVariable("origin_level", $event->getOrigin()->getFolderName());
            $variables["target_level"] = new StringVariable("target_level", $event->getTarget()->getFolderName());
        }
        return array_merge($result, $variables);
    }
}<?php

namespace aieuo\ip\manager;

use aieuo\ip\variable\StringVariable;
use aieuo\ip\variable\NumberVariable;
use aieuo\ip\variable\ListVariable;
use aieuo\ip\ifPlugin;
use aieuo\ip\form\Elements;

class FormIFManager extends IFManager {

    public function __construct($owner) {
        parent::__construct($owner, "forms");
    }

    public function set($key, $datas = [], $options = []) {
        if (!isset($datas["ifs"])) $datas["ifs"] = [];
        parent::set($key, $datas);
    }

    public function get($key, $options = []) {
        if (!$this->isAdded($key)) return [];
        $datas = parent::get($key);
        if (!isset($datas["ifs"][$options["place"]])) return $this->repairIF([]);
        $ifdata = $this->repairIF($datas["ifs"][$options["place"]]);
        return $ifdata;
    }

    public function getIF($key) {
        return parent::get($key);
    }

    public function add($key, $type, $id, $content, $options = []) {
        $datas = $this->getIF($key);
        if (!isset($options["place"])) {
            $data = $this->repairIF([]);
            $data[$type][] = [
                "id" => $id,
                "content" => $content
            ];
            $datas["ifs"][] = $data;
        } else {
            $datas["ifs"][$options["place"]][$type][] = [
                "id" => $id,
                "content" => $content
            ];
            $datas["ifs"][$options["place"]] = $this->repairIF($datas["ifs"][$options["place"]]);
        }
        $this->set($key, $datas);
    }

    public function updateContent($key, $type, $num, $new, $options = []) {
        if (!$this->isAdded($key)) return false;
        $datas = $this->getIF($key);
        $datas["ifs"][$options["place"]][$type][$num]["content"] = $new;
        $this->set($key, $datas);
        return true;
    }

    public function setName($key, $name, $options = []) {
        if (!$this->isAdded($key)) return false;
        $datas = $this->getIF($key);
        $datas["ifs"][$options["place"]]["name"] = $name;
        $this->set($key, $datas);
        return true;
    }

    public function del($key, $type, $num, $options = []) {
        if (!$this->isAdded($key)) return false;
        $datas = $this->getIF($key);
        unset($datas["ifs"][$options["place"]][$type][$num]);
        $datas["ifs"][$options["place"]][$type] = array_merge($datas["ifs"][$options["place"]][$type]);
        $this->set($key, $datas);
        return true;
    }

    public function remove($key, $options = []) {
        if (!$this->isAdded($key)) return false;
        $datas = $this->getIF($key);
        unset($datas["ifs"][$options["place"]]);
        $datas["ifs"] = array_merge($datas["ifs"]);
        $this->set($key, $datas);
        return true;
    }

    public function removeIF($key) {
        parent::remove($key);
    }

    public function getReplaceDatas($datas) {
        $variables = parent::getReplaceDatas($datas);
        $variables["form_name"] = new StringVariable("form_name", $datas["form_name"]);
        $form = $datas["form"];
        switch ($form["type"]) {
            case 'form':
                $variables["form_data"] = new NumberVariable("form_data", $datas["form_data"]);
                $variables["form_button"] = new StringVariable("form_button", $form["buttons"][$datas["form_data"]]["text"]);
                break;
            case "modal":
                $variables["form_data"] = new StringVariable("form_data", $datas["form_data"]?"true":"false");
                break;
            case "custom_form":
                $add = [];
                $dropdowns = [];
                foreach ($datas["form_data"] as $key => $value) {
                    $content = $form["content"][$key];
                    switch ($content["type"]) {
                        case 'label':
                        case 'input':
                        case "slider":
                            $add[] = $value;
                            break;
                        case "dropdown":
                            $add[] = $value;
                            $dropdowns[] = $content["options"][$value];
                            break;
                        case "toggle":
                            $add[] = $value ? "true" : "false";
                            break;
                    }
                }
                $variables["form_data"] = new ListVariable("form_data", $add);
                $variables["form_dropdown"] = new ListVariable("form_dropdown", $dropdowns);
                break;
        }
        return $variables;
    }

    public function getForm($name, $replaces) {
        $form = json_decode($this->getIF($name)["form"], true);
        $variableHelper = ifPlugin::getInstance()->getVariableHelper();
        $form["title"] = $variableHelper->replaceVariables($form["title"], $replaces);
        switch ($form["type"]) {
            case "modal":
                $form["content"] = $variableHelper->replaceVariables($form["content"], $replaces);
                $form["button1"] = $variableHelper->replaceVariables($form["button1"], $replaces);
                $form["button2"] = $variableHelper->replaceVariables($form["button2"], $replaces);
                break;
            case "form":
                $form["content"] = $variableHelper->replaceVariables($form["content"], $replaces);
                $buttons = [];
                foreach ($form["buttons"] as $button) {
                    $variables = $variableHelper->findVariables($button["text"], $replaces);
                    foreach ($variables as $variableName => $variable) {
                        if ($variable instanceof ListVariable) {
                            $add = array_map(function ($value) use ($button, $variableName, $variableHelper, $replaces) {
                                $text = str_replace("{".$variableName."}", $value, $button["text"]);
                                $text = $variableHelper->replaceVariables($text, $replaces);
                                return Elements::getButton($text);
                            }, $variable->getValue());
                            $buttons = array_merge($buttons, $add);
                            continue 2;
                        }
                    }
                    $buttons[] = Elements::getButton($variableHelper->replaceVariables($button["text"], $replaces));
                }
                $form["buttons"] = $buttons;
                break;
            case "custom_form":
                $contents = [];
                foreach ($form["content"] as $content) {
                    $content["text"] = $variableHelper->replaceVariables($content["text"], $replaces);
                    switch ($content["type"]) {
                        case "input":
                            $content["default"] = $variableHelper->replaceVariables($content["default"], $replaces);
                            $content["placeholder"] = $variableHelper->replaceVariables($content["placeholder"], $replaces);
                            break;
                        case "dropdown":
                            $options = [];
                            foreach ($content["options"] as $option) {
                                $variables = $variableHelper->findVariables($option, $replaces);
                                foreach ($variables as $variableName => $variable) {
                                    if ($variable instanceof ListVariable) {
                                        $add = array_map(function ($value) use ($option, $variableName, $variableHelper, $replaces) {
                                            $text = str_replace("{".$variableName."}", $value, $option);
                                            return $variableHelper->replaceVariables($text, $replaces);
                                        }, $variable->getValue());
                                        $options = array_merge($options, $add);
                                        continue 2;
                                    }
                                }
                                $options[] = $variableHelper->replaceVariables($option, $replaces);
                            }
                            $content["options"] = $options;
                            break;
                    }
                    $contents[] = $content;
                }
                $form["content"] = $contents;
                break;
        }
        return $form;
    }
}<?php

namespace aieuo\ip\manager;

use pocketmine\utils\Config;

use aieuo\ip\IFAPI;

class IFManager extends IFAPI {

    const BLOCK = 0;
    const COMMAND = 1;
    const EVENT = 2;
    const CHAIN = 3;

    private $owner;
    private $config;

    public function __construct($owner, $type) {
        $this->owner = $owner;
        $this->config = new Config($owner->getDataFolder() . $type. ".yml", Config::YAML, []);
    }

    public function getOwner() {
        return $this->owner;
    }

    public function getServer() {
        return $this->getOwner()->getServer();
    }

    /**
     * @return Config
     */
    public function getConfig() {
        return $this->config;
    }

    /**
     * @param  string  $key
     * @param  array   $options
     * @return boolean
     */
    public function isAdded($key, $options = []) {
        return $this->config->exists($key);
    }

    /**
     * @param  strign $key
     * @param  bool $options
     * @return bool | array
     */
    public function get($key, $options = []) {
        if (!$this->isAdded($key)) return false;
        $datas = $this->config->get($key);
        $datas = $this->repairIF($datas);
        return $datas;
    }

    /**
     * @return array
     */
    public function getAll() {
        return $this->config->getAll();
    }

    /**
     * @param string $key
     * @param string $type
     * @param int $id
     * @param string $content
     * @param array  $options
     */
    public function add($key, $type, $id, $content, $options = []) {
        $datas = [];
        if ($this->isAdded($key))$datas = $this->get($key);
        $datas = $this->repairIF($datas);
        $datas[$type][] = [
            "id" => $id,
            "content" => $content
        ];
        $this->config->set($key, $datas);
    }

    /**
     * @param string $key
     * @param array  $datas
     * @param array  $options
     */
    public function set($key, $datas = [], $options = []) {
        $this->config->set($key, $datas);
    }

    /**
     * @param  string $key
     * @param  string $type
     * @param  int $num
     * @return bool
     */
    public function del($key, $type, $num, $options = []) {
        if (!$this->isAdded($key)) return false;
        $datas = $this->get($key);
        unset($datas[$type][$num]);
        $datas[$type] = array_merge($datas[$type]);
        $this->config->set($key, $datas);
        return true;
    }

    /**
     * @param  string $key
     * @param  string $type
     * @param  int $num
     * @return bool
     */
    public function updateContent($key, $type, $num, $new, $options = []) {
        if (!$this->isAdded($key)) return false;
        $datas = $this->get($key);
        $datas[$type][$num]["content"] = $new;
        $this->config->set($key, $datas);
        return true;
    }

    /**
     * @param string $key
     * @param string $name
     * @param array $options
     */
    public function setName($key, $name, $options = []) {
        if (!$this->isAdded($key)) return false;
        $datas = $this->get($key);
        $datas["name"] = $name;
        $this->config->set($key, $datas);
        return true;
    }

    /**
     * @param  string $key
     */
    public function remove($key) {
        $this->config->remove($key);
    }

    public function save() {
        $this->config->save();
    }

    /**
     * @param  array $datas
     * @return array
     */
    public function repairIF($datas) {
        if (!isset($datas["if"]))$datas["if"] = [];
        if (!isset($datas["match"]))$datas["match"] = [];
        if (!isset($datas["else"]))$datas["else"] = [];
        return $datas;
    }

    public function getReplaceDatas($datas) {
        return parent::getReplaceDatas($datas);
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\entity\Effect;
use pocketmine\entity\EffectInstance;

use aieuo\ip\utils\Language;
use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class AddEffect extends Process {

    protected $id = self::ADD_EFFECT;
    protected $name = "@process.addeffect.name";
    protected $description = "@process.addeffect.description";

    public function getMessage() {
        $effect = $this->getEffect();
        if (!($effect instanceof EffectInstance)) return false;
        return Language::get("process.addeffect.detail", [$effect->getId(), $effect->getAmplifier(), $effect->getDuration() / 20]);
    }

    public function getEffect() {
        return $this->getValues();
    }

    public function setEffect(EffectInstance $effect) {
        $this->setValues($effect);
    }

    public function parse(string $content) {
        $args = explode(",", $content);
        if (!isset($args[1]) or (int)$args[1] <= 0) $args[1] = 1;
        if (!isset($args[2]) or (float)$args[2] <= 0) $args[2] = 30;
        $effect = Effect::getEffectByName($args[0]);
        $args[1] --;
        if ($effect === null) $effect = Effect::getEffect((int)$args[0]);
        if ($effect === null) return null;
        return new EffectInstance($effect, (float)$args[2] * 20, (int)$args[1], true);
    }

    public function execute() {
        $player = $this->getPlayer();
        $effect = $this->getEffect();
        if (!($effect instanceof EffectInstance)) {
            if ($effect === false) $player->sendMessage(Language::get("input.invalid", [$this->getName()]));
            if ($effect === null) $player->sendMessage(Language::get("process.addeffect.notfound"));
            return;
        }
        $player->addEffect($effect);
    }


    public function getEditForm(string $default = "", string $mes = "") {
        $effect = $this->parse($default);
        $id = $default;
        $power = "";
        $time = "";
        if ($effect instanceof EffectInstance) {
            $id = $effect->getId();
            $power = $effect->getAmplifier() + 1;
            $time = $effect->getDuration() / 20;
        } elseif ($default !== "") {
            if ($effect === false)$mes .= Language::get("form.error");
            if ($effect === null)$mes .= Language::get("process.addeffect.notfound");
        }
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("process.addeffect.form.id"), Language::get("input.example", ["1"]), $id),
                Elements::getInput(Language::get("process.addeffect.form.power"), Language::get("input.example", ["5"]), $power),
                Elements::getInput(Language::get("process.addeffect.form.time"), Language::get("input.example", ["5"]), $time),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        $effect_str = $datas[1].",".$datas[2].",".$datas[3];
        if ($datas[1] === "" or $datas[2] === "" or $datas[3] === "") $status = null;
        return ["status" => $status, "contents" => $effect_str, "delete" => $datas[4], "cancel" => $datas[5]];
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\item\enchantment\Enchantment;
use pocketmine\item\enchantment\EnchantmentInstance;

use aieuo\ip\utils\Language;
use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class AddEnchantment extends Process {

    protected $id = self::ADD_ENCHANTMENT;
    protected $name = "@process.addenchant.name";
    protected $description = "@process.addenchant.description";

    public function getMessage() {
        $enchant = $this->getEnchantment();
        if (!($enchant instanceof EnchantmentInstance)) return false;
        return Language::get("process.addenchant.detail", [$enchant->getId(), $enchant->getLevel()]);
    }

    public function getEnchantment() {
        return $this->getValues();
    }

    public function setEnchantment(EnchantmentInstance $enchant) {
        $this->setValues($enchant);
    }

    public function parse(string $content) {
        $args = explode(",", $content);
        if (!isset($args[1]) or (int)$args[1] <= 0) $args[1] = 1;
        if (is_numeric($args[0])) {
            $enchantment = Enchantment::getEnchantment((int)$args[0]);
        } else {
            $enchantment = Enchantment::getEnchantmentByName($args[0]);
        }
        if (!($enchantment instanceof Enchantment)) return null;
        return new EnchantmentInstance($enchantment, (int)$args[1]);
    }

    public function execute() {
        $player = $this->getPlayer();
        $enchant = $this->getEnchantment();
        if (!($enchant instanceof EnchantmentInstance)) {
            if ($enchant === false) $player->sendMessage(Language::get("input.invalid", [$this->getName()]));
            if ($enchant === null) $player->sendMessage(Language::get("process.addenchant.notfound"));
            return;
        }
        $item = $player->getInventory()->getItemInHand();
        $item->addEnchantment($enchant);
        $player->getInventory()->setItemInHand($item);
    }


    public function getEditForm(string $default = "", string $mes = "") {
        $enchant = $this->parse($default);
        $id = $default;
        $power = "";
        if ($enchant instanceof EnchantmentInstance) {
            $id = $enchant->getId();
            $power = $enchant->getLevel();
        } elseif ($default !== "") {
            if ($enchant === false) $mes .= Language::get("form.error");
            if ($enchant === null) $mes .= Language::get("process.addenchant.notfound");
        }
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("process.addenchant.form.id"), Language::get("input.example", ["1"]), $id),
                Elements::getInput(Language::get("process.addenchant.form.power"), Language::get("input.example", ["5"]), $power),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        $enchant_str = $datas[1].",".$datas[2];
        if ($datas[1] === "" or $datas[2] === "") $status = null;
        return ["status" => $status, "contents" => $enchant_str, "delete" => $datas[3], "cancel" => $datas[4]];
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\item\Item;

use aieuo\ip\utils\Language;

class AddItem extends TypeItem {

    protected $id = self::ADD_ITEM;
    protected $name = "@process.additem.name";
    protected $description = "@process.additem.description";

    public function getMessage() {
        $item = $this->getItem();
        if (!($item instanceof Item)) return false;
        return Language::get("process.additem.detail", [$item->getId(), $item->getDamage(), $item->getName(), $item->getCount()]);
    }

    public function execute() {
        $player = $this->getPlayer();
        $item = $this->getItem();
        if (!($item instanceof Item)) {
            $player->sendMessage(Language::get("input.invalid", [$this->getName()]));
            return;
        }
        $player->getInventory()->addItem($item);
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\utils\Language;
use aieuo\ip\ifPlugin;

class AddMoney extends TypeMoney {

    protected $id = self::ADDMONEY;
    protected $name = "@process.addmoney.name";
    protected $description = "@process.addmoney.description";

    public function getMessage() {
        return Language::get("process.addmoney.detail", [$this->getAmount()]);
    }

    public function execute() {
        $player = $this->getPlayer();
        $economy = ifPlugin::getInstance()->getEconomy();
        if ($economy === null) {
            $player->sendMessage(Language::get("economy.notfound"));
            return;
        }
        $economy->addMoney($player->getName(), $this->getAmount());
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\ifPlugin;
use aieuo\ip\variable\Variable;

use aieuo\ip\utils\Language;
use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class AddVariable extends Process {

    protected $id = self::ADD_VARIABLE;
    protected $name = "@process.addvariable.name";
    protected $description = "@process.addvariable.description";

    public function getMessage() {
        $variable = $this->getVariable();
        if ($variable === false) return false;
        return Language::get("process.addvariable.detail", [$variable->getName(), $variable->getString()]);
    }

    public function getVariable() {
        return $this->getValues();
    }

    public function setVariable(Variable $variable) {
        $this->setValues($variable);
    }

    public function parse(string $content) {
        $datas = explode(";", $content);
        if (!isset($datas[1]) or $datas[1] === "") return false;
        $helper = ifPlugin::getInstance()->getVariableHelper();
        $value = $helper->changeType($datas[1]);
        return Variable::create($datas[0], $value, $helper->getType($datas[1]));
    }

    public function execute() {
        $player = $this->getPlayer();
        $variable = $this->getVariable();
        if ($variable === false) {
            $player->sendMessage(Language::get("input.invalid", [$this->getName()]));
            return;
        }
        ifPlugin::getInstance()->getVariableHelper()->add($variable);
    }


    public function getEditForm(string $default = "", string $mes = "") {
        $var = $this->parse($default);
        $name = $default;
        $value = "";
        if ($var instanceof Variable) {
            $name = $var->getName();
            $value = $var->getString();
            if (is_numeric($value) and $var->getType() === Variable::STRING) {
                $value = "(str)".$value;
            } elseif (!is_numeric($value) and $var->getType() === Variable::NUMBER) {
                $value = "(num)".$value;
            }
        } elseif ($default !== "") {
            $mes .= Language::get("form.error");
        }
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("process.addvariable.form.name"), Language::get("input.example", ["aieuo"]), $name),
                Elements::getInput(Language::get("process.addvariable.form.value"), Language::get("input.example", ["1000"]), $value),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        $var_str = $datas[1].";".$datas[2];
        if ($datas[1] === "" or $datas[2] === "") {
            $status = null;
        } else {
            $var = $this->parse($var_str);
            if ($var === false) $status = false;
        }
        return ["status" => $status, "contents" => $var_str, "delete" => $datas[3], "cancel" => $datas[4]];
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\event\entity\EntityDamageEvent;

use aieuo\ip\utils\Language;
use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class Attack extends Process {

    protected $id = self::ATTACK;
    protected $name = "@process.attack.name";
    protected $description = "@process.attack.description";

    public function getMessage() {
        $damage = $this->getDamage();
        if ($damage === false) return false;
        return Language::get("process.attack.detail", [$damage]);
    }

    public function getDamage() {
        return $this->getValues();
    }

    public function setDamage(float $damage) {
        $this->setValues($damage);
    }

    public function parse(string $content) {
        $damage = (float)$content;
        if ($damage <= 0) return false;
        return $damage;
    }

    public function execute() {
        $player = $this->getPlayer();
        $damage = $this->getDamage();
        if ($damage === false) {
            $player->sendMessage(Language::get("process.attack.error", [$this->getName()]));
            return;
        }
        $event = new EntityDamageEvent($player, EntityDamageEvent::CAUSE_ENTITY_ATTACK, (float)$damage);
        $player->attack($event);
    }

    public function getEditForm(string $default = "", string $mes = "") {
        $damage = $this->parse($default);
        if ($damage === false) {
            if ($default !== "") $mes .= Language::get("process.attack.form.error");
            $damage = $default;
        }
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("process.attack.form.damage"), Language::get("input.example", ["5"]), $damage),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        if ($datas[1] === "") {
            $status = null;
        } else {
            $damage = $this->parse($datas[1]);
            if ($damage === false) $status = false;
        }
        return ["status" => $status, "contents" => $datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\Server;

use aieuo\ip\utils\Language;

class BroadcastMessage extends TypeMessage {

    protected $id = self::BROADCASTMESSAGE;
    protected $name = "@process.broadcastmessage.name";
    protected $description = "@process.broadcastmessage.description";

    public function getMessage() {
        $message = $this->getSendMessage();
        return Language::get("process.broadcastmessage.detail", [$message]);
    }

    public function execute() {
        $player = $this->getPlayer();
        Server::getInstance()->broadcastMessage($this->getSendMessage());
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\ifPlugin;
use aieuo\ip\variable\Variable;
use aieuo\ip\variable\StringVariable;
use aieuo\ip\variable\NumberVariable;
use aieuo\ip\variable\ListVariable;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Language;

class Calculation extends Process {

    protected $id = self::CALCULATION;
    protected $name = "@process.calculation.name";
    protected $description = "@process.calculation.description";

    const ERROR = -1;
    const ADDITION = 0;
    const SUBTRACTION = 1;
    const MULTIPLICATION = 2;
    const DIVISION = 3;
    const MODULO = 4;

    public function getMessage() {
        if ($this->getValues() === false) return false;
        $variable1 = $this->getValue1();
        $variable2 = $this->getValue2();
        for ($i = 1; $i <= 2; $i ++) {
            ${"value".$i} = ${"variable".$i}->getValue();

            if (${"variable".$i} instanceof StringVariable and is_numeric(${"value".$i})) {
                ${"value".$i} = "(str)".${"value".$i};
            } elseif (${"variable".$i} instanceof NumberVariable and !is_numeric(${"value".$i})) {
                ${"value".$i} = "(num)".${"value".$i};
            } elseif (${"variable".$i} instanceof ListVariable) {
                ${"value".$i} = ${"variable".$i}->toStringVariable()->getValue();
            }
        }
        $operator = $this->getOperator();
        switch ($operator) {
            case self::ADDITION:
                $mes = Language::get("process.calculation.detail.add", [$value1, $value2]);
                break;
            case self::SUBTRACTION:
                $mes = Language::get("process.calculation.detail.sub", [$value1, $value2]);
                break;
            case self::MULTIPLICATION:
                $mes = Language::get("process.calculation.detail.mul", [$value1, $value2]);
                break;
            case self::DIVISION:
                $mes = Language::get("process.calculation.detail.div", [$value1, $value2]);
                break;
            case self::MODULO:
                $mes = Language::get("process.calculation.detail.mod", [$value1, $value2]);
                break;
            default:
                return false;
        }
        return $mes;
    }

    public function getValue1() {
        return $this->getValues()[0];
    }

    public function getValue2() {
        return $this->getValues()[1];
    }

    public function getOperator() {
        return $this->getValues()[2];
    }

    public function getAssignName() {
        return $this->getValues()[3];
    }

    public function setNumbers(Variable $value1, Variable $value2, int $ope, string $assign = "result") {
        $this->setValues([$value1, $value2, $ope, $assign]);
    }

    public function parse(string $numbers) {
        if (!preg_match("/\s*(.+)\s*\[ope:([0-9])\]\s*(.+)\s*;\s*([^;]*)\s*$/", $numbers, $matches)) return false;
        $helper = ifPlugin::getInstance()->getVariableHelper();
        $operator = (int)$matches[2];
        $value1 = $matches[1];
        $value2 = $matches[3];
        $assign = $matches[4] === "" ? "result" : $matches[4];
        $type1 = $helper->getType($value1);
        $value1 = $helper->changeType($value1);
        $var1 = Variable::create("value1", $value1, $type1);
        $type2 = $helper->getType($value2);
        $value2 = $helper->changeType($value2);
        $var2 = Variable::create("value2", $value2, $type2);
        return [$var1, $var2, $operator, $assign];
    }

    public function execute() {
        $player = $this->getPlayer();
        if ($this->getValues() === false) {
            $player->sendMessage(Language::get("input.invalid", [$this->getName()]));
            return;
        }
        $variable1 = $this->getValue1();
        $variable2 = $this->getValue2();
        $operator = $this->getOperator();
        $name = $this->getAssignName();
        switch ($operator) {
            case self::ADDITION:
                $result = $variable1->addition($variable2, $name);
                break;
            case self::SUBTRACTION:
                $result = $variable1->subtraction($variable2, $name);
                break;
            case self::MULTIPLICATION:
                $result = $variable1->multiplication($variable2, $name);
                break;
            case self::DIVISION:
                $result = $variable1->division($variable2, $name);
                break;
            case self::MODULO:
                $result = $variable1->modulo($variable2, $name);
                break;
            default:
                $player->sendMessage(Language::get("process.calculation.invalid", [$this->getName()]));
                return;
        }
        if ($result->getName() == "ERROR") {
            $player->sendMessage(Language::get("process.calculation.error"), [$this->getName(), $result->getValue()]);
            return;
        }
        ifPlugin::getInstance()->getVariableHelper()->add($result);
    }

    public function getEditForm(string $default = "", string $mes = "") {
        $values = $this->parse($default);
        $value0 = $default;
        $value1 = "";
        $operator = self::ADDITION;
        $name = "";
        if ($values !== false) {
            for ($i = 0; $i <= 1; $i ++) {
                ${"value".$i} = $values[$i]->getValue();

                if ($values[$i] instanceof StringVariable and is_numeric(${"value".$i})) {
                    ${"value".$i} = "(str)".${"value".$i};
                } elseif ($values[$i] instanceof NumberVariable and !is_numeric(${"value".$i})) {
                    ${"value".$i} = "(num)".${"value".$i};
                } elseif ($values[$i] instanceof ListVariable) {
                    ${"value".$i} = $values[$i]->toStringVariable()->getValue();
                }
            }
            $operator = $values[2];
            $name = $values[3];
        } elseif ($default !== "") {
            $mes .= Language::get("form.error");
        }
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("process.calculation.form.value1"), Language::get("input.example", ["100"]), $value0),
                Elements::getDropdown(Language::get("process.calculation.form.operator"), [
                    Language::get("process.calculation.form.operator.add"),
                    Language::get("process.calculation.form.operator.sub"),
                    Language::get("process.calculation.form.operator.mul"),
                    Language::get("process.calculation.form.operator.div"),
                    Language::get("process.calculation.form.operator.mod"),
                ], $operator),
                Elements::getInput(Language::get("process.calculation.form.value2"), Language::get("input.example", ["50"]), $value1),
                Elements::getInput(Language::get("process.calculation.form.result"), Language::get("input.example", ["aieuo"]), $name),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        $values_str = $datas[1]."[ope:".$datas[2]."]".$datas[3].";".$datas[4];
        if ($datas[1] === "" or $datas[2] === "" or $datas[3] === "") {
            $status = null;
        } else {
            $values = $this->parse($values_str);
            if ($values === false) $status = false;
        }
        return ["status" => $status, "contents" => $values_str, "delete" => $datas[5], "cancel" => $datas[6]];
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\Server;

use aieuo\ip\utils\Language;

class Command extends TypeCommand {

    protected $id = self::COMMAND;
    protected $name = "@process.command.name";
    protected $description = "@process.command.description";

    public function getMessage() {
        $command = $this->getCommand();
        return Language::get("process.command.detail", [$command]);
    }

    public function execute() {
        $player = $this->getPlayer();
        Server::getInstance()->dispatchCommand($player, $this->getCommand());
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\Server;
use pocketmine\command\ConsoleCommandSender;

use aieuo\ip\utils\Language;

class CommandConsole extends TypeCommand {

    protected $id = self::COMMAND_CONSOLE;
    protected $name = "@process.commandconsole.name";
    protected $description = "@process.commandconsole.description";

    public function getMessage() {
        $command = $this->getCommand();
        return Language::get("process.commandconsole.detail", [$command]);
    }

    public function execute() {
        Server::getInstance()->dispatchCommand(new ConsoleCommandSender, $this->getCommand());
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\event\Event;

use aieuo\ip\ifPlugin;
use aieuo\ip\utils\Language;
use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;

class Cooperation extends Process {

    protected $id = self::COOPERATION;
    protected $name = "@process.cooperation.name";
    protected $description = "@process.cooperation.description";

    public function getMessage() {
        $name = $this->getCooperationName();
        return Language::get("process.cooperation.detail", [$name]);
    }

    public function getCooperationName() {
        return $this->getValues();
    }

    public function setCooperationName(string $name) {
        $this->setValues($name);
    }

    public function execute() {
        $player = $this->getPlayer();
        $manager = ifPlugin::getInstance()->getChainManager();
        if (!$manager->isAdded($this->getCooperationName())) {
            $player->sendMessage(Language::get("process.cooperation.notfount"));
            return;
        }
        $datas = $manager->get($this->getCooperationName());
        $options = [
            "player" => $player,
        ];
        if ($this->getEvent() instanceof Event) $options["event"] = $this->getEvent();
        $manager->executeIfMatchCondition(
            $player,
            $datas["if"],
            $datas["match"],
            $datas["else"],
            $options
        );
    }

    public function getEditForm(string $default = "", string $mes = "") {
        $manager = ifPlugin::getInstance()->getChainManager();
        if ($default !== "" and !$manager->isAdded($default)) $mes .= Language::get("process.cooperation.notfount");
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("process.cooperation.form.name"), Language::get("input.example", ["aieuo"]), $default),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        if ($datas[1] === "") $status = null;
        return ["status" => $status, "contents" => $datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\event\Event;

use aieuo\ip\ifPlugin;
use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Language;

class CooperationRepeat extends Process {

    protected $id = self::COOPERATION_REPEAT;
    protected $name = "@process.cooperationrepeat.name";
    protected $description = "@process.cooperationrepeat.description";

    public function getMessage() {
        $name = $this->getCooperationName();
        $count = $this->getCount();
        return Language::get("process.cooperationrepeat.detail", [$name, $count]);
    }

    public function getCooperationName() {
        return $this->getValues()[0];
    }

    public function getCount() {
        return $this->getValues()[1];
    }

    public function setNames(string $name, int $count) {
        $this->setValues([$name, $count]);
    }

    public function parse(string $content) {
        $datas = explode(";", $content);
        if (!isset($datas[1])) return false;
        $count = array_pop($datas);
        $name = implode(";", $datas);
        return [$name, $count];
    }

    public function execute() {
        $player = $this->getPlayer();
        $manager = ifPlugin::getInstance()->getChainManager();
        if (!$manager->isAdded($this->getCooperationName())) {
            $player->sendMessage(Language::get("process.cooperation.notfound"));
            return;
        }
        $datas = $manager->get($this->getCooperationName());
        $count = $this->getCount();
        for ($i = 0; $i < $count; $i ++) {
            $options = [
                "player" => $player,
                "count" => $i,
            ];
            if ($this->getEvent() instanceof Event) $options["event"] = $this->getEvent();
            $manager->executeIfMatchCondition(
                $player,
                $datas["if"],
                $datas["match"],
                $datas["else"],
                $options
            );
        }
    }

    public function getEditForm(string $default = "", string $mes = "") {
        $manager = ifPlugin::getInstance()->getChainManager();
        $names = $this->parse($default);
        $name = $default;
        $count = "";
        if ($names === false and $default !== "") {
            $mes .= Language::get("form.error");
        } else {
            $name = $names[0];
            $count = $names[1];
        }
        if ($default !== "" and !$manager->isAdded($name)) $mes .= Language::get("process.cooperation.notfound");
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("process.cooperation.form.name"), Language::get("input.example", ["aieuo"]), $name),
                Elements::getInput(Language::get("process.cooperationrepeat.form.count"), Language::get("input.example", ["5"]), $count),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        $status = true;
        if ($datas[1] === "" or $datas[2] === "") {
            $status = null;
        } else {
            $names = $this->parse($datas[1].";".$datas[2]);
            if ($names === false) $status = false;
        }
        return ["status" => $status, "contents" => $datas[1].";".$datas[2], "delete" => $datas[3], "cancel" => $datas[4]];
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\ifPlugin;
use aieuo\ip\task\DelayedCommandTask;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Language;

class DelayedCommand extends Process {

    protected $id = self::DELAYED_COMMAND;
    protected $name = "@process.delayedcommand.name";
    protected $description = "@process.delayedcommand.description";

    public function getMessage() {
        if ($this->getValues() === false) return false;
        $command = $this->getCommand();
        $time = $this->getTime();
        return Language::get("process.delayedcommand.detail", [$time, $command]);
    }

    public function getTime() {
        return $this->getValues()[1];
    }

    public function getCommand() {
        return $this->getValues()[0];
    }

    public function setCommands(string $command, int $time) {
        $this->setValues($command, $time);
    }

    public function parse(string $commands) {
        if (!preg_match("/([0-9]+),(.+)/", $commands, $matches)) return false;
        return [$matches[2], (int)$matches[1]];
    }

    public function execute() {
        $player = $this->getPlayer();
        if ($this->getValues() === false) {
            $player->sendMessage(Language::get("input.invalid", [$this->getName()]));
            return;
        }
        $time = $this->getTime();
        $command = $this->getCommand();
        ifPlugin::getInstance()->getScheduler()->scheduleDelayedTask(new DelayedCommandTask($player, $command), $time*20);
    }

    public function getEditForm(string $default = "", string $mes = "") {
        $commands = $this->parse($default);
        $command = $default;
        $time = "";
        if ($commands !== false) {
            $command = $commands[0];
            $time = $commands[1];
        } elseif ($default !== "") {
            $mes .= Language::get("form.error");
        }
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("process.delayedcommand.form.command"), Language::get("input.example", ["help"]), $command),
                Elements::getInput(Language::get("process.delayedcommand.form.time"), Language::get("input.example", ["10"]), $time),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        if ($datas[1] === "" or $datas[2] === "") {
            $status = null;
        } else {
            $value = $this->parse($datas[2].",".$datas[1]);
            if ($value === false) $status = false;
        }
        return ["status" => $status, "contents" => $datas[2].",".$datas[1], "delete" => $datas[3], "cancel" => $datas[4]];
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\ifPlugin;
use pocketmine\command\ConsoleCommandSender;
use aieuo\ip\task\DelayedCommandTask;
use aieuo\ip\utils\Language;

class DelayedCommandConsole extends DelayedCommand {

    protected $id = self::DELAYED_COMMAND_CONSOLE;
    protected $name = "@process.delayedcommandconsole.name";
    protected $description = "@process.delayedcommandconsole.description";

    public function getMessage() {
        if ($this->getValues() === false) return false;
        $command = $this->getCommand();
        $time = $this->getTime();
        return Language::get("process.delayedcommandconsole.detail", [$time, $command]);
    }

    public function execute() {
        $player = $this->getPlayer();
        if ($this->getValues() === false) {
            $player->sendMessage(Language::get("input.invalid", [$this->getName()]));
            return;
        }
        $time = $this->getTime();
        $command = $this->getCommand();
        ifPlugin::getInstance()->getScheduler()->scheduleDelayedTask(new DelayedCommandTask(new ConsoleCommandSender(), $command), $time*20);
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\ifPlugin;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Language;

class DeleteVariable extends Process {

    protected $id = self::DELETE_VARIABLE;
    protected $name = "@process.deletevariable.name";
    protected $description = "@process.deletevariable.description";

    public function getMessage() {
        return Language::get("process.deletevariable.detail", [$this->getVariableName()]);
    }

    public function getVariableName() {
        return $this->getValues();
    }

    public function setVariableName(string $variable) {
        $this->setValues($variable);
    }

    public function execute() {
        ifPlugin::getInstance()->getVariableHelper()->del($this->getVariableName());
    }


    public function getEditForm(string $default = "", string $mes = "") {
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("process.deletevariable.form.name"), Language::get("input.example", ["aieuo"]), $default),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        if ($datas[1] === "") $status = null;
        return ["status" => $status, "contents" => $datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\utils\Language;

class DoNothing extends Process {

    protected $id = self::DO_NOTHING;
    protected $name = "@process.donothing.name";
    protected $description = "@process.donothing.description";

    public function getMessage() {
        return Language::get("process.donothing.detail");
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\event\Event;
use pocketmine\event\Cancellable;
use aieuo\ip\utils\Language;

class EventCancel extends Process {

    protected $id = self::EVENT_CANCEL;
    protected $name = "@process.eventcancel.name";
    protected $description = "@process.eventcancel.description";

    public function getMessage() {
        return Language::get("process.eventcancel.detail");
    }

    public function getCancelEvent() {
        return $this->getValues();
    }

    public function setCancelEvent(Event $event) {
        $this->setValues($event);
    }

    public function execute() {
        $event = $this->getCancelEvent();
        if ($event instanceof Cancellable) $event->setCancelled();
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\Server;

use aieuo\ip\ifPlugin;
use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Language;

class ExecuteOtherPlayer extends Process {

    protected $id = self::EXECUTE_OTHER_PLAYER;
    protected $name = "@process.executeotherplayer.name";
    protected $description = "@process.executeotherplayer.description";

    public function getMessage() {
        $cname = $this->getCooperationName();
        $pname = $this->getPlayerName();
        return Language::get("process.executeotherplayer.detail", [$cname, $pname]);
    }

    public function getCooperationName() {
        return $this->getValues()[0];
    }

    public function getPlayerName() {
        return $this->getValues()[1];
    }

    public function setNames(string $name, string $playerName) {
        $this->setValues([$name, $playerName]);
    }

    public function parse(string $content) {
        $datas = explode(";", $content);
        if (!isset($datas[1])) return false;
        $pname = array_pop($datas);
        $cname = implode(";", $datas);
        return [$cname, $pname];
    }

    public function execute() {
        $player = $this->getPlayer();
        $manager = ifPlugin::getInstance()->getChainManager();
        if (!$manager->isAdded($this->getCooperationName())) {
            $player->sendMessage(Language::get("process.cooperation.notfount"));
            return;
        }
        $playerName = $this->getPlayerName();
        $target = Server::getInstance()->getPlayer($playerName);
        if ($target === null) {
            $player->sendMessage(Language::get("process.executeotherplayer.offline", [$playerName]));
            return;
        }
        $datas = $manager->get($this->getCooperationName());
        $manager->executeIfMatchCondition(
            $target,
            $datas["if"],
            $datas["match"],
            $datas["else"],
            [
                "player" => $target,
                "origin" => $player
            ]
        );
    }

    public function getEditForm(string $default = "", string $mes = "") {
        $manager = ifPlugin::getInstance()->getChainManager();
        $names = $this->parse($default);
        $cname = $default;
        $pname = "";
        if ($names === false and $default !== "") {
            $mes .= Language::get("form.error");
        } else {
            $cname = $names[0];
            $pname = $names[1];
        }
        if ($default !== "" and !$manager->isAdded($cname)) $mes .= Language::get("process.cooperation.notfount");
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("process.executeotherplayer.form.name"), Language::get("input.example", ["aieuo"]), $cname),
                Elements::getInput(Language::get("process.executeotherplayer.form.player"), Language::get("input.example", ["aiueo421"]), $pname),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        $status = true;
        if ($datas[1] === "" or $datas[2] === "") {
            $status = null;
        } else {
            $names = $this->parse($datas[1].";".$datas[2]);
            if ($names === false) $status = false;
        }
        return ["status" => $status, "contents" => $datas[1].";".$datas[2], "delete" => $datas[3], "cancel" => $datas[4]];
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\ifPlugin;
use aieuo\ip\task\KickTask;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Language;

class Kick extends Process {

    protected $id = self::KICK;
    protected $name = "@process.kick.name";
    protected $description = "@process.kick.description";

    public function getMessage() {
        $reason = $this->getReason();
        return Language::get("process.kick.detail", [$reason]);
    }

    public function getReason() {
        return $this->getValues();
    }

    public function setReason(string $reason) {
        $this->setValues($reason);
    }

    public function execute() {
        $player = $this->getPlayer();
        $reason = $this->getReason();
        ifPlugin::getInstance()->getScheduler()->scheduleDelayedTask(new KickTask($player, $reason), 5);
    }

    public function getEditForm(string $default = "", string $mes = "") {
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("process.kick.form.reason"), Language::get("input.example", ["æªãããšããããã"]), $default),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        if ($datas[1] === "") $status = null;
        return ["status" => $status, "contents" => $datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\math\Vector3;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Language;

class Motion extends TypePosition {

    protected $id = self::MOTION;
    protected $name = "@process.motion.name";
    protected $description = "@process.motion.description";

    public function getMessage() {
        $pos = $this->getPosition();
        if ($pos === false) return false;
        return Language::get("process.motion.detail", [$pos->x, $pos->y, $pos->z]);
    }

    public function execute() {
        $player = $this->getPlayer();
        $pos = $this->getPosition();
        if (!($pos instanceof Vector3)) {
            $player->sendMessage(Language::get("input.invalid", [$this->getName()]));
            return;
        }
        $player->setMotion($pos);
    }

    public function getEditForm(string $default = "", string $mes = "") {
        $pos = $this->parse($default);
        $x = $default;
        $y = "";
        $z = "";
        if ($pos instanceof Vector3) {
            $x = $pos->x;
            $y = $pos->y;
            $z = $pos->z;
        } elseif ($default !== "") {
            $mes .= Language::get("form.error");
        }
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("process.motion.form.x"), Language::get("input.example", ["1"]), $x),
                Elements::getInput(Language::get("process.motion.form.y"), Language::get("input.example", ["10"]), $y),
                Elements::getInput(Language::get("process.motion.form.z"), Language::get("input.example", ["100"]), $z),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        if ($datas[1] === "" and $datas[2] === "" and $datas[3] === "") {
            $status = null;
        } else {
            $pos = $this->parse($datas[1].",".$datas[2].",".$datas[3]);
            if ($pos === false) $status = false;
        }
        return ["status" => $status, "contents" => $datas[1].",".$datas[2].",".$datas[3], "delete" => $datas[4], "cancel" => $datas[5]];
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\Player;
use pocketmine\event\Event;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Language;

class Process implements ProcessIds {

    /** @var Player */
    private $player;

    /** @var array */
    private $values = [];

    /** @var Event */
    private $event = null;

    /** @var int */
    protected $id;
    /** @var string */
    protected $name;
    /** @var string */
    protected $description;
    /** @var string */
    protected $detail;

    public $replaceDatas = [];

    public function __construct($player = null) {
        $this->player = $player;
    }

    public static function get($id) {
        return ProcessFactory::get($id);
    }

    public function getId() {
        return $this->id;
    }

    public function getName() {
        if ($this->name[0] === "@") {
            return Language::get(substr($this->name, 1));
        }
        return $this->name;
    }

    public function getDescription() {
        if ($this->description[0] === "@") {
            return Language::get(substr($this->description, 1));
        }
        return $this->description;
    }

    public function getDetail() {
        if ($this->detail[0] === "@") {
            return Language::get(substr($this->detail, 1));
        }
        return $this->detail;
    }

    public function parse(string $str) {
        return $str;
    }

    public function setPlayer(Player $player) : self {
        $this->player = $player;
        return $this;
    }

    public function getPlayer() : Player {
        return $this->player;
    }

    public function setValues($values) : self {
        $this->values = $values;
        return $this;
    }

    public function getValues() {
        return $this->values;
    }

    public function setEvent(Event $event) {
        $this->event = $event;
    }

    public function getEvent() : ?Event {
        return $this->event;
    }

    public function getEditForm(string $default = "", string $mes = "") {
        if ($mes !== "") $mes = "\n".$mes;
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().$mes),
                Elements::getToggle("åé€ãã"),
                Elements::getToggle("ã­ã£ã³ã»ã«")
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        return ["status" => true, "contents" => "", "delete" => $datas[1], "cancel" => $datas[2]];
    }

    public function execute() {
    }
}<?php

namespace aieuo\ip\processes;

class ProcessFactory {
    private static $list = [];

    public static function init() {
        self::register(new DoNothing());
        self::register(new SendMessage());
        self::register(new SendTip());
        self::register(new SendTitle());
        self::register(new BroadcastMessage());
        self::register(new SendMessageToOp());
        self::register(new SendVoiceMessage());
        self::register(new SendForm());
        self::register(new Command());
        self::register(new CommandConsole());
        self::register(new DelayedCommand());
        self::register(new DelayedCommandConsole());
        self::register(new AddMoney());
        self::register(new TakeMoney());
        self::register(new SetMoney());
        self::register(new Teleport());
        self::register(new Motion());
        self::register(new SetScale());
        self::register(new Calculation());
        self::register(new AddVariable());
        self::register(new DeleteVariable());
        self::register(new AddItem());
        self::register(new RemoveItem());
        self::register(new SetItem());
        self::register(new SetImmobile());
        self::register(new UnSetImmobile());
        self::register(new AddEnchantment());
        self::register(new AddEffect());
        self::register(new SetNametag());
        self::register(new SetSleeping());
        self::register(new SetSitting());
        self::register(new EventCancel());
        self::register(new SetGamemode());
        self::register(new Cooperation());
        self::register(new CooperationRepeat());
        self::register(new ExecuteOtherPlayer());
        self::register(new SetBlocks());
        self::register(new SaveDatas());
        self::register(new SetHealth());
        self::register(new SetMaxHealth());
        self::register(new Attack());
        self::register(new Kick());
    }

    /**
     * @param  int $id
     * @return Process
     */
    public static function get($id) {
        if (isset(self::$list[$id])) {
            return clone self::$list[$id];
        }
        return new Process();
    }

    public static function getAll() {
        return self::$list;
    }

    /**
     * @param  Condition $process
     */
    public static function register(Process $process) {
        self::$list[$process->getId()] = clone $process;
    }
}<?php

namespace aieuo\ip\processes;

interface ProcessIds {
    const COMMAND = 100;
    const SENDMESSAGE = 101;
    const SENDTIP = 102;
    const TELEPORT = 103;
    const BROADCASTMESSAGE = 104;
    const COMMAND_CONSOLE = 105;
    const DO_NOTHING = 106;
    const ADD_ITEM = 107;
    const REMOVE_ITEM = 108;
    const SET_IMMOBILE = 109;
    const UNSET_IMMOBILE = 110;
    const SET_HEALTH = 111;
    const SET_MAXHEALTH = 112;
    const SET_GAMEMODE = 113;
    const SET_NAMETAG = 114;
    const ADD_ENCHANTMENT = 115;
    const ADD_EFFECT = 116;
    const EVENT_CANCELL = 117;
    const SENDMESSAGE_TO_OP = 118;
    const SET_SLEEPING = 119;
    const SET_SITTING = 120;
    const ATTACK = 121;
    const KICK = 122;
    const SENDVOICEMESSAGE = 123;
    const SENDTITLE = 124;
    const MOTION = 125;
    const DELAYED_COMMAND = 126;
    const CALCULATION = 127;
    const ADD_VARIABLE = 128;
    const SET_SCALE = 129;
    const EVENT_CANCEL = 130;
    const SET_ITEM = 131;
    const SAVE_DATAS = 132;
    const ADDMONEY = 133;
    const TAKEMONEY = 134;
    const COOPERATION = 135;
    const DELETE_VARIABLE = 136;
    const SET_BLOCKS = 137;
    const COOPERATION_REPEAT = 138;
    const EXECUTE_OTHER_PLAYER = 139;
    const DELAYED_COMMAND_CONSOLE = 140;
    const SEND_FORM = 141;
    const SETMONEY = 142;
}<?php

namespace aieuo\ip\processes;

use pocketmine\item\Item;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Language;

class RemoveItem extends TypeItem {

    protected $id = self::REMOVE_ITEM;
    protected $name = "@process.removeitem.name";
    protected $description = "@process.removeitem.description";

    public function getMessage() {
        $item = $this->getItem();
        if (!($item instanceof Item)) return false;
        return Language::get("process.removeitem.detail", [$item->getId(), $item->getDamage(), $item->getName(), $item->getCount()]);
    }

    public function execute() {
        $player = $this->getPlayer();
        $item = $this->getItem();
        if ($item->getCount() > 0) {
            $player->getInventory()->removeItem($item);
            return;
        }
        $count = 0;
        foreach ($player->getInventory()->getContents() as $item1) {
            if ($item1->getId() == $item->getId() and $item1->getDamage() == $item->getDamage()) {
                $count += $item1->getCount();
            }
        }
        $item->setCount($count);
        if ($item->getCount() > 0) {
            $player->getInventory()->removeItem($item);
        }
    }


    public function getEditForm(string $default = "", string $mes = "") {
        $item = $this->parse($default);
        $id = $default;
        $count = "";
        $name = "";
        if ($item instanceof Item) {
            $id = $item->getId().":".$item->getDamage();
            $count = $item->getCount();
            $name = $item->hasCustomName() ? $item->getName() : "";
            if ($count === 0) $mes .= Language::get("process.removeitem.removeall");
        } elseif ($default !== "") {
            $mes .= Language::get("process.item.form.invalid");
        }
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("process.item.form.id"), Language::get("input.example", ["1:0"]), $id),
                Elements::getInput(Language::get("process.removeitem.form.count"), Language::get("input.example", ["5"]), $count),
                Elements::getInput(Language::get("process.item.form.name"), Language::get("input.example", ["aieuo"]), $name),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\ifPlugin;
use aieuo\ip\utils\Language;

class SaveDatas extends Process {

    protected $id = self::SAVE_DATAS;
    protected $name = "@process.savedatas.name";
    protected $description = "@process.savedatas.description";

    public function getMessage() {
        return Language::get("process.savedatas.detail");
    }

    public function execute() {
        ifPlugin::getInstance()->getBlockManager()->save();
        ifPlugin::getInstance()->getCommandManager()->save();
        ifPlugin::getInstance()->getEventManager()->save();
        ifPlugin::getInstance()->getChainManager()->save();
        ifPlugin::getInstance()->getFormIFManager()->save();
        ifPlugin::getInstance()->getVariableHelper()->save();
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\ifPlugin;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\Session;
use aieuo\ip\utils\Language;

class SendForm extends Process {

    protected $id = self::SEND_FORM;
    protected $name = "@process.sendform.name";
    protected $description = "@process.sendform.description";

    public function getMessage() {
        $name = $this->getFormName();
        return Language::get("process.sendform.detail", [$name]);
    }

    public function getFormName() {
        return $this->getValues();
    }

    public function setFormName(string $name) {
        $this->setValues($name);
    }

    public function execute() {
        $player = $this->getPlayer();
        $name = $this->getFormName();
        $manager = ifPlugin::getInstance()->getFormIFManager();
        if (!$manager->isAdded($name)) {
            $player->sendMessage(Language::get("process.sendform.notfound", [$this->getName()]));
            return;
        }
        $form = json_encode($manager->getForm($name, $this->replaceDatas));
        Session::get($player)->setData("form_name", $name);
        Form::sendForm($player, $form, $this, "onRecive");
    }

    public function onRecive($player, $data) {
        $session = Session::get($player);
        if ($data === null) {
            $session->setValid(false, false);
            return;
        }
        $formName = $session->getData("form_name");
        $manager = ifPlugin::getInstance()->getFormIFManager();
        if (!$manager->isAdded($formName)) {
            $player->sendMessage(Language::get("process.sendform.notfound", [$this->getName()]));
            return;
        }
        $datas = $manager->getIF($formName);
        $form = $manager->getForm($formName, $this->replaceDatas);
        foreach ($datas["ifs"] as $ifdata) {
            $manager->executeIfMatchCondition(
                $player,
                $ifdata["if"],
                $ifdata["match"],
                $ifdata["else"],
                [
                    "player" => $player,
                    "form" => $form,
                    "form_name" => $formName,
                    "form_data" => $data,
                ]
            );
        }
    }

    public function getEditForm(string $default = "", string $mes = "") {
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("process.sendform.form.name"), Language::get("input.example", ["aieuo"]), $default),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        if ($datas[1] === "") $status = null;
        return ["status" => $status, "contents" => $datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\utils\Language;

class SendMessage extends TypeMessage {

    protected $id = self::SENDMESSAGE;
    protected $name = "@process.sendmessage.name";
    protected $description = "@process.sendmessage.description";

    public function getMessage() {
        $message = $this->getSendMessage();
        return Language::get("process.sendmessage.detail", [$message]);
    }

    public function execute() {
        $player = $this->getPlayer();
        $player->sendMessage($this->getSendMessage());
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\Server;

use aieuo\ip\utils\Language;

class SendMessageToOp extends TypeMessage {

    protected $id = self::SENDMESSAGE_TO_OP;
    protected $name = "@process.sendmessagetoop.name";
    protected $description = "@process.sendmessagetoop.description";

    public function getMessage() {
        $message = $this->getSendMessage();
        return Language::get("process.sendmessagetoop.detail", [$message]);
    }

    public function execute() {
        $players = Server::getInstance()->getOnlinePlayers();
        foreach ($players as $player) {
            if ($player->isOp()) {
                $player->sendMessage($this->getSendMessage());
            }
        }
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\utils\Language;

class SendTip extends TypeMessage {

    protected $id = self::SENDTIP;
    protected $name = "@process.sendtip.name";
    protected $description = "@process.sendtip.description";

    public function getMessage() {
        $message = $this->getSendMessage();
        return Language::get("process.sendtip.detail");
    }

    public function execute() {
        $player = $this->getPlayer();
        $player->sendTip($this->getSendMessage());
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\utils\Language;

class SendTitle extends TypeMessage {

    protected $id = self::SENDTITLE;
    protected $name = "@process.sendtitile.name";
    protected $description = "@process.sendtitile.description";

    public function getMessage() {
        $message = $this->getSendMessage();
        return Language::get("process.sendtitile.detail", [$message]);
    }

    public function execute() {
        $player = $this->getPlayer();
        $player->addTitle($this->getSendMessage(), "", 20, 100, 20);
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\lang\TranslationContainer;

use aieuo\ip\utils\Language;

class SendVoiceMessage extends TypeMessage {

    protected $id = self::SENDVOICEMESSAGE;
    protected $name = "@process.sendvoicemessage.name";
    protected $description = "@process.sendvoicemessage.description";

    public function getMessage() {
        $message = $this->getSendMessage();
        return Language::get("process.sendvoicemessage.detail", [$message]);
    }

    public function execute() {
        $player = $this->getPlayer();
        $text = new TranslationContainer($this->getSendMessage());
        $player->sendMessage($text);
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\Server;
use pocketmine\math\Vector3;
use pocketmine\level\Level;
use pocketmine\block\Block;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Language;

class SetBlocks extends TypePosition {

    protected $id = self::SET_BLOCKS;
    protected $name = "@process.setblocks.name";
    protected $description = "@process.setblocks.description";

    public function getMessage() {
        if ($this->getValues() === false) return false;
        $spos = $this->getStartPosition();
        $epos = $this->getEndPosition();
        $level = $this->getLevel();
        $block = $this->getBlock();
        $sx = min($spos->x, $epos->x);
        $sy = min($spos->y, $epos->y);
        $sz = min($spos->z, $epos->z);
        $ex = max($spos->x, $epos->x);
        $ey = max($spos->y, $epos->y);
        $ez = max($spos->z, $epos->z);
        return Language::get("process.setblocks.detail", [$level->getFolderName(), $sx, $sy, $sz, $ex, $ey, $ez, $block->getId(), $block->getDamage()]);
    }

    public function getStartPosition() {
        return $this->getValues()[0];
    }

    public function getEndPosition() {
        return $this->getValues()[1];
    }

    public function getLevel() {
        return $this->getValues()[2];
    }

    public function getBlock() {
        return $this->getValues()[3];
    }

    public function setSettings(Vector3 $spos, Vector3 $epos, Level $level, Block $block) {
        $this->setValues([$spos, $epos, $level, $block]);
    }

    public function parse(string $content) {
        $settings = explode(";", $content);
        if (!isset($settings[3])) return false;
        $spos = parent::parse($settings[0]);
        if (!($spos instanceof Vector3)) return false;
        $epos = parent::parse($settings[1]);
        if (!($epos instanceof Vector3)) return false;
        $level = Server::getInstance()->getLevelByName($settings[2]);
        if (!($level instanceof Level)) return false;
        $ids = explode(":", $settings[3]);
        $block = Block::get($ids[0], isset($ids[1]) ? $ids[1] : 0);
        return [$spos, $epos, $level, $block];
    }

    public function execute() {
        if ($this->getValues() === false) return false;
        $spos = $this->getStartPosition();
        $epos = $this->getEndPosition();
        $level = $this->getLevel();
        $block = $this->getBlock();
        $sx = min($spos->x, $epos->x);
        $sy = min($spos->y, $epos->y);
        $sz = min($spos->z, $epos->z);
        $ex = max($spos->x, $epos->x);
        $ey = max($spos->y, $epos->y);
        $ez = max($spos->z, $epos->z);
        for ($x = $sx; $x <= $ex; $x ++) {
            for ($y = $sy; $y <= $ey; $y ++) {
                for ($z = $sz; $z <= $ez; $z ++) {
                    $level->setBlock(new Vector3($x, $y, $z), $block);
                }
            }
        }
    }


    public function getEditForm(string $default = "", string $mes = "") {
        $settings = $this->parse($default);
        $spos_str = $default;
        $epos_str = "";
        $level_str = "";
        $id = "";
        if ($settings !== false) {
            $spos = $settings[0];
            $spos_str = $spos->x.",".$spos->y.",".$spos->z;
            $epos = $settings[1];
            $epos_str = $epos->x.",".$epos->y.",".$epos->z;
            $level = $settings[2];
            $level_str = $level->getFolderName();
            $block = $settings[3];
            $id = $block->getId().":".$block->getDamage();
        } elseif ($default !== "") {
            $mes .= Language::get("form.error");
        }
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("process.setblocks.form.spos"), Language::get("input.example", ["0,0,0"]), $spos_str),
                Elements::getInput(Language::get("process.setblocks.form.epos"), Language::get("input.example", ["5,10,5"]), $epos_str),
                Elements::getInput(Language::get("process.setblocks.form.level"), Language::get("input.example", ["world"]), $level_str),
                Elements::getInput(Language::get("process.setblocks.form.id"), Language::get("input.example", ["1:0"]), $id),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        if ($datas[1] === "" or $datas[2] === "" or $datas[3] === "" or $datas[4] === "") {
            $status = null;
        } else {
            $settings = $this->parse($datas[1].";".$datas[2].";".$datas[3].";".$datas[4]);
            if ($settings === false) $status = false;
        }
        return ["status" => $status, "contents" => $datas[1].";".$datas[2].";".$datas[3].";".$datas[4], "delete" => $datas[5], "cancel" => $datas[6]];
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\Server;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Language;

class SetGamemode extends Process {

    protected $id = self::SET_GAMEMODE;
    protected $name = "@process.gamemode.name";
    protected $description = "@process.gamemode.description";

    private $gamemodes = [
        "process.gamemode.survival",
        "process.gamemode.creative",
        "process.gamemode.adventure",
        "process.gamemode.spectator"
    ];

    public function getGamemode(): ?int {
        $gamemode = $this->getValues();
        if (!(is_int($gamemode) and $gamemode >= 0 and $gamemode <= 3)) return null;
        return $gamemode;
    }

    public function setGamemode(int $gamemode) {
        $this->setValues($gamemode);
    }

    public function parse(string $content) {
        $gamemode = Server::getInstance()->getGamemodeFromString($content);
        if ($gamemode === -1) return false;
        return $gamemode;
    }

    public function getMessage() {
        $gamemode = $this->getGamemode();
        if ($gamemode === false) return false;
        return Language::get("process.gamemode.detail", [Language::get($this->gamemodes[$gamemode])]);
    }

    public function execute() {
        $player = $this->getPlayer();
        $gamemode = $this->getGamemode();
        if ($gamemode === false) {
            $player->sendMessage(Language::get("process.gamemode.notfound"));
            return;
        }
        $player->setGamemode($gamemode);
    }

    public function getEditForm(string $default = "", string $mes = "") {
        $gamemode = $this->parse($default);
        if ($gamemode === false) {
            if ($default !== "") $mes .= Language::get("process.gamemode.notfound");
            $gamemode = 0;
        }
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getDropdown(
                    Language::get("process.gamemode.form.gamemode"),
                    array_map(function ($g) {
                        return Language::get($g);
                    }, $this->gamemodes),
                    $gamemode
                ),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        if ($datas[1] === "") {
            $status = null;
        } else {
            $gamemode = $this->parse($datas[1]);
            if ($gamemode === false) $status = false;
        }
        return ["status" => $status, "contents" => $datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Language;

class SetHealth extends Process {

    protected $id = self::SET_HEALTH;
    protected $name = "@process.sethealth.name";
    protected $description = "@process.sethealth.description";

    public function getMessage() {
        $health = $this->getHealth();
        if ($health === false) return false;
        return Language::get("process.sethealth.detail", [$health]);
    }

    public function getHealth(): ?int {
        $health = $this->getValues();
        if (!is_int($health) or $health <= 0) return null;
        return $health;
    }

    public function setHealth(int $health) {
        $this->setValues($health);
    }

    public function parse(string $content) {
        $health = (int)$content;
        if ($health <= 0) return false;
        return $health;
    }

    public function execute() {
        $player = $this->getPlayer();
        $health = $this->gethealth();
        if ($health === false) {
            $player->sendMessage(Language::get("process.sethealth.zero", [$this->getName()]));
            return;
        }
        $player->setHealth($health);
    }

    public function getEditForm(string $default = "", string $mes = "") {
        $health = $this->parse($default);
        if ($health === false) {
            if ($default !== "") $mes = Language::get("process.sethealth.form.zero");
            $health = $default;
        }
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("process.sethealth.form.health"), Language::get("input.example", ["10"]), $health),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        if ($datas[1] === "") {
            $status = null;
        } else {
            $health = $this->parse($datas[1]);
            if ($health === false) $status = false;
        }
        return ["status" => $status, "contents" => $datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\utils\Language;

class SetImmobile extends Process {

    protected $id = self::SET_IMMOBILE;
    protected $name = "@process.immobile.name";
    protected $description = "@process.immobile.description";

    public function getMessage() {
        return Language::get("process.immobile.detail");
    }

    public function execute() {
        $player = $this->getPlayer();
        $player->setImmobile();
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\item\Item;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Language;

class SetItem extends Process {

    protected $id = self::SET_ITEM;
    protected $name = "@process.setitem.name";
    protected $description = "@process.setitem.description";

    public function getMessage() {
        if ($this->getValues()) return false;
        $item = $this->getItem();
        if (!($item instanceof Item)) return false;
        $index = $this->getIndex();
        return Language::get("process.setitem.detail", [$index, $item->getId(), $item->getDamage(), $item->getName(), $item->getCount()]);
    }

    public function getIndex() {
        return $this->getValues()[0];
    }

    public function getItem() {
        return $this->getValues()[1];
    }

    public function setItems(int $index, Item $item) {
        $this->setValues([$index, $item]);
    }

    public function parse(string $id) {
        if (!preg_match("/\s*([0-9]+)\s*,\s*([0-9]+)\s*:?\s*([0-9]*)\s*:?\s*([0-9]*)\s*:?\s*(\.*)\s*/", $id, $ids)) return false;
        $item = Item::get((int)$ids[2], empty($ids[3]) ? 0 : (int)$ids[3], empty($ids[4]) ? 0 : (int)$ids[4]);
        if (!empty($ids[5])) $item->setCustomName($ids[5]);
        return [(int)$ids[1], $item];
    }

    public function execute() {
        $player = $this->getPlayer();
        if ($this->getValues() === false) {
            $player->sendMessage(Language::get("input.invalid", [$this->getName()]));
            return;
        }
        $item = $this->getItem();
        $index = $this->getIndex();
        $player->getInventory()->setItem($index, $item);
    }


    public function getEditForm(string $default = "", string $mes = "") {
        $items = $this->parse($default);
        $id = $default;
        $count = "";
        $name = "";
        $index = "";
        if ($items === false and $default !== "") {
            $mes .= Language::get("process.item.form.invalid");
        } elseif ($items[1] instanceof Item) {
            $item = $items[1];
            $id = $item->getId().":".$item->getDamage();
            $count = $item->getCount();
            $name = $item->hasCustomName() ? $item->getName() : "";
            if ($count === 0) $mes .= Language::get("process.item.form.zero");
        }
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("process.item.form.id"), Language::get("input.example", ["1:0"]), $id),
                Elements::getInput(Language::get("process.item.form.count"), Language::get("input.example", ["5"]), $count),
                Elements::getInput(Language::get("process.item.form.name"), Language::get("input.example", ["aieuo"]), $name),
                Elements::getInput(Language::get("process.setitem.form.index"), Language::get("input.example", ["0"]), $index),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        $id = explode(":", $datas[1]);
        if (!isset($id[1])) $id[1] = 0;
        $ids_str = $datas[4].",".$id[0].":".$id[1].":".$datas[2].($datas[3] !== "" ? ":".$datas[3] : "");
        if ($datas[1] === "" or $datas[2] === "" or $datas[4] === "") {
            $status = null;
        } else {
            $ids = $this->parse($ids_str);
            if ($ids === false) $status = false;
        }
        return ["status" => $status, "contents" => $ids_str, "delete" => $datas[5], "cancel" => $datas[6]];
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\utils\Language;

class SetMaxHealth extends SetHealth {

    protected $id = self::SET_MAXHEALTH;
    protected $name = "@process.setmaxhealth.name";
    protected $description = "@process.setmaxhealth.description";

    public function getMessage() {
        $health = $this->getHealth();
        if ($health === false) return false;
        return Language::get("process.setmaxhealth.detail", [$health]);
    }

    public function execute() {
        $player = $this->getPlayer();
        $health = $this->getHealth();
        if ($health === false) {
            $player->sendMessage(Language::get("process.setmaxhealth.zero", [$this->getName()]));
            return;
        }
        $player->setMaxHealth($health);
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\utils\Language;
use aieuo\ip\ifPlugin;

class SetMoney extends TypeMoney {

    protected $id = self::SETMONEY;
    protected $name = "@process.setmoney.name";
    protected $description = "@process.setmoney.description";

    public function getMessage() {
        return Language::get("process.setmoney.detail", [$this->getAmount()]);
    }

    public function execute() {
        $player = $this->getPlayer();
        $economy = ifPlugin::getInstance()->getEconomy();
        if ($economy === null) {
            $player->sendMessage(Language::get("economy.notfound"));
            return;
        }
        $economy->setMoney($player->getName(), $this->getAmount());
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Language;

class SetNametag extends Process {

    protected $id = self::SET_NAMETAG;
    protected $name = "@process.setnametag.name";
    protected $description = "@process.setnametag.description";

    public function getMessage() {
        return Language::get("process.setnametag.detail", [$this->getChangeName()]);
    }

    public function getChangeName(): ?string {
        $name = $this->getValues();
        if (!is_string($name)) return null;
        return $name;
    }

    public function setChangeName(string $name) {
        $this->setValues($name);
    }

    public function execute() {
        $player = $this->getPlayer();
        $name = $this->getChangeName();
        $player->setNametag($name);
        $player->setDisplayName($name);
    }

    public function getEditForm(string $default = "", string $mes = "") {
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("process.setnametag.form.name"), Language::get("input.example", ["aieuo"]), $default),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        if($datas[1] === "") $status = null;
        return ["status" => $status, "contents" => $datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Language;

class SetScale extends Process {

    protected $id = self::SET_SCALE;
    protected $name = "@process.setscale.name";
    protected $description = "@process.setscale.description";

    public function getMessage() {
        $scale = $this->getScale();
        if ($scale === false) return false;
        return Language::get("process.setscale.detail", [$this->getName()]);
    }

    public function getScale(): ?float {
        $scale = $this->getValues();
        if (!is_numeric($scale)) return null;
        return (float)$scale;
    }

    public function setScale(float $scale) {
        $this->setValues($scale);
    }

    public function parse(string $content) {
        $scale = (float)$content;
        if ($scale <= 0) return false;
        return $scale;
    }

    public function execute() {
        $player = $this->getPlayer();
        $scale = $this->getScale();
        if ($scale === false) {
            $player->sendMessage(Language::get("input.invalid", [$this->getName()]));
            return;
        }
        $player->setScale($scale);
    }


    public function getEditForm(string $default = "", string $mes = "") {
        $scale = $this->parse($default);
        if ($scale === false and $default !== "") {
            $scale = $default;
            $mes .= Language::get("process.setscale.form.error");
        }
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("process.setscale.form.scale"), Language::get("input.example", ["2"]), $scale),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        if ($datas[1] === "") {
            $status = null;
        } else {
            $scale = $this->parse($datas[1]);
            if ($scale === false) $status = false;
        }
        return ["status" => $status, "contents" => $datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\Player;
use pocketmine\entity\Entity;
use pocketmine\level\Position;
use pocketmine\network\mcpe\protocol\AddActorPacket;
use pocketmine\network\mcpe\protocol\types\EntityLink;
use pocketmine\network\mcpe\protocol\RemoveActorPacket;

use aieuo\ip\utils\Language;

class SetSitting extends TypePosition {

    protected $id = self::SET_SITTING;
    protected $name = "@process.setsitting.name";
    protected $description = "@process.setsitting.description";

    private static $entityIds = [];

    public function getMessage() {
        $pos = $this->getPosition();
        if ($pos === false) return false;
        return Language::get("process.setsitting.detail", [$pos->x.",".$pos->y.",".$pos->z.",".$pos->level->getFolderName()]);
    }

    public function execute() {
        $player = $this->getPlayer();
        $pos = $this->getPosition();
        if (!($pos instanceof Position)) {
            $player->sendMessage(Language::get("input.invalid", [$this->getName()]));
            return;
        }
        $pk = new AddActorPacket();
        $pk->entityRuntimeId = ++Entity::$entityCount;
        $pk->type = 84;
        $pk->position = $pos;
        $pk->links = [new EntityLink($pk->entityRuntimeId, $player->getId(), EntityLink::TYPE_RIDER)];
        $pk->metadata = [
            Entity::DATA_FLAGS => [Entity::DATA_TYPE_LONG, 1 << Entity::DATA_FLAG_INVISIBLE]
        ];
        $player->dataPacket($pk);
        self::leave($player);
        self::$entityIds[$player->getName()] = $pk->entityRuntimeId;
    }

    public static function leave(Player $player) {
        if (isset(self::$entityIds[$player->getName()])) {
            $pk = new RemoveActorPacket();
            $pk->entityUniqueId = self::$entityIds[$player->getName()];
            if ($player->isOnline()) $player->dataPacket($pk);
            unset(self::$entityIds[$player->getName()]);
        }
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\level\Position;

use aieuo\ip\utils\Language;

class SetSleeping extends TypePosition {

    protected $id = self::SET_SLEEPING;
    protected $name = "@process.setsleeping.name";
    protected $description = "@process.setsleeping.description";

    public function getMessage() {
        $pos = $this->getPosition();
        if ($pos === false) return false;
        return Language::get("process.setsleeping.description", [$pos->x.",".$pos->y.",".$pos->z.",".$pos->level->getFolderName()]);
    }

    public function execute() {
        $player = $this->getPlayer();
        $pos = $this->getPosition();
        if (!($pos instanceof Position)) {
            $player->sendMessage(Language::get("input.invalid", [$this->getName()]));
            return;
        }
        $player->sleepOn($pos);
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\ifPlugin;
use aieuo\ip\utils\Language;

class TakeMoney extends TypeMoney {

    protected $id = self::TAKEMONEY;
    protected $name = "@process.takemoney.name";
    protected $description = "@process.takemoney.description";

    public function getMessage() {
        return Language::get("process.takemoney.detail", [$this->getAmount()]);
    }

    public function execute() {
        $player = $this->getPlayer();
        $economy = ifPlugin::getInstance()->getEconomy();
        if ($economy === null) {
            $player->sendMessage(Language::get("economy.notfound"));
            return;
        }
        $economy->takeMoney($player->getName(), $this->getAmount());
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\level\Position;

use aieuo\ip\utils\Language;

class Teleport extends TypePosition {

    protected $id = self::TELEPORT;
    protected $name = "@process.teleport.name";
    protected $description = "@process.teleport.description";

    public function getMessage() {
        $pos = $this->getPosition();
        if ($pos === false) return false;
        return Language::get("process.teleport.detail", [$pos->x.",".$pos->y.",".$pos->z.",".$pos->level->getFolderName()]);
    }

    public function execute() {
        $player = $this->getPlayer();
        $pos = $this->getPosition();
        if (!($pos instanceof Position)) {
            $player->sendMessage(Language::get("input.invalid", [$this->getName()]));
            return;
        }
        $player->teleport($pos);
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Language;

class TypeCommand extends Process {

    public function getCommand(): ?string {
        $command = $this->getValues();
        if (!is_string($command)) return null;
        return $command;
    }

    public function setCommand(string $command) {
        $this->setValues($command);
    }

    public function getEditForm(string $default = "", string $mes = "") {
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("process.command.form.command"), Language::get("input.example", ["help"]), $default),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        if ($datas[1] === "") {
            $status = null;
        } else {
            $command = $this->parse($datas[1]);
            if ($command === false) $status = false;
        }
        return ["status" => $status, "contents" => $datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\item\Item;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Language;

class TypeItem extends Process {

    public function getItem(): ?Item {
        $item = $this->getValues();
        if (!($item instanceof Item)) return null;
        return $item;
    }

    public function setItem(Item $item) {
        $this->setValues($item);
    }

    public function parse(string $id) {
        if (!preg_match("/\s*([0-9]+)\s*:?\s*([0-9]*)\s*:?\s*([0-9]*)\s*:?\s*(\.*)\s*/", $id, $ids)) return false;
        $item = Item::get((int)$ids[1], empty($ids[2]) ? 0 : (int)$ids[2], empty($ids[3]) ? 0 : (int)$ids[3]);
        if (!empty($ids[4])) $item->setCustomName($ids[4]);
        return $item;
    }

    public function getEditForm(string $default = "", string $mes = "") {
        $item = $this->parse($default);
        $id = $default;
        $count = "";
        $name = "";
        if ($item instanceof Item) {
            $id = $item->getId().":".$item->getDamage();
            $count = $item->getCount();
            $name = $item->hasCustomName() ? $item->getName() : "";
            if ($count === 0) $mes .= Language::get("process.item.form.zero");
        } elseif ($default !== "") {
            $mes .= Language::get("process.item.form.invalid");
        }
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("process.item.form.id"), Language::get("input.example", ["1:0"]), $id),
                Elements::getInput(Language::get("process.item.form.count"), Language::get("input.example", ["5"]), $count),
                Elements::getInput(Language::get("process.item.form.name"), Language::get("input.example", ["aieuo"]), $name),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        $id = explode(":", $datas[1]);
        if (!isset($id[1])) $id[1] = 0;
        $ids_str = $id[0].":".$id[1].":".$datas[2].":".$datas[3];
        if ($datas[1] === "" or $datas[2] === "") {
            $status = null;
        } else {
            $ids = $this->parse($ids_str);
            if ($ids === false) $status = false;
        }
        return ["status" => $status, "contents" => $ids_str, "delete" => $datas[4], "cancel" => $datas[5]];
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Language;

class TypeMessage extends Process {

    public function getSendMessage(): ?string {
        $message = $this->getValues();
        if (!is_string($message)) return null;
        return $message;
    }

    public function setSendMessage(string $message) {
        $this->setValues($message);
    }

    public function getEditForm(string $default = "", string $mes = "") {
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("process.message.form.message"), Language::get("input.example", ["aieuo"]), $default),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        if ($datas[1] === "") $status = null;
        return ["status" => $status, "contents" => $datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\Processes;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Language;

class TypeMoney extends Process {

    public function getAmount() {
        return $this->getValues();
    }

    public function setAmount(int $amount) {
        $this->setValues($amount);
    }

    public function parse(string $amount) {
        $amount = (int)mb_convert_kana($amount, "n");
        return $amount;
    }

    public function getEditForm(string $default = "", string $mes = "") {
        $money = $this->parse($default);
        if ($money <= 0) $money = $default;
        if ($money <= 0 and $default !== "") $mes .= Language::get("process.money.zero");
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)."\n"),
                Elements::getInput(Language::get("process.money.form.amount"), Language::get("input.example", ["1000"]), $money),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        if ($datas[1] === "") $status = null;
        return ["status" => $status, "contents" => $datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\processes;

use pocketmine\Server;
use pocketmine\level\Position;

use aieuo\ip\form\Form;
use aieuo\ip\form\Elements;
use aieuo\ip\utils\Language;

class TypePosition extends Process {

    public function getPosition() {
        return $this->getValues();
    }

    public function setPosition(string $pos) {
        $this->setValues($pos);
    }

    public function parse(string $pos) {
        if (!preg_match("/\s*(-?[0-9]+\.?[0-9]*)\s*,\s*(-?[0-9]+\.?[0-9]*)\s*,\s*(-?[0-9]+\.?[0-9]*)\s*,?\s*(.*)\s*/", $pos, $matches)) return false;
        if (empty($matches[4])) $matches[4] = "world";
        return new Position((float)$matches[1], (float)$matches[2], (float)$matches[3], Server::getInstance()->getLevelByName($matches[4]));
    }

    public function getEditForm(string $default = "", string $mes = "") {
        $pos = $this->parse($default);
        if ($pos instanceof Position) {
            if ($pos->level === null) {
                $mes .= Language::get("process.position.level.notfound");
                $position = $default;
            } else {
                $position = $pos->x.",".$pos->y.",".$pos->z.",".$pos->level->getFolderName();
            }
        } else {
            if ($default !== "") $mes .= Language::get("form.error");
            $position = $default;
        }
        $data = [
            "type" => "custom_form",
            "title" => $this->getName(),
            "content" => [
                Elements::getLabel($this->getDescription().(empty($mes) ? "" : "\n".$mes)),
                Elements::getInput(Language::get("process.position.form.position"), Language::get("input.example", ["1,15,30,world"]), $position),
                Elements::getToggle(Language::get("form.delete")),
                Elements::getToggle(Language::get("form.cancel"))
            ]
        ];
        $json = Form::encodeJson($data);
        return $json;
    }

    public function parseFormData(array $datas) {
        $status = true;
        if ($datas[1] === "") {
            $status = null;
        } else {
            $pos = $this->parse($datas[1]);
            if ($pos === false) $status = false;
        }
        return ["status" => $status, "contents" => $datas[1], "delete" => $datas[2], "cancel" => $datas[3]];
    }
}<?php

namespace aieuo\ip\processes;

use aieuo\ip\utils\Language;

class UnSetImmobile extends Process {

    protected $id = self::UNSET_IMMOBILE;
    protected $name = "@process.mobile.name";
    protected $description = "@process.mobile.description";

    public function getMessage() {
        return Language::get("process.mobile.detail");
    }

    public function execute() {
        $player = $this->getPlayer();
        $player->setImmobile(false);
    }
}<?php

namespace aieuo\ip;

use pocketmine\Player;

class Session {

	const BLOCK = 0;
	const COMMAND = 1;
	const EVENT = 2;
	const CHAIN = 3;
    const FORM = 4;

    private static $sessions = [];

    /**
     * @param  Player $player
     * @return Session | null
     */
    public static function get(Player $player): ?Session {
        if(!isset(self::$sessions[$player->getName()])) return null;
        return self::$sessions[$player->getName()];
    }

    public static function register(Player $player) {
        self::$sessions[$player->getName()] = new Session();
    }

////////////////////////////////////////////////////////////////////////

    /** @var bool */
	private $valid = false;
	private $if_type = self::BLOCK;
    /** @var array */
	private $datas = [];

	public function isValid() {
		return $this->valid;
	}

    public function setValid($valid = true, $deleteDatas = true): self {
		$this->valid = $valid;
        if(!$valid and $deleteDatas) $this->removeAllData();
		return $this;
	}

	public function getIfType() : int {
		return $this->if_type;
	}

	public function setIfType($type) : self {
		$this->if_type = $type;
		return $this;
	}

    public function getData($key, $default = null) {
        if(!isset($this->datas[$key])) return $default;
        return $this->datas[$key];
	}

    public function setData($key, $data): self {
        $this->datas[$key] = $data;
		return $this;
	}

    public function removeData($key) {
        unset($this->datas[$key]);
	}

	public function removeAllData() {
		$this->datas = [];
	}
}<?php
namespace aieuo\ip\task;

use pocketmine\scheduler\Task;

class DelayedCommandTask extends Task {
	public function __construct($player, $command) {
        $this->player = $player;
        $this->command = $command;
	}

	public function onRun(int $currentTick) {
		$this->player->getServer()->dispatchCommand($this->player, $this->command);
	}
}<?php
namespace aieuo\ip\task;

use pocketmine\scheduler\Task;

class KickTask extends Task {
	public function __construct($player, $reason) {
        $this->player = $player;
        $this->reason = $reason;
	}

	public function onRun(int $currentTick) {
		$this->player->kick($this->reason);
	}
}<?php
namespace aieuo\ip\task;

use pocketmine\scheduler\Task;

class SaveTask extends Task {
    public function __construct($owner) {
        $this->owner = $owner;
    }

    public function onRun(int $currentTick) {
        $this->owner->getBlockManager()->save();
        $this->owner->getCommandManager()->save();
        $this->owner->getEventManager()->save();
        $this->owner->getChainManager()->save();
        $this->owner->getVariableHelper()->save();
    }
}<?php

namespace aieuo\ip\utils;

class Language {

    public static $messages = [];

    public function __construct($messages) {
        $this->setMessages($messages);
    }

    public function setMessages($messages) {
        self::$messages = $messages;
    }

    public static function get(string $key, array $replaces = []) {
        if(isset(self::$messages[$key])) {
            $message = self::$messages[$key];
            foreach($replaces as $cnt => $value) {
                $message = str_replace("{%".$cnt."}", $value, $message);
            }
            $message = str_replace(["\\n", "\\q", "\\dq"], ["\n", "\'", "\""], $message);
            return $message;
        }
        return $key;
    }
}<?php

namespace aieuo\ip\utils;

use aieuo\ip\conditions\Condition;
use aieuo\ip\processes\Process;

use aieuo\ip\utils\Language;

class Messages {

    public static function createMessage($ifs, $matchs, $elses){
    	$mes = Language::get("message.if")."\n";
        foreach($ifs as $if){
            $content = Condition::get($if["id"]);
            $content->setValues($content->parse($if["content"]));
            $mes .= $content->getMessage() === false ?
                        $content->getDescription()."Â§f,\n":
                        $content->getMessage()."Â§f,\n";
        }
        $mes .= "\nãªã\n";
        foreach ($matchs as $match) {
            $process1 = Process::get($match["id"]);
            $process1->setValues($process1->parse($match["content"]));
            $mes .= $process1->getMessage() === false ?
                        $process1->getDescription()."Â§f,\n":
                        $process1->getMessage()."Â§f,\n";
        }
        $mes .= "\næ¡ä»¶ã«åããªãã£ãã\n";
        foreach ($elses as $else) {
            $process2 = Process::get($else["id"]);
            $process2->setValues($process2->parse($else["content"]));
            $mes .= $process2->getMessage() === false ?
                        $process2->getDescription()."Â§f,\n":
                        $process2->getMessage()."Â§f,\n";
        }
        return $mes;
    }
}<?php

namespace aieuo\ip\variable;

class ListVariable extends Variable {

    public $type = Variable::LIST;

    public function getString() {
        return implode(", ", $this->getValue());
    }

    public function addition(Variable $var, string $name = "result") {
        if ($var->getType() !== Variable::LIST) {
            return new StringVariable("ERROR", "ãªã¹ãã«ãªã¹ãä»¥å€ãè¶³ãããšã¯ã§ããŸãã");
        }
        $result = array_merge($this->getValue(), $var->getValue());
        return new ListVariable($name, $result);
    }

    public function subtraction(Variable $var, string $name = "result") {
        if ($var->getType() !== Variable::LIST) {
            return new StringVariable("ERROR", "ãªã¹ããããªã¹ãä»¥å€ãåŒãããšã¯ã§ããŸãã");
        }
        $result = array_diff($this->getValue(), $var->getValue());
        $result = array_values($result);
        return new ListVariable($name, $result);
    }

    public function multiplication(Variable $var, string $name = "result") {
        if ($var->getType() !== Variable::NUMBER) {
            return new StringVariable("ERROR", "ãªã¹ãæ°å­ä»¥å€ããããäºã¯ã§ããŸãã");
        }
        $result = [];
        $max = (int)$var->getValue();
        for ($i=0; $i<$max; $i ++) {
            $result = array_merge($result, $this->getValue());
        }
        return new ListVariable($name, $result);
    }

    public function division(Variable $var, string $name = "result") {
        return new StringVariable("ERROR", "ãªã¹ãã¯å²ãç®ã§ããŸãã");
    }

    public function modulo(Variable $var, string $name = "result") {
        return new StringVariable("ERROR", "ãªã¹ãã¯å²ãç®ã§ããŸãã");
    }

    public function getValueFromIndex($index) {
        if (!isset($this->value[$index])) return null;
        return $this->value[$index];
    }

    public function getCount() {
        return count($this->value);
    }

    public function toStringVariable() {
        $variable = new StringVariable($this->getName(), "(list)".implode(",", $this->getValue()));
        return $variable;
    }
}<?php

namespace aieuo\ip\variable;

class NumberVariable extends Variable {

    public $type = Variable::NUMBER;

    public function getString() {
        return (string)$this->getValue();
    }

    public function addition(Variable $var, string $resultname = "result") {
        if ($var->getType() !== Variable::NUMBER) {
            return new StringVariable("ERROR", "æ°å­ã«æå­åãè¶³ãããšã¯ã§ããŸãã");
        }
        $result = $this->getValue() + $var->getValue();
        return new NumberVariable($resultname, $result);
    }

    public function subtraction(Variable $var, string $resultname = "result") {
        if ($var->getType() !== Variable::NUMBER) {
            return new StringVariable("ERROR", "æ°å­ããæå­åãåŒãããšã¯ã§ããŸãã");
        }
        $result = $this->getValue() - $var->getValue();
        return new NumberVariable($resultname, $result);
    }

    public function multiplication(Variable $var, string $resultname = "result") {
        if ($var->getType() !== Variable::NUMBER) {
            return new StringVariable("ERROR", "æ°å­ã«æå­åãæããããšã¯ã§ããŸãã");
        }
        $result = $this->getValue() * $var->getValue();
        return new NumberVariable($resultname, $result);
    }

    public function division(Variable $var, string $resultname = "result") {
        if ($var->getType() !== Variable::NUMBER) {
            return new StringVariable("ERROR", "æ°å­ãæå­åã§å²ãããšã¯ã§ããŸãã");
        }
        if ($var->getValue() === 0) {
            return new StringVariable("ERROR", "0ã§å²ããŸãã");
        }
        $result = $this->getValue() / $var->getValue();
        return new NumberVariable($resultname, $result);
    }

    public function modulo(Variable $var, string $resultname = "result") {
        if ($var->getType() !== Variable::NUMBER) {
            return new StringVariable("ERROR", "æ°å­ãæå­åã§å²ãããšã¯ã§ããŸãã");
        }
        if ($var->getValue() === 0) {
            return new StringVariable("ERROR", "0ã§å²ããŸãã");
        }
        $result = $this->getValue() % $var->getValue();
        return new NumberVariable($resultname, $result);
    }

    public function toStringVariable() {
        $variable = new StringVariable($this->getName(), (string)$this->getValue());
        return $variable;
    }
}<?php

namespace aieuo\ip\variable;

class StringVariable extends Variable {

    public $type = Variable::STRING;

    public function getString() {
        return $this->getValue();
    }

    public function addition(Variable $var, string $name = "result") {
        $result = $this->getValue().$var->getValue();
        return new StringVariable($name, $result);
    }

    public function subtraction(Variable $var, string $name = "result") {
        $result = str_replace((string)$var->getValue(), "", $this->getValue());
        return new StringVariable($name, $result);
    }

    public function multiplication(Variable $var, string $name = "result") {
        if ($var->getType() !== Variable::NUMBER) {
            return new StringVariable("ERROR", "æå­åãšæå­åãæããããšã¯ã§ããŸãã");
        }
        if ($var->getValue() <= 0) {
            return new StringVariable("ERROR", "æããæ°ã¯1ä»¥äžã«ããŠãã ãã");
        }
        $result = str_repeat($this->getValue(), (int)$var->getValue());
        return new StringVariable($name, $result);
    }

    public function division(Variable $var, string $name = "result") {
        if ($var->getType() !== Variable::STRING and $var->getType() !== Variable::NUMBER) {
            return new StringVariable("ERROR", "æå­åãæå­åä»¥å€ã§å²ãããšã¯ã§ããŸãã");
        }
        $result = array_map(function ($value) { return trim(rtrim($value)); }, explode($var->getValue(), (string)$this->getValue()));
        return new ListVariable($name, $result);
    }

    public function modulo(Variable $var, string $name = "result") {
        return new StringVariable("ERROR", "æå­åã¯å²ãç®ã§ããŸãã");
    }
}<?php
namespace aieuo\ip\variable;

abstract class Variable {
    const STRING = 0;
    const NUMBER = 1;
    const LIST = 2;
    const MAP = 3;

    /** @var string å€æ°ã®åå */
    protected $name;
    /** @var string å€æ°ã®å€ */
    protected $value;
    /** @var int å€æ°ã®å */
    public $type;

    public static function create($name, $value, $type = self::STRING) {
        if ($type === self::STRING) {
            $var = new StringVariable($name, $value);
        } elseif ($type === self::NUMBER) {
            $var = new NumberVariable($name, $value);
        } elseif ($type === self::LIST) {
            if (is_array($value)) {
                $var = new ListVariable($name, $value);
            } else {
                $var = (new StringVariable("string", $value))->division(new StringVariable("delimiter", ","), $name);
            }
        }
        return $var;
    }

    public function __construct($name, $value) {
        $this->name = $name;
        $this->value = $value;
    }

    public function getName() {
        return $this->name;
    }

    /**
     * @return string|int|array
     */
    public function getValue() {
        return $this->value;
    }

    public function getType() {
        return $this->type;
    }

    /**
     * å€æ°åå£«ãè¶³ã
     * @param Variable $var
     * @param string   $name
     */
    abstract public function addition(Variable $var, string $name = "result");

    /**
     * å€æ°åå£«ãåŒã
     * @param Variable $var
     * @param string   $name
     */
    abstract public function subtraction(Variable $var, string $name = "result");

    /**
     * å€æ°åå£«ãæãã
     * @param Variable $var
     * @param string   $name
     */
    abstract public function multiplication(Variable $var, string $name = "result");

    /**
     * å€æ°åå£«ãå²ã
     * @param Variable $var
     * @param string   $name
     */
    abstract public function division(Variable $var, string $name = "result");

    /**
     * å€æ°åå£«ãå²ã£ãäœã
     * @param Variable $var
     * @param string   $name
     */
    abstract public function modulo(Variable $var, string $name = "result");
}<?php

namespace aieuo\ip\variable;

class VariableHelper {

    const STRING_VARIABLE = 0;
    const INTEGER_VARIABLE = 1;
    const ARRAY_VARIABLE = 2;

    private $variables = [];

    public function __construct($owner) {
        $this->owner = $owner;
    }

    public function loadDataBase() {
        $owner = $this->owner;
        if (!file_exists($owner->getDataFolder()."if.db")) {
            $this->db = new \SQLite3($owner->getDataFolder()."if.db", SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE);
        } else {
            $this->db = new \SQLite3($owner->getDataFolder()."if.db", SQLITE3_OPEN_READWRITE);
        }
        $this->db->query("CREATE TABLE IF NOT EXISTS variables (name TEXT, value TEXT, type INT)");
    }

    /**
     * @param  string $name
     * @param  bool $save
     * @return bool
     */
    public function exists(String $name, $save = false) {
        if (isset($this->variables[$name]) and !$save)return true;
        $datas = $this->db->query("SELECT * FROM variables WHERE name=\"$name\"")->fetchArray();
        return !empty($datas);
    }

    /**
     * @param  string $name
     * @param  bool $save
     * @return string | Variable
     */
    public function get(String $name, $save = false) {
        if (isset($this->variables[$name]) and !$save) return $this->variables[$name];
        if (!$this->exists($name, true)) return "";
        $datas = $this->db->query("SELECT * FROM variables WHERE name=\"$name\"")->fetchArray();
        return Variable::create($datas["name"], $this->changeType($datas["value"]), $datas["type"]);
    }

    /**
     * @param Variable $val
     * @param bool $save
     */
    public function add(Variable $val, $save = false) {
        if (!$save) {
            $this->variables[$val->getName()] = $val;
            return;
        }
        $name = $val->getName();
        $type = $val->getType();
        if (!($val instanceof StringVariable)) $val = $val->toStringVariable();
        $value = $val->getValue();
        if ($this->exists($name, true)) {
            $stmt = $this->db->prepare("UPDATE variables set value=:value type=:type WHERE name=:name");
        } else {
            $stmt = $this->db->prepare("INSERT OR REPLACE INTO variables VALUES(:name,:value,:type)");
        }
        $stmt->bindValue(":name", $name, SQLITE3_TEXT);
        $stmt->bindValue(":value", $value, SQLITE3_TEXT);
        $stmt->bindValue(":type", $type, SQLITE3_INTEGER);
        $stmt->execute();
    }

    /**
     * @param  String $name
     * @return bool
     */
    public function del(String $name) {
        if (isset($this->variables[$name])) {
            unset($this->variables[$name]);
        }
        if (!$this->exists($name))return false;
        $this->db->query("DELETE FROM variables WHERE name=\"$name\"");
        return true;
    }

    public function save() {
        unset($this->variables["result"]);
        foreach ($this->variables as $variable) {
            $this->add($variable, true);
        }
        $this->variables = [];
    }

    public function findVariables($string, $variables = []) {
        foreach (["/\[({[^{}]+})\]/" => 2, "/({[^{}]+})/" => 1] as $pattern => $n) {
            $result = [];
            if (preg_match_all($pattern, $string, $matches)) {
                foreach ($matches[0] as $name) {
                    $name = mb_substr($name, $n, -$n);
                    $val = isset($variables[$name]) ? $variables[$name] : $this->get($name);
                    if (!($val instanceof Variable)) continue;
                    $result[$name] = $val;
                }
            }
        }
        return $result;
    }

    /**
     * æå­åã®äž­ã«ããå€æ°ãçœ®ãæãã
     * @param  string $string
     * @param  array $variables
     * @return string
     */
    public function replaceVariables($string, $variables = []) {
        foreach (["/\[({[^{}]+})\]/" => 2, "/({[^{}]+})/" => 1] as $pattern => $n) {
            while (preg_match_all($pattern, $string, $matches)) {
                foreach ($matches[0] as $name) {
                    $name = mb_substr($name, $n, -$n);
                    $val = isset($variables[$name]) ? $variables[$name] : $this->get($name);
                    if (!($val instanceof Variable)) {
                        $string = str_replace("{".$name."}", "Â§cUndefined variable: ".$name."Â§r", $string);
                        continue;
                    }
                    $string = $this->replace($string, $val);
                }
            }
        }
        return $string;
    }

    /**
     * å€æ°ãçœ®ãæãã
     * @param  string $string
     * @param  Variable $variable
     * @return string
     */
    public function replace($string, $variable) {
        if (strpos($string, "{".$variable->getName()."}") === false) return $string;
        if ($variable instanceof ListVariable) {
            $haystack = explode("{".$variable->getName()."}", $string)[1];
            if (preg_match("/^\[([0-9]+)\].*/", $haystack, $index)) {
                $value = $variable->getValueFromIndex($index[1]);
                if ($value === null) $value = "Â§cUndefined index: ".$variable->getName()."[".$index[1]."]Â§r";
                $string = str_replace("{".$variable->getName()."}"."[".$index[1]."]", $value, $string);
                return $string;
            }
            if (preg_match("/^\.([a-z]+[0-9a-z]*).*/", $haystack, $method)) {
                if ($method[1] === "length") {
                    $string = str_replace("{".$variable->getName()."}".".".$method[1], $variable->getCount(), $string);
                }
                return $string;
            }
            $variable = new StringVariable($variable->getName(), $variable->getString());
        }
        $string = str_replace("{".$variable->getName()."}", $variable->getValue(), $string);
        return $string;
    }

    /**
     * æå­åãå€æ°ãèª¿ã¹ã
     * @param  string  $variable
     * @return boolean
     */
    public function isVariable(string $variable) {
        return preg_match("/^{.+}$/", $variable);
    }

    /**
     * æå­åã«å€æ°ãå«ãŸããŠãããèª¿ã¹ã
     * @param  string  $variable
     * @return boolean
     */
    public function containsVariable(string $variable) {
        return preg_match("/.*{.+}.*/", $variable);
    }

    /**
     * æå­åã®åãèª¿ã¹ã
     * @param  string $string
     * @return int
     */
    public function getType(string $string) {
        if (substr($string, 0, 5) === "(str)") {
            $type = Variable::STRING;
        } elseif (substr($string, 0, 5) === "(num)") {
            $type = Variable::NUMBER;
        } elseif (substr($string, 0, 6) === "(list)") {
            $type = Variable::LIST;
        } elseif (is_numeric($string)) {
            $type = Variable::NUMBER;
        } else {
            $type = Variable::STRING;
        }
        return $type;
    }

    /**
     * æå­åã®åãå€æŽãã
     * @param  string $string
     * @return string | float | value
     */
    public function changeType(string $value) {
        if (mb_substr($value, 0, 5) === "(str)") {
            $value = mb_substr($value, 5);
        } elseif (mb_substr($value, 0, 5) === "(num)") {
            $value = mb_substr($value, 5);
            if (!$this->containsVariable($value)) $value = (float)$value;
        } elseif (substr($value, 0, 6) === "(list)") {
            $value = mb_substr($value, 6);
            if (!$this->containsVariable($value)) $value = Variable::create("list", $value, Variable::LIST)->getValue();
        } elseif (is_numeric($value)) {
            $value = (float)$value;
        }
        return $value;
    }
}ÛÀÔ%95É8ôuÍvÁ?2_ó   GBMB