class URPGS
  include Purugin::Plugin, Purugin::Items, Purugin::Recipes, Purugin::Tasks
  
  description 'a plugin for urpgs', 0.3
  def on_enable
    
    all_recipes = {
       :stone => shaped_recipe(item_stack(:mossy_cobblestone, 4), "xxy\nxxy\nyyy", x: :cobblestone,y: :leaves),
       :glow_stone => shaped_recipe(item_stack(:glowstone,1),"xxx\nxyx\nxxx",x: :torch,y: :cobblestone),
    }
    all_recipes.each do |k,v|
      server.add_recipe v
    end
    
    
    #event(:plugin_enable) do |e|
      #puts e
    #end
    
    
    @hot_spring_dic = {}
    hot_spring_event
    sync_task(3, 3) { update_hot_spring }
    
  end
  
  
  def hot_spring_event
    event(:player_move) do |e|
        detect_hot_spring(e)
    end
    
    
    
  end
  
  
  def detect_hot_spring(e)
     p = e.player
       block = p.world.block_at(e.to)#.block_at(:down)
       has_taiga = block.biome.name.include?('Taiga')
       is_water  = block.is? :stationary_water
       if has_taiga && is_water
         unless @hot_spring_dic[p]
           p.msg 'This is a hot spring area, you can regain health here'
           @hot_spring_dic[p] = true
         end
       else
         if @hot_spring_dic[p]
           @hot_spring_dic[p] = false
         end
       end
  end
  
  
  def update_hot_spring
    @hot_spring_dic.keys.each do |h|
      if @hot_spring_dic[h]
        if h.health<=19
          h.health+=1
        end
      end
    end
    
  end
  
  
  
  
=begin
 event(:player_move) do |e|
    p = e.player_move
    block = p.world.block_at(e.to)#.block_at(:down)
    if block.is? :stationary_water
      puts 'hot_spring' 
      if block.biome.name.include?('Taiga')
        if p.health<=19
          p.health+=1 if rand(3)==0
        end
      end
    end
  end
=end
  
  
end